pdf: multiple PDF reads accumulate images exceeding provider limit, causing unrecoverable error · Issue #48781 · anomalyco/opencode · GitHub
Skip to content

pdf: multiple PDF reads accumulate images exceeding provider limit, causing unrecoverable error #48781

Closed as duplicate

Description

@Ayush12358

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

  1. Open a session and ask the agent to read several PDF files (e.g., 6+ lecture PDFs with multiple pages each).
  2. The agent reads all PDFs in parallel using multiple read tool calls.
  3. Each PDF page is rendered as an image and added to the request context.
  4. 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
  1. 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.

Activity

  1. github-actions commented on Sep 13, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. angeloruggieridj commented on Oct 2, 2026

    @angeloruggieridj

    Same root cause on a variant: the built-in read tool on PNG files (not PDF), with provider opencode-go / model deepseek-v4.1-flash, where the gateway cap is 30 images.

    • opencode 2.0.22, Windows 11 (NT 10.0.26300.0, win32 x64), VS Code integrated terminal, cmd.exe. No plugins.
    • After the last compaction, session_message held exactly 31 type: "file" parts with mime: "image/png" — one per read of a PNG. Some files were read 3–7 times, so the count grows fast. Every subsequent turn then fails:
    Upstream request failed: [invalid_request_error] Too many images in request: 31 > 30
    

    So this is not PDF-specific: any workflow that repeatedly reads rendered PNGs (e.g. reviewing generated report/figure pages) hits it. The fix direction is discussed in #48095; the gateway 30-image cap and the blocked /compact are in #51073.

  3. neriousy commented on Oct 20, 2026

    @neriousy
    Member

    Thanks for the detailed report about PDF page images building up and blocking further messages. This is the same image-count problem as #47721, and we're tracking it there. Please subscribe or add a 👍 there; your PDF example and the follow-up about the 30-image limit are useful details worth adding.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions