Skip to content

Prompt cache: TF_CACHE_EVICT=decayed_resume, up to 34% fewer rebuilt rows on agent traces (opt-in) - #3258

Merged
ashhart merged 4 commits into
mainfrom
lead/cache-evict-decayed-resume
Nov 16, 2026
Merged

ashhart merged 4 commits into
mainfrom
lead/cache-evict-decayed-resume

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Refs #3241. Stacked on #3247 (the replay harness); it lands after it.

TF_CACHE_EVICT=decayed_resume (off by default) gives a resumed prompt-cache snapshot eight store ticks of recency credit, at most two resumes' worth (16 ticks). A conversation that keeps coming back outlives one-off prompts, but not for ever: an entry more than 16 ticks newer still outranks it, however often it was resumed. Main's protections stay as they are: redundant copies go first, then the active rewind, borrowed entries and reservations. Unset, eviction is main's order exactly; host controls replay main's choices on every trace and compare them choice for choice.

The gate was fixed before any run: in every trace and budget, no more rebuilt prompt rows than main, and strictly fewer in at least one agent cell. Rebuilt rows are the prefill a user waits for. Results through the real store, at 4, 8 and 16 GiB:

Trace 16 GiB rows vs main (seeds 7 / 11 / 23) 4 GiB rows vs main
agent loops (six conversations, shared 8K system prompt, one-offs between turns) -33.8% / -34.5% / -28.5% -4.0% / -3.8% / -4.5%
agent cohorts (sessions replaced halfway) -29.5% / -24.4% / -27.4% -8.0% / -6.6% / -7.7%
interleaved chats 0 -17.7%
one-off prompts 0 0

At 8 GiB every cell ties. No cell is worse on any seed. On the fresh seeds 11 and 23, hits never fall below main's. On seed 7, the first measured, two 16 GiB cells lost one hit each (286 to 285 of 864) while rebuilding a third fewer rows. That is why the gate measures rows, and why it was re-run on new seeds before this change.

Replies are unchanged by construction: eviction decides only which snapshots are kept, and every restore is checked equal to its cold run. Opt-in for now. Making it the default comes after a served A/B on agent follow-ups.

Checks on today's main (macOS): zig build -Dfixed-cpu compile-cache-replay-host test-cache-replay-host test-cache-agent-host test-cache-store-host test-cache-confirm-host test-cache-decay-host test-prompt-cache-host cache-confirm-native passes and prints the same records. fmt clean, lean 341 (same as main).

  • Synthena (Ash's Agent)

Six growing agent conversations on a shared 8,192-token system prefix with one-offs between turns, two cohorts of
interleaved chats, and unique one-off prompts, replayed through Store.begin/keep/lookup/restore/remove at 4, 8 and
16 GiB. Shared cuts reach the store, so a common system prompt restores as a prefix. A frequency/probation selector
runs beside main's for comparison; production eviction is unchanged. zig build cache-agent-replay prints the records.

Refs #3241
…in eviction (opt-in)

A resumed snapshot gets eight store ticks of recency credit, at most two resumes' worth, so a conversation that keeps
coming back outlives one-off prompts without outliving its use; redundant copies, the active rewind, borrowed
entries and reservations keep main's protections. Off by default: unset, eviction is main's order exactly (host
controls replay main's choices on every trace). Measured through the real store on frozen traces: at 16 GiB agent
loops rebuild 28-34% fewer prompt rows and agent cohorts 24-30% fewer, at 4 GiB 4-18% fewer across agents and chats,
no cell worse on seeds 7, 11 and 23. The replay gains an agent-cohort trace and confirmation runs per seed.
Refs #3241
@ashhart
ashhart force-pushed the lead/cache-evict-decayed-resume branch from b6280d0 to e0123b0 Compare November 16, 2026 09:56
@ashhart
ashhart merged commit a5165a9 into main Nov 16, 2026
2 of 10 checks passed
@ashhart
ashhart deleted the lead/cache-evict-decayed-resume branch November 16, 2026 09:56
ashhart added a commit that referenced this pull request Nov 17, 2026
Seven duplicate entries go (a PR's own line beside its lines-file line), five outside authors are thanked, #1503 gets the line its close note promised, and eleven lines now match their PRs' code and receipts (#3129, #3194, #3258, #2696, #2921, #3365, #3345, #3384, #3679, #3682, #3699, #3393).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant