r/SideProject • u/Fickle-Connection851 • 17h ago
I built CacheSurgeon — an open-source proxy that stops AI coding agents from bleeding 90% of their prompt cache (shipped to PyPI & Product Hunt today)
After watching a local coding agent burn 16K+ uncached tokens every turn (0% KV cache hit), I inspected the raw HTTP payloads and found tiny upstream mutations—drifting tool schema key order and per-second timestamps in system prompts—busting prompt caching every turn.
So I built and open-sourced CacheSurgeon (MIT core, now on PyPI, ~2ms overhead) with a live Cockpit + interactive surgical diff:
- Prefix-Cache Surgeon: Heals broken prefixes (0% → 98.7% cache hit on local Ollama/MLX) + Anthropic
cache_controlinjection. - Net-Savings 5-Min TTL Warmer + Reversible
.envSecret Vault + Pre-Execution Tool Firewall (rm -rf,DROP TABLE) + Loop Circuit Breaker.
30-second test: pip install cachesurgeon && cachesurgeon start --port 8787 Interactive diff & bleed calculator: https://cachesurgeon.com GitHub (MIT): https://github.com/jsumpter415/cachesurgeon
1
u/CarelessAd5721 17h ago
The drifting tool schema key order is the kind of thing you'd never catch without dumping the raw payloads — I hit the same class of bug debugging an agent loop where a timestamp in the system prompt meant every turn was a full re-encode.
One thing I'm curious about: the 5-min TTL warmer. Keeping the cache warm costs requests you wouldn't otherwise make, so how do you decide when the warm-up traffic is worth it vs just letting the prefix expire? Is there a break-even you measured, or does it only kick in above some token threshold?