You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Image/file payload not counted toward context — long sessions die with generic 400 invalid_request_error instead of compacting #54690
A long-running session (~318 msgs / 3.7MB history, 7 base64 screenshots ≈2MB, plus 2 attached PNGs ≈2MB b64) against an OpenAI-compatible proxy (muse-spark-1.3-contributor, 1M context) started failing every LLM call with:
AI.Error.InvalidRequest: The request contains invalid parameters. Check the request body for any errors or inconsistencies. (HTTP 400, type: invalid_request_error, null code/param)
Every retry failed identically — including a bare "Continue" with no new content (failed in ~8s). Two consecutive runs terminally failed; the session was unrecoverable without manual history surgery (revert to an older checkpoint dropped 373 msgs / 5.26MB and the session works again).
Evidence it's context size, not content
Same 2 PNGs in a fresh session with the same model: works fine.
Bare "Continue" on the bloated session: instant 400. The history is poisoned, not the new input.
Session DB: 691 messages / 8.95MB total, 9 data:image refs / 4.1MB base64. Base64 tokenizes at roughly 1 token per 3–4 chars, so image payload alone is well over 1M tokens.
Same failure signature killed several other long sessions weeks earlier (all image-heavy agentic work).
Expected
opencode should account image/file parts when estimating context usage (currently it seems to undercount — no compaction was ever triggered) and auto-compact (or at least warn) before the provider rejects. A terminal 400 with a generic message and no payload-size info leaves the user with a dead session and no actionable signal.
Thanks for the detailed report. I think this is a duplicate of #46564: the provider rejects the request with a bare HTTP 400 invalid_request_error, OpenCode doesn't classify that as a context overflow, so the automatic compact-and-retry recovery never runs and every later prompt (even "Continue") re-sends the same history and fails. Someone there reproduced it on the first-party provider with muse-spark-1.3-contributor, the same model you're using.
One note on the image part: v2 already counts attached images in its context estimate, as a fixed ~1,500 tokens per image (and ~2,000 per PDF) rather than by base64 length. That matches how providers count images; they don't tokenize the base64 as text. So the undercount is unlikely to come from images alone. A gateway payload or limit rejection that ends up as an unclassified 400 fits your symptoms better.
Possible duplicates and related issues, ordered from most to least likely:
Related (not a duplicate): #53107 covers HTTP 413 payload-too-large never reaching recovery; the open fix #53108 handles that path. This report is the HTTP 400 variant — invalid_request_error with null code/param from an OpenAI-compatible proxy on an oversized (image-heavy) body — which is classified as neither overflow nor payload-too-large, so no compaction recovery triggers either. If #53108's classification can be extended to generic 400 payload rejections, it would cover this case too.
Thanks, that's a helpful distinction, and I agree #53107 is related but not the same: it covers HTTP 413 payload-too-large, and its fix #53108 only adds that case to the one-shot compaction recovery. A 400 classified as provider.invalid-request still wouldn't start recovery with that change alone.
The 400 case you describe (invalid_request_error, no code or param, so the error is classified as neither overflow nor payload-too-large and compaction never starts) is what #46564 tracks. Someone there reproduced it on the first-party provider with muse-spark-1.3-contributor, the same model you're using. So I still think this is a duplicate of #46564. Your suggestion to extend #53108's handling to generic 400 payload rejections would be useful as a comment on #46564 or #53108, where maintainers will decide the fix.
Closing this as a duplicate of #46564. That issue tracks the same failure: a bare HTTP 400 invalid_request_error isn't treated as context overflow, so compaction recovery never runs and the session stays stuck. It was reproduced there with muse-spark-1.3-contributor, the same model you're using. Please follow #46564 for updates, and feel free to add your details there, including the image-heavy session and your idea of extending #53108's payload-too-large handling to generic 400 rejections. Related: #53107 / #53108 (the 413 variant and its open fix), #50574 and #50446. Thanks for the thorough report! If you find this behaves differently from #46564, reply here and we can reopen.
Activity
opencode-agent commentedon Oct 12, 2026
Thanks for the detailed report. I think this is a duplicate of #46564: the provider rejects the request with a bare HTTP 400
invalid_request_error, OpenCode doesn't classify that as a context overflow, so the automatic compact-and-retry recovery never runs and every later prompt (even "Continue") re-sends the same history and fails. Someone there reproduced it on the first-party provider withmuse-spark-1.3-contributor, the same model you're using.One note on the image part: v2 already counts attached images in its context estimate, as a fixed ~1,500 tokens per image (and ~2,000 per PDF) rather than by base64 length. That matches how providers count images; they don't tokenize the base64 as text. So the undercount is unlikely to come from images alone. A gateway payload or limit rejection that ends up as an unclassified 400 fits your symptoms better.
Possible duplicates and related issues, ordered from most to least likely:
muse-spark-1.3-contributor)The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.
ImBIOS commentedon Oct 12, 2026
Related (not a duplicate): #53107 covers HTTP 413
payload-too-largenever reaching recovery; the open fix #53108 handles that path. This report is the HTTP 400 variant —invalid_request_errorwith null code/param from an OpenAI-compatible proxy on an oversized (image-heavy) body — which is classified as neither overflow nor payload-too-large, so no compaction recovery triggers either. If #53108's classification can be extended to generic 400 payload rejections, it would cover this case too.opencode-agent commentedon Oct 12, 2026
Thanks, that's a helpful distinction, and I agree #53107 is related but not the same: it covers HTTP 413
payload-too-large, and its fix #53108 only adds that case to the one-shot compaction recovery. A 400 classified asprovider.invalid-requeststill wouldn't start recovery with that change alone.The 400 case you describe (
invalid_request_error, no code or param, so the error is classified as neither overflow nor payload-too-large and compaction never starts) is what #46564 tracks. Someone there reproduced it on the first-party provider withmuse-spark-1.3-contributor, the same model you're using. So I still think this is a duplicate of #46564. Your suggestion to extend #53108's handling to generic 400 payload rejections would be useful as a comment on #46564 or #53108, where maintainers will decide the fix.Related issues, most relevant first:
payload-too-largevariant and its open fixUnless something else shows how your problem differs from #46564, this issue will still be closed as a duplicate of it.
opencode-agent commentedon Oct 13, 2026
Closing this as a duplicate of #46564. That issue tracks the same failure: a bare HTTP 400
invalid_request_errorisn't treated as context overflow, so compaction recovery never runs and the session stays stuck. It was reproduced there withmuse-spark-1.3-contributor, the same model you're using. Please follow #46564 for updates, and feel free to add your details there, including the image-heavy session and your idea of extending #53108'spayload-too-largehandling to generic 400 rejections. Related: #53107 / #53108 (the 413 variant and its open fix), #50574 and #50446. Thanks for the thorough report! If you find this behaves differently from #46564, reply here and we can reopen.ImBIOS commentedon Oct 14, 2026
Fix PR open: #55286 (also linked on #46564).