Skip to content

fix(relay): let a draining cell pass restart-safe through refused redials - #24347

Merged
Jinwoo-H merged 2 commits into
mainfrom
fix/relay-restart-safe-draining
Oct 1, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
fix/relay-restart-safe-draining

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12

ELI5

Before a same-cap rollout restarts a drained relay cell, a wait step checks that the cell holds no real work for one full drain window, about 61 clean samples five seconds apart. On production-gce-c29 that wait kept restarting from zero. Phones and hosts that still remembered the old cell kept dialling it, and the cell was about to turn every one of them away. The step timed out and left the cell isolated. This change stops counting those doomed dials as work.

What Changed

Before. The restart-safe wait treated any in-flight or reserved connection unit on the cell as live work. The 2026-10-01 c29 roll was run 36839965464. The cell drained from 2,750 hosts to zero between 09:05:34 and 09:10:39Z. The streak then reset about 20 times between 09:10:50 and 09:21:52Z. The step's 20-minute timeout expired at 09:25:42Z with the streak at 38 of 61.

What reset it. c29's per-minute runtime metrics show the same shape every time the cell held a connection: one physical socket, one reserved unit, two enforced units, zero in-flight units, and zero controls. That is the phone admission path, which reserves a host-data unit beside the phone's socket. The cell keeps that unit through the first frame, the assignment lookup, and the credential check, then answers wrong-cell or host-offline. Host control redials, the earlier suspect, briefly hold an in-flight unit and then a physical socket. The gate never read physical sockets, and its in-flight check would only fire if a sample landed inside a microsecond window. The progress line did not print the reserved counter, so the job log alone could not show this.

After. On a cell whose live runtime reports draining, restart-safe still requires zero controls, splices, pending splices, and queued bytes, plus zero incoming and outgoing migrations from the director. It tolerates in-flight and reserved units. Those counters are still parsed, so a malformed runtime still fails the step. Non-draining runtimes behave as before, and the quiescent and allowed modes are untouched. The progress line now prints the admission state, the draining flag, every runtime counter, and director heartbeat freshness, so the next reset can be diagnosed from the job log.

Why it is safe. The cell's draining flag is read live, in the same synchronous response as the counters, and the cell only ever sets it to true. A draining cell closes every new control upgrade with a draining code. It also refuses any host proof that completes after the drain began. So once controls are zero, no session can appear, and a reserved or in-flight unit can only belong to a dial that ends refused. Explicit migrations are gated separately on the director's counters. A restart loses nothing such a dial holds; the dialler simply redials and the director places it.

Why

  • A persistence bound was rejected. I considered treating a reservation seen on two consecutive samples as real work. The counters carry no identity, so a phone retrying every few seconds looks exactly like a stuck reservation. c29 itself showed reserved units on back-to-back metrics samples. A leaked reservation is also not work a restart destroys; the restart clears it. A bound would bring back the false resets without making anything safer.
  • Gating on physical sockets was rejected. The gate already ignored total and pre-auth connections for the same reason.
  • Fixing it in the cell was deferred. That needs a separate, compatibility-checked change, described in the follow-up below.

Follow-up, not in this PR. The cell should refuse a control upgrade while draining before it reserves a ledger unit and completes the WebSocket upgrade. It should do the same for the phone path when the host is not here. Desktop and mobile clients update independently of cells. That change needs an old-client check that a pre-upgrade HTTP refusal still makes every shipped client re-ask the director, rather than back off as if the relay were down.

Linked Issue

N/A. This is a maintainer change, and the incident has no existing issue.

Visual Proof

N/A. This changes a rollout verification script, with no UI.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • The new tests are in the script's existing test file. A draining cell reaches the 61-sample window while phone-shaped and control-shaped refused dials alternate. A persistent control beside those dials never counts a sample. A runtime that is not draining never passes. Quiescent transitions still reject both dial shapes. The progress line carries every counter the gate reads.

  • I tightened the existing suite named "restart gate rejects live or durable cell work". Its zero timeout meant every case timed out whether or not the blocker worked. It now asserts that the blocked sample did not count.

  • Mutation checks. Disabling the draining tolerance fails the new redial test. Dropping controls from the gate fails eight tests.

  • New fail-closed tests send a negative, fractional, or non-numeric in-flight or reserved counter to a draining cell, and the step must throw. Removing that validation fails them.

  • The cloud script list from the test script in cloud/package.json passes with node --test.

AI Disclosure

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

There is no client, SSH, mobile, or wire impact. The change only touches operator tooling that reads cell and director admin status.

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)

…ials

A draining cell refuses every control and host proof, so once no session,
splice, or queued byte remains, an in-flight or reserved connection unit can
only belong to a dial the cell is about to refuse. The restart-safe wait no
longer resets its pace-window streak on those units, and its progress line
now prints every counter the gate reads.

Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4b1dd863-7240-42cb-a81d-34c81bd4781a

