Skip to content

fix(relay): define restart-safe by the cell runtime, and refuse waves without headroom - #24259

Merged
Jinwoo-H merged 4 commits into
mainfrom
relay-same-cap-stranded-escape
Oct 1, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
relay-same-cap-stranded-escape

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​369 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​350
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​258 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​230

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:

  • New definition of restart-safe. --activity restart-safe now passes when all of the following hold:
    • the cell runtime reports zero controls, in-flight connections, reserved connection units, splices, pending splices, and queued bytes;
    • the runtime is draining and the director holds the cell migration-only;
    • no migration into or out of the cell is open;
    • all of that holds on consecutive samples covering one drain pace window.
  • What still refuses. A non-zero runtime counter or an open migration resets the window. The identity, image, capacity, and heartbeat checks are unchanged.
  • Director leases are reported, not gated on. Restart-blocking leases, their request units, and the reserved-request remainder no longer block. Every progress sample prints them under stranded, as a relay_capacity_transition_restart_progress line, together with the migration counts. The final verified line includes the same stranded object.
  • Window length, one definition for every caller. --pace-window-ms is 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.
    • The same-cap drain passes its existing DRAIN_PACE_WINDOW_MS.
    • The production capacity job and the staging capacity proof drain without pacing and have no pace value of their own. They pass the same production value, 300000 ms, through a RESTART_SAFE_PACE_WINDOW_MS job variable.
    • The capacity job's two restart gates keep their 450000 ms timeouts and its one-line stderr timeout parse. The calls that relied on the 180000 ms default, which is shorter than the window, now pass 480000 ms.
    • The offline-rollback calls, where the runtime is unreachable, take no window and are unchanged.
  • Pre-auth and total connections are printed, not gated on. Each progress sample shows them next to the stranded counts.
  • Headroom gate before mutation. A new read-only step runs in canary-apply and batch-apply before 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. verify and rollback are 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 --test over every script in cloud/package.json's pretest and test lists passes: 835 tests, 0 failures. pnpm typecheck in cloud/ 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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Critical risk] Changes relay capacity deployment and restart-safe verification logic.

The PR does not appear safe to merge because the headroom check still does not run for apply waves.

Findings

  1. P1 Headroom gate never runs ▶

Summary

The PR changes restart-safe verification to require an empty cell runtime across a drain pace window, reports director-side stranded activity without gating on it, and adds a pre-drain headroom check to the same-capacity apply workflow.

  • Production and staging workflows pass the new pace-window argument.
  • Tests cover the quiet window, runtime blockers, headroom calculation, and reported progress.

Reviews (2) · Last reviewed commit: "fix(relay): require the pace window for ..."


# 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' }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Suggested change
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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.mjs gains an opt-in --stranded-quiet-ms/--max-stranded-leases mode 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 a relay_capacity_transition_stranded_escape event.
  • Pre-mutation headroom gate — new check-relay-same-cap-headroom.mjs refuses canary-apply/batch-apply when 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`.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H Jinwoo-H changed the title fix(relay): let a same-cap drain finish when only unplaceable hosts remain fix(relay): define restart-safe by the cell runtime, and refuse waves without headroom Oct 1, 2026
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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-safe now passes on the runtime's live counters plus no open migration, for a whole drain pace window; director restartBlocking* counters are validated and reported under stranded instead of gating, and the opt-in stranded-escape flags are gone.
  • Pace-window sampling — new --pace-window-ms makes the verifier require a full pace window of consecutive quiet samples (61 for the 5-minute window, 2 for callers that pass none) and emits relay_capacity_transition_restart_progress on 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 stranded reporting.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues in the latest commit. It resolves the headroom free-slot arithmetic (previous thread replied and resolved) and makes --pace-window-ms mandatory 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 — freeSlots now subtracts max(observedConnections, enforcedConnectionUnits) plus pendingControlReservations, matching the director's connectionHeadroomByCell placement predicate.
  • Pace window made mandatory — every live restart-safe wait must pass --pace-window-ms and every offline one must not; the production capacity and staging-proof jobs define RESTART_SAFE_PACE_WINDOW_MS and 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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 7c11946 into main Oct 1, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant