Repository navigation
Measure prompt-cache usage per turn - #180
Merged
Merged
Conversation
Auto picks a model on every turn and treats a switch as free. On a long thread a switch re-reads the whole history without the prompt cache, so the "cheaper" model is often the more expensive turn. The spec measures cache usage first, then holds the model while the cache is warm. Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
Coven-Harness: Claude Code / claude-opus-5-5
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Oct 12, 2026
This was referenced Oct 18, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Auto picks a model on every turn and treats a switch as free. On a long thread a switch
re-reads the whole history without the prompt cache (Anthropic's cache is scoped to one model),
so the "cheaper" model is often the more expensive turn. Before changing routing, Modex needs to
see what each turn actually read from the cache. This is part 1 of
sticky Auto routing
(plan). Routing behavior is unchanged.
What changes
TurnResult.usage(backends/usage.ts): the first model call's cache read / cache write /uncached input, the last call's total input (what the next turn re-reads), output tokens and
call count.
message.usageon eachassistantstream message, each message id counted once,sub-agent messages (
parent_tool_use_id) excluded, follow-up turns after background workincluded; output from each
result.thread/tokenUsage/updatedfor the turn's own thread; output is the change in thethread's running total, so a repeated notification cannot double count.
Thread.lastTurn: model, effort, fast mode, end time and context size of the last turn thatreached a model. Written after any turn that made a call (or completed without usage);
cleared on a backend switch.
routing-fit.json) add idle time and context size at decision timeand the turn's first-call cache figures afterwards.
codex-cli 0.162.1.
Evidence gathered on the way
A resumed
claude -psession keeps its session id. Claude Code writes 1-hour cache entries.Codex
inputTokensincludes cached tokens; one notification per response.Cache probe (same session, one change per turn):
--settings {"fastMode":true}reportedspeed: standardVerification
npm run build && npm test: 857 tests, 844 passed, 13 skipped (Windows-only), 0 failednpm run test:e2e -w @modex/desktop: 242 passed, 3 skipped (real OpenKnowledge cases, environment-gated)