Repository navigation
perf: a session never pays a cache bust for bytes it is not riding (#165) - #166
Merged
Merged
Conversation
) #162 stopped a write the session is never SHOWN from busting. This stops the other half, which is the bulk of the cost: a session was billed a full re-prefill to be shown memories it wrote itself. Lifetime dogfood evidence: 145 store_changed busts across 35 sessions, 134 of them (92%) attributable to the session's own writes — a fact the model produced, already in its transcript. The epoch now also stores the rows this session had authored when the riding bytes were rendered, plus the prompt those bytes were scored against. On a store change it re-renders the section with every row authored SINCE then taken back out; if that reproduces the frozen bytes exactly, the entire difference is the session's own additions and the bytes keep riding, with no epoch_recompute and no invalidation. Anything else survives the subtraction and still busts: a riding row removed or rewritten (blocklist, hand-redaction, forget, supersession, decay), another session's row, a viewer edit, an import, a moved convergence line. Authorship is in-process (src/state.ts, under the shared SESSION_CAP LRU), filled at the one place a row is created on behalf of a named session; the viewer's writes are deliberately unattributed, so a human edit always lands. A lost entry degrades to today's behavior, never to a wrong freeze. Two things the design in #165 got wrong and this corrects: - Eviction by a self-authored row does not need to bust. Freezing never removes anything from what a session rides, so it cannot lose information; the eviction only materialises at the next real adoption. - The counterfactual must re-score with the prompt the frozen bytes came from. Scoring it with the current prompt made a topic change followed by a write look like a content change, billing the session for a refresh the epoch deliberately refuses to perform on a prompt alone. Bench (full section, deterministic): A naive 20 recomputes / 19 busts, B pre-#162 4 / 3, C pre-#165 4 / 3, D shipped 1 / 0 and 12.3% fewer chars than naive. Contract change outside the plugin: a writing session no longer earns src=inject ledger credit for rows it is no longer shown, so e2e/ledger.test.ts now asserts that (and the store report shows honest dead weight, 1 retrieved / 1 never, where both rows previously looked used). neverRetrieved counts rise after this; the number is now telling the truth about what was retrieved. Tests: 5 new cases in test/epoch.test.ts (one red on main — the self-authored addition; the rest pin that foreign writes, corrections of riding rows and hand-redactions still land), and the ledger e2e updated to the new contract. Gate: 620 pass / 12 skip / 0 fail unit, 11 pass e2e, tsc clean, biome exit 0.
|
🎉 This PR is included in version 0.14.17 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
What
Follow-up on #162 (shipped in 0.14.16). #162 stopped a write the session is never shown from busting the prompt cache. This stops the other half, which is the bulk of the cost: a session was billed a full re-prefill to be shown memories it wrote itself.
Lifetime dogfood evidence behind this: 145
store_changedbusts across 35 sessions, 134 of them (92%) attributable to the session's own writes — facts the model produced, already sitting in its own transcript.Implements #165.
Change
The epoch now also carries the rows this session had authored when the riding bytes were rendered, and the prompt those bytes were scored against. On a store change it re-renders the section with every row authored since then taken back out:
memory_rememberof a row that would be selectedmemory_import,memory_undoAuthorship is in-process (
src/state.ts, under the sharedSESSION_CAPLRU), recorded at the single place a row is created on behalf of a named session —runWriteGate, afterappendMemoryreturns the ts. The viewer's own writes are deliberately not attributed, so a human edit always looks foreign and always lands. A lost entry (server restart) degrades to today's behavior — one bust — never to a wrong freeze.Two corrections to the design in the issue
Recorded rather than absorbed silently:
a topic change plus a self-authored write still costs nothing, which is red without the prompt pinning.Measured
Full memory section (digest + frontier + block), deterministic, byte-identical across runs:
The three synthetic writes are made by the measured session, which is how memory actually gets written. All three change what that session would be shown, so B and C each pay for them; D pays nothing.
One contract this changes outside the plugin
e2e/ledger.test.tsasserted that a session writing two facts earnedsrc=injectledger credit for the block that then carried them. It no longer does — because it is no longer shown them. The test now asserts that explicitly (injected.length === 1: the next session is the first to be shown them), and the store report consequently shows honest dead weight — 1 retrieved, 1 never retrieved (50%) — where both rows previously looked used.This means
neverRetrievedcounts rise after it ships. That is the correct reading (a row nobody retrieved is dead weight), but anyone using that number as a quality signal should know why it moved.Boundary worth keeping in view
A very long-lived session that writes constantly will not see its own rows injected until a foreign change or a compaction drops the epoch. That is the requested trade and compaction is the existing reset, but it is a real staleness window, not a theoretical one.
Test evidence
Five new cases in
test/epoch.test.ts. Exactly one is red onmain—a memory this session wrote itself costs ZERO cache busts, the behavior change. The other four are deliberately green before and after, pinning that foreign writes, corrections of riding rows, hand-redactions and topic pivots behave as required:a memory this session wrote itself costs ZERO cache busts— red on maina topic change plus a self-authored write still costs nothinga memory ANOTHER session wrote still lands on the next requestcorrecting a row the session is riding still busts, even its owna hand-redaction of a row this session authored still bustsPlus the updated
e2e/ledger.test.ts, run against a realopencode run --standalonehost.Gate: 620 unit pass / 12 skip / 0 fail, 11 e2e pass / 0 fail,
tsc --noEmitclean,biome lintexit 0, bench byte-identical across runs.Closes #165.