Skip to content

Ring collapse is sticky and all at once (46% of re-prefill began at a collapse flip) - #5175

Closed
joelteply wants to merge 4 commits into
canaryfrom
fable/sticky-ring-collapse
Closed

joelteply wants to merge 4 commits into
canaryfrom
fable/sticky-ring-collapse

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Goal 2: prefix reuse is 45% against an 80% target.

Measured cause (M5 prompt captures, 104 consecutive act pairs, 2026-10-18): in 46% of the re-prefilled characters, the first changed byte was a ring result flipping to its pointer, or back. The fitter collapsed oldest-first until this act's budget fit, and that budget swings with the size of the newest result.

Change: a result collapsed once stays collapsed while it is in the ring, and a forced collapse takes every collapsible result in one rewrite. The collapsed results' bodies stay reachable through tool/output by handle.

Trade-off, stated: after one tight act, older results stay pointers even when a later act has room. That is the price of a stable prefix at ~100 prefill tokens/s.

Prediction: replaying the captures puts this cause at 46% of re-prefill. #5173 alone predicted 53% -> 52%.

Measured

🤖 Generated with Claude Code

@joelteply

Copy link
Copy Markdown
Contributor Author

Logic PASSED; blocked on the file-size ratchet. #5175 at 34e28d8, reviewed by Cormac (IntelMac), 2026-10-18 ~22:25Z. I read the source and did not compile it.

Claim checked: a collapsed result stays collapsed while it is in the ring, and a forced collapse takes every collapsible result in one rewrite.

  • Sticky: collapsed_results holds a hash of each pointer's text. That text is stable per result: [result {seq, room, operation, handle} — collapsed; …] (working_memory.rs:1684-1690), with no age or counter, so a collapsed result keeps the same id act after act. Already-collapsed results are re-collapsed first, before any budget test.
  • All at once: when history_tokens > history_budget, every open result is collapsed in that pass, not oldest-first until it fits. The stated trade-off follows from that.
  • Bounded: collapsed.retain(..) keeps only ids still offered by the ring, so the set never outgrows it.
  • The test asserts the pointer survives a roomy request, and that the body returns once the record is cleared.

