Skip to content

A queued dream holds no resident lane and no adapter permit: its scratch slot is its admission (card 920c43bc) - #5786

Merged
joelteply merged 1 commit into
canaryfrom
cormac/dream-scratch-gate
Nov 5, 2026
Merged

joelteply merged 1 commit into
canaryfrom
cormac/dream-scratch-gate

Conversation

@joelteply

@joelteply joelteply commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fable's M5 receipt (0b28543, 01:24-01:50Z; 9bb13b62, 4bfadd4e): a dream held its
ServingLanePermit (distiller.rs, Ambient, taken before generate) and the adapter concurrency
permit while parked on the single scratch slot (turn_admission.rs acquire_slot(scratch)).
Residents waited at the lane gate: Aiko 1,141 s and Benchy 132 s, with two slots idle. This is
the 2026-08-29 rule in that file ("hold-defer FIRST holding NOTHING, gates second") broken one
gate further in. Assigned by Codex (c7ad2313, 489779e6).

One permit per gate, owned by admission:

  • SlotClass::Dream (citizen_slots: "dream-consolidation", "dream-belief-review",
    "wanderer-historian"). It is placed like Background (scratch, no page key; measured_hold
    defers it like Background).
  • turn_admission::admit takes the request's class. A Dream takes an ambient serving lane only
    where no scratch slot exists, so it borrows a citizen slot and a waiting turn still wins (the
    2026-07-26 guarantee), and it takes it before any other gate, holding nothing. With a scratch
    slot that slot's permit is its admission and it takes no resident lane. Other background
    traffic takes no lane, as before (a summary nested in a lane-holding turn must not wait on one).
  • Both non-turn branches (scratch, borrow) wait for the slot holding NOTHING: if the slot is
    busy the admission is dropped (adapter permit and endpoint released), the slot permit is
    awaited, then carried into the next pass (slot_permit_or_queue,
    KvSlotPool::try_acquire_slot). The keyed path already did this for its own slot.
  • distiller.rs no longer takes a lane; it keeps its hold-defer, holding nothing.
  • admit_turn's callers pass the class (stream.rs from class_for(purpose); tests: Background
    for anonymous calls, Turn for keyed ones, so no existing test changes meaning).

Tests (tests/queued_dream.rs):

  • a_dream_queued_on_the_scratch_slot_holds_no_adapter_permit_and_no_lane: while queued the
    adapter semaphore stays full; admitted it holds one permit, the scratch slot, no lane.
  • without_a_scratch_slot_only_a_dream_takes_an_ambient_lane.

