Skip to content

feat(inference): measured work holds the core — Background generations defer at the adapter seam (restore-economy 1.a) - #2544

Merged
joelteply merged 3 commits into
canaryfrom
feat/measured-hold-gates-background-inference
Aug 28, 2026
Merged

joelteply merged 3 commits into
canaryfrom
feat/measured-hold-gates-background-inference

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Restore-economy Phase 1.a (plan: restore-economy-fourteen-personas-one-core.md). Fixes the measured cause of the 0.29 KV hit rate.

The defect

agent/solve quiesces the other citizens' service loops (verified quiesced_peers=3) — and the GPU still spent ~half its generations on dream-belief-review (52 of 109 inference.prefill.complete rows) during a measured solve. Dreams never run in the loops the lease gates; they spawn their own tasks and walked straight past the quiesce onto the one serving slot, evicting the solve's warm KV every time. At ~32.9s re-prefill vs ~0.1s restore (~330×, measured), the bypass didn't slow the solve — it halved the machine.

One seam, not whack-a-mole

Gating each background producer means the next tokio::spawn forgets. The adapter is where every generation already crosses with its purpose in hand — the hold is consulted there and nowhere else. Producers never learn it exists.

The RTOS audit (the "too-FIFO / blocking cognition" hazard, explicitly)

  • Deferral sits after classification, before the concurrency permit — a parked request holds nothing: no lock, no decode permit, just its own task on a notify. Parking after the permit would be priority inversion (a sleeping dream holding the only decode slot while a real turn queues behind it).
  • No lock across an await — the state mutex is sync-scoped.
  • Turn and Sidecar never enter the await path. A human talking to a citizen outranks a measurement; blocking the measured drive's own traffic would deadlock it. The holder's own Background rides through.
  • Broadcast wake, never FIFO — deferred work re-races admission at release instead of draining serially.
  • Bounded: a 4h ceiling proceeds loudly (inference.hold.defer_ceiling) — a lease-leak detector, never a silent forever-park.

RAII with a generation counter: a stale lease's late drop cannot release a newer hold (that would silently re-open the dream-clobber).

TDD

The defer table, the stale-drop hazard, and both ends of the bounded wait (wake-on-release + ceiling-proceeds) — written first, via the injected-core pattern (spill.rs precedent) after the process-global singleton made the first parallel test run race itself.

VDD receipt (at the boundary deploy)

Zero Background-class inference.prefill.complete rows during a hold, and the solve's delib.generate.cache hit rate vs tonight's 0.29 baseline. Probes: inference.hold.{acquired,released,replaced,deferred,resumed,defer_ceiling}.

3 measured_hold + 19 solve + 36 slots/adapter tests green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…rations defer at the adapter seam (restore-economy 1.a)

agent/solve quiesces the other citizens' SERVICE LOOPS (verified
quiesced_peers=3) — and the GPU still spent ~half its generations on
dream-belief-review (52 of 109 inference.prefill.complete rows) DURING a
measured solve. Dreams never run in the loops the lease gates; they spawn
their own tasks and walked straight past the quiesce onto the ONE serving
slot, evicting the solve's warm KV every time. At ~32.9s re-prefill vs
~0.1s restore (~330x, measured), the bypass didn't slow the solve — it
halved the machine.

ONE seam, not whack-a-mole: gating each background producer means the
next tokio::spawn forgets. The adapter is where every generation already
crosses with its purpose in hand, so the hold is consulted there and
nowhere else; producers never learn it exists.

