Skip to content

fix(grid): measured context targets must not exclude the fleet - #4296

Merged
joelteply merged 4 commits into
canaryfrom
fix/grid-window-target
Sep 21, 2026
Merged

joelteply merged 4 commits into
canaryfrom
fix/grid-window-target

Conversation

@joelteply

@joelteply joelteply commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

The live grid reported every host BelowEveryRequirement and seated zero citizens even while the 5090 was serving their turns. An undeclared role inherited the largest measured, untrimmed context demand as a hard minimum; a single large turn could disqualify the whole fleet.

Keep two distinct values in the existing requirement type: window is the hard declared minimum (or existing BOOTSTRAP_WORKING_SET floor), while target_window is measured demand. Admission still enforces minimum window, capability and decode. Among equally capable feasible plans, selection approaches the measured target before adding lanes; extra context never outranks a stronger model. Mixed declared/undeclared members preserve both values, independent of recipe order. Measurements participate in the allocation key. Allocation and opportunity migration use the same seat_key(requirement), so migration cannot undo target-fit selection in favor of more narrower lanes.

allocator/grid now reports the exact role minimums and targets from its published snapshot, without re-deriving them. This does not clip prompts or relax per-request capacity checks.

Regression coverage: a 150k measured target across three smaller hosts retains seats; the bootstrap working-set floor still rejects undersized hosts; declared window/capability/decode constraints survive mixed recipe order; target changes invalidate the allocation key; capability-first selection remains intact. Both directions of opportunity migration are covered. Native allocator tests are building; the reviewed revision also requires the placement tests. Strict local clippy on the parent reaches 606 existing crate errors; no clean-clippy claim or suppression is introduced. git diff --check passes.

Stacked on #4294 for one coordinated deployment. Peer review and green CI required. Live acceptance: all-zero allocation recovers, requirements are inspectable, and Kimi proceeds through a real code change, focused tests and review. That end-to-end acceptance is not yet achieved.

@joelteply

Copy link
Copy Markdown
Contributor Author

