Skip to content

feat(cognition): each request's lost prompt reuse splits into the slot's part and the prompt's part (card 9e4d61e8) - #4487

Merged
joelteply merged 5 commits into
canaryfrom
feat/prefix-reuse-attribution
Sep 28, 2026
Merged

joelteply merged 5 commits into
canaryfrom
feat/prefix-reuse-attribution

Conversation

@joelteply

@joelteply joelteply commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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:

Until now nothing split one from the other, so a fix would be a guess.

What

  • prompt_prefix::observe records the in-flight request's kept share per persona.
  • attribute_reuse, called where the engine's timings land (beside delib.segment.attribution), probes delib.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.
  • An engine that reused MORE than the prompt kept (a prefix shared across minds on one slot) is no slot loss. A mind's first request, or a provider without timings, says nothing.
  • Characters vs tokens: within one persona's prompt, the chars-per-token ratio drifts little, so the two shares compare. The split is for attribution, not billing.

Test

a_requests_lost_reuse_splits_into_the_slots_part_and_the_prompts_part pins 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

…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
joelteply and others added 4 commits September 27, 2026 18:48
…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
@joelteply
joelteply merged commit d0a4c5b into canary Sep 28, 2026
11 of 13 checks passed
@joelteply
joelteply deleted the feat/prefix-reuse-attribution branch September 28, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant