[KongchangAI]
· 2 min read· 1,417 words

1,772 Deliberate Cache Breaks Put to the Test: Is the Attribution Tool on vLLM and SGLang Accurate?

1,772 Deliberate Cache Breaks Put to the Test: Is the Attribution Tool on vLLM and SGLang Accurate?

Open-source tool Prefixwise validated through 1,772 deliberate break tests that it can accurately attribute the causes of prompt cache invalidation.

The open-source tool Prefixwise (MIT license) provides field-level attribution for the pain point that prompt cache invalidation in LLM inference services "only reports the loss, not the cause." The author replayed agent conversations on vLLM and SGLang with Qwen3-4B, deliberately creating 1,772 known changes, including reordering tools, changing timestamps, and editing historical messages, with half the traffic coming from 150 real Claude Code sessions. Results showed fully correct attribution on generated traffic and zero false positives in real sessions; all 26 misses occurred when editing the latest tool output, because that segment is not cached and incurs no cost waste, which is correct handling. The author also acknowledges that the test is limited to a single model, the first 10 calls per session, and artificial changes, and needs independent reproduction.

Title

1,772 Deliberate Cache Breaks Put to the Test: Is the Attribution Tool on vLLM and SGLang Accurate?

Meta Description

Open-source tool Prefixwise ran 1,772 deliberate cache-break tests on vLLM and SGLang: generated-traffic attribution was fully correct, real sessions had zero false positives, and all 26 misses came from changes landing in uncached regions. Learn the principles, test methodology, and limits of prompt cache attribution.

Article Content

LLM inference services (vLLM, SGLang, Anthropic, OpenAI) all cache the beginning of the prompt. An agent resends the entire conversation every turn, so in theory you should only pay for the new content. But if even a single byte near the start changes—tool list order swapped, a timestamp in the system prompt ticking forward—the cache is invalidated and the whole prompt is billed again. The server only tells you how many tokens you missed, not why.

The open-source tool Prefixwise (MIT license) aims to fill that gap: pointing out what changed, how much it cost, and how to fix it. The author published a round of stress testing on Reddit—deliberately breaking the cache 1,772 times to verify whether the tool can identify the real cause.

How the test was done

The test replays agent conversations against real engines (Qwen3-4B, Colab L4) and injects a known change at random turns: reordering tools, adding/removing tools, changing a timestamp in the system prompt, rewording the system prompt, editing earlier messages, editing tool outputs.

Half the traffic comes from 150 real Claude Code sessions (nvidia/Open-SWE-Traces), with their own tools and system prompts; the other half is generated.

reddit source: I broke the prompt cache 1,772 times on purpose to test whether my tool finds the right cause. Resul

Prompt cache and prefix caching: Most inference engines (vLLM's Automatic Prefix Caching, SGLang's RadixAttention) reuse KV cache at the granularity of a token-sequence prefix—only when the start of a new request matches a historical request token-for-token can the KV of subsequent tokens be reused directly, skipping redundant prefill. Cache hits therefore exhibit "prefix continuity": once a position changes, all KV from that position onward is invalidated. This explains why a single timestamp in the system prompt or one reordering of the tool list can cause an entire long prompt to be billed again.

How KV cache is billed: The server typically returns usage as two counts, "cached tokens" and "prompt tokens," and cache invalidation shows up as a sharp drop in cached tokens. But the API only exposes "how many tokens were missed," not "from which token the miss started and what change caused it." This is exactly the information gap Prefixwise tries to close—it needs to compare prefix fingerprints for each request on the client side to map "missed amount" back to a specific field-level change.

Attribution results: zero false positives

The author breaks results into three categories: correct cause, wrong cause, and alerting when nothing changed.

EngineTrafficCorrect causeWrong causeFalse positives
vLLM 0.33Generated441/44100/909
vLLM 0.33Real sessions425/44100/906
SGLang 0.5.23Generated456/45600/894
SGLang 0.5.23Real sessions424/43400/913

On generated traffic, everything was correct. In real sessions, vLLM missed 16 and SGLang missed 10, 26 total, all pointing to the same situation: editing the latest tool output.

