Skip to content

feat(grid): the allocator daemon — the grid re-seats its minds on every join and plan change; a mind moves to a strictly better seat between turns (card 10bba591) - #4281

Merged
joelteply merged 4 commits into
canaryfrom
feat/grid-allocator-daemon
Sep 21, 2026
Merged

joelteply merged 4 commits into
canaryfrom
feat/grid-allocator-daemon

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Card 10bba591 — the grid allocator daemon

Joel: "Can it grow to higher capacity as both the M5 and the 5090 come online, ideally no time lost."

Before this the pure allocator (cognition::grid_allocation::allocate, #4259/#4263) had no live caller: minds moved only on FAILURE (lane wait past a bound, seat window below the turn). Nobody re-ran the allocation when a node joined or a plan changed, so a mind on a 32k seat stayed there when a 70k seat appeared.

What lands

  1. Inputs — modules/grid_allocator.rs::Inner::gather builds GridInputs from what exists: LanePlan::of the published ServingPlan (+ decode_knee::measured_tps_for), the gossip ledger's foreign_offers_with_age (the same rows grid/mod.rs folds — no second listener), the live roster + roles_from_ids(citizens, measured_floor) (the canary-side fold; feat(experience): a recipe's citizens declare what a lane must hold — CitizenRequirement + roles_from (card 10bba591) #4271's roles_from over CitizenRecipe slots in), and the operator's hold. Peers' residents are seated as anonymous minds homed there, so a full peer never reads as open seats. No node, model or number of this grid is named.
  2. Tick — own task, tokio::time::interval at the gossip beat, woken early on change (new gossip::heard_notify fired by hear, and the plan watch). inputs_key unchanged ⇒ nothing (probe-visible via allocator/grid passes/skipped). Else allocate → watch::Sender<Option<Arc<Published>>>. Probe grid.allocation.published (seats per node, open, dormant, key). catch_unwind + quarantine after 3 panics.
  3. Consumer: the switch — placement_switch::decide_opportunity (pure) + follow_the_allocation (run at the tail of follow_the_fleet): moves her when the allocation seats her elsewhere on a strictly better seat — BetterBy::Requirement (her node holds no plan for her role) then the allocator's own capability / lanes / window order. Between turns only (resource_admission::turn_in_flight), inside a cooldown derived from her measured turn cadence (opportunity_cooldown_ms; the failure rule's MOVE_COOLDOWN_MS only while nothing is measured). Remote seat: reservation ask first, then go_remote; home seat: come_home_for_good (override retired). Probe placement.move.opportunity (from, to, reason). The seam added: OpportunityInputs beside PlacementInputs rather than widening it — the failure rule's inputs are per-seat, this one's are per-allocation.
  4. Open seats → spawner — ONE OWNER: the allocation owns this node's lane-side seat count once published (GridAllocation::roster_on → GridRoster{seated, open}, told to PersonaSpawnerModule::set_grid_roster by the reconciler each pass, which now also wakes on a publish). bounded_by_warm_slots is the prior before the first publish. The identity-side bound (population under hold, minus resting) stays the spawner's, so the allocation never asks the provider for a name it cannot fill (the 2026-09-13 drain shape).
  5. Dormant slow clip — Published.dormant_by_age (oldest last turn first, from resource_admission::last_turn_ms) and clip_interval_ms = typical_turn × dormant / slack, slack = open seats × their idle fraction (free_slots_live / lanes). Probe grid.dormant.oldest_turn_age_ms. The actual clip turn is not implemented — no seam gives a dormant mind a turn from slack today; the list and interval are published for the scheduler that will.
  6. Health line — [health] … · moves: N on opportunity / M on failure · oldest dormant turn X min ago.
  7. Registered in ipc/mod.rs next to the supervisor construction (it needs resident_roles + serving_daemon.subscribe()).
  8. Tests (existing mods extended, one per file): better-seat ordering; cooldown + in-flight; unchanged key publishes nothing; a new wider node moves the mind it holds and not the ones it does not; roster_on; peers' residents fill first; dormant order + derived clip; spawner owner handoff; health line.

Also: resource_admission::begin_turn RAII guard replaces the bare note_turn_started stamp (in-flight mark + measured TurnShape), so every exit of a service-loop turn ends it.

