Skip to content

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

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

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

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

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