Skip to content

Request Entity Too Large with images blocks session — compaction also fails #14562

Closed

Description

@shkumbinhasani

Bug

When a conversation includes images (e.g. from the Read tool reading an image file), the base64 data can push the request payload beyond provider limits, resulting in a 413 "Request Entity Too Large" error. Once this happens, the session is stuck — even /compact fails with the same error.

Root Causes

1. 413 not recognized as context overflow

The overflow detection in src/provider/error.ts doesn't match "Request Entity Too Large" or bare 413 status codes. The existing 4(00|13) (no body) pattern only catches Cerebras/Mistral-style empty-body responses. A standard 413 with a body like "Request Entity Too Large" is classified as a generic API error, so auto-compaction is never triggered.

2. Compaction sends full base64 images

SessionCompaction.process() calls MessageV2.toModelMessages(input.messages, model) which includes all base64 image data from user file parts and tool result attachments. If images caused the overflow, compaction will hit the same size limit.

Relevant code: src/session/compaction.ts:188

3. No auto-recovery on context overflow API errors

When context overflow is caught at src/session/processor.ts:356, there's only a // TODO: Handle context overflow error comment with no implementation. The error is stored on the assistant message and the session stops.

Expected Behavior

  • 413 errors should be classified as context overflow
  • Context overflow should trigger auto-compaction
  • Compaction should strip images/media from messages since they aren't needed for summarization

Reproduction

  1. Start a session with a model that has a relatively small request size limit
  2. Read several image files (or one large one) using the Read tool
  3. Continue the conversation until the accumulated base64 data exceeds the provider's payload limit
  4. Observe the "Request Entity Too Large" error
  5. Try /compact — it fails with the same error

Relevant Files

  • packages/opencode/src/provider/error.ts — overflow pattern matching
  • packages/opencode/src/session/processor.ts:356 — TODO for context overflow handling
  • packages/opencode/src/session/compaction.ts:188 — compaction sends full messages with images
  • packages/opencode/src/session/message-v2.ts:491 — toModelMessages() includes all media
  • packages/opencode/src/tool/read.ts:121-142 — Read tool returns images as base64 attachments with no size limit

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    on Feb 21, 2026
  2. github-actions commented on Feb 21, 2026

    @github-actions
    Contributor

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

    If these don't fully cover your issue (particularly the compaction-also-fails aspect and the missing 413 detection in error.ts), feel free to keep this open with a note on how it differs.

  3. github-actions commented on Apr 23, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  4. johncoffee715 commented on Jul 15, 2026

    @johncoffee715

    Status: Already Handled

    PR: https://github.com/johncoffee715/opencode/pull/1

    The 413 'Request Entity Too Large' error is already classified as context_overflow in provider/error.ts (line 170):

    No additional changes needed for this issue.

  5. dotCipher commented on Aug 2, 2026

    @dotCipher

    For anyone landing here from a search: this is fixed for the 413 Request Entity Too Large spelling, but Azure OpenAI returns the same semantic failure as a 400 with a prose message, which still slips past classification:

    Request content length exceeded 32 MB limit.
    Exceeded maximum number of images (50) allowed in the request.
    

    So the session-wedging behaviour described here still reproduces on 1.18.5 via Azure — media-strip compaction never triggers, and /compact fails identically. Tracked in #39677, fix in #40167.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions