Skip to content

fix(core): preserve derived MIME in attachment materialization fallbacks - #807

Merged
agenteinstinct1-max merged 2 commits into
dev-vibecodedfrom
arena/061af746-silvercode
Nov 2, 2026
Merged

agenteinstinct1-max merged 2 commits into
dev-vibecodedfrom
arena/061af746-silvercode

Conversation

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #806

Type of change

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

What does this PR do?

PromptInput.FileAttachment accepts attachments without mime, while durable Prompt.FileAttachment requires mime: string. In packages/core/src/attachment-store.ts, AttachmentStore.materialize already derived mime with finalMime(attachment.uri, undefined, attachment.name) on the happy path, but three non-persisting branches (Effect.catch error fallback, unsupported-URI scheme, and post-read bytes.length > MAX_BYTES) spread the MIME-less input into FileAttachment.create({ ...attachment, ... } as FileAttachment) and rejected with Expected string, got undefined at ["mime"].

This change computes id and mime via the existing finalMime helper and builds the unmaterialized FileAttachment explicitly (removing all as FileAttachment casts) across the error fallback, unsupported-URI, and oversize branches:

  • Derives MIME from the attachment URI/name via finalMime (text/plain, image/png, application/pdf, image/svg+xml, application/zip, video/mp4, application/json, or application/octet-stream when unknown) rather than guessing text/plain.
  • Preserves client id (or assigns one ascending id), uri, name, description, and source while leaving path and size unset so AttachmentStore.inventory flags unmaterialized entries unavailable: true and copyTo fails on its typed Error channel.
  • Preserves external_directory, read, and web permission checks, PermissionV2.BlockedError graceful degradation, PermissionV2.DeclinedError defect propagation, MAX_BYTES budgets, and fiber interruption/resource cleanup.

Scope and separation:

  • Owned diff vs accepted base 0143c2697c015a8cd954104764e012321c404fc2: packages/core/src/attachment-store.ts and packages/core/test/attachment-materialize-fallback.test.ts only (incoming #804 harness files from 0143c269 retained unchanged via normal merge).
  • Keeps #806 separate from #790: the tests exercise the real AttachmentStore service (AttachmentStore.node) with injected dependencies rather than the full production dependency graph, and do not identify #790's historical focused-run trigger (which remains unknown).

How did you verify your code works?

Linux x64, Bun 1.3.14 (npm_config_nodedir=/usr/local bun install --frozen-lockfile).

Baseline counterfactual against unmodified packages/core/src/attachment-store.ts at 20492cd738dca7592b1cbdc9a7aa31cc4f46eb13:

  • cd packages/core && bun test test/attachment-materialize-fallback.test.ts --timeout 15000: 2 pass, 6 fail, 19 expect() calls across 1 file (723ms) — success and fiber-cancellation controls passed; filesystem read failure, managed write / HTTP fetch failure, blocked permission fallback, unsupported-URI (:234), post-read oversize bytes (:236), and stat / Content-Length oversize budget cases each failed with Expected string, got undefined at ["mime"].

Exact merged head dbd9a299adcb16543efba08e6ffe992f99738bc0 (parents 903ffe2 and accepted dev-vibecoded tip 0143c2697c015a8cd954104764e012321c404fc2):

  • cd packages/core && bun test test/attachment-materialize-fallback.test.ts --timeout 15000: 8 pass, 0 fail, 64 expect() calls across 1 file (808ms).
  • cd packages/core && bun test test/attachment-materialize-fallback.test.ts test/session-runner-attachment.test.ts --timeout 15000: 11 pass, 0 fail, 71 expect() calls across 2 files (736ms).
  • cd packages/opencode && bun test test/tool/attachment-readiness.test.ts --timeout 30000: 1 pass, 0 fail, 3 expect() calls across 1 file (3.54s).
  • cd packages/core && bun test --timeout 15000 --only-failures: 1524 pass, 3 skip, 0 fail, 4257 expect() calls across 168 files (54.39s).
  • cd packages/opencode && bun test --timeout 30000 --only-failures: 4934 pass, 25 skip, 1 todo, 0 fail, 50 snapshots, 21345 expect() calls across 343 files (1290.30s).
  • NODE_OPTIONS=--max-old-space-size=3072 bun turbo typecheck --concurrency=1: 17/17 tasks successful (1m17.821s) (plus earlier uncached 17/17 run in 2m11.458s).
  • ./node_modules/.bin/prettier --check, ./node_modules/.bin/oxlint (0 warnings, 0 errors), and git diff --check on the two changed files: exit 0.
  • Normal .husky/pre-push hook during git push -u origin arena/061af746-silvercode: 17/17 tasks successful, exit 0.

Screenshots / recordings

N/A (no UI changes).

Checklist

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

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@agenteinstinct1-max
agenteinstinct1-max marked this pull request as ready for review November 2, 2026 11:42
@agenteinstinct1-max
agenteinstinct1-max merged commit cecc80b into dev-vibecoded Nov 2, 2026
6 checks passed
@kilo-code-bot

kilo-code-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/core/src/attachment-store.ts
  • packages/core/test/attachment-materialize-fallback.test.ts

Reviewed by free · Input: 26.1K · Output: 1K · Cached: 99.4K

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.

1 participant