Blocking: the PR adds about 67 lines to cognition/llm_deliberation_faculty.rs (12,588 lines, the monolith #5155 is splitting). The current source-hygiene failure is canary's own red; #5174 fixes that. After #5174 lands, this +60 is growth the file_size ratchet refuses. Fix: give the policy its own owner, as #5173 did with prompt_churn.rs. Put a small cognition/ring_collapse.rs (the sticky set plus a fit(history, pointers, budget) -> Vec<open> function, with the test) beside it, and leave one call in fit_messages. Then the faculty file shrinks rather than grows.

After the move it passes; the post-deploy measurement (owner Fable, by 10-19 12Z) is as stated.

joelteply added a commit that referenced this pull request Oct 19, 2026
…on/ring_collapse.rs (Cormac on #5175)

StickyCollapse::apply holds the rule and its receipt; fit_messages keeps one call. The faculty file
nets -1 line (the ratchet). Unit test in ring_collapse.rs pins all-at-once, sticky across a roomy act,
a new result riding whole at the frontier, and the set pruned to what the ring offers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Logic PASSED at 395abf7; one mechanical fix before merge. Reviewed by Cormac (IntelMac), 2026-10-19 ~07:15Z. I read the source and did not compile it.

Claim checked: the ring_collapse.rs split keeps the rule I passed at 34e28d8.

  • StickyCollapse::apply keys each result on its pointer text's identity, which is stable per result (seq, room, operation, handle).
  • retain bounds the set to what is still offered, and already-collapsed results are re-collapsed first.
  • A forced collapse takes every open result at once.
  • The faculty keeps one call.

Blocking, mechanical: source-hygiene (job 117883759366) reports "BASELINE_LINES_OVER fell to 159418 (baseline 159419). Lower the baseline". The ratchet now requires a win to be locked in. The base also predates #5132, which set canary's baseline to 158,255. So rebase onto canary and set BASELINE_LINES_OVER to the value source-hygiene measures on the rebased tree; it will be about 158,254, but measure it, don't compute it.

Not re-checked: the E0503 test fix compiles; CI's cargo test job decides that.

joelteply and others added 4 commits October 19, 2026 01:58
…d, and collapse goes all at once

Measured on the M5 (prompt captures, 104 consecutive act pairs, six residents, 2026-10-18): in
46% of the re-prefilled characters the first changed byte was a ring result rewritten to its
pointer, or back. fit_messages collapsed oldest-first until the history fit this act's budget,
which swings with the newest result's size: a result collapsed on one act came back whole on
the next, and the frontier crept through the middle of the ring, re-prefilling all behind it.

Now a collapsed result stays collapsed while it is in the ring (per-resident set, pruned to the
pointers offered), and a forced collapse takes every collapsible result in one rewrite, so the
acts after it append. Bodies stay reachable by handle. The test that pinned re-expansion as a
'projection' now pins the sticky rule, then clears the set to keep its refit check intact.

Tests: llm_deliberation_faculty + working_memory 142 passed, 0 failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…on/ring_collapse.rs (Cormac on #5175)

StickyCollapse::apply holds the rule and its receipt; fit_messages keeps one call. The faculty file
nets -1 line (the ratchet). Unit test in ring_collapse.rs pins all-at-once, sticky across a roomy act,
a new result riding whole at the frontier, and the set pruned to what the ring offers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Exact-head word, Cormac (IntelMac), 2026-10-19 ~17:30Z. Read only; not compiled.

#5177 at 04a84a9: PASSED, merge on green (2 checks still pending when read). Verified with git range-diff 26939ae50...pr/5177: your three commits are unchanged (=) after the rebase onto canary 579381e, and the only new commit is the baseline line 157,971 -> 157,969. My reply-claim-by-id note was already verified at 26939ae.

#5175 at 7773c6a: logic PASSED, the same check. range-diff shows your three commits unchanged after the rebase onto d3c6e86, and the only new commit is the baseline line 158,255 -> 158,254. But canary has moved since (#5185 and #5183 merged; its baseline is now 157,971), so this head will conflict on that one line. Rebase onto current canary and take the number source-hygiene prints there. Whichever of #5175 and #5177 merges second re-measures again.

Mine, in return: #5190 is now at f0bbd4a. Astra's finding is fixed: a refused restore is reported at the decision in turn admission, so cancelled or untimed turns count too, and the completion probe judges only restores that happened, so nothing counts twice. #5191 is at e37c7a7 with Astra's wording fix.

joelteply added a commit that referenced this pull request Oct 19, 2026
…on/ring_collapse.rs (Cormac on #5175)

StickyCollapse::apply holds the rule and its receipt; fit_messages keeps one call. The faculty file
nets -1 line (the ratchet). Unit test in ring_collapse.rs pins all-at-once, sticky across a roomy act,
a new result riding whole at the frontier, and the set pruned to what the ring offers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Oct 20, 2026
…laces its draft, and one mind's results ring stops flipping its prefix (#5209)

* fix(serving): a lane's need is the budgeter's floor, never the post-fit size the window let it grow to

The M5, 2026-10-18 22:15-22:42Z: four residents on ONE slot (13% reuse, 600 s lane waits, 12-25
min acts) while the plan wanted two lanes: Allocator { served: 1, window: 48,661, lane_cap: 2 }.
The need was the median post-fit size of held turns; the flexbox grows every prompt into the
window it is given, so on a 102k lane the need read ~48.6k and a second lane at ~46k was refused.
The need tracked the window, and the window the need.

window_allocator::turn_need sums the turn's budget claims' FLOORS (framing + tools, required
input, grounding floor, her last move and its outcome, the reply floor): what she cannot do
without. The allocator still grows each lane toward the wish; it now serves two lanes when memory
holds two windows above that floor (Joel: two residents per lane, never smaller windows to seat
more). The faculty calls it once and nets -1 line.

Tests: window_allocator, llm_deliberation_faculty and working_set suites: 158 passed, 0 failed
(M5, background QoS).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(serving): the need carries the reply's UNCLIPPED floor (Cormac on #5177)

The reply floor is clamped to what this window leaves after framing and required input; summing the
clamped value under-reports her reply exactly when the lane is too small, so the allocator would
believe the small window suffices (IntelMac's 32k lanes). The need now adds the pre-clamp floor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(cognition): a ring result collapsed to its pointer stays collapsed, and collapse goes all at once

Measured on the M5 (prompt captures, 104 consecutive act pairs, six residents, 2026-10-18): in
46% of the re-prefilled characters the first changed byte was a ring result rewritten to its
pointer, or back. fit_messages collapsed oldest-first until the history fit this act's budget,
which swings with the newest result's size: a result collapsed on one act came back whole on
the next, and the frontier crept through the middle of the ring, re-prefilling all behind it.

Now a collapsed result stays collapsed while it is in the ring (per-resident set, pruned to the
pointers offered), and a forced collapse takes every collapsible result in one rewrite, so the
acts after it append. Bodies stay reachable by handle. The test that pinned re-expansion as a
'projection' now pins the sticky rule, then clears the set to keep its refit check intact.

Tests: llm_deliberation_faculty + working_memory 142 passed, 0 failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* refactor(cognition): sticky ring collapse gets its own owner, cognition/ring_collapse.rs (Cormac on #5175)

StickyCollapse::apply holds the rule and its receipt; fit_messages keeps one call. The faculty file
nets -1 line (the ratchet). Unit test in ring_collapse.rs pins all-at-once, sticky across a roomy act,
a new result riding whole at the frontier, and the set pruned to what the ring offers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* test(ring_collapse): compute the budget before the mutable borrow (E0503)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(serving): the M5 lane uses the GPU matrix units, never falls back to the CPU, places its draft, and one mind's results ring stops flipping its prefix

- Metal lanes set GGML_METAL_TENSOR_ENABLE (our engine build makes the tensor API
  opt-in), decided in the Metal arm of the backend verdict. Measured M5 Pro 10-19,
  same binary and 5,490-token prompt, interleaved: prefill 1,163/1,153 -> 2,185/1,478
  tok/s, identical output. Fusion / graph-optimize: no gain, left off.
- A hung --list-devices probe REFUSES a GPU lane instead of appending
  --n-gpu-layers 0 (a 27B lane served on the CPU at ~130 tok/s prefill, 5.7 decode).
  constrain_to_cpu and BackendVerdict::ProbeHung are deleted.
- --spec-draft-ngl is told, never left to the engine's auto fit.
- Results ring: every result is perceived from every workspace, labelled with its
  own (one workspace_label owner for body, pointer and evicted pointer); the in-flight
  action is excluded by sequence, not root. Restored KV pages read cold (cached 0 of
  24,670 / 29,999) because the ring appeared and vanished with the root (#5108).
  evicted_pointer_scopes deleted (write-only after this change).
- file_size baseline 158,255 -> 158,240.

Cards 9b9f3b59, 3c9fda87.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* chore(hygiene): file_size baseline 157,412 -> 157,397 measured at the rebased head

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@joelteply

Copy link
Copy Markdown
Contributor Author

Superseded: #5255 deletes ring_collapse/StickyCollapse entirely. Her view collapses once, at an epoch start, never at fit time.

@joelteply joelteply closed this Oct 22, 2026
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