Repository navigation
opencode-go: long sessions stuck at provider input limit; auto-compaction never triggers #56296
Description
Description
Using opencode-go/deepseek-v4.1-flash in one long session, once the accumulated prompt reached ~270k tokens, every request was rejected by the upstream gateway with:
400 [unsupported_request] This text request is too large for the model's configured input limit.
The session cannot recover on its own:
/api/model(provideropencode-go) advertiseslimit.context = 1000000for this model, so automatic compaction never runs before the gateway's actual input limit (~just above 270k) is reached.- The documented "recover once when a provider rejects a request as too long" behavior (v2 compaction docs) does not trigger: the message history contains zero
compactionmessages after the first rejection, and three consecutive attempts in ~2 minutes all failed identically. Server log shows repeatedFailed to drain Sessionwith the sameAI.Error.InvalidRequest. - Even trivial prompts fail, because the full history is resent every time; the session stays permanently stuck (outcome
failed). - Workaround that works: manual
opencode api post /api/session/{sessionID}/compact --data '{}'— the summary is generated by the same model/endpoint and completes, after which the session is usable again (outgoing context payload shrank ~7x).
Plugins
None. Config only sets "shell": "powershell"; no plugin entries or plugin files.
OpenCode version
2.0.32 — opencode --version prints opencode v2.0.32 (OpenCode Desktop, bundled CLI 2.0.32-x64).
Steps to reproduce
- Use
opencode-go/deepseek-v4.1-flashin one session through a long stretch of heavy tool use until the request payload approaches ~270k tokens. Last successful request observed: 270,421 tokens (11,070 input + 259,351 cache read; prompt caching active). - Send any next prompt.
- Every request now fails with
AI.Error.InvalidRequest: Upstream request failed: [unsupported_request] This text request is too large for the model's configured input limit.(HTTP 400). Nosession.compaction.*activity and no compaction message is ever created; auto-recovery never runs, so the session is stuck. - Manual
POST /api/session/{sessionID}/compact --data '{}'succeeds and unblocks the session.
OS
Windows 10.0.26300.9711 (win32 x64)
Terminal
Not a terminal — OpenCode Desktop app.
Additional context
Expected: either auto-compaction fires before the provider's actual limit, or a "too large" rejection triggers the documented compact-and-retry-once recovery.
Server log excerpt (redacted paths):
level=ERROR message="Failed to drain Session" cause="AI.Error: Upstream request failed: [unsupported_request] This text request is too large for the model's configured input limit.
at SessionStep.attempt
at SessionRunner.runStep
at SessionRunner.drain }
[cause]: AI.Error.InvalidRequest: Upstream request failed: [unsupported_request] This text request is too large for the model's configured input limit."
This looks like two separate problems:
- Catalog/gateway mismatch: advertised
limit.context = 1000000vs enforced ~270k input limit, which makes the automatic compaction threshold unreachable (default 10% buffer ⇒ ~900k). - The provider's "too long" rejection doesn't appear to be classified for the documented recover-once path.
Manually compacting the same session proves the provider is fine — only the oversized prompt is rejected, and summarization (same model/endpoint) succeeds.
Identifiers, local paths, and account details redacted.
Activity
opencode-agent commentedon Oct 17, 2026
Thanks for the detailed report. I reproduced this on v2.0.32, and it still happens on the latest
dev(512165cec).To test it, I pointed OpenCode at a mock OpenAI-compatible provider that advertises a 1M context and answers normal requests with HTTP 400 and the gateway's exact message,
This text request is too large for the model's configured input limit.. Compaction requests get a successful reply.opencode runfails with the error, and no compaction request is ever sent.prompt is too longin its place (a message OpenCode already recognises as context overflow) and everything else the same, OpenCode sends compaction requests right after the 400.So the recover-once compaction works, but this gateway's wording isn't on the list of context-overflow errors in
packages/ai/src/provider-error.ts, so it never starts. That matches what you saw. The script below reproduces it.The other half of your report, the catalog advertising a 1M context while the gateway enforces about 270k, is on the opencode-go side, and a mock can't confirm it. It is tracked in #50446 (same pattern on qwen3.8-flash) and #50761 (route-dependent limits on deepseek-v4.1-flash). Until this is fixed, compacting manually, as you did, is the workaround.
Reproduction script (repro.sh)
Run it:
bash repro.shz99733543-cell commentedon Oct 17, 2026
Thanks — the reproduction makes sense (the wording isn't in the context-overflow classification, so the recover-once never starts).
One more data point from the same machine/time, suggesting the compact-and-retry would be worth extending to provider 400s of this class generally: a second failure mode on the same model wedges sessions identically — if any message/tool-result contains an image/file part (e.g.
readon a.png), every subsequent request fails with:while the catalog advertises
capabilities.input: ["text","image"]for the model. Like the size case, the session only unblocks via manualPOST /api/session/{id}/compact(the summary path drops attachments).Also, FWIW, the size side looks route-dependent rather than a fixed ~270k cap: the same account/day shows successful requests at 272k–900k tokens on this model (max 899,929; incl. one 884,448 fully uncached), and the two wedging points measured ≈276k and ≈302k prompt tokens — consistent with the known #50761 route-dependent limits.