Repository navigation
Closed as duplicate
Closed as duplicate
Copy link
Labels
Description
Summary
A request rejected by the provider with HTTP 413 (payload too large) is surfaced as the misleading provider.invalid-request: Upstream request failed: [server_error] Upstream response was not valid JSON, the session is marked failed, and no automatic compaction or retry happens — even though the compaction docs promise one recovery when a provider rejects a request as too long. Every later prompt fails identically until a manual /compact.
Environment
- opencode version: 2.1.4
- OS: Windows 10.0.26200 (win32 x64)
- Terminal: TERM_PROGRAM=vscode, COLORTERM=truecolor
- Shell: cmd.exe
- Install/channel: latest (npm global
@opencode/cli) - Active plugins: none
- Provider/model:
opencode-go/deepseek-v4.1-flash
Reproduction
- Run a long session that inspects screenshots: ~180 tool results, each a
readof an emulator PNG, returned as base64 and kept in history. - Send any prompt. The outgoing body reaches ~17 MB because every previous image result is re-sent.
- The provider rejects it with 413. OpenCode reports:
provider.invalid-request Upstream request failed: [server_error] Upstream response was not valid JSON status: 413 body: {"error":{"type":"server_error","code":"server_error","message":"Upstream request failed: [server_error] Upstream response was not valid JSON"}} - Send another prompt (a one-word
devam et). Same failure. The session is stuck.
Diagnostics for that session:
| Metric | Value |
|---|---|
GET /api/session/<id>/context response |
17,086,630 bytes |
| Content inside tool results | 11,579,996 chars |
| Tool results in context | 182 |
| Messages / assistant tool calls | 1,307 / 1,152 |
| Session outcome | failed |
Expected Behavior
- A 413 /
payload too largerejection should be classified as an oversize request, not as an invalid upstream response, and should trigger the documented single recovery (compact, then retry once). - If recovery is impossible, the error should say the request was too large and suggest compaction, instead of implying the provider returned malformed JSON.
- Compaction thresholds should account for request bytes, not only tokens: here the conversation was nowhere near the token limit (~40k tokens after the previous compaction) yet exceeded the gateway's body limit, so token-based
buffer/keepnever fired.
Actual Behavior
- The provider's raw body text is passed through as the error message, which points at the wrong layer (JSON parsing) and hides the real cause (body size).
- No compaction attempt and no retry; the session becomes permanently unusable because every subsequent prompt resends the same oversized history.
- Session outcome is
failedwith no hint that compaction would fix it.
Additional Context
- Workaround that resolves it completely:
Context dropped from 17.1 MB to 160 KB and the session outcome flipped from
opencode api post /api/session/<id>/compact --data '{}'
failedtosucceeded; the same session continued normally afterwards. GET /api/session/<id>/contextwas the only way to see the real problem (response size, and that 11.6 MB of it lived in tool results). A size warning in the UI or an entry in/api/sessionwould have made this diagnosable without guesswork.- Repro is deterministic for this session (100%), and presumably for any session that accumulates enough image tool results.
- Related but distinct:
readon a PNG embeds base64 into history permanently, so the request grows monotonically. Even with compaction working, some guidance or a per-result size cap would help.
Activity
opencode-agent commentedon Oct 25, 2026
Thanks for the detailed report and the diagnostics. I think this is a duplicate of #53107. In v2, an HTTP 413 is already classified as a payload-too-large error, which is why you see
provider.invalid-request. But the automatic compact-and-retry only runs for errors classified as context overflow, so a 413 never triggers it. Every later prompt then resends the same oversized history. The "Upstream response was not valid JSON" text is the message the OpenCode Go gateway sent back with the 413, not a JSON parsing problem in OpenCode.Possible duplicates and closely related issues, ordered from most to least likely:
payload-too-largenever reaches compaction recovery, so image-heavy sessions fail on every prompt (open fix PR: fix(core): recover sessions after payload size rejection #53108)deepseek-v4.1-flashon OpenCode Go with large payloadsUntil that's fixed, compacting the session manually (
/compact, orPOST /api/session/<id>/compactas you did) is the workaround.The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.
opencode-agent commentedon Oct 26, 2026
We haven't heard back since this was flagged as a likely duplicate, so I'm closing it as a duplicate of #53107. Both issues have the same cause: an HTTP 413 is classified as
payload-too-large, but automatic compact-and-retry only runs for context-overflow errors. Please follow #53107 for updates (its fix PR is #53108). Your request for byte-based compaction thresholds is covered in #48095.Until it's fixed, compacting manually (
/compact, orPOST /api/session/<id>/compact) gets the session working again. If your problem turns out to be different, reply here and we can reopen.