Skip to content

Check media size before loading and keep unreadable files from aborting chat - #74

Draft
MiguelsPizza wants to merge 2 commits into
mainfrom
alex/pdf-history-recovery
Draft

MiguelsPizza wants to merge 2 commits into
mainfrom
alex/pdf-history-recovery

Conversation

@MiguelsPizza

@MiguelsPizza MiguelsPizza commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

A hundreds-of-megabytes PDF could exhaust a browser host before Think rejected it: the pinned renderer loaded the entire file before checking its 3.5 MiB inline limit. Separately, an expired folder grant made saved image/PDF reads abort later turns and recovery, even when the next message supplied a fresh attachment.

Check current metadata before loading inline media, preserve the post-read size check, and leave oversized untyped files as metadata instead of reading them just to detect their format. Convert failed rereads into explicit tool errors containing the path and original failure. Saved history remains unchanged, so restored access or a smaller replacement renders again. This belongs in Think under Rook’s SDK ownership policy.

Validation:

  • All five new PDF/image cases failed before their corresponding fixes. The current workspace-tool suite passes all 39 tests and is included in test:think.
  • Current pnpm sdk:check passes. The preceding access-error commit passed the full pnpm sdk:test gate (1,863 tests); the size change was checked with the targeted native suite.
  • Built Think works with Rook’s installed AI SDK 6: a simulated 389 MiB PDF is refused with zero content reads, and a smaller replacement renders from the same history. A package candidate is packed locally.
  • An additional standalone Think test-tree typecheck on the access-error revision reported eight errors in untouched action-types, execute-HITL, execute-tool, and messenger fixtures. The required SDK check passes.

Remaining boundaries: Rook’s current just-bash head/tail request whole-file data before slicing, and its composer serializes direct attachments as whole-file base64. This change does not make those paths stream or establish that the reported crash was an out-of-memory termination. Rook adoption still requires a new immutable SDK release and a verified consumer pin update; this PR does not deploy to the extension.

Think rereads image and PDF tool results when assembling later model requests. An expired folder grant therefore aborted both ordinary turns and recovery, even when the next message supplied a fresh attachment. Render the filesystem failure as an error tool result while preserving the saved reference so reconnection restores the original media.

Exercise AI SDK history conversion with denied PDF and image reads, unchanged saved history, and restored access. Include the existing workspace-tool suite in the SDK gate so this regression remains covered.
The inline media limit was enforced only after readFileBytes, so a hundreds-of-megabytes PDF could exhaust a browser worker before the tool rejected it. Check fresh metadata before loading media and leave oversized untyped files as metadata instead of reading them solely to sniff their format.

Keep the post-read check for changing files and prove that a file which grows is rejected without a content read, while a smaller replacement renders from the same saved reference.
@MiguelsPizza MiguelsPizza changed the title Keep chat usable when saved PDFs or images lose filesystem access Check media size before loading and keep unreadable files from aborting chat Sep 20, 2026

This branch has not been deployed

No deployments
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.

1 participant