How attribution and false positives are judged: Here, "correct cause" means the causal label the tool reports matches the type of change deliberately injected in the experiment (e.g., "tool order reordered," "system prompt timestamp changed"); "false positive" means the request prefix did not actually change and the cache could not have been invalidated, yet the tool reported an invalidation event. Zero false positives is harder to achieve than high recall—it requires the tool's prefix fingerprint to align strictly with the engine's internal tokenization and chat template rendering. If the client renders messages with a different tokenizer or template version, you can get false positives where "locally it changed, but the engine says it didn't," so the accuracy of such tools is highly dependent on being adapted to the target engine version.

What those 26 "misses" were

The change landed at the very end of the prompt, and the engine does not cache that segment anyway, so no waste was incurred. Prefixwise reported "no waste" and also recorded the edit—it did not label the cause as "primary cause," but it did not miss the event itself. From a cost-attribution perspective, this is the correct handling: a change that costs nothing should not be blamed as the culprit for cache invalidation.

Uncached tail region: Prefix caching only builds KV entries for tokens that have already been prefilled, while the newly added tail content in the latest turn (the last message, the latest tool output) is being computed for the first time in this request; there is no reusable historical KV, so editing it incurs no extra cost. To judge whether a change is a "cause," you must first determine the cache boundary—that is, the length of the longest common prefix between this request and the previous request; changes that fall after the boundary are zero-cost. This is also where attribution tools easily go wrong: naively treating the "text diff position" as the "invalidation start point" will mislabel tail edits as the culprit, producing misleading optimization advice.

What this test cannot prove

The author lists the boundaries himself: only one model was tested; only the first 10 calls per session were taken; the changes were artificially designed rather than occurring naturally in production. These limitations deserve serious attention—in real production environments, cache invalidation often results from a combination of factors such as framework upgrades and jitter in tool registration order, and clean experiments with single-point changes may not cover that.

But the test suite and per-run records are all in the repository and can be re-run, which is exactly the transparency this kind of tool most needs.

Reproducibility and benchmark transparency: Cache attribution is a class of tools that strongly depend on the environment; conclusions vary with engine version, tokenizer, chat template, sampling parameters, and even token-boundary alignment. Therefore, when evaluating such tools, the key is not just the accuracy numbers, but whether the tests disclose the complete input of each run, the engine version, and the judgment logs, so that third parties can re-run them on their own stack. For teams planning to adopt attribution tools for cost governance, it is advisable to first run a small-scale shadow comparison on your own traffic (shadow mode, only record without changing routing), confirm that the causes reported by the tool are consistent with the actual changes in the engine's cached tokens, and then integrate it into the alerting pipeline.

How to use it

pip install prefixwise and put it in front of the server or agent. It stores only hashes and token counts, not prompt content.

For teams working on agent cost optimization, the value of such attribution tools lies in turning a vague alert like "cache hit rate dropped" into an actionable conclusion like "your tool order changed." The premise is that the cause it states is actually correct—this round of 1,772 break tests, at least within the scope of a single model and the first 10 calls, gives a reproducible affirmative answer.

Repository: https://github.com/tejachavali/prefixwise

The above data all come from the test records published by the author and have not been independently reproduced.

One-line Summary

Open-source tool Prefixwise was validated through 1,772 deliberate break tests to accurately attribute the causes of prompt cache invalidation.

Paragraph Summary

The open-source tool Prefixwise (MIT license) addresses the pain point that prompt cache invalidation in LLM inference services "only reports the loss, not the cause," providing field-level attribution. The author replayed agent conversations on vLLM and SGLang with Qwen3-4B, deliberately creating 1,772 known changes, including reordering tools, changing timestamps, and editing historical messages, with half the traffic coming from 150 real Claude Code sessions. Results showed fully correct attribution on generated traffic and zero false positives in real sessions; all 26 misses occurred when editing the latest tool output, because that segment is not cached and incurs no cost waste, which is correct handling. The author also acknowledges that the test is limited to a single model, the first 10 calls per session, and artificial changes, and needs independent reproduction.

#prompt cache#Prefixwise#vLLM#SGLang#cache attribution#LLM inference cost
Share:

Related articles