mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1013] [CLOSED] serve: a continued batch request reports its own prompt's reuse; input_tokens never 0 #2966
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#2966
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?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1013
Author: @CurtisThe
Created: 10/6/2026
Status: ❌ Closed
Base:
main← Head:fix/batch-usage-input-tokens📝 Commits (10+)
fa16567setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459)749d957setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)5a30024calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)9f60d13serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)eb8da1d/metrics: each request's speculative draft counts, and their sums in the totals (#457)6a09387setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)d6a91e2docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)d8d4ad3Merge branch 'f-135-eng' into rel-0.1.357b600d5Merge branch 'f-135-small' into rel-0.1.35d9ab843Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it📊 Changes
2 files changed (+51 additions, -7 deletions)
View changed files
📝
serve/server.py(+11 -2)📝
serve/test_parallel.py(+40 -5)📄 Description
With
"parallel": 2, our Claude Code agents stopped with "Prompt is too long · automatic compaction failed" at 60–65k tokens of a 137k window. The engine never rejected a request: every turn was HTTP 200, with no SSE error event and no stream cut short.Cause. A request that is STOPped on the solo path and continued in a batch slot (or sent back to the solo path) is sent again as its prompt plus what it generated. The DONE of that last leg counts this request's own output as
reused.min(reused, len(ids))then turns it into the whole prompt, somessage_deltasaysinput_tokens: 0andcache_read_input_tokens= the whole prompt.Claude Code keeps
message_start'sinput_tokenswhenmessage_delta's is 0 and addscache_read_input_tokens, so it counts the prompt twice and compacts or blocks at half the window.Measured (RTX 5090 32 GB, Ryzen 9 9950X3D, 91 GB RAM, Qwen3.8-Flash-Next IQ3_S, v0.1.39 at
6f32ec0, Claude Code 2.1.290, a 137k window):input_tokens: 0Claude Code's side was measured against a stub that sends these exact usage events:
input_tokens: 0with a 64k prompt: auto-compaction atpreTokens: 128073, the same as a real 128k prompt.input_tokens: 1with the rest ascache_read_input_tokens: no compaction.Change
generate_batchedkeeps the first leg'sreused, which is the request's own prompt, across a continuation.anthropic_eventsclamps the reported reuse tolen(ids) - 1. The last prompt token is always read, soinput_tokensis never 0 andinput_tokens + cache_read_input_tokensis still the prompt.test_parallel.py: the fake engine can report a held prefix (--reuse). The new test,test_a_continued_request_reports_its_own_prompt_reuse, fails without the fix (input_tokens: 0,cache_read_input_tokens: 260) and passes with it.serve/pass (python -m unittest discover -s serve -t . -p 'test_*.py', Linux, Python 3.12,jsonschemainstalled). No engine change.The OpenAI path (
prompt_tokens_details.cached_tokens, timingscache_n) uses the samereused, so it now also reports the first leg's figure for a continued request. I left its clamp alone.Related open PRs
--fail-windowtotest_parallel's fake engine where this adds--reuse. #751 adds a line togenerate_batched's cleanup block next to the one added here. In both cases the fix is to keep both changes; I can rebase onto whichever lands first.reused0part of this change. This PR is the minimal fix on currentmain.reasoning_budget_tokenscontinuations, which use a different code path.I wrote this with an AI coding assistant and checked the change and the test runs myself.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.