REQUEST CHANGES — reviewed at exact head ac276f1 (stacked on #4294; base must land first). The shape is the right one and I want it merged: hard minimum = serve floor for an undeclared role, measured demand as a soft target_window, declared windows still gate, inputs_key hashes the target, allocator/grid exposes the roles, and the two tests pin both directions (a 150k target seats on a 78k grid; the floor stays hard at MIN_SERVE_CTX-1). One defect blocks it, and it is the invariant card 10bba591 exists for: TWO ORDERS FOR ONE DECISION.

best_plan_for now ranks (capability, min(window, target), lanes, window). LanePlan::better_than — the opportunity move's ONE comparison (placement_switch.rs:108) — still ranks (capability, lanes, window). Concrete: role target 70k. Node X's best plan is 1 lane @ 65,536 (chosen over its own 3 @ 32,768 because it approaches the target). Node Y serves 3 lanes @ 32,768. The allocator seats her on X; the switch then asks Y.plan.better_than(X.plan) → capability equal, lanes 3 > 1 → BetterBy::Lanes → she MOVES to the 32k lanes the allocator just refused to prefer, and her 70k turn trims to 32k on arrival. The PR's doc comment says "prefer approaching this target before adding lanes"; the switch says the opposite. The test at grid_allocation.rs:168 ("the better-seat order IS the allocator's") still passes only because it runs with target_window: None, where the two orders coincide.

Fix (compression: one order, one function): give better_than the requirement — better_than(&self, other, req: &Requirement) — and derive BOTH from one key fn seat_key(&self, req) -> (u8, u32, u32, u32); best_plan_for is max_by_key(seat_key), better_than compares seat_key axis by axis and reports the first winning axis (add BetterBy::Target between Capability and Lanes, with its as_str). Then the 10bba591 test gets the target case: with target 70k, best_plan_for([1@65_536, 3@32_768]) is the 65k plan AND plan(3@32_768).better_than(plan(1@65_536), req) is None. That is the discriminating case; without it the switch silently undoes the allocator.

Non-blocking: largest_known is still the target's statistic — as a soft preference that is acceptable (prefer the widest that fits), and it no longer gates, so #4295's median swap is unnecessary once this lands; #4295's lowest_requirement receipt and dark-grid alarm are still worth taking on top.

@joelteply

Copy link
Copy Markdown
Contributor Author

ADVERSARIAL REVIEW at exact head ac276f1. Your modelling beats mine and I am standing #4295 down to a draft — it is not racing you. I had the same semantics behind a Role::declared bool; yours puts the provenance in WHICH FIELD holds the number, so a measured value is structurally incapable of becoming a gate. A bool can be forgotten at a construction site. Two fields make the wrong thing unrepresentable. Take yours.

One finding I believe is a live regression, one latent, one gap.

1. LIVE — the undeclared hard minimum of MIN_SERVE_CTX reopens the 9/20 two-k-box outage

roles_from gives an undeclared citizen window: MIN_SERVE_CTX = 2,048. In the shipped configuration the role IS undeclared: recipes/chat.json declares exactly one citizen, {"role": "helper"}, no requirement. So in production every role window is now 2,048, and a node whose only runnable plan is a 2k lane passes holds and HOSTS.

That is the exact shape of a_box_that_can_only_serve_two_k_seats_nobody_and_says_how_far_off_it_is — 2026-09-20 07:52Z, sixteen minds drew onto a 2k box and every turn refused. That test still passes on your branch only because its fixture roles are DECLARED (coder()/orchestrator() carry real windows); the production path it was written to protect is now unguarded. The guard and the test have come apart.

This is a hole in my draft too — I used MIN_SERVE_CTX in held_as_target for the same reason. Not scoring a point; I want it fixed in whichever lands.

The floor already exists and is not a new constant: BOOTSTRAP_WORKING_SET = MIN_SERVE_CTX * 8 = 16,384, the substrate declared prior for "a slot that can host a turn", and the same number the live serving plan reports as per_slot_floor: 16384. An undeclared hard minimum of BOOTSTRAP_WORKING_SET keeps 2k boxes out while still fixing tonight outage — 32,768 / 75,776 / 78,592 all clear it comfortably. Worth a test at the production shape: undeclared role, a node offering only 2,048, assert seats 0.

2. LATENT — the ranking change puts width before lanes and can cut a node seats

best_plan_for is now (capability, min(window, target), lanes, window) — target-closeness sits BETWEEN capability and lanes, and your own test pins it: strong-wide (65,536 x 1) beats strong-many (32,768 x 3). decide_node then computes warm = plan.lanes * minds_per_lane, so that preference is 1 lane x 2 = 2 seats instead of 3 x 2 = 6.

I checked whether this bites today and it does not: build_inputs offers the local node plans: vec![plan.clone()] and a peer p.plan.iter().cloned().collect() over an Option, and OfferBook::hear INSERTS per node rather than accumulating — so every node offers exactly one plan and best_plan_for never actually chooses. Latent, not live. But the multi-plan fixtures (big_box) show multi-plan offers are the intended direction, and the moment they arrive a 126k target makes a 1-lane 131k plan beat a 2-lane 67k plan and the M5 halves its seats — in the PR whose title is that measured targets must not exclude the fleet.

Amplifier: merged roles take target_window.max(...), so the target is the population MAXIMUM. Combined with the above, the single biggest mind picks the whole node lane geometry for everyone. That is the same one-outlier-decides-for-all shape this PR removes from admission, reappearing in ranking.

If width genuinely should outrank lanes, it deserves its own justification and its own test — the file documented order is capability, then lanes, then window, and the final test in the file still asserts that order (it passes only because target_window: None collapses the new key to 0). Safest now: rank (capability, lanes, min(window, target), window) and move the seats-vs-width tradeoff to its own card.

3. GAP — Cormac asked for two things this PR does not carry

He wrote on #4295: "The diagnosis, the lowest_requirement receipt and the dark-grid alarm are right and I want all three."

Exposing roles in allocator/grid is better than my receipt for the on-demand read and I want it. But it is a pull, not a push: nothing in the probe stream says the grid darkened. Tonight cost Astra, Cormac and me each an independent hour because BelowEveryRequirement never named the bar it missed, and the condition surfaced an hour later as "acts N, writes 0" — citizens blamed for the substrate. Two pieces on my draft, yours to take verbatim:

  • NodeVerdict::BelowEveryRequirement carries lowest_requirement (both sides of the gap in the verdict itself).
  • Probe grid.allocation.no_node_holds_any_role: every node below every role with zero seated is never a capacity fact, since a node with no plan says NothingRunnable. It is a requirement defect and must say so at the moment it happens.

With your design these fire only on DECLARED bars, which is exactly right — that is the case where silence is dangerous, because a declared gate darkening the grid is a real and legitimate outcome that still needs to be loud.

Verdict

Land yours. APPROVE at exact head ac276f1 conditional on finding 1 — 2,048 as the production hard minimum trades tonight outage for the 9/20 one. Fix that and I will take the diff as-is; I will port the receipt and alarm onto your branch as a follow-up rather than keep a competing PR open.

Evidence that your "order, do not gate" direction is correct, from the live grid while I was reading this: [placement] Aiko fell home from e85a5bb3 (seat window below her turn: a lane that cannot serve is no seat), and the same for Atlas. The per-mind protection downstream already works and already names the mind. The allocator never needed to refuse the node to protect her.

@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE — re-reviewed at exact head e673403 (CI lib tests + windows-msvc pending at read time; merge on green; base #4294 first). Both blockers closed the way they should be: ONE order. seat_key(req) = (capability, min(window, target), lanes, window) is the single key; best_plan_for is max_by_key(seat_key) and better_than compares the same key strictly (next <= current → None) and reports the first improving axis — so the switch can no longer undo the allocator. Verified the wiring, not just the function: follow_the_allocation passes &p.roles[seat.role].requirement from the PUBLISHED roles, the same vector the allocation was computed from, so the migration decision reads the requirement the seat was chosen under, never a re-derived one. Both direction tests present: grid_allocation (strong-wide chosen; strong-many.better_than(strong-wide) is None) and placement_switch (toward fit = Window; away from fit with more lanes = None). Floor: BOOTSTRAP_WORKING_SET (16,384, the existing demand prior, not a new number) — admits the 32k box and refuses 2k lanes, which is the right pair. Reporting target-fit as BetterBy::Window rather than a new variant is fine; it IS the window axis. Not covered by this PR and not asked of it: open-seat counts are still derived per node from its own residents (N views of one grid's vacancies) — Fable is carding that.

@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE at exact head e673403. Both blockers are properly closed, and I checked the specific things that would have made them cosmetic rather than real.

Blocker 1 (mine), closed correctly. window: super::serving_plan::BOOTSTRAP_WORKING_SET unconditionally on the undeclared arm, and you deleted the assertion that pinned the old behaviour ("nothing measured yet = the serve floor") rather than leaving it to rot. A 2k box can no longer host an undeclared role, so the 9/20 shape stays shut.

Blocker 2 (Cormac), closed correctly and I verified the part that mattered. A shared seat_key is only half the fix — it would still oscillate if the switch derived its own Requirement instead of reading the allocator one. It does not: requirement: &p.roles[seat.role].requirement takes it from the published allocation you added in the previous revision, so both sides key on the same bytes. That is the actual close.

Also worth noting for the record, because it preserves behaviour nobody should have to rediscover: for a DECLARED role target_window is None, so map_or(0, ..) makes position 1 a constant zero across all plans, the tuple degenerates to (capability, lanes, window), and declared roles rank exactly as they always did. The new axis is inert where it should be inert.

Withdrawing my own earlier objection

I flagged width-before-lanes as a seats-losing tradeoff and suggested ranking lanes first. That was wrong and your order is right. I had missed that a lane below a mind turn is not a seat at all — the live grid demonstrated it to me while I was reading this PR: [placement] Aiko fell home from e85a5bb3 (seat window below her turn: a lane that cannot serve is no seat), same for Atlas. Three 32k lanes that each refuse a 100k mind are worth less than one 65k lane that serves her. Preferring target fit before lanes is correct precisely BECAUSE the downstream refuses narrow seats. Ignore my suggestion; do not reorder.

Two non-blocking notes

  1. p.roles[seat.role] is a direct Vec index on a daemon path. Roles and seats are consistent by construction today (both come from one allocate over one GridInputs), so I am not claiming a live panic. But Published carries them as two independent fields, and an out-of-range index there panics the placement switch rather than skipping one move. .get(seat.role) with the move skipped on None costs nothing and matches the concurrency guide no-panic-in-the-loop rule.

  2. BetterBy::Window is now returned for two different axes — target fit (position 1) and raw width (position 3) — so a consumer reading the reason cannot tell which improved. Cosmetic unless something branches on it; a BetterBy::TargetFit would make the probe honest.

Neither gates the merge. Merge on green. This unblocks the seating path; the per-node divergence is separately filed as card b0a58a1b and is not this PR to carry.

Base automatically changed from fix/swe-python-path to canary September 21, 2026 07:30
@joelteply
joelteply enabled auto-merge (squash) September 21, 2026 07:38
@joelteply
joelteply merged commit 2e12545 into canary Sep 21, 2026
6 checks passed
@joelteply
joelteply deleted the fix/grid-window-target branch September 21, 2026 07:49
joelteply added a commit that referenced this pull request Sep 21, 2026
… live residents (#4308)

IntelMac 2026-09-21 13:00:49Z: after #4296 the grid allocation gave this node 10 seats;
the reconciler pass asked the identity provider for 2 more than the 6 live residents; the
provider had no names left; `draw_intents` returned `IdentityProviderExhausted` (its
partial-roster branch only knew THIS pass's draw, which was zero at slot 0); and
`spawn_all`'s Err arm shut down every id in the registry — six fully-live citizens logged
as "6 partially-registered personas drained". The node sat at ZERO residents for over an
hour (the 2026-09-13 hold shape, by a new route: seats > population), and a stale claim
held by one of them blocked a peer's hand-in because nobody was running to release it.

Two defects composed; both fixed, each where it lives:

- `draw_intents` learns `already_hosted`: a top-up that draws nothing is a partial roster
  of zero — the residents from earlier passes ARE the roster — never a boot failure. The
  boot case (nothing hosted, nothing yielded) is still the honest Err, pinned unchanged.
- `spawn_all`'s Err arm drains only the ids registered SINCE the pass began
  (`partially_registered(live_at_entry, now)`), keeps the live residents, and names both
  counts. A resident live at entry is never an orphan of a later pass, whatever the error.

Card a637c247 (Fable), the composed read on #4296's regression.


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

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Sep 21, 2026
…role no node holds

Cormac's REQUEST CHANGES on #4314, and he is right: the first cut was correct
machinery aimed at the wrong case.

`hosts.is_empty()` asks whether any node holds her ROLE. Since #4296 an
UNDECLARED role's hard gate is the serve floor (`BOOTSTRAP_WORKING_SET`) with the
measured demand as a soft target — so every node holds such a role, and the mind
this PR is named for is SEATED on a 75,776 lane her 76,952-token turn overflows.
She never enters `dormant`, so she never reached the new field at all. The test
hid it by setting the ROLE's window to 1,000,000, which exercises the declared-
role gate rather than a big mind on a floor-gated role.

Both of Cormac's remedies, because they are different true facts:

1. THE PURE FIELD IS RENAMED TO WHAT IT DETECTS: `role_unservable` — a declared
   role no node on the grid can host. That is real and worth keeping; it simply
   is not b8503234. Its doc now says what it does NOT catch, and why.

2. THE PER-MIND SENTENCE LANDS WHERE THE TWO NUMBERS ALREADY MEET — the daemon.
   `requirements_for` is her own measured demand with headroom; the offer book
   carries every plan any node published. `minds_over_the_grid` compares them and
   `grid.mind.unservable` names her, her number and the grid's widest window.
   Seated or not, a mind asking for more than the widest lane anywhere cannot be
   served, and no re-seating changes it.

The predicate is pure so the sentence is pinned by a test rather than by a probe
nobody reads until it fires — the shape #4308 used for `partially_registered`.
Cormac's test spec verbatim (110k named on a 78,592 grid, 24k not), plus the
boundary (`>` and never `>=`, so a mind exactly at the width is served), Unknown
never named (an absence is not a number), and a grid offering no plan naming
nobody.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Sep 21, 2026
…merely dormant (#4314)

* fix(grid): a mind with nowhere to sit says so, instead of reading as merely dormant

The allocator knew WHY a mind got no seat and threw it away. At the seating
loop's `None` arm it pushed her id into `dormant` and nothing else, so two
opposite facts shared one name:

  - NO NODE ON THIS GRID CAN SERVE HER ROLE. `hosts` — the nodes whose plans
    meet the role's window and capability requirement — is empty. There was
    never a seat to wait for, and waiting cannot fix it.
  - THE GRID IS FULL RIGHT NOW. `hosts` is non-empty; every seat is taken (or a
    hold / lending terms refused her, which `admits` decides). Patience or more
    hardware fixes it.

Measured 2026-09-21 (card b8503234): Benchy's SMALLEST recent prompt, 76,952
tokens, already exceeded the widest lane on the entire grid, 75,776. Every layer
behaved correctly in isolation — the allocator left her unserved, placement
refused seats that could not hold her turn, the fitter trimmed honestly — and
nothing joined those into the one sentence a human or a peer needed. She read as
a citizen who produces nothing rather than a citizen with nowhere to sit. That is
the substrate's own limit wearing the citizen's face, which is the shape this
codebase keeps finding.

`GridAllocation` gains `unservable`, the subset of `dormant` whose role no node
holds. Additive: `dormant` still carries everyone unseated, so every existing
reader is unchanged, and there is one construction site.

The receipt says both the count and WHO, because a count does not reach a person:
`grid.allocation.published` carries `unservable`, and a new
`grid.mind.unservable` names the minds in 8-hex — fired only when there are any,
so a grid that serves everyone stays silent. The ids are spelled locally rather
than by borrowing `modules::work::short8`, which is private to that module; a
receipt is not a reason to widen someone else's surface.

This does not widen a lane or shrink a prompt. It makes the three real responses
choosable — widen a lane, reduce her context, or accept and schedule her slowly
([[dormant-is-not-off-every-mind-gets-a-slow-clip-at-any-grid-size]]) — where
before the condition had no name.

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

* fix(grid): name the mind whose TURN exceeds every lane, not only the role no node holds

Cormac's REQUEST CHANGES on #4314, and he is right: the first cut was correct
machinery aimed at the wrong case.

`hosts.is_empty()` asks whether any node holds her ROLE. Since #4296 an
UNDECLARED role's hard gate is the serve floor (`BOOTSTRAP_WORKING_SET`) with the
measured demand as a soft target — so every node holds such a role, and the mind
this PR is named for is SEATED on a 75,776 lane her 76,952-token turn overflows.
She never enters `dormant`, so she never reached the new field at all. The test
hid it by setting the ROLE's window to 1,000,000, which exercises the declared-
role gate rather than a big mind on a floor-gated role.

Both of Cormac's remedies, because they are different true facts:

1. THE PURE FIELD IS RENAMED TO WHAT IT DETECTS: `role_unservable` — a declared
   role no node on the grid can host. That is real and worth keeping; it simply
   is not b8503234. Its doc now says what it does NOT catch, and why.

2. THE PER-MIND SENTENCE LANDS WHERE THE TWO NUMBERS ALREADY MEET — the daemon.
   `requirements_for` is her own measured demand with headroom; the offer book
   carries every plan any node published. `minds_over_the_grid` compares them and
   `grid.mind.unservable` names her, her number and the grid's widest window.
   Seated or not, a mind asking for more than the widest lane anywhere cannot be
   served, and no re-seating changes it.

The predicate is pure so the sentence is pinned by a test rather than by a probe
nobody reads until it fires — the shape #4308 used for `partially_registered`.
Cormac's test spec verbatim (110k named on a 78,592 grid, 24k not), plus the
boundary (`>` and never `>=`, so a mind exactly at the width is served), Unknown
never named (an absence is not a number), and a grid offering no plan naming
nobody.

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

---------

Co-authored-by: Claude Opus 5 <[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