Skip to content

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

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

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