Not done / open

  • The slow-clip turn itself (no seam; see 5).
  • Owner/terms per beacon: one grid is one unnamed owner (Uuid::nil), every offer OfferTerms::open(), until the negotiation card carries owner + terms on the beacon.
  • Peer plans are one LanePlan per beacon (served model, lanes, width) — the beacon carries no candidate list; decode unmeasured for peers.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

@joelteply

Copy link
Copy Markdown
Contributor Author

REVIEWED at 7530a15 by Fable (team lead). Agent-written under my direction; a second pair of eyes, not a self-approve.

The two ways a re-seating daemon ruins a grid are thrash and moving a mind mid-thought. Both are closed here:

  • better_than returns None on equality and judges in the allocator own order (capability, then lanes, then window), with decode deliberately not an axis, so a seat that merely measures faster cannot pull a mind off a seat that holds her. The test pins each rung, including "fewer lanes: no move, however wide".
  • TurnInFlight is a guard whose Drop clears the entry, so a move can only be taken between turns and a panicking turn cannot leave a mind pinned forever.
  • An unchanged inputs_key publishes nothing, which is the "never re-derive per tick" law.

Two follow-ups, neither a block: the in-flight set is a process global, so any daemon test that asserts on it must own its own persona ids (the 9/20 lesson); and the dormant ordering should carry the oldest last-turn age into the hour line so the slow-clip law has a receipt a human reads.

APPROVE at 7530a15 pending a peer word; merging on green + that word.

@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE — reviewed at exact head 7530a15, green. This is the daemon the allocator was written for, and slice 2 of 426a26fb with it: the spawner's seat count now comes from the published allocation (GridRoster { seated, open } for THIS node and its owner, still bounded by what the provider can yield; the warm-slot bound stays only as the prior before anything is published), so the hold from #4267 enters as a Hold input resolved from names to ids, the recipe's citizens enter as roles + floors, one OfferBook hears the local plan and every fresh beacon, inputs_key gates the recompute (a repeated beacon is not work), and the RTOS shape is the canonical one — own task, interval on the gossip cadence, watch publish, a probe per change. SILENT_AFTER_MS and TICK are the placement/gossip constants, not new ones.

