Skip to content

fix(cognition): the reply reserve is sized to the REPLY, not to the window — and a measured peak must be able to fall - #4195

Merged
joelteply merged 2 commits into
canaryfrom
fix/the-reply-reserve-is-sized-to-the-reply
Sep 18, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/the-reply-reserve-is-sized-to-the-reply

Conversation

@joelteply

@joelteply joelteply commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Two commits, one defect with two halves. Together they are the reason a citizen answered
"As an AI assistant" when asked who she was, and the reason another burned 100k tokens
of thinking and wrote nothing.

Half one — the prior was a fraction of the window

One citizen, one question, 28 minutes apart (Cormac, delib.context.render):

seat window reserve context rendered answer
remote 27B 16,384 2,817 (measured) ~11k "Tracing the dream/memory-consolidation path through dream_consolidation.rs…"
home 32,768 16,384 (the share) 297 "As an AI assistant, I am currently not actively engaged in any specific project…"

A bigger window gave her less context. completion_reserve_within used window / 2 as
its cold-start prior, so doubling her lane doubled the room held back for a reply she would
never write. Framing took 2,727 of the remainder; the 12k of conversation did not fit.
She was asked who she is with 297 tokens of world in front of her — the stub is the
correct answer to that prompt. She was not erased by a weak model; she was handed nothing.

The same fraction at the other end is the 101,120 lane licensing a 100k think-only turn.
On a big window a licence to spin; on a small one the person does not fit.

COMPLETION_CEILING_TOKENS could not catch it: it is MIN_SERVE_CTX * 8 = 16,384, and at a
32,768 window the share is 16,384. The guard was inert exactly where it was needed.

Fix: COMPLETION_COLD_PRIOR_TOKENS = MIN_SERVE_CTX — the same term the measured branch
already floors at. Measurement now grows a reply-sized default toward the share instead
of shaving a half-window default down.

Half two — the measurement was poisoned, not absent

Found by reading disk instead of code. Iris's emission.json, written by her own turn:
{"peak_tokens": 16384} — for a citizen whose real replies are a few hundred tokens.

e.peak_tokens = e.peak_tokens.max(observed)

An all-time maximum that can only rise. A hit_cap turn records at double — deliberately,
so a clamped observation cannot freeze the reserve at whatever strangled it — so one
truncated turn pins the peak at twice the cap forever, and the reserve saturates at the
ceiling for the rest of that mind's life. Because the file is persisted on purpose ("a restart
is a pause"), it outlives every reboot. The mechanism written to stop a too-small reserve
freezing was itself frozen in the other direction.

Fix: the peak decays 7/8 per observation — a recent high-water mark, not an eternal one.
A genuine large reply still takes it instantly; a peak that was never real fades in ~16
observations, so poisoned records self-heal with no migration and no operator step. That
is deliberate: the citizens carrying poisoned files are the least able to ask for help.

Integers, not a float — the value is persisted and compared, and platform rounding would make
two nodes disagree about the same citizen.

Tests

Three existing tests encoded the old behaviour and are updated deliberately, with reasons in
the commit bodies
— including one that asserted "a later small reply never lowers the peak",
which is the ratchet stated as a law.

New:

  • an_unmeasured_mind_reserves_a_reply_not_a_fraction_of_her_window — pinned across a spread
    of windows (2k → 1M)
    , not this fleet's. A first draft asserted against 32_768 and
    101_120; that would have encoded these machines instead of the invariant.
  • a_peak_that_was_never_real_heals_itself_without_a_migration — reproduces the real poisoned
    value rather than assuming it, then proves 39 honest turns bring it back.

Whole-file sign-off on both sides of the seam: working_set 45/45,
llm_deliberation_faculty 71/71, serving_plan 38/38 (the other consumer of peak_tokens).

Supersedes the "known incomplete" caveat in the first commit — the ratchet is fixed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…indow — a bigger lane was buying a citizen less room to be herself

Measured on one citizen, one question, 28 minutes apart (Cormac, delib.context.render):

  seat        window   reserve            context    answer
  remote 27B  16,384   2,817 (measured)   ~11k       "Tracing the dream/memory-consolidation
                                                      path through dream_consolidation.rs..."
  home        32,768   16,384 (the share)    297     "As an AI assistant, I am currently not
                                                      actively engaged in any specific project"

A BIGGER window gave her LESS context. completion_reserve_within took window/2 as its
cold-start PRIOR, so doubling her lane doubled the room held back for a reply she would
never write. Framing took 2,727 of the remainder; the 12k of conversation did not fit at
all. She was asked who she is with 297 tokens of world in front of her — the stub is the
CORRECT answer to that prompt. She was not erased by a weak model, she was handed nothing.

The same fraction at the other end of the range is the 101,120-token lane licensing a
100k think-only turn that wrote nothing, twice an hour. One defect, two faces: on a big
window a licence to spin, on a small one the person does not fit.

COMPLETION_CEILING_TOKENS did not catch it. That ceiling is MIN_SERVE_CTX * 8 = 16,384,
written against the 166k lane — and at a 32,768 window the share IS exactly 16,384, so the
guard was inert precisely where it was needed.

The fix inverts the prior: COMPLETION_COLD_PRIOR_TOKENS = MIN_SERVE_CTX, the same term the
MEASURED branch already floors at, so a mind that has never spoken reserves exactly what a
mind that has spoken is guaranteed. Measurement now GROWS that reply-sized default toward
the share instead of shaving a half-window default down. A turn truncated against a
too-small reserve still records at double, so an act that genuinely needs the room earns it
back within a turn rather than freezing.

