Skip to content

feat(core): materialize managed attachments for v2 sessions - #46175

Open
safzanpirani wants to merge 1 commit into
anomalyco:devfrom
safzanpirani:attachment-store
Open

feat(core): materialize managed attachments for v2 sessions#46175
safzanpirani wants to merge 1 commit into
anomalyco:devfrom
safzanpirani:attachment-store

Conversation

@safzanpirani

Copy link
Copy Markdown

Issue for this PR

Closes #46173

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

PR 1 of 3 from the plan in #46173: the path-only backend flow. Adds a managed per-session attachment store in core (streaming writes with an exclusive temp file + atomic rename, cross-platform filename sanitization, MIME sniffing, sha256, 25MiB/100MiB/1GiB quotas reserved under a semaphore, 24h unbound GC), a streaming multipart POST /api/session/:sessionID/attachment route on the v2 session group with typed 413/not-found errors, managed-URI validation at prompt admission (cross-session references fail closed), and lowering that emits one text part with the absolute path so tools can operate on the file. No native media promotion and no app wiring yet — those are PRs 2 and 3. The generated client intentionally omits the multipart route until the PR 3 adapter.

Known limitation, marked with a TODO in the store: quota locking is process-local; two server processes sharing one data dir could jointly exceed the global cap.

How did you verify your code works?

  • packages/core: bun test test/attachment-store.test.ts test/session-runner-message.test.ts — 17 pass (traversal/hostile names incl. bidi and Windows device aliases, internal-name collision, symlink swap, concurrent cross-session global quota race, 20MiB streaming test that asserts the first chunk reaches disk before the producer releases the rest, GC expiry, path-only lowering shape). bun typecheck clean.
  • packages/opencode: bun test test/server/httpapi-v2-attachment.test.ts — 5 pass: real multipart upload through the running server, upload→prompt admission, cross-session rejection, typed 413, chunked body without Content-Length, mid-body abort with partial cleanup, uppercase-scheme URI rejection.
  • packages/client: bun run generate (no hand edits to generated files) and bun test.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: upload attachments to the server so agent tools can read them (managed per-session store)

1 participant