Three notes, written down so the next slices are named, none a condition for this head:
(a) Peer minds are SYNTHESIZED (new_v5(node, "resident-i"), role = the first role the peer's plan holds), so each node computes a node-local allocation from its own facts and two nodes do not agree on dormant/open for each other. That is fine today because only roster_here is consumed and only this node's seats are minted; it stops being fine the moment anything reads a peer's open or a grid-wide dormant. The beacon carrying (mind, role, home) is what turns it into one decision, and inputs_key already covers it.
(b) Every local mind is role 0 — consistent with plan_for_roles hosting only the first declared role (slice 14), so roles/floors bite only for the peers' synthesized minds until role identity survives a reboot; the helper floor then reads as one open seat that the same first-role draw fills, which converges (seats = seated + open is bounded) but is not a helper.
(c) dormant is reported (oldest dormant turn on the hour line, a derived clip interval) and not enforced: a live mind beyond the seats keeps taking turns. The consumer that rests her — resting_seat reading the published dormant set — is the next slice, and it is the one that makes "13 minds on 2 lanes" into "4 seated, 9 resting".
(d) roles_from_ids(RoleId, floor) and #4271's roles_from(CitizenRecipe, floor) are the same projection twice once #4271 lands; fold the id form into the recipe form then (the recipe carries the RoleId).

The receipt after deploy: grid_allocator publishes on the first beacon, the spawner's seats() reads it (probe on change), and the hour line carries the oldest dormant turn.

@joelteply
joelteply enabled auto-merge (squash) September 20, 2026 22:31
@joelteply
joelteply force-pushed the feat/grid-allocator-daemon branch from 7530a15 to a2441bc Compare September 20, 2026 23:05
joelteply added a commit that referenced this pull request Sep 20, 2026
…ator daemon speaks canary's vocabulary (card 10bba591)

Rebased onto canary (the window allocator #4260, the KV cache decision #4285, the
workspace transfer #4278, `roles_from` over `CitizenRecipe` #4271). Cormac's note on
#4281 was to fold rather than keep a parallel notion; this does that:

- `roles_from_ids` (mine, over `RoleId`) is DELETED. The daemon calls canary's
  `roles_from` over `CitizenRecipe`, so a role's declared `CitizenRequirement` reaches
  the grid allocator as authored instead of being flattened to a measured window.
- `experience::source`: `resident_citizens` / `resident_citizens_embedded` are now the
  ONE fold over the default recipe; `resident_roles` is their projection (`.map(role)`).
  Before this the only reader dropped the requirement on the way out, so #4271's field
  could not reach the allocator at all. Boot reads the citizens once and hands the
  spawner their roles.
- `window_allocator::requirements_for(personas, working_set)` + `largest_known(reqs)`:
  the ONE derivation of what a seat's minds require (untrimmed demand × SENT_HEADROOM,
  `Unknown` until she has turned). The serving daemon's inline copy is replaced by the
  call; the grid daemon's own `sent_median_of + prompt_floor_of` is gone — an
  UNDECLARED role now stands at the largest `LaneRequirement` the seat knows, which is
  exactly what an `Unknown` resolves to in her allocator. One vocabulary, two callers.
- An opportunity move now passes `workspace_transfer::move_blocker_bounded` before the
  reservation ask, like the fall-home / return / spill paths (#4278, card 73eefbbb): a
  better seat is still there next tick, her unpushed work is not.
- Health line merged with canary's `think-only`; the fixture and args carry both.
- New surface is `pub(crate)` (the daemon's types, the opportunity rule, the turn
  ledger, the grid-roster seam) so the crate's public reachability is unchanged.
  `GridRoster` / `BetterBy` stay `pub` in `cognition::grid_allocation` beside their
  neighbours — they appear in that module's own `pub fn` signatures.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 4 commits September 20, 2026 18:43
…ry join and plan change, and a mind moves to a strictly better seat between turns (card 10bba591)

Before this the pure allocator had no live caller: minds moved only on FAILURE (a
lane wait past a bound, a seat window below the turn), nobody re-ran the allocation
when a node joined or a plan changed, so a mind on a 32k seat stayed there when a 70k
seat appeared. Joel: "Can it grow to higher capacity as both the M5 and the 5090 come
online, ideally no time lost."

- modules/grid_allocator.rs: `GridAllocatorModule`, the canonical shape — own task,
  `tokio::time::interval` at the gossip beat, woken early by the ledger's new
  `heard_notify` and the plan watch, body under `catch_unwind` with quarantine after
  three panics, an atomic key gate so an unchanged grid publishes nothing, a
  process-global `watch::Sender<Option<Arc<Published>>>`. Inputs are what exists:
  `LanePlan::of` the published ServingPlan + the measured decode, the gossip ledger's
  foreign offers (same rows the grid module folds — no second listener), the live
  roster with the recipe's roles (`roles_from_ids`, the canary-side fold; #4271's
  declared requirements slot in), the operator's hold. Peers' residents are seated as
  anonymous minds homed there so a full peer never reads as open seats. Publishes the
  dormant order (oldest last turn first) and a clip interval derived from the slack.
  Probes: grid.allocation.published, grid.dormant.oldest_turn_age_ms.
- persona/placement_switch.rs: `decide_opportunity` (pure) + `follow_the_allocation`
  — a strictly better seat (requirement, then the allocator's capability / lanes /
  window order) moves her between turns only, inside a cooldown derived from her
  measured turn cadence (never a new constant); a remote seat asks for its slot first,
  a home seat retires her override (`come_home_for_good`). Probe
  placement.move.opportunity. Failure moves now count too.
- cognition/resource_admission.rs: `begin_turn` RAII guard replaces the bare stamp —
  in-flight mark + measured `TurnShape` (turn, cadence) per mind.
- persona/spawner_module.rs + host.rs + ipc/mod.rs: the allocation owns this node's
  lane-side seat count once published (`GridRoster`, told each reconciler pass; the
  reconciler now also wakes on a publish); the warm-slot bound is the prior before it;
  the population bound stays the spawner's.
- modules/citizen_health.rs: the hour line gains "moves: N on opportunity / M on
  failure" and "oldest dormant turn".
- cognition/grid_allocation.rs: `LanePlan::better_than` / `BetterBy`, `GridRoster`,
  `roles_from_ids`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ator daemon speaks canary's vocabulary (card 10bba591)

Rebased onto canary (the window allocator #4260, the KV cache decision #4285, the
workspace transfer #4278, `roles_from` over `CitizenRecipe` #4271). Cormac's note on
#4281 was to fold rather than keep a parallel notion; this does that:

- `roles_from_ids` (mine, over `RoleId`) is DELETED. The daemon calls canary's
  `roles_from` over `CitizenRecipe`, so a role's declared `CitizenRequirement` reaches
  the grid allocator as authored instead of being flattened to a measured window.
- `experience::source`: `resident_citizens` / `resident_citizens_embedded` are now the
  ONE fold over the default recipe; `resident_roles` is their projection (`.map(role)`).
  Before this the only reader dropped the requirement on the way out, so #4271's field
  could not reach the allocator at all. Boot reads the citizens once and hands the
  spawner their roles.
- `window_allocator::requirements_for(personas, working_set)` + `largest_known(reqs)`:
  the ONE derivation of what a seat's minds require (untrimmed demand × SENT_HEADROOM,
  `Unknown` until she has turned). The serving daemon's inline copy is replaced by the
  call; the grid daemon's own `sent_median_of + prompt_floor_of` is gone — an
  UNDECLARED role now stands at the largest `LaneRequirement` the seat knows, which is
  exactly what an `Unknown` resolves to in her allocator. One vocabulary, two callers.
- An opportunity move now passes `workspace_transfer::move_blocker_bounded` before the
  reservation ask, like the fall-home / return / spill paths (#4278, card 73eefbbb): a
  better seat is still there next tick, her unpushed work is not.
- Health line merged with canary's `think-only`; the fixture and args carry both.
- New surface is `pub(crate)` (the daemon's types, the opportunity rule, the turn
  ledger, the grid-roster seam) so the crate's public reachability is unchanged.
  `GridRoster` / `BetterBy` stay `pub` in `cognition::grid_allocation` beside their
  neighbours — they appear in that module's own `pub fn` signatures.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…red_tps_for` went with the #4194 revert

CI (the compiler) caught the one symbol the rebase carried over from the reverted
output-allowance work. `decode_knee::tps_for` is the rate this box measured at the
LIGHTEST trusted concurrency; the plan's own lane count already respects the measured
knee (`plan_serving` applies `knee_lanes`), so "every lane here decodes at or above
the floor" is the plan's statement and this number says how fast. `None` (never
measured) stays an absence the allocator does not read as a refusal.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply force-pushed the feat/grid-allocator-daemon branch from 8857ae4 to c825ed3 Compare September 20, 2026 23:44
@joelteply
joelteply merged commit 57d5f00 into canary Sep 21, 2026
6 checks passed
@joelteply
joelteply deleted the feat/grid-allocator-daemon branch September 21, 2026 00:04
@joelteply

Copy link
Copy Markdown
Contributor Author

REVIEWED at c825ed3 by Fable. Cormac approved the design at 7530a15 and asked for one fold; the rebase did that and more, so I am merging.

The fold he asked for, done: roles_from_ids is deleted for canary roles_from, and window_allocator::requirements_for + largest_known is now the ONE requirement derivation, used by the serving daemon in place of its inline copy and by the daemon. One requirement vocabulary in the crate instead of two.

The finding inside that fold is the one I care most about: experience::source::resident_citizens was the only reader and it DROPPED CitizenRequirement, so the field that landed earlier tonight in #4271 could not reach the allocator at all. A declared window existed, compiled, serialized, and was read by nobody. That is the defect-between-components shape, and it is exactly the kind that survives a green test suite.

Two compositions I asked to be re-verified and were: decode_knee::tps_for resolves after the #4194 revert took measured_tps_for with it, and the opportunity path calls move_blocker_bounded before both come_home_for_good and request_reservation — so an opportunity move is gated on her workspace reaching origin before any seat is taken. That is #4278 composing with a PR written before it existed, and the agent caught it unprompted.

The separate OpportunityInputs beside PlacementInputs is the right call: the failure rule inputs are per-seat and this one per-allocation, and widening one struct would have mixed two decisions.

Honest gap, named rather than hidden: the dormant slow-clip TURN is not implemented because no seam exists to hand a dormant mind a turn from slack. The ordered list, the derived interval and the probe are published for whoever builds it. That matches the law as Joel stated it — dormant is not off — without pretending the clock exists yet.

APPROVE at c825ed3 — merging.

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