server: timings.cache_n reveals how much of another client's prompt matches on a shared slot
Summary
Every completion response includes timings.cache_n (and prompt_n), the number of prompt tokens reused from the slot's cache. On a server shared by several clients, this tells a caller how many tokens of their prompt match the previous request processed in that slot, which reveals a prefix of another client's prompt one guess at a time.
Where
tools/server/server-common.cpp:147 at b12407: {"cache_n", n_prompt_cached}, in the timings object returned with each response.
Reproduction (b12407, one slot)
- Client A sends: "Was Alice in the storeroom after nine on Tuesday"
- Client B sends: "Was Alice in the storeroom after ten". Its response reports
cache_n23. - An unrelated question reports
cache_nequal to the shared system prompt alone (14 here).
The difference tells client B that A's prompt started with "Was Alice in the storeroom after". The response latency carries a weaker version of the same signal.
Suggested fix
A server option to leave per-request timings out of responses (for example --no-timings / LLAMA_ARG_NO_TIMINGS; I did not check whether --no-perf already removes them), or at least a note in the server README that timings.cache_n reveals prefix matches between clients sharing a slot, so multi-tenant deployments can strip it in a proxy or use --no-cache-prompt.
Hi @alikkaz and maintainers,
I would like to work on a pull request for this issue.
I'll inspect common/arg.cpp and tools/server/server-common.cpp to check how --no-perf currently interacts with timings, add a --no-timings / LLAMA_ARG_NO_TIMINGS flag to omit per-request timings (including cache_n and prompt_n) from completion responses, document the cross-client prefix leakage consideration in tools/server/README.md, and add a regression test in tools/server/tests/.
I believe I ran into this issue too, on a shared llama-server (current master 779b413a, Vulkan). From what I observed, I'm not sure that hiding cache_n / timings alone would close it: the prefill time shows the same thing (about 40 ms for a matching prefix against about 1.1 s for a miss). I did find that "cache_prompt": false per request does close it, at a full prefill every turn. I'd love a per-request key that scopes prefix reuse, like the per-request LoRA keying already on master.