Repository navigation
Conversation
…date victimBut asked extended() of every candidate, and extended() compared the candidate's tokens with every other entry's: O(E^2 L) a victim, and eviction loops pick several. Each entry now keeps the entries that extend it (longer tokens with them as a prefix, born later), linked once when an entry joins the store and unlinked when it leaves; tokens and born never change, and expired is read when asked, so extended() answers as the scan did. victimBut also compares each entry's tokens with the prompt once, for both of its passes, instead of again in every pairwise order of the oldest scan. If a link allocation fails, extended() falls back to the scan. keepBorn copies the prompt once: the state's tokens are a prefix of the kept `last`, which a later resume replaces as before. prompt_cache_scan_test.zig checks every victim and extended() against the old scans on random many-entry stores whose prompts share long prefixes.
Owner
This was referenced Oct 26, 2026
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.
Branch
hostfix-prompt-cache, commit74be69cd3(on main c0c7bd2).victimButasksextended()about every candidate.extended()compares the candidate's tokens with every other entry's (prompt_cache_policy.zig:21-25, called fromvictimButat:9). That is O(E²·L) per victim, and eviction loops (reserve,keepBorn,giveBack, recall) pick several. For a 27B the slot count is unbounded (most), so E reaches hundreds. Entries of one conversation share long prefixes, so each compare runs almost the whole length before it mismatches.Changes, all bookkeeping, with the same choices:
ext, the entries that extend it: longer, its tokens as their prefix, and born later. Links are made once when an entry joins the store (keepBorn,recall,rows_read) and dropped when it leaves (remove).tokensandbornnever change after that, andexpiredis read when asked, soextended()gives the same answer as the scan. If a link allocation fails,extended()falls back to the scan.victimButcompares each entry's tokens with the prompt once and uses the result in both passes. Before, it compared them again for every pair in the oldest scan (before→isActiveRewindtwice).keepBorncopies the prompt once instead of twice (prompt_cache.zig:482/:486). The state's tokens are a prefix of the keptlast, and a later resume replaceslastas before.Test:
prompt_cache_scan_test.zigruns random stores at 24 and 200 slots. Prompts share long prefixes from a small vocabulary. Each run does keeps at random positions and births, lookups that resume or fail, and expiries. After every operation it checksvictimBut(random skip, prompt, born and active rewind) andextended()against copies of the old scans. Over 1000 evictions. Broken variants fail it: links for equal births, or dropping the rewind tiebreak.Measured on the previous base (ReleaseFast, host only; one conversation of 220 turns, 8k to 30k tokens, every other turn a fork, 200 slots, 3 runs):
victimButkeepBorn(evicting when full)lookupRewindGates: full
zig build test -Dnvccexits 0. Lean: 0 new. Served on GB10: identical replies (61 of 61 replies match main c0c7bd2 (Qwen3.6-35B-A3B, 8 lanes), drafted==plain 8/8, concurrent==solo 15/15, resumed==fresh).Overlap: #1291, #1254, #1241 and #1240 touch
prompt_cache.zig. #896 touchesprompt_cache_policy.zig.Metal (M-series Mac, zig 0.17.0):
zig build testpasses (RC=0). A served Qwen3.5-2B smoke run (strict JSON schema solo and two at once, tool_choice required, a three-turn chat with turn 3 repeated, a plain prompt, temperature 0) is byte-identical to main c0c7bd2.