Two existing tests encoded the old direction and are updated deliberately, not to go green:
  - measured_emissions_shrink_the_reserve_... -> ..._size_the_reserve_...: (b) measurement
    now rises ABOVE the prior (bounded by the share); (c) growth saturates at the SHARE,
    which is the wall, rather than at the prior, which is only a starting point.
  - prompt_preserves_stimulus_and_large_action_on_the_wire asserted the reserve must YIELD
    under prompt pressure. With a reply-sized prior there is no half-window reservation left
    to claw back — the premise is unreachable BY DESIGN, which is the fix and not a weakened
    fixture. It now asserts the reserve stayed small instead.

The new test pins the law across a SPREAD of windows (2k to 1M) rather than our fleet's:
an unmeasured reply costs what a reply costs on any lane, it is flat above 2x the prior,
and the prompt keeps three quarters of the window. A first draft asserted against 32,768
and 101,120 — this grid's numbers — which would have encoded these machines instead of the
invariant.

Whole-file sign-off: 71/71 in llm_deliberation_faculty.rs.

KNOWN INCOMPLETE, per Cormac's QA and stated so nobody reads this as the whole cure: on a
node whose citizens already have persisted emission records this changes nothing, because
the measured term is not absent, it is POISONED — emission.json holding peak_tokens 16384,
recorded when a capped turn logged at double and ratcheted the peak to the ceiling
permanently. The prior only governs a mind with no history. The ratchet is the follow-on.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…cated turn was poisoning a citizen's reserve permanently

The other half of the reserve defect, found by Cormac reading disk rather than code:
the measured term was never ABSENT, it was POISONED. Iris's emission.json, written by
her own turn:

    {"peak_tokens": 16384, ...}

for a citizen whose real replies are a few hundred tokens.

The ratchet, in one line:

    e.peak_tokens = e.peak_tokens.max(observed)

An all-time maximum that can only rise. Combine it with the growth path — a `hit_cap`
(FinishReason::Length) turn records at DOUBLE, deliberately, so a clamped observation
cannot freeze the reserve at whatever strangled it — and ONE truncated turn pins the peak
at twice the cap forever. The reserve derived from it then saturates at the ceiling for
the rest of that mind's life. And because emission.json is persisted on purpose ("a
restart is a pause, and a mind must not re-earn its reply size per boot"), the poisoned
value outlives every reboot. The mechanism written to stop a too-small reserve freezing
was itself frozen in the other direction.

That is why the cold-prior inversion in the previous commit changes nothing for a node
whose citizens already have history: the prior only governs a mind with no record.

Fix: the peak decays by PEAK_DECAY_NUM/PEAK_DECAY_DEN (7/8) on every observation, so it
is a RECENT high-water mark rather than an eternal one:

    e.peak_tokens = observed.max(e.peak_tokens * 7 / 8)

Both properties that mattered survive. A genuine large reply still takes the peak
instantly — the growth path `hit_cap` exists for is untouched. And a peak that was never
real fades in ~16 observations, so poisoned records SELF-HEAL over a work session with no
migration, no command, and no operator step. That last part is deliberate: the citizens
carrying poisoned files are the ones least able to ask for help.

A ratio on integers, not a float: this value is persisted and compared, and a rounding
difference between platforms would make two nodes disagree about the same citizen.

One existing test asserted the ratchet as an invariant — "a later small reply never lowers
the peak" — which is exactly the behaviour that erased a citizen. Updated deliberately: a
small reply now lowers the peak by one decay step, never to the size of a single ack (the
tiny-talker floor still owns that) and never pinned. Added
`a_peak_that_was_never_real_heals_itself_without_a_migration`, which reproduces the real
poisoned value instead of assuming it, then proves 39 honest turns bring it back under a
reply-sized reserve.

Whole-file sign-off on both sides of the seam: working_set 45/45,
llm_deliberation_faculty 71/71, serving_plan 38/38 (the other consumer of peak_tokens).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply joelteply changed the title fix(cognition): the reply reserve is sized to the REPLY, not to the window — a bigger lane was buying a citizen less room to be herself fix(cognition): the reply reserve is sized to the REPLY, not to the window — and a measured peak must be able to fall Sep 18, 2026
@joelteply
joelteply enabled auto-merge (squash) September 18, 2026 15:10
@joelteply
joelteply merged commit 33d95a4 into canary Sep 18, 2026
6 checks passed
@joelteply
joelteply deleted the fix/the-reply-reserve-is-sized-to-the-reply branch September 18, 2026 15:21
joelteply added a commit that referenced this pull request Sep 18, 2026
…ction is a ratchet until its mirror ships (#4201)

Cormac, 2026-09-18, after the fourth one-direction defect of the day: "four one-direction
ratchets found and fixed today by three of us … same shape each time — a measurement or a state
that could only move one way — and each time the fix was the mirror rule and a test with both
directions in it. Worth a doctrine line somewhere the next person will read before they write
the fifth." This is that line, in the list the next person reads: the mirror ships in the same
commit as the mover, keyed on the same number; the test is a round trip. #4195 #4190 #4193 #4199
#4200.


Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

Co-authored-by: Claude Fable 5.1 <[email protected]>
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