CacheSurgeon fixes silent KV-prefix cache collapse in coding agents, 0%→98.7% hits

Fickle-Connection851 · reddit · 2026-12-01

Debugging a local coding agent burning 16K+ uncached tokens per turn, the author found the culprit: tiny prefix mutations upstream of the model — non-deterministic tool JSON ordering, per-second timestamps in system prompts, missing Anthropic cachecontrol breakpoints, and 5-minute TTL expirations forcing 1.25× cold rebuilds. The open-source CacheSurgeon proxy (MIT, FastAPI, <2ms overhead) fixes these in flight: canonicalizing tool schemas and injecting cachecontrol breakpoints lifted turn-2 cache hits from 0% to 98.7% (109s → 1.07s) on Apple Silicon MLX/Ollama. It also includes a cost-aware TTL warmer, a reversible secret vault that scrubs credentials before egress across split SSE chunks, and a tool firewall with loop circuit breaker that blocks destructive calls (rm -rf, DROP TABLE, force-pushes). 30-second setup: pip install cachesurgeon, point your base URL at the local proxy.

Related event: CacheSurgeon Open-Sourced to Fix Silent Cache Misses in Coding Agents(2 posts)→

Original post →

More from coding & agent

coding & agent channel →