Repository navigation
Request Entity Too Large with images blocks session — compaction also fails #14562
Description
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 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
Activity
github-actions commentedon Feb 21, 2026
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.
github-actions commentedon Apr 23, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
johncoffee715 commentedon Jul 15, 2026
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.
dotCipher commentedon Aug 2, 2026
For anyone landing here from a search: this is fixed for the 413
Request Entity Too Largespelling, but Azure OpenAI returns the same semantic failure as a 400 with a prose message, which still slips past classification:So the session-wedging behaviour described here still reproduces on 1.18.5 via Azure — media-strip compaction never triggers, and
/compactfails identically. Tracked in #39677, fix in #40167.