mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4838] [Engine] Claude Code treats the context-overflow 400 on /v1/messages as a generic API error: three identical retries, no compaction #2219
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2219
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gdevenyi on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4838
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Source (START-HERE.bat, setup.sh or a build)
A source checkout with the mock engine. No model and no GPU were used.
What happened
Earlier discussion: #1675, with #1615 and #1623. This report is about a different client.
When a prompt no longer fits, Claude Code 2.1.316 treats Strata's overflow 400 on
/v1/messagesas a generic API error. It sends the same request three times, does not compact, and the session stays stuck: the next short message fails the same way.Strata answers (
serve/server.py:5290):Expected: Claude Code compacts the conversation and carries on, as it does for this error from Anthropic's API.
A different client from the earlier threads. #1615, #1623 and #1675 were about Pi and about llama.cpp's phrase. #1623 added
request exceeds the context window, and the #1615 reporter confirmed that Pi matches it. #1675 proposed llama.cpp's phrase as a second phrase, and was closed with "Two phrases for one error would be noise", because Pi already matched. On a 400, Claude Code does not match that phrase: in the 2.1.316 bundle a 400 is classified byprompt is too longorinput is too long for requested model. (Unconfirmed static analysis, from reading the bundle:context windowis matched only on an HTTP 413, which Anthropic's errors page defines as a byte limit on the request.) The #1615 reply said: "If a harness you use matches a different phrase, tell us which and we will check it against the message." This is that report. CONTRIBUTING.md says new evidence goes to the original discussion, and those threads are closed; the closing note on #1615 says "A new issue that links this one works too", so I am filing it here. The decision is yours. I have not opened a PR, and CONTRIBUTING.md says a declined proposal is not resubmitted.Results. Same mock server each time, with a 25,000-token context. Only the text of the 400 differs.
api_error, 3 POSTs, all identicalapi_error, 3 POSTsprompt is too long: N tokens > C maximum(control)completed, 3 POSTs: the 400, a compaction request, the smaller retrycompleted, 1 POST;completed, 3 POSTscompleted, 1 POSTWhat the control proves. With the same status (400), the same error type and the same server, the words alone decide whether Claude Code recovers.
What it does not prove.
ByteTokenizercounts one token per byte, and the model's replies are scripted, including the summary.strata launchsetsCLAUDE_CODE_MAX_CONTEXT_TOKENS(strata_cli/launch/harness.py:115), so Claude Code should normally compact by itself first. This 400 is the backstop for a prompt that jumps past the limit in one turn. Setting that variable andCLAUDE_CODE_MAX_OUTPUT_TOKENS=4096by hand gave the same results as the table. I did not run throughstrata launchitself.claude -pwith--tools "", and the overflow came from a user prompt./^prompt is too long: \d+ tokens > \d+ maximum$/, which that message does not satisfy. I did not trace what it gates; recovery happened in the run anyway.exceeds the context window, the text the #1615 reporter says Pi matches.A one-turn session shows only half of it. With a 4,000-token context and a single prompt, Strata's text gives
api_errorand 3 POSTs. The control givesprompt_too_longand 1 POST, with no compaction. So the wording changes the classification there, but nothing recovers. Claude Code's docs say a single exchange cannot be compacted.The wording, from primary docs:
invalid_request_error("prompt is too long") on every model."Prompt is too long, and has a precedent for a provider with other words: "Amazon Bedrock reports this condition asInput is too long for requested model., which Claude Code handles the same way. Before v2.1.217, Claude Code didn't recognize the Bedrock wording, so auto-compact never triggered on it".N tokens > C maximum. I took it from the Claude Code 2.1.316 bundle, so this is unconfirmed static analysis (/prompt is too long[^0-9]*(\d+)\s*tokens?\s*>\s*(\d+)/). The error reference says only that the message changes "When the API reports token counts in its error". The doc phrase is the part that matters for matching; the numbers are client code, not a documented format.The second 400 (
serve/server.py:5297), a smaller case. It is reached only with--no-fit-max-tokens/"fit_max_tokens": false; by default Strata shortensmax_tokensinstead. With a 20,000-token context and one prompt, Strata's text gaveapi_errorand 3 identical POSTs withmax_tokens128000. Withinput length andmax_tokensexceed context limit: P + M > C, decrease input length ormax_tokensand try again, Claude Code retried once withmax_tokens12073 and completed. That wording comes from the bundle's matcher (the part up toP + M > C; the tail is my own), not from a doc page. Anthropic's page says newer models accept such a request, so this case may not be worth a change.The choices as I see them, for you to decide:
/v1/messagesonly, and keep the current text on the other routes.Service.prepareraises the error for all of them today, so this needs a catch in the Messages route.Do you want a fix PR? If yes, say which of 1 or 2 and I will send it. If you pick 3, or would rather not change this, I will not open one.
Smallest steps or command that reproduce it
Needs Claude Code on the PATH and a Python with the repo's dependencies. It talks only to the local mock, with a dummy key and a temporary config folder.
Save these two files in the repo root, then run
sh overflow_run.sh strata,sh overflow_run.sh anthropicandsh overflow_run.sh both.overflow_mock.py:overflow_run.sh:I ran these inside
unshare -rnwith only the loopback interface up, so that nothing could reach the real API, and with the mock file kept outside the repo and its path passed in. The output is under Logs.Reproduction status
Reproduced locally
With the mock engine only (
MockEngineinserve/server.py). Not reproduced on a real engine or GPU. What I say about the Claude Code bundle's code is unconfirmed static analysis; the table above is what I saw it do.Strata version
Git commit
c62d5e3a(0.2.9, main). Claude Code 2.1.316.Graphics card, memory and system
None used (mock engine). Linux 7.2.9, x86-64.
Model, size and settings
MockEnginewithByteTokenizer, context 25000 (max_context), defaultfit_max_tokens. Claude Code run with--model claude-sonnet-5-5 --tools "", a name Strata ignores.Logs
The three POSTs of the control's overflow turn, from a server-side request log in an equivalent run:
Written with an AI agent (Claude Code), which also ran the steps above.
🤖 Generated with Claude Code
https://claude.ai/code/session_01W53iURzvDQMjnYemag8uvv
@gdevenyi commented on GitHub (Nov 3, 2026):
Fixed on
mainby24739780: on/v1/messagesan overflow now starts with Anthropic's own wording and keeps Strata's sentence after it. Thank you. I have not rerun the reproduction steps against it.