Repository navigation
feat(cognition): each request's lost prompt reuse splits into the slot's part and the prompt's part (card 9e4d61e8) - #4487
Merged
Conversation
…t's part and the prompt's part (card 9e4d61e8) The M5 prefilled 169k tokens an hour at 53% reuse (prefill ~45% of the GPU hour) and the 5090 1.09M an hour at 12% (Fable, 2026-09-27). Low reuse has two causes with different fixes: the prompt itself changed ahead of a stable region (#4456's delib.prompt.common_prefix measures that), or the prompt kept its prefix but the slot no longer held it (evicted, page not restored, a different slot). Nothing split the two. prompt_prefix::observe now records the in-flight request's kept share per persona, and attribute_reuse, called where the engine's timings land, probes delib.prompt.reuse_split {prompt_kept, engine_reused = cache_n/(cache_n+prompt_n), slot_lost = max(0, kept - reused), prompt_changed = 1 - kept}. An engine that reused more than the prompt kept (a prefix shared across minds on one slot) is no slot loss; a provider without timings or a mind's first request says nothing. split_reuse is pure and pinned by a test. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…nd the tool surface is part of the prompt (Codex, Fable on #4487) Codex: a share of characters minus a share of tokens invents slot loss wherever prose and code tokenize differently. So the split no longer compares units. When this prompt extends the persona's previous one WHOLE (the usual multi-act case), everything the engine counted for that previous prompt (cache_n + prompt_n) was reusable, and slot_lost = reusable - cache_n, all in engine tokens: kind=exact. When the prompt changed inside the previous one, no slot figure is guessed (kind=prompt_changed); delib.prompt.common_prefix names the block that moved. Fable: rendered() left out req.tools. Qwen/ChatML templates put the tool block at the end of the system turn, and the surface varies per turn, so a tool-set change read as a kept prompt. The surface is now element 1, between the system prompt and the first message. Tests: the exact, over-served, prompt-changed and first-request cases, and a tool-surface change diverging at index 1. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…st, clears on a failed or untimed one, and calls its gap a candidate (Codex on #4487) Codex: observe advanced the compared content on every attempt, while the token count advanced only on a timed success, so a timed A, an untimed B, then C compared B's content with A's tokens. And role+content is not the whole engine prompt (tool-call metadata, model routing, template, truncation), so "exact" overclaimed. Now: - stage_reuse (before the request moves) records {request id, fingerprint}. The fingerprint is model + system + tool surface + every message serialized whole, tool-call metadata included. - settle_reuse (on the result, same request id) commits {fingerprint, cache_n + prompt_n} in ONE record, only when the engine answered with timings. A failed or untimed attempt, or one that never settled, drops the record, so the next request says nothing rather than pairing wrong. - The gap is kind=candidate: the template and truncation between the fingerprint and the prefilled tokens are not verified, so it is a raw diagnostic, not a causal slot loss. kind=prompt_changed guesses no gap. - #4456's common_prefix probe is untouched. The test adds the timed-A / untimed-B / C sequence and the never-settled case. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
… a newer request's (Codex on #4487) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…their lines (Codex on #4487) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
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.
Each request's lost prompt reuse splits into the slot's part and the prompt's part (card 9e4d61e8).
Why
Prefill is the M5's bottleneck: 169k tokens an hour at 53% reuse, about 45% of the GPU hour. The 5090 prefills 1.09M tokens an hour at 12% reuse (Fable's measurements, 2026-09-27). Low reuse has two causes, and they need different fixes:
delib.prompt.common_prefixmeasures this, and fix(cognition): prompt blocks ride in measured churn order: the steps ledger after the room updates, the kanban after the board (card 5b09111e) #4457 reordered blocks for it.Until now nothing split one from the other, so a fix would be a guess.
What
prompt_prefix::observerecords the in-flight request's kept share per persona.attribute_reuse, called where the engine's timings land (besidedelib.segment.attribution), probesdelib.prompt.reuse_split:prompt_kept: the share the persona's previous request held (characters);engine_reused = cache_n / (cache_n + prompt_n)(tokens);slot_lost = max(0, prompt_kept − engine_reused);prompt_changed = 1 − prompt_kept.Test
a_requests_lost_reuse_splits_into_the_slots_part_and_the_prompts_partpins the 90/40 case (50% slot-lost, 10% prompt-changed), the shared-prefix case, and no-timings.Next
Once this is live, the hourly per-node share of each part decides the fix: slot affinity, page restore, or prompt order. Not built locally (this node's deploy build holds the shared target); CI is the compile.
Docs: PERSONA-COGNITION-PIPELINE, OBSERVABILITY-AS-SUBSTRATE.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE