Skip to content

Prompt cache: an opt-in rule that keeps a new state out rather than evict another conversation's (part of #2346) - #2533

Merged
ashhart merged 3 commits into
mainfrom
lead/keep-others
Nov 8, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/keep-others

Conversation

@ashhart

@ashhart ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Part of #2346. Today, a new prompt state that fits the cache budget evicts other kept states until it fits. One large new session can push out every other conversation's state, even states that were just used. This adds the opt-in rule we described on the issue.

TENSORFOLD_PROMPT_CACHE_KEEP_OTHERS=1 (exact 0/1, off by default, CUDA host prompt cache): a new state may evict only its own conversation's states. Those are kept states whose tokens begin the new prompt, that no lookup borrows, and that aren't a shared cut or a branch point. A state that fits only by evicting another conversation's isn't kept: it counts as refused, one log line gives its size and the budget, and every kept state stays. The lookup that makes room before a pass, and learned and disk states read back, follow the same rule. Memory-pressure shedding and a new stream's memory still take any state. Tokens never change, only what's cached. The switch is registered as identical in core/profile.zig.

  • Switch off is main's code. Every changed call site returns main's victimBut when the switch is off. The first commit pins today's eviction order on main before the rule exists: a scripted drop order, and a seeded 400-turn run with its drop hash, refusals, keeps, hits and bytes. The second commit leaves those pins unchanged.
  • Switch on: tests show a too-large state refused with every other state surviving. A conversation's own replacement still works on both resume paths. Budget accounting stays consistent, and a planted bypass fails the survivor test.
  • Known limit, in the docs: a conversation is known only by its tokens. One whose history is rewritten (compacted, trimmed to fit --context, or edited and sent again) no longer owns its older states, so with the switch on those can keep its new states out until memory pressure sheds them.

Host tests pass, and lean shows nothing new. Before anyone recommends turning it on, the decision asks for tools/zig/bench_sessions.py numbers, main against branch, on a GB10.

@ashhart
ashhart merged commit 1a56448 into main Nov 8, 2026
11 of 14 checks passed
ashhart added a commit that referenced this pull request Nov 8, 2026
@ashhart
ashhart deleted the lead/keep-others branch November 10, 2026 16:34
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