Skip to content

A grants waiter marks the current grants seen before it waits: an ungranted mind parks until a newer publish, never spins - #5753

Merged
joelteply merged 3 commits into
canaryfrom
fable/grants-waiter-marks-seen
Nov 4, 2026
Merged

joelteply merged 3 commits into
canaryfrom
fable/grants-waiter-marks-seen

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Fixes the spin that #5752 (d394694) put on the M5, which was rolled back to 0b28543 at 03:18Z. Serves the minds by making a mind without a grant wait quietly for one instead of burning the core.

The defect (measured)

On d394694 the core sat at 339% CPU, and delib.window.ungranted fired 751 times for Atlas in about a minute. grants_changed() cloned the installed watch receiver. That receiver never marks a value seen, so every clone's changed() resolved at once, and an ungranted mind looped measure -> wake -> ungranted with nothing changed. Atlas was ungranted because the pool launched small (49,664). The same latent spin sat in CapacityReadiness::wait's grants arm on any node with grants.

The change

  • GrantsWaiter::new marks the current grants seen (borrow_and_update); changed() resolves only on a newer publish.
  • The waiter is taken before the check it guards: decide_window takes one before each decision, and the readiness takes one eagerly before self.changed(), never lazily inside a later-polled block. A publish in between is never lost.
  • decide_window refuses with GrantsUnavailable only when she's ungranted. A decided window needs no watch.

Tests (on a LIVE tokio watch, not a fake future)

Measured

  • M5 serving-down windows 03:24-03:32Z: continuum-engine capacity:: 207 passed; continuum-cognition workspace + llm_deliberation_faculty 164; continuum-mind placement_switch 25. Clippy clean on changed lines.
  • Deploy order, per Joel's CPU gate: the IntelMac first (Cormac). Pass means the core's idle CPU is near zero between acts, and no delib.window.ungranted storm. Then the M5, with an interim read at 1 minute and the same CPU check.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 2 commits November 3, 2026 21:14
…ranted mind parks until a NEWER publish, never spins

d394694 (#5752) pegged the M5 core at 339% CPU: delib.window.ungranted fired 751 times for Atlas in about
a minute. grants_changed() cloned the installed watch receiver, which never marks a value seen, so every
clone's changed() resolved at once, and an ungranted mind looped measure -> wake -> ungranted with nothing
changed. The same latent spin was in CapacityReadiness::wait's grants arm on any node with grants. Rolled
back to 0b28543.

- GrantsWaiter::new marks the current grants seen (borrow_and_update); changed() resolves only on a newer
  publish. grants_waiter() is taken BEFORE each decision (decide_window) and before the readiness check, so
  a publish between the two is never lost.
- decide_window refuses with GrantsUnavailable only when she is ungranted; a decided window needs no watch.
- Tests on a LIVE tokio watch: a waiter over unchanged grants is Pending and one send wakes it; an ungranted
  mind is measured once, parks, and runs at her grant; no watch refuses only an ungranted mind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

PASS at 3d3672e (Cormac; author session 01LoTjvf…, not mine). This time I checked the wake semantics on the real primitive, which is where my #5752 pass failed.

Verified:

  • The live-watch test (a_waiter_parks_on_unchanged_grants_and_wakes_on_a_newer_publish) drives a real tokio::sync::watch. A clone of a receiver that never marked a value seen, exactly the M5's spin, is Pending on its first poll once GrantsWaiter::new has run borrow_and_update; one newer send wakes it.
  • No lost wakeup: decide_window takes the waiter FIRST in each iteration, before decide() and measure(). The grant her measurement triggers on the next serving tick is a change that waiter sees.
  • No wake without a change: publish_grants sends through send_if_modified (grants.rs:14), only when the grants differ. An ungranted mind wakes on a real change, never on every tick.
  • decide_window refuses only an ungranted mind when there is no watch; a decided or bound window needs none (tested).

Per Joel's gate: after merge, its binary goes to the IntelMac FIRST for idle CPU and CPU per act. I'm recording the b03d7c5 baseline now.

…future (unwired-machinery ratchet)

GrantsWaiter was a pub type constructed only in its own file, which the production_reachability ratchet
counts as unwired public machinery. Callers only await a newer publish, so grants_waiter() returns that
future and the type stays private; it still marks the current grants seen when called (eager), so no
publish between the waiter and the decision is lost. decide_window takes any such future.

M5 03:36Z: ratchets against canary pass; engine capacity::mind_window 3; cognition workspace::capacity 4;
clippy clean on changed lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

PASS at d1ecefa (Cormac). The delta from 3d3672e is visibility only: GrantsWaiter is private, grants_waiter() returns the opaque future, and decide_window is generic over it.

The one thing that could have broken: grants_waiter() still marks the current grants seen EAGERLY. GrantsWaiter::new(rx) (borrow_and_update) runs inside the map closure when it is called, and only .changed() is the lazy future. A publish between taking the waiter and polling it still wakes it, so there is no lost wakeup. The live-watch test (a_waiter_parks_on_unchanged_grants_and_wakes_on_a_newer_publish) is unchanged.

@joelteply
joelteply merged commit 95f8ebb into canary Nov 4, 2026
32 checks passed
@joelteply
joelteply deleted the fable/grants-waiter-marks-seen branch November 4, 2026 03:49
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