anomalyco / anomalyco/opencode
pdf: multiple PDF reads accumulate images exceeding provider limit, causing unrecoverable error
@neriousy is already working on this.
Since Sep 13, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
When the agent reads multiple PDF files in a single session, all PDF page images accumulate in the request context. Once the total image count exceeds the provider's per-request image limit (50 for Console Go), every subsequent request fails with invalid_request_error. The agent cannot recover because the accumulated images remain in context and are re-sent on every retry.
Environment
- opencode version: 2.0.2
- OS: Windows_NT 10.0.26200 (win32 x64)
- Terminal: xterm-256color
- Shell: C:\WINDOWS\system32\cmd.exe
- Install/channel: latest
- Active plugins: None
Reproduction
- Open a session and ask the agent to read several PDF files (e.g., 6+ lecture PDFs with multiple pages each).
- The agent reads all PDFs in parallel using multiple
readtool calls. - Each PDF page is rendered as an image and added to the request context.
- Once the total image count exceeds 50, the next provider request fails with:
Error from provider (Console Go): Upstream request failed:
[invalid_request_error] request contains 98 images, exceeding the
maximum of 50 allowed per request
- Every subsequent message (including "try again" or new instructions) fails with the same error because the accumulated images persist in context.
Expected Behavior
The agent or opencode core should either:
- Limit the number of PDF pages sent per request to stay within provider image limits, or
- Remove stale PDF page images from context before sending new requests, or
- At minimum, surface a clear recovery path so the session is not permanently broken.
Actual Behavior
After reading ~6 multi-page PDFs, the session becomes permanently broken. Every retry fails with the same invalid_request_error. The user must start a new session to continue working.
The agent attempted to work around this by:
- Saying "try again" — failed (same error, same images in context).
- Saying "don't process all the images at once" — failed (same error, images already accumulated).
- Attaching a single PDF via
@mention — failed (101 images now, still over limit).
None of these recoveries work because the old images remain in context.
Additional Context
- Provider: Console Go (opencode-go), model
muse-spark-1.3-contributor(xhigh variant). - The provider limit is 50 images per request.
- The accumulated images come from base64-encoded PDF page renders stored in message content.
- Session outcome:
failed. Total cost before failure: ~$0.003. - This may affect other providers with different image limits, but Console Go's 50-image limit is the one encountered here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.