mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #965] [CLOSED] serve: pin Claude Code's per-request billing stamp, so the conversation cache reuses agent prompts #2938
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#2938
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/965
Author: @signalnine
Created: 10/5/2026
Status: ❌ Closed
Base:
main← Head:serve-cc-billing-stamp📝 Commits (1)
a59c13dserve: pin Claude Code's per-request billing stamp, so the conversation cache reuses agent prompts📊 Changes
3 files changed (+108 additions, -2 deletions)
View changed files
📝
docs/DETAILS.md(+3 -1)📝
serve/frontend.py(+30 -1)📝
serve/test_server.py(+75 -0)📄 Description
Claude Code sessions reuse 91.7% of their prompt tokens with this change, up from 49.8%, and a SWE-bench run drops from 80 s to 60 s per instance.
Claude Code starts its system prompt with a block like
cchchanges on every request and the 4th part ofcc_versionchanges on every session. The template renders the tool list before the system text, so with Claude Code's ~22K tokens of tools every turn's prompt differed at token ~22,060. The engine's turn checkpoint never matched the next request, only the periodic 16,384-token one did, and every follow-up turn read 8-13K tokens again.anthropic_to_messagesnow pins both stamps tofs, the way llama.cpp does (ggml-org/llama.cpp#21793). It only touches a header at the very start of the system text, only inside its first 160 characters, and only acchvalue of at most 16 characters or acc_versionwith more than three parts. The rest of the system prompt and the same text in a user message stay as they are.I found it from the logs: every follow-up request logged exactly
16384 reused. Rendering consecutive recorded/v1/messagesbodies throughanthropic_to_messages+Service.encode_promptput the first differing token at 22,060-22,061 in every pair, right at thecch=value.Measured
Unsloth UD-IQ4_XS on one RTX 5090 (Ryzen 9 9900X, 128 GB, Linux), 128K context, int8 KV. Claude Code 2.1.170 (headless,
claude -p) on 12 pinned SWE-bench Verified instances, one run each, same harness and engine, only this change between the two runs:Follow-up turns read ~2.5K tokens instead of ~12.8K. Both runs edited the gold patch's file in 10-11 of 12 instances; with one run each, that difference is noise.
Tests
ClaudeCodeBillingStampinserve/test_server.py: both stamp forms (block-list and string system prompts), Claude Code's newer form withoutcch, a plain 3-part version kept, a header not at the start (or in a user message) left alone, the bounds, and two turns throughService.encode_promptsharing the whole system prompt. 4 of the 7 fail onmainand all pass with the change.python -m unittest discover -s serve -p 'test_*.py' -t .: 275 tests, plus one error thatmainhas too (test_responses.OverHttp.test_json_schema_text_format).docs/DETAILS.md: one sentence in the conversation cache paragraph.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.