Repository navigation
Can a cache entry be poisoned by silent prompt truncation? #704
behrnt-slatgng
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Disclosure first: I build Grunz, a hosted chat + coding agent on open-weight models. Nothing to sell — there is an interaction between caching and a provider-side variable that I have not seen discussed, and it seems like it could poison a cache quietly.
A cached response may have been generated from a truncated prompt
The context window on a model card is a property of the weights. The window you actually receive is whatever the provider configured — a KV-cache budget traded against concurrency. Most hosted endpoints serve around 32K regardless of what the card claims, it is rarely documented, and exceeding it does not error. The request is served against whichever ceiling is lowest and the front of the prompt is silently dropped.
Now add a cache.
If a response was generated from a silently truncated prompt, you have cached a degraded answer against the full prompt's key. The cache is now confidently serving an answer that was produced without seeing part of its own input, and it will keep serving it. The defect outlives the conditions that caused it.
Three ways this gets worse with semantic caching
1. Similarity hits inherit the defect. A truncated-origin answer does not just serve its exact prompt again. It serves every semantically similar query that lands within threshold — so one bad generation contaminates a neighbourhood.
2. Long prompts are the most valuable to cache and the most likely to be truncated. Cache value scales with generation cost, so the entries you most want are exactly the long ones most at risk. The incentive points the wrong way.
3. Provider changes invalidate correctness, not just freshness. Cache invalidation is normally about staleness. Here, switching provider or a provider changing its own config can mean previously-fine entries were generated under a smaller ceiling than current requests would get. There is no timestamp that captures that.
What might help
Record the serving conditions in the cache entry — provider, model, and if it can be discovered, the effective context ceiling. Then a change in ceiling can invalidate, and you can at least ask the question later.
Flag entries whose input was near or over a known ceiling as lower confidence, or exclude them from similarity serving even if they are kept for exact hits.
Questions
Does GPTCache record anything about the serving conditions of a cached generation beyond the model name? If it does, that is most of the fix already.
Is there a supported way to invalidate on something other than time or explicit key — a config-change-driven invalidation?
Has anyone hit this in practice? I am reasoning from the mechanism rather than from a diagnosed incident, and I would find it useful to know whether it shows up in the wild or whether something else prevents it.
Discovery method for the ceiling, in case it is useful: send a deliberately oversized prompt and read the error text — providers usually leak the true maximum there even when their docs do not.
All reactions