📥 Commits

Reviewing files that changed from the base of the PR and between f0f6f39 and 4468daf.

📒 Files selected for processing (1)
  • cloud/dev/scripts/verify-relay-capacity-transition.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The restart safety check now allows nonzero in-flight and reserved connection units when the runtime is draining. Other listed activity counts must remain zero. Restart progress events now report runtime state, counters, and director heartbeat freshness, with a runtime heartbeat fallback. Tests cover refused redials, persistent controls, non-draining states, timeout samples, and progress data.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 4468d

During draining, malformed reserved-connection data can be overlooked and a sample can be counted as restart-safe. Fix the counter validation before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 4468d

The restart gate can now accept malformed reservation data under a particular draining state. Existing identity, admission, migration, and active-work checks constrain the impact, but the assessment did not establish that every deployed cell version enforces the refusal behavior on which the relaxed gate depends.

Retained concerns

  • Medium · reliability · observed: A draining runtime with valid nonzero inFlightConnections can bypass validation of malformed reservedConnectionUnits. With other blockers clear, that observation can count toward restart authorization, weakening the gate's fail-closed telemetry contract. This is a restart failure-containment defect, not evidence of an unauthorized restart or active-session loss.
Security review details

Security Blast Radius

  • inferred — The demonstrated exposure is a restart decision for the operator-selected relay cell and any work whose safety depends on that decision. The inspected consumer targets that cell's template and instance group; the change does not demonstrate additional IAM authority, credential access, or arbitrary-cell selection.

Security Findings and Attack Paths

  • inferred — The counter-validation defect is conditional on malformed admin telemetry alongside nonzero in-flight activity. Refused redials provide the activity scenario modeled by the tests, but no inspected evidence establishes that an unauthenticated peer can forge the malformed reserved counter or bypass the remaining restart controls.

Trust Boundaries and Controls

  • observed — Runtime and director reads carry an admin bearer token. Live restart-safe checks require migration-only admission and draining, bind responses to the expected cell and image, require zero active-work counters and migrations, and apply configured capacity and heartbeat expectations. These controls constrain the relaxed handshake-counter branch.

Resilience and Maintainability Implications

  • observed — The expanded progress event exposes the state used to interpret the gate. However, observation normalization converts malformed counters to null without rejecting them, so diagnostic reporting does not compensate for skipped reservation validation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: allowing a draining relay cell to pass the restart-safe check when refused redials occur.
Description check ✅ Passed The description is detailed and covers the required change, rationale, testing, visual proof, scope, and checklist. It also explains why the linked issue is not provided for this maintainer change. Th…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 14b2dda9-513c-42a7-8243-4e75591bef7d

📥 Commits

Reviewing files that changed from the base of the PR and between 67014c8 and f0f6f39.

📒 Files selected for processing (2)
  • cloud/dev/scripts/verify-relay-capacity-transition.mjs
  • cloud/dev/scripts/verify-relay-capacity-transition.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

].every((value) => integer(value, 'live runtime count') === 0)
]) &&
// Still validated on a draining cell so a malformed runtime fails closed.
(liveIdle([runtime.runtime?.inFlightConnections, runtime.runtime?.reservedConnectionUnits]) ||

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n 360,395p cloud/dev/scripts/verify-relay-capacity-transition.mjs
rg -n 'reservedConnectionUnits|inFlightConnections|const integer|function integer' cloud/dev/scripts/verify-relay-capacity-transition.mjs

Repository: stablyai/orca

Length of output: 2339


🏁 Script executed:

sed -n '1,25p' cloud/dev/scripts/verify-relay-capacity-transition.mjs
sed -n '250,330p' cloud/dev/scripts/verify-relay-capacity-transition.mjs
sed -n '396,521p' cloud/dev/scripts/verify-relay-capacity-transition.mjs

Repository: stablyai/orca

Length of output: 9868


Validate both counters before applying draining tolerance.

When inFlightConnections is nonzero, liveIdle stops before it parses reservedConnectionUnits. transitionObservation does not make this safe because aggregateCount converts malformed values to null instead of throwing. A draining sample can therefore count as restart-safe with malformed reservedConnectionUnits.

🐛 Suggested fix
   const liveIdle = (values) =>
-    values.every((value) => integer(value, 'live runtime count') === 0)
+    values.map((value) => integer(value, 'live runtime count'))
+      .every((value) => value === 0)

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Updates relay capacity transition verification logic.

The PR appears safe to merge based on this review.

Summary

The PR allows a draining relay cell to accumulate restart-safe samples through refused redials while retaining checks for controls, splices, queued data, and migrations.

  • Adds restart-progress diagnostics and tests for refused redials and malformed counters.

Reviews (2) · Last reviewed commit: "test(relay): pin fail-closed parsing of ..."

…ing cell

Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
@Jinwoo-H
Jinwoo-H merged commit 5f728f7 into main Oct 1, 2026
25 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