One sweeping supervisor per mesh
Measured 2026-11-23 on the control instance (three portal replicas). ThreadSupervisor is a hosted service, so
every replica ran its own sweep clock over the same thread set and wrote the one Admin/Threads node. Two
consequences:
- Duplicated recovery. A relaunch is not idempotent (it counts toward
maxRetries), and each replica read the same parked thread and acted on it. Idempotent filing into triage (the id is the episode's) hid the worst of it. - A write storm on the status node. The dispatch pool is per PROCESS, and each replica's pool published its own census (rows, bulkhead counters) over the shared node, so the replicas rewrote each other's facts. The node's version history showed one write every 4 to 15 s (about 8 per minute) although the sweep summary is heartbeat-limited to 600 s.
The rule
The sweeper is whoever holds a lease recorded on the status node (leaseHolder, leaseToken,
leaseRenewedAt, leaseReleasedAt; SweepLease is the pure rule, the same as the babysitter's).
| State | Decision |
|---|---|
| no lease | take it, token 1 |
| held by this process | renew, WRITTEN only every third of the lifetime (a renewal that is not due is not a version) |
| released, or no renewal for the lifetime | take over, token + 1 (the failover) |
| held by another process | stand by |
The lifetime is five minutes, or three sweep intervals when the operator slows the sweep.
- Every sweep tick begins with a beat. Only the holder runs the scan, the actions (wake, relaunch, settle) and the summary write. A standby still refreshes the model catalog, which feeds its own pool.
- The pool's census publisher is gated on the lease (
ThreadDispatchPool.PublishGate), so one process writes the census. The gate is open until a supervisor's first beat, so a booting mesh is never left without one. - A takeover is contested: standbys that see the same expiry compute the same next token, both write, the owner applies the writes one after the other and the later wins. A replica therefore believes a take only after it has settled (two seconds) and a fresh read of the node still names it; the loser stands by. A failed read or write answers "stand by": a standby is safe, a double sweeper is not.
- The summary write is fenced by token and holder: a replaced holder finishing its sweep cannot overwrite its successor.
- A clean shutdown releases the lease at once (
StopAsync); a crash is covered by the lifetime, so a dead owner's sweeps resume within five minutes.
SweepOnce() stays the un-gated test seam; only the clock is gated.
Evidence
SweepLeaseTest (the pure rule, including the expiry boundary and the negative control that a replaced owner
stands by) and ThreadSupervisorSingleOwnerTest (two supervisors on one mesh: the standby sweeps and writes
nothing across its ticks, takes over when the holder's lease lapses with token 2, and the old holder then stands
by).
Not covered
The pool's census still describes only the owner's process. A thread queued in another replica's pool is
protected by the queuedUntil stamp on its node, not by the owner's pool. Making the census fleet-wide is a
separate change.