Repository navigation
fix(relay): define restart-safe by the cell runtime, and refuse waves without headroom - #24259
Conversation
…emain The c28 canary on 2026-10-01 drained the cell to zero live connections, but four hosts with no free slot anywhere kept redialling and held director leases on it, so the restart-safe wait timed out and left the cell isolated and empty. The drain wait now also passes once the runtime has carried nothing for a sustained quiet window while a small, capped number of leases remain, and logs the escape. Apply modes also refuse a cell whose hosts exceed 80% of the free slots on the other general cells, so a wave cannot strand hosts in the first place. Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
|
|
|
||
| # Hosts drained with nowhere to go keep redialling and pin the cell empty (c28, 2026-10-01). | ||
| - name: Require free general-cell slots for the selected cell's hosts | ||
| if: ${{ inputs.mode == 'canary-apply' || inputs.mode == 'batch-apply' }} |
There was a problem hiding this comment.
Headroom gate never runs The parent workflow changes both
canary-apply and batch-apply to apply before calling this job. This condition therefore never matches: apply runs skip the new headroom check and can still drain a cell when its hosts have nowhere to go.
| if: ${{ inputs.mode == 'canary-apply' || inputs.mode == 'batch-apply' }} | |
| if: ${{ inputs.mode == 'apply' }} |
Knowledge Base Used: Roll a cell stranded after its drain
Replaces the opt-in stranded-host escape with a corrected definition. A restart is safe when the cell runtime carries nothing live and no migration is open, sustained for the drain pace window. Director activity leases lag hosts that already left or cannot be placed, so they are reported in a progress line and the verified result instead of blocking the restart. The same-cap drain passes its existing pace window. The headroom script is added to the trusted evidence code paths with the other production scripts. Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
There was a problem hiding this comment.
Important
The new headroom gate measures free slots differently from the director's authoritative placement predicate, so it can approve a wave whose hosts then find nowhere to go — the c28 failure it was written to prevent.
Reviewed changes
- Stranded-host drain escape —
verify-relay-capacity-transition.mjsgains an opt-in--stranded-quiet-ms/--max-stranded-leasesmode that accepts a restart-safe drain while up to 25 restart-blocking leases remain, provided the cell runtime carries nothing and the state holds unbroken for the quiet window; emits arelay_capacity_transition_stranded_escapeevent. - Pre-mutation headroom gate — new
check-relay-same-cap-headroom.mjsrefusescanary-apply/batch-applywhen the target cell's hosts exceed 80% of free slots on other general cells. - Workflow wiring — the same-cap job runs the gate before isolation and passes the escape flags to the drain verifier.
- Docs and package — documents both behaviors and registers the new test file.
The escape itself checks out: an independent trace confirms enforcedConnectionUnits is derived (= totalConnections + inFlight + reserved), the union of strandedHostsOnly and runtimeQuiescent's restart-safe list covers every live runtime counter, and the director counters it omits are reconnect reservations that survive replacement or stale heartbeat snapshots superseded by the live runtime read.
⚠️ Headroom gate overcounts free slots relative to the director's placement predicate
freeSlots computes normalAdmissionPause - observedConnections, where observedConnections maps to the DB column total_connections and pendingControlReservations is ignored. The director's own admission predicate is stricter: it requires enforced_connection_units + outstanding_reservations + unobserved_bound < hard_cap - reservedHostControls. Because the heartbeat contract enforces enforced_connection_units = total_connections + in_flight_connections + reserved_connection_units, the gate reports up to in_flight + reserved + pendingControlReservations extra free slots per cell, and allowedHosts = floor(freeSlots * 0.8) inherits the inflation. A cell can show headroom on the gate while the director's connectionHeadroomByCell returns false, so the gate can pass a drain whose hosts then strand. Details and a one-function fix are inline.
Technical details
# New headroom gate does not mirror the director's placement predicate
## Affected sites
- `cloud/dev/scripts/check-relay-same-cap-headroom.mjs:75-76` — `freeSlots` subtracts only `observedConnections`.
- `cloud/docs/relay-workflows.md:405-406` — repeats "normal admission pause minus observed connections".
## Evidence
- `cloud/apps/relay/src/assignment-store.ts:7680-7686` (`connectionHeadroomByCell`):
`enforced_connection_units + outstanding_reservations + unobserved_bound < hard_cap - reservedHostControls`.
- `cloud/apps/relay/src/app.ts:1507-1521` and `cloud/apps/relay/src/assignment-store.ts:1440-1443` enforce
`enforced_connection_units = total_connections + in_flight_connections + reserved_connection_units`.
- `cloud/apps/relay/src/assignment-store.ts:3449-3472` maps the status fields:
`observedConnections -> total_connections`, `pendingControlReservations -> outstanding_reservations`.
## Required outcome
- The gate's free-slot count and pass/fail verdict should agree with what `connectionHeadroomByCell` will actually place.
## Suggested approach
- Subtract `enforcedConnectionUnits + pendingControlReservations` instead of `observedConnections`; `unobserved_bound` is already baked into `normalAdmissionPause`.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Each restart-safe poll now prints its sample count and the director's restart-blocking leases, request units, reserved remainder, and migrations under `stranded`; the verified line carries the same object. Open migrations still block because each is pinned to the cell incarnation a restart replaces. Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
Pre-auth and total connections no longer reset the restart-safe window: on drained c28 they flickered with unauthenticated redials in a third of samples, which a restart does not lose. They stay in the progress output. Every live restart-safe call must now pass --pace-window-ms. The capacity job and staging proof drain unpaced, so they pass the production 300000 ms window, and the calls that relied on the 180000 ms default get 480000 ms. Headroom free slots now follow the director's placement rule: the admission pause minus the larger of observed and enforced units, minus outstanding control reservations. Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
There was a problem hiding this comment.
Important
The restart-safe rework is a clean simplification — an independent trace confirms it cannot pass while a live host session exists. One timing regression: the drain verifier's timeout no longer covers the wait it now requires.
Reviewed changes
- Restart-safe defined by the cell runtime —
--activity restart-safenow passes on the runtime's live counters plus no open migration, for a whole drain pace window; directorrestartBlocking*counters are validated and reported understrandedinstead of gating, and the opt-in stranded-escape flags are gone. - Pace-window sampling — new
--pace-window-msmakes the verifier require a full pace window of consecutive quiet samples (61 for the 5-minute window, 2 for callers that pass none) and emitsrelay_capacity_transition_restart_progresson every sample. - Wiring and provenance — the same-cap drain and verify steps pass
DRAIN_PACE_WINDOW_MS, and the headroom script joins the trusted evidence paths. - Docs and tests — updated for the new definition and the
strandedreporting.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| --heartbeat either --admission migration-only --draining required \ | ||
| --activity restart-safe --expected-image-digests "${PREDECESSOR_IMAGE_DIGEST}" \ | ||
| --timeout-ms 1200000 | ||
| --pace-window-ms "${DRAIN_PACE_WINDOW_MS}" --timeout-ms 1200000 |
There was a problem hiding this comment.
The verifier now needs a full 5-minute quiet window (61 consecutive samples) after the last open migration clears, but --timeout-ms stays 1200000. This workflow's own comment budgets that timeout as the 15-minute migration lease (ASSIGNMENT_LIMITS.migrationLeaseMs) plus the 5-minute window — 900s + 300s = 1200s exactly — so the per-poll HTTP latency pushes the worst case past the deadline and the verify step fails.
Technical details
# verify timeout equals lease + window, leaving no polling margin
## Affected sites
- `.github/workflows/cloud-deploy-relay-production-same-cap-job.yml:593` — passes the pace window while keeping `--timeout-ms 1200000`.
- `cloud/dev/scripts/verify-relay-capacity-transition.mjs:423-424` — `requiredRestartSafeSamples = max(ceil(paceWindowMs / 5000) + 1, 2)`, so 61 samples = 60 waits of `>= 5000ms` after the window starts.
- `cloud/dev/scripts/verify-relay-capacity-transition.mjs:210-221` — an open migration resets `restartSafeSamples`, so the 300s window only begins once migrations clear.
- `cloud/packages/relay-contract/src/assignment-invariants.ts:7` — `migrationLeaseMs: 15 * 60 * 1000` (900s).
- `.github/workflows/cloud-deploy-relay-production-same-cap-job.yml:65-66` — the comment already states the transition wait is the 15-min lease plus this window.
## Required outcome
- `--timeout-ms` should exceed the migration lease plus the pace window by enough margin for the per-poll HTTP round trips the verifier makes, so a migration that clears near its lease end does not guarantee a timeout.
## Suggested approach
- Raise `--timeout-ms` (e.g. `1500000`) in this step; the budget is currently consumed entirely by `900_000 + 300_000`.
- Optionally cap `--pace-window-ms` in `parseCapacityTransitionArguments` at `DRAIN_PACE_WINDOW_MAX_MS` (the drain script already rejects anything above 300000), so a hand-run cannot request a window larger than the timeout can cover.There was a problem hiding this comment.
ℹ️ No new issues in the latest commit. It resolves the headroom free-slot arithmetic (previous thread replied and resolved) and makes
--pace-window-msmandatory for every live restart-safe wait, with all live callers updated. The verify-timeout margin raised in the previous review is untouched and remains open.
Reviewed changes
- Headroom arithmetic corrected —
freeSlotsnow subtractsmax(observedConnections, enforcedConnectionUnits)pluspendingControlReservations, matching the director'sconnectionHeadroomByCellplacement predicate. - Pace window made mandatory — every live restart-safe wait must pass
--pace-window-msand every offline one must not; the production capacity and staging-proof jobs defineRESTART_SAFE_PACE_WINDOW_MSand pass it with raised timeouts. Verified no live caller across the workflows is missing the flag. - Restart-safe counters narrowed — pre-auth and total connections are printed but no longer reset the window, since they count unauthenticated redials; docs and tests follow.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Before a relay cell is restarted for an update, the workflow moves every connected computer off it, then waits until restarting is safe. "Safe" used to mean the central director had no record of any computer still using the cell. When the rest of the fleet is full, a few computers have nowhere to go and keep retrying. The director keeps a record for each one even though none of them is connected, so the wait never ends. This PR makes "safe" mean what it is for: the cell itself is carrying nothing. It also stops an update from starting when the fleet has no room for the cell's computers.
What Changed
Before: On 2026-10-01 the same-cap canary drained production cell c28 until its runtime reported zero connections. Four hosts could not be placed anywhere and redialled every 30 seconds. Each redial left a director-side activity lease on c28. The restart-safe check required those leases to be zero, so it waited out its 20-minute timeout and failed the wave. That left the cell isolated, empty, and never restarted. Rollback re-runs the same check, so it could not recover either. Recovery needed a manual VM reset.
After:
--activity restart-safenow passes when all of the following hold:stranded, as arelay_capacity_transition_restart_progressline, together with the migration counts. The final verified line includes the samestrandedobject.--pace-window-msis now required on every restart-safe wait against a live runtime. Each poll waits the full five-second interval, so the sample count is a floor on real elapsed time.DRAIN_PACE_WINDOW_MS.RESTART_SAFE_PACE_WINDOW_MSjob variable.canary-applyandbatch-applybefore anything is isolated. It counts the target cell's hosts from its runtime, and the free slots on every other general cell from the director's existing per-cell status. A cell's free slots are its normal admission pause, minus the larger of its observed connections and enforced connection units, minus its outstanding control reservations. That mirrors the director's placement rule, which admits a host only while enforced units plus outstanding reservations stay under the pause. A cell that is stale, disabled, not general, or missing capacity data counts as zero. The step prints the totals split by same region and other regions, and fails when hosts exceed 80% of the free slots.verifyandrollbackare unaffected.Why
Restart-safety exists so a restart loses no live session. The cell runtime's counters measure that directly. Director leases are a record that lags behind hosts that already left or cannot be placed, so gating on them blocks safe restarts and protects nothing.
Open migrations still block. Each open migration is pinned to the source and target cell incarnations, and a restart replaces this cell's incarnation. The director then rejects the next drain with
drain_migration_source_incarnation_mismatch.Pre-auth and total connections do not reset the window. While c28 sat drained, it was sampled 58 times between 00:37Z and 01:06Z. Controls, in-flight connections and splices were zero throughout. Total connections read 1 to 3 in 19 samples and pre-auth connections read 1 in 5 samples. Both came from stranded hosts' unauthenticated redials and probes. A restart loses none of that, because the client simply retries, and gating on them would mean the window never closes.
An earlier version added an opt-in escape with its own quiet window and lease cap. It was dropped because it kept the wrong definition and added two tuning numbers. Changing the director so an unplaceable redial leaves no lease would touch live placement code and still leave the verifier's definition wrong.
The headroom gate reuses the per-cell status endpoint the workflow and incident preflight already read with the same token, so no new director endpoint is needed. It counts hosts as controls. Each moved host also brings its splices, and the 20% margin is for those. The script is added to the trusted evidence code paths with the other scripts these jobs run against production.
Linked Issue
N/A, internal incident follow-up.
Visual Proof
N/A. This changes deploy workflow scripts only, with no UI.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Verifier tests cover these cases. The check passes after one pace window of an empty runtime. The window resets on any non-zero live sample. Alternating pre-auth and total-connection redials still let the window complete. Every live counter and each migration direction still fails whatever the lease counts are. Each sample prints the stranded counts. The pace window is required exactly for live restart-safe waits. Existing tests that treated leases or pre-auth sockets as unsafe were moved to the new rule.
New headroom tests cover the slot arithmetic, including enforced units and reservations, the 80% boundary, stale and non-general cells, an empty general list, mismatched answers, and the printed output.
node --testover every script incloud/package.json'spretestandtestlists passes: 835 tests, 0 failures.pnpm typecheckincloud/passes after the workspace packages are built.Nothing ran against production. The first live run of both changes will be the next same-cap wave.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Mixed versions: the gate reads only fields the director already returns under capacity protocol 2, which the workflow already requires. Both new code paths are read-only.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)