r/codex • u/BringinItDirty • 5d ago
Showcase I built kvdiff (MIT): local wire-level proxy for debugging OpenAI Responses API prompt-cache misses in Codex
Full disclosure: I built this (https://github.com/flipcyde101/kvdiff).
Prompt caching on the OpenAI Responses and Chat APIs requires an exact prefix match past the 1,024-token floor. If a tool list reorders, instructions mutates slightly, or a prefix drops under 1,024 tokens, cached_tokens quietly collapses to 0 and burns through your quota and spend.
I built kvdiff to wrap Codex with zero code changes:
# Try pre-seeded demo UI (no API key needed)
# Wrap Codex CLI (strict zero-mutation passthrough by default)
# Opt-in deterministic tool-schema sorting
It computes the UTF-8 byte-level Longest Common Prefix between consecutive turns, maps the divergent byte directly to its JSONPath ($.tools[9].name, $.instructions, etc.), flags TOOL_REORDER, TOOL_MUTATED, VOLATILE_SYSTEM, PREFIX_TOO_SHORT (<1,024 tokens), and TTL_EXPIRED, and tracks wasted dollars in a local UI at 127.0.0.1:4318.
Technical guardrails: 63 kB tarball, Node 24 built-in node:sqlite (zero native addons), strict 127.0.0.1 bind, zero telemetry, zero-buffering SSE flush, and --heal never reorders input[], messages[], or schema enum[]. Let me know if you hit any Codex Responses API edge cases.
•
u/dexterthebot 5d ago
You might want to consider listing your project on the weekly Show-Us-What-You-Built post. Look out for it on Tuesday/Wednesday. Highest commented project wins a week promotion on r/Codex and gets on the Hall of Fame sidebar. See below for last week's winner.**
Light Wars AR: real-life laser tag app with no extra gear. Your phone is the gun and your room is the map. Play up to 6 friends in the same room, or fight drone waves and bosses solo. The vision models run on the phone, and camera frames never leave it. Free on iPhone and Android.
Website: https://lightwarsar.com
iPhone: https://apps.apple.com/us/app/light-wars-ar-laser-tag-party/id6508168951
Android: https://play.google.com/store/apps/details?id=com.lasertag.lightwars.
Contact: contact@lightwarsar.com
1
u/quarrelau 5d ago
Do you have any stats on how effective --heal is in practice?
Cool idea and project.
1
u/VShulcz 4d ago
Does
--healonly sort the top-leveltoolsarray by name, or does it canonicalize nested JSON schema keys inside each tool too? I've seen MCP servers emit tool input schemas with non-deterministic property ordering after a reconnect, which breaks prefix caching even when the tool list order stays the same. Mapping the first divergent byte straight to JSONPath is a neat way to spot that.