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
- Start a session with a model that has a relatively small request size limit
- Read several image files (or one large one) using the Read tool
- Continue the conversation until the accumulated base64 data exceeds the provider's payload limit
- Observe the "Request Entity Too Large" error
- 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
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
/compactfails with the same error.Root Causes
1. 413 not recognized as context overflow
The overflow detection in
src/provider/error.tsdoesn't match "Request Entity Too Large" or bare 413 status codes. The existing4(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()callsMessageV2.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:1883. 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 errorcomment with no implementation. The error is stored on the assistant message and the session stops.Expected Behavior
Reproduction
/compact— it fails with the same errorRelevant Files
packages/opencode/src/provider/error.ts— overflow pattern matchingpackages/opencode/src/session/processor.ts:356— TODO for context overflow handlingpackages/opencode/src/session/compaction.ts:188— compaction sends full messages with imagespackages/opencode/src/session/message-v2.ts:491—toModelMessages()includes all mediapackages/opencode/src/tool/read.ts:121-142— Read tool returns images as base64 attachments with no size limit