THE RTOS SHAPE (Joel: "be careful with await-based code ... we're trying
to be many RTOSes"), audited explicitly:
- Deferral sits AFTER classification and BEFORE the concurrency permit —
  a parked request holds NOTHING (no lock, no decode permit, just its own
  task on a notify). Parking after the permit would be priority inversion:
  a sleeping dream holding the only decode slot while a real turn queues.
- No lock is ever held across an await (the state mutex is sync-scoped).
- Turn and Sidecar never enter the await path at all — a human talking to
  a citizen outranks a measurement, and blocking the measured drive's own
  traffic would deadlock it. The holder's own Background rides through.
- Release wakes ALL waiters (broadcast, never FIFO) — deferred work
  re-races admission instead of draining serially.
- Bounded: a 4h ceiling proceeds LOUDLY (inference.hold.defer_ceiling) —
  a lease-leak detector, not a policy. Never a silent forever-park.

RAII with a generation counter: a stale lease's late drop cannot release
a newer hold (the exact silent re-open of the dream-clobber).

TDD: the defer table, the stale-drop hazard, and both ends of the
bounded wait (wake-on-release, ceiling-proceeds) — via the injected-core
pattern (spill.rs precedent) after the process-global singleton made the
first parallel test run race itself.

Probes / VDD receipt: inference.hold.{acquired,released,replaced,
deferred,resumed,defer_ceiling}. The phase receipt is ZERO
Background-class inference.prefill.complete rows during a hold, plus the
solve's own delib.generate.cache hit rate vs tonight's 0.29 baseline.

3 measured_hold + 19 solve + 36 slots/adapter tests green.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 2 commits August 28, 2026 13:43
… zero polling

Joel: "Ideally you operate causally via events triggering actions ...
all without stalling, like cbar. Concurrency first ... serial only when
you can truly justify it."

Audited 1.a against that and it fell short in one place: the defer loop
waited on Notify with a 30s re-check tick, because Notify can miss a
wakeup that fires before the waiter arms. A tick to paper over a missable
event is a poll wearing an event's coat.

Now the hold IS the substrate-canonical snapshot shape (watch::Sender,
CONCURRENCY-STYLE-GUIDE):
- acquire/release are EVENTS (send_replace / send_if_modified — the
  release event fires exactly when state actually changed, so watchers
  wake causally, never spuriously);
- a deferred waiter awaits changed() and CANNOT miss a transition (watch
  keeps the latest value) — the tick is deleted; the only clock left is
  the leak-detector ceiling;
- subscribe() is public: a component that would only park at the adapter
  door can instead REACT — skip assembling work while held, resume on the
  release event (the dream scheduler's future cheap early-skip);
- the Mutex is gone entirely — one fewer lock in the substrate;
- serial remains in exactly one justified place: admission to the one
  physical GPU slot, because the device is serial. Every mind and every
  deferred task stays concurrent and holds nothing while waiting.

Same tests, same contracts (defer table, stale-drop generation guard,
wake-on-release, ceiling-proceeds) — the refactor changes the mechanism,
not the behavior, and the suite proves it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ell, and split the act ledger (model_ms vs residue_ms)

Three tightenings from CI + the stall audit:

1. THE RATCHET WAS RIGHT. subscribe() shipped with zero callers —
   unwired public machinery, the #27 shape the hygiene test exists to
   block. Now wired to the consumer it was designed for: dream_pass
   parks on the hold's RELEASE EVENT before assembling anything —
   cluster gathering, budget math and prompt composition are wasted work
   for a generation the adapter seam would only park at the door. Events
   trigger actions (CBAR); the adapter gate remains the enforcement and
   its leak ceiling still bounds the pathological case.
   Probe: dream.deferred_to_hold.

2. HoldCell demoted to module-private — it was pub only for the
   injected-core test pattern, and the tests live in this module. A pub
   type nothing outside constructs is exactly what tripped the ratchet
   (107 -> 108); the ratchet is back at baseline.

3. THE ACT LEDGER SPLIT (stall-audit finding, Joel: "we're all about
   latency and limiting locked up minds, or time spent between
   actions"). persona.act.pace now carries model_ms + residue_ms per
   act. Measured tonight: acts p50 123s = prefill 40s + decode 52s +
   ~29s residue — but the residue was only DERIVABLE by subtracting log
   aggregates; a stall hiding in tools and a stall hiding in the model
   were the same number. Now every act names where its time went, at the
   moment it happens, on the probe row that already carries the
   slow/stuck verdicts.

41 act_observe + 4 reachability + 3 measured_hold tests green.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@github-actions github-actions Bot added size: XL and removed size: L labels Aug 28, 2026
@joelteply
joelteply merged commit d0b34e7 into canary Aug 28, 2026
5 checks passed
@joelteply
joelteply deleted the feat/measured-hold-gates-background-inference branch August 28, 2026 19:17
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