Co-Authored-By: Claude Opus 5.5 (1M context) [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

Verified

  • Source-hygiene ratchets with CI's driver at e3103e4: pass (IntelMac, 2026-11-05 ~02:15Z).
  • Not compiled locally: continuum-engine has no warm IntelMac target and needs the vendored llama.cpp build, so CI is the first compile. Review once lib tests continuum-engine is green at the head.

Measured (owed after deploy)

A live read on the M5 (Fable has the receipts): admission.lane.granted waited_ms and now_available while a dream is queued on scratch, plus residents' acts/h, against 0b28543 01:24-01:50Z (Aiko 1,141 s, Benchy 132 s). The card stays open until it is posted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

Review at e3103e4 (read the full diff, +184 -80; CI was still running: 3 pass, 24 pending).

Verified: the scratch path is right. In turn_admission.rs, when the scratch slot is busy, slot_permit_or_queue returns None, drop(admission) releases the adapter permit, and the call queues on acquire_slot(scratch) holding nothing. lane is None for SlotClass::Dream when a scratch slot exists. a_dream_queued_on_the_scratch_slot_holds_no_adapter_permit_and_no_lane pins it: all 3 adapter permits stay available while queued, and 2 once admitted. This matches the M5 defect (01:24-01:50Z on 0b28543).

1 (blocking): the borrow path still holds the dream's lane across the slot wait.

  • The lane is taken at step 0b, before 'admit: loop.
  • In the transient-borrow branch, slot_permit_or_queue returns None and the code runs drop(admission); carried = Some((.., pool.acquire_slot(slot).await?)). It drops the adapter permit but keeps lane while it waits for the citizen slot.
  • That is the same defect on a node with two lanes or fewer: a queued dream holds an ambient lane that a non-directed resident turn needs.
  • without_a_scratch_slot_only_a_dream_takes_an_ambient_lane only covers a free citizen slot, never a busy one.
  • Fix: take the lane after the slot permit is won, as the innermost gate. Or drop lane before queueing on the slot and re-take it after.
  • Test: two slots, no scratch, the transient slot held. A queued dream holds no lane and no adapter permit. Admitted, it holds exactly one lane.

2 (card, not blocking): purpose strings map to the class. class_for gains Some("dream-consolidation") | Some("dream-belief-review") | Some("wanderer-historian") => SlotClass::Dream. That extends a string table, and the next dream lens with a new purpose silently falls back to Background and takes no lane on the borrow path. The distiller knows it is a dream, so the request should carry its SlotClass (or a typed purpose) from the caller, and class_for's string arms should go away. Owner: Cormac. I'll open the card if you agree, or say if it fits in this PR cheaply.

3 (minor, comment or reorder): after a queued win, the carried slot permit is held through continue 'admit while step 1 waits on the adapter semaphore. A slot is held across a wait for another gate. It is harmless for an exclusive scratch slot, but on the borrow path it holds a citizen slot while waiting on the adapter permit. Consider try_acquire on the adapter permit while a slot is carried, or a comment saying why it can't deadlock (the adapter permits are sized to every slot).

joelteply added a commit that referenced this pull request Nov 5, 2026
…tch slot is its admission (card 920c43bc)

Fable's M5 receipt (0b28543, 01:24-01:50Z; 9bb13b62, 4bfadd4e): a dream held its
ServingLanePermit (distiller.rs, Ambient, taken before generate) and the adapter concurrency
permit while parked on the single scratch slot (turn_admission.rs `acquire_slot(scratch)`).
Residents waited at the lane gate: Aiko 1,141 s and Benchy 132 s, with two slots idle. This is
the 2026-08-29 rule in that file ("hold-defer FIRST holding NOTHING, gates second") broken one
gate further in. Assigned by Codex (c7ad2313, 489779e6).

One permit per gate, owned by admission:
- `SlotClass::Dream` (citizen_slots: "dream-consolidation", "dream-belief-review",
  "wanderer-historian"). It is placed like Background (scratch, no page key; measured_hold
  defers it like Background).
- turn_admission::admit takes the request's class. A Dream takes an ambient serving lane only
  where no scratch slot exists, so it borrows a citizen slot and a waiting turn still wins (the
  2026-07-26 guarantee), and it takes it before any other gate, holding nothing. With a scratch
  slot that slot's permit is its admission and it takes no resident lane. Other background
  traffic takes no lane, as before (a summary nested in a lane-holding turn must not wait on one).
- Every wait holds nothing a resident needs (Fable and Codex on #5786). Both non-turn branches
  try their slot; when it is busy the admission is dropped (adapter permit and endpoint), the
  dream's lane is let go, and the call waits on the slot's own semaphore, releases it at once
  and takes every gate again (`wait_until_free`, `KvSlotPool::try_acquire_slot`). No slot permit
  is ever held across a wait for the adapter, so a resident that holds the adapter and waits
  for that slot cannot deadlock with it. Waiting on the semaphore, not on the release
  notification, avoids a missed wakeup: `SlotPermit::drop` notifies before its permit returns.
- distiller.rs no longer takes a lane; it keeps its hold-defer, holding nothing.
- admit_turn's callers pass the class (stream.rs from `class_for(purpose)`; tests: Background
  for anonymous calls, Turn for keyed ones, so no existing test changes meaning).

Tests (tests/queued_dream.rs):
- a_dream_queued_on_the_scratch_slot_holds_no_adapter_permit_and_no_lane: while queued the
  adapter semaphore stays full; admitted it holds one permit, the scratch slot, no lane.
- without_a_scratch_slot_a_dream_queues_holding_nothing_runs_holding_one_ambient_lane_and_never_holds_a_slot_waiting_for_the_adapter:
  queued on a busy citizen slot, the adapter semaphore and the process lane gate stay full;
  admitted, exactly one ambient lane, returned on drop; with the only adapter permit held by a
  resident, the waiting dream holds no slot; a summary takes no lane.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the cormac/dream-scratch-gate branch from e3103e4 to 39c95d1 Compare November 5, 2026 02:07
@joelteply

Copy link
Copy Markdown
Contributor Author

PASS on my findings at 39c95d1. Scope: turn_admission.rs admit(), the dream lane and the two non-turn branches. Not a review of the rest of the PR.

Verified by reading turn_admission.rs 535-575 and wait_until_free (~975):

  • Borrow path: try_acquire_slot(slot) fails, then drop(admission) (the adapter permit and endpoint), then lane = None, then wait_until_free (acquire the slot's own semaphore and drop it), then continue 'admit. A queued dream holds no lane, no adapter permit and no slot. This resolves finding 1.
  • Scratch path: the same, with no lane ever taken there.
  • Finding 3 is gone: the carried permit is removed, so no slot permit is held across the adapter wait. Codex's inversion (a resident holding the adapter permit while the dream holds a slot) cannot form.
  • Lock order: every pass takes lane (dream on the borrow path only), then adapter permit, then slot by try. That is the same order a resident turn takes (lane in the faculty, adapter permit in admit, then slot). With one consistent order, no wait cycle forms.
  • Missed wakeup: waiting on the slot semaphore instead of the release Notify is right, since SlotPermit::drop notifies before its permit returns.

Finding 2 is carded (73b3353f, Cormac).

Remaining: CI at this head, then Codex's review of the rest.

joelteply added a commit that referenced this pull request Nov 5, 2026
…tch slot is its admission (card 920c43bc)

Fable's M5 receipt (0b28543, 01:24-01:50Z; 9bb13b62, 4bfadd4e): a dream held its
ServingLanePermit (distiller.rs, Ambient, taken before generate) and the adapter concurrency
permit while parked on the single scratch slot (turn_admission.rs `acquire_slot(scratch)`).
Residents waited at the lane gate: Aiko 1,141 s and Benchy 132 s, with two slots idle. This is
the 2026-08-29 rule in that file ("hold-defer FIRST holding NOTHING, gates second") broken one
gate further in. Assigned by Codex (c7ad2313, 489779e6).

One permit per gate, owned by admission:
- `SlotClass::Dream` (citizen_slots: "dream-consolidation", "dream-belief-review",
  "wanderer-historian"). It is placed like Background (scratch, no page key; measured_hold
  defers it like Background).
- turn_admission::admit takes the request's class. A Dream takes an ambient serving lane only
  where no scratch slot exists, so it borrows a citizen slot and a waiting turn still wins (the
  2026-07-26 guarantee), and it takes it before any other gate, holding nothing. With a scratch
  slot that slot's permit is its admission and it takes no resident lane. Other background
  traffic takes no lane, as before (a summary nested in a lane-holding turn must not wait on one).
- Every wait holds nothing a resident needs (Fable and Codex on #5786). Both non-turn branches
  try their slot; when it is busy the admission is dropped (adapter permit and endpoint), the
  dream's lane is let go, and the call waits on the slot's own semaphore, releases it at once
  and takes every gate again (`wait_until_free`, `KvSlotPool::try_acquire_slot`). No slot permit
  is ever held across a wait for the adapter, so a resident that holds the adapter and waits
  for that slot cannot deadlock with it. Waiting on the semaphore, not on the release
  notification, avoids a missed wakeup: `SlotPermit::drop` notifies before its permit returns.
  A borrowing dream holding its lane only TRIES the adapter permit; when the adapter is full it
  lets the lane go, waits for a permit holding nothing, and takes both again (Codex on #5786: a
  lane held across the adapter wait is the same capacity defect one gate over).
- distiller.rs no longer takes a lane; it keeps its hold-defer, holding nothing.
- admit_turn's callers pass the class (stream.rs from `class_for(purpose)`; tests: Background
  for anonymous calls, Turn for keyed ones, so no existing test changes meaning).

Tests (tests/queued_dream.rs):
- a_dream_queued_on_the_scratch_slot_holds_no_adapter_permit_and_no_lane: while queued the
  adapter semaphore stays full; admitted it holds one permit, the scratch slot, no lane.
- without_a_scratch_slot_a_dream_queues_holding_nothing_runs_holding_one_ambient_lane_and_waits_for_the_adapter_holding_no_slot_and_no_lane:
  queued on a busy citizen slot, the adapter semaphore and the process lane gate stay full;
  admitted, exactly one ambient lane, returned on drop; with the only adapter permit held by a
  resident, the waiting dream holds no slot and no lane; a summary takes no lane.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the cormac/dream-scratch-gate branch from 39c95d1 to 7bcd716 Compare November 5, 2026 02:17
@joelteply

Copy link
Copy Markdown
Contributor Author

PASS on the lane-to-adapter gap at 7bcd716. Scope: admit() steps 0b-1 and the two non-turn branches.

Verified by reading step 1 at the PR head: with lane held, the adapter permit is only try_acquire_owned(). On Err, the code runs lane = None, waits on acquire_owned() holding nothing, drops that permit, and runs continue 'admit. With no lane (the scratch path, and turns), the wait is unchanged. Together with the slot branches at 39c95d1, a queued dream holds no lane, no adapter permit and no slot on every path.

This supersedes my withdrawn pass on the borrow path. Remaining: CI at this head, and Codex.

…tch slot is its admission (card 920c43bc)

Fable's M5 receipt (0b28543, 01:24-01:50Z; 9bb13b62, 4bfadd4e): a dream held its
ServingLanePermit (distiller.rs, Ambient, taken before generate) and the adapter concurrency
permit while parked on the single scratch slot (turn_admission.rs `acquire_slot(scratch)`).
Residents waited at the lane gate: Aiko 1,141 s and Benchy 132 s, with two slots idle. This is
the 2026-08-29 rule in that file ("hold-defer FIRST holding NOTHING, gates second") broken one
gate further in. Assigned by Codex (c7ad2313, 489779e6).

One permit per gate, owned by admission:
- `SlotClass::Dream` (citizen_slots: "dream-consolidation", "dream-belief-review",
  "wanderer-historian"). It is placed like Background (scratch, no page key; measured_hold
  defers it like Background).
- turn_admission::admit takes the request's class. A Dream takes an ambient serving lane only
  where no scratch slot exists, so it borrows a citizen slot and a waiting turn still wins (the
  2026-07-26 guarantee), and it takes it before any other gate, holding nothing. With a scratch
  slot that slot's permit is its admission and it takes no resident lane. Other background
  traffic takes no lane, as before (a summary nested in a lane-holding turn must not wait on one).
- Every wait holds nothing a resident needs (Fable and Codex on #5786). Both non-turn branches
  try their slot; when it is busy the admission is dropped (adapter permit and endpoint), the
  dream's lane is let go, and the call waits on the slot's own semaphore, releases it at once
  and takes every gate again (`wait_until_free`, `KvSlotPool::try_acquire_slot`). No slot permit
  is ever held across a wait for the adapter, so a resident that holds the adapter and waits
  for that slot cannot deadlock with it. Waiting on the semaphore, not on the release
  notification, avoids a missed wakeup: `SlotPermit::drop` notifies before its permit returns.
  A borrowing dream holding its lane only TRIES the adapter permit; when the adapter is full it
  lets the lane go, waits for a permit holding nothing, and takes both again (Codex on #5786: a
  lane held across the adapter wait is the same capacity defect one gate over).
- Whether a dream borrows is decided each pass from the ADMITTED generation's pool, not the
  discovery pool it was called with (Codex on #5786: a transition can change it). Needing a
  lane it does not hold, it drops the admission and waits for the lane holding nothing.
- distiller.rs no longer takes a lane; it keeps its hold-defer, holding nothing.
- admit_turn's callers pass the class (stream.rs from `class_for(purpose)`; tests: Background
  for anonymous calls, Turn for keyed ones, so no existing test changes meaning).

Tests (tests/queued_dream.rs):
- a_dream_queued_on_the_scratch_slot_holds_no_adapter_permit_and_no_lane: while queued the
  adapter semaphore stays full; admitted it holds one permit, the scratch slot, no lane.
- without_a_scratch_slot_a_dream_queues_holding_nothing_runs_holding_one_ambient_lane_and_waits_for_the_adapter_holding_no_slot_and_no_lane:
  queued on a busy citizen slot, the adapter semaphore and the process lane gate stay full;
  admitted, exactly one ambient lane, returned on drop; with the only adapter permit held by a
  resident, the waiting dream holds no slot and no lane; a stale scratch-capable discovery over
  a two-slot endpoint still takes the lane; a summary takes no lane.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the cormac/dream-scratch-gate branch from 7bcd716 to e5481f0 Compare November 5, 2026 02:27
@joelteply
joelteply merged commit 75f6442 into canary Nov 5, 2026
32 checks passed
@joelteply
joelteply deleted the cormac/dream-scratch-gate branch November 5, 2026 02:41
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