Skip to content

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

@shkumbinhasani

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:491toModelMessages() includes all media
  • packages/opencode/src/tool/read.ts:121-142 — Read tool returns images as base64 attachments with no size limit

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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions