Skip to content

fix(relay-ops): roll a cell a wave stranded after its drain - #21321

Merged
Jinwoo-H merged 2 commits into
mainfrom
relay-same-cap-stranded-recovery
Sep 18, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
relay-same-cap-stranded-recovery

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​133 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​133
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80

ELI5

Before a cell is upgraded it is told to shed its connections. That instruction is a
one-way switch inside the running program: the only thing that turns it off is the
program starting again.

If the upgrade then fails before the machine is replaced, the switch stays on. The
cell is left half way through an upgrade that will never finish, and neither
recovery path will touch it. Retrying the upgrade says the cell is in the wrong
state, and rolling back thinks the work is already done. This teaches the rollback
to recognise that cell and actually roll it.

What Changed

Before. A general cell whose wave failed between its drain and its template
apply was stuck. apply refused it, because apply needs the cell general and not
draining, and it is neither. rollback refused it too: it still serves the
rollback image, so rollback classified it as a resume, and the resume path both
refuses a draining cell and skips the isolate, the drain, and the template apply,
so it could not have cleared the flag even if it had accepted it.

After. That cell is classified stranded and rolled. It comes back on a new
instance, so the drain clears, and it is restored to general.

The mechanism. Two different failures leave a cell on the rollback image, and
the image alone cannot separate them. The restart can:

live image draining stage meaning
rollback no resume a rollback that failed after its template apply, so its cell restarted
rollback yes stranded a wave that stopped before its template apply, so nothing restarted
target either roll the ordinary rollback

stranded runs the ordinary rolling path. Three things follow from the cell having
never restarted:

  • Its template still carries the image it is serving, so that is the predecessor
    its plan is reviewed against, not the target the wave was heading for. A template
    that already moved on to the target is refused rather than rolled backwards under
    a stale review.
  • The drain wait expects the image the cell actually serves. This is one variable
    rename that is identical on every existing path.
  • When the reviewed template is already in place the plan changes nothing, so the
    apply replaces no instance. The MIG is then rolled explicitly, with
    --max-surge 0 --max-unavailable 1, which is exactly the update_policy a
    template change uses. The existing check that the incarnation must change is what
    proves the instance came back.

Why

The brief proposed classifying on the MIG's current template digest as well as the
incarnation and the drain flag. I used the drain flag alone, and let the plan
review cover what the template digest would have told us.

Reading the MIG's template needs a second gcloud call, an extraction of the relay
digest from a startup script, and a fourth branch for "template applied, instance
not replaced". Validating the plan against the image the cell serves already
rejects that case, fail-closed, with no new code: if the template carries the
target, relayImage(before) does not match the reviewed rollback image and the
plan is refused. That state also self-heals, because the MIG keeps replacing the
instance on its own, after which the cell reads as roll and takes the path it
already had.

The incarnation is not usable as a classifier across dispatches. Nothing durable
records what it was before, so a fresh read cannot tell a restarted cell from one
that never moved.

I considered clearing the flag instead of rolling the cell, which would be far
smaller. There is no route for it: draining is set in host-session-registry.ts
and never assigned false anywhere, so a restart is the only way out.

Linked Issue

N/A - operational follow-up to #21315, needed before populated general cells roll.

Visual Proof

N/A. No UI. This changes a GitHub Actions rollout workflow.

Testing

All from cloud/.

  • pnpm test — 625 pass, 0 fail in the dev-script suite; 156 pass, 0 fail in
    pretest; relay-ops 134, relay 717 passed / 121 skipped, push 139 passed / 4
    skipped, postgres-schema 108, relay-contract 35, push-contract 30,
    relay-fence-broker 16. No failures.
  • pnpm typecheck, pnpm lint, pnpm build — clean.
  • actionlint — clean apart from the pre-existing unknown blacksmith runner label.

The unchanged-paths claim is measured, not asserted. I extracted the
classification block from origin/main and from this branch and ran both over
every combination of mode, live image, and drain flag, comparing the stage, the
predecessor image, the predecessor protocol, and the plan's reviewed rollback
image. One row differs:

apply    live=rollback draining=false same    main[roll false ROLLBACK 0 ROLLBACK] branch[roll false ROLLBACK 0 ROLLBACK]
apply    live=rollback draining=true  same    main[roll false ROLLBACK 0 ROLLBACK] branch[roll false ROLLBACK 0 ROLLBACK]
apply    live=target   draining=false same    main[roll false ROLLBACK 0 ROLLBACK] branch[roll false ROLLBACK 0 ROLLBACK]
verify   live=rollback draining=false same    main[roll false ROLLBACK 0 ROLLBACK] branch[roll false ROLLBACK 0 ROLLBACK]
verify   live=rollback draining=true  same    main[roll false ROLLBACK 0 ROLLBACK] branch[roll false ROLLBACK 0 ROLLBACK]
rollback live=target   draining=false same    main[roll false TARGET 0 TARGET] branch[roll false TARGET 0 TARGET]
rollback live=target   draining=true  same    main[roll false TARGET 0 TARGET] branch[roll false TARGET 0 TARGET]
rollback live=rollback draining=false same    main[resume true ROLLBACK 1 TARGET] branch[resume true ROLLBACK 1 TARGET]
rollback live=rollback draining=true  CHANGED main[resume true ROLLBACK 1 TARGET] branch[stranded false ROLLBACK 1 ROLLBACK]

rows changed: 1

The census now runs the same nine combinations against the committed block, plus a
tenth where the runtime reports no drain flag at all, which must never read as
stranded. Two further census tests hold the explicit MIG roll, its gating on a
zero-change plan, its surge and unavailable values against the Terraform
update_policy they have to match, the drain wait's image, and the incarnation
check that proves the restart. The eight-combination draining test from #21315 is
unchanged and still passes.

Not verified: the explicit rolling-action replace against a live MIG. It is
gated on a stage no cell is in right now, and it uses the same surge and
unavailable values the MIG's own update policy declares, which the census asserts.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

The judgement worth checking is dropping the MIG template digest from the
classifier in favour of the plan review. If you would rather the stage were read
directly off the MIG, that is a bigger change and a fourth branch, and I would
rather add it deliberately than tonight.

The same-cap job workflow is in TRUSTED_EVIDENCE_CODE_PATHS, so merging
invalidates any canary authority sealed before it.

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

Security: no identity, audience, lock, confirmation, or evidence rule changes. The
stranded path runs the same isolate, drain, plan review, and verification the
ordinary rolling path runs, and is reviewed against a stricter predecessor than
before, because the plan must match the image the cell is actually serving.

Backwards compatibility: measured above. Eight of nine combinations are unchanged.

Cross-platform, SSH, mobile, performance: N/A. CI-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)

A wave that stops any time after its drain leaves the cell migration-only and
draining on the rollback image, and nothing clears it: the drain flag is a
one-way latch on the running process, and the failsafe restarts nothing. Both
recovery modes then refuse the cell. Apply wants it general and not draining.
Rollback sees the rollback image, reads it as a resume, refuses the draining,
and would not have restarted it anyway.

The image alone cannot separate a rollback that failed after its template apply
from a wave that stopped before one. The restart can: the first left a fresh
process, the second did not. Classify on that, so the cell that never restarted
takes the rolling path instead of the resuming one.

Its template still carries the image it serves, so that is the predecessor its
plan is reviewed against, and a template already moved on to the target is
refused rather than rolled backwards under a stale review. When the reviewed
template is already in place the plan changes nothing, so the MIG is rolled
explicitly on the same replacement policy a template change uses; the existing
incarnation check is what proves the instance came back.

Every other combination of mode, live image, and drain flag keeps the value it
had, held by a census that runs the real block over all nine.
@pullfrog

pullfrog Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

This run was cancelled 🛑

The workflow was cancelled before completion. Please check the link below for details.

Pullfrog  | View workflow run | via Pullfrog | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The same-cap rollback workflow now distinguishes resume, stranded, and roll states from the live image and draining status. It uses state-specific images for drain and plan validation. Stranded rollbacks with no Terraform changes trigger a single-instance MIG replacement. Tests cover classification, replacement settings, image verification, and incarnation changes. Documentation describes the recovery procedure.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 532eb

The recovery command is currently correct, but its regression test could miss a later change that makes stranded replacement fall back to default policy settings. Bind the assertion to the command before merging or accept the bounded test-coverage gap.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1… 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 identifies the primary fix: rolling a cell that becomes stranded after draining during a relay wave. It is concise and specific.
Description check ✅ Passed The description is complete and detailed. It explains the problem, behavior before and after, implementation, alternatives, testing, scope, linked issue context, and checklist status. The linked issue…
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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: af57ae17-177e-4ebf-844f-2ad814c0e310

📥 Commits

Reviewing files that changed from the base of the PR and between 27bddc6 and 665f33e.

📒 Files selected for processing (3)
  • .github/workflows/cloud-deploy-relay-production-same-cap-job.yml
  • cloud/dev/scripts/relay-same-cap-script-census.test.mjs
  • cloud/docs/relay-workflows.md

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment on lines +676 to +677
if test "${ROLLBACK_STAGE}" = stranded \
&& test "$(jq -er '.changes' <<< "${PLAN_REVIEW}")" = 0; then

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

validator="$(fd -a '^validate-relay-capacity-plan\.mjs$' . | head -n1)"
test -n "${validator}"

rg -n -C6 \
  'changes|obsolete|delete|instance_group_manager|instance_template|no-op|read' \
  "${validator}" cloud/dev/scripts

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- validator files ---'
fd -a '^validate-relay-capacity-plan\.mjs$' .

printf '%s\n' '--- workflow ---'
sed -n '620,710p' .github/workflows/cloud-deploy-relay-production-same-cap-job.yml

printf '%s\n' '--- validator source ---'
for validator in $(fd -a '^validate-relay-capacity-plan\.mjs$' .); do
  printf '\n### %s\n' "$validator"
  wc -l "$validator"
  cat -n "$validator"
done

Repository: stablyai/orca

Length of output: 33266


Use replacement semantics, not total change count, for stranded cells. In same-cap-cell mode, convergenceCellPlan accepts a deposed template delete as the only mutation and returns changes: 1. The workflow then skips rolling-action replace, so the stranded drain flag can persist. Base the explicit replacement decision on whether the accepted plan replaces an instance, including zero-change and obsolete-template-only plans.

gcloud persists every rolling-action bound into the group's update policy, and
it defaults the replacement method to substitute on a group with no stateful
config. Passing surge and unavailable without the method would patch the policy
off the declared RECREATE, and the next targeted plan would then carry a MIG
change outside version.0.instance_template, which the plan validator refuses.

Pass all three so the patch is identical to the declared policy, and read the
declared values in the census instead of restating two of them. Dropping the
flag, or moving any of the three in Terraform, now fails the census.
@Jinwoo-H
Jinwoo-H merged commit 6c913a9 into main Sep 18, 2026
24 checks passed

@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: c4526034-17d2-493f-a536-a59031fb8544

📥 Commits

Reviewing files that changed from the base of the PR and between 665f33e and 532ebd0.

📒 Files selected for processing (2)
  • .github/workflows/cloud-deploy-relay-production-same-cap-job.yml
  • cloud/dev/scripts/relay-same-cap-script-census.test.mjs

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +679 to +692
assert.match(apply, /rolling-action replace "\$\{MIG_NAME\}"/)
const declared = migUpdatePolicy()
assert.deepEqual(declared, {
replacementMethod: 'recreate',
maxSurge: '0',
maxUnavailable: '1'
})
assert.match(
apply,
new RegExp(
`--replacement-method ${declared.replacementMethod}` +
` --max-surge ${declared.maxSurge} --max-unavailable ${declared.maxUnavailable}`
)
)

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 | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '640,715p' cloud/dev/scripts/relay-same-cap-script-census.test.mjs
sed -n '640,700p' .github/workflows/cloud-deploy-relay-production-same-cap-job.yml
rg -n -C3 'const apply|apply =|rolling-action replace|replacement-method|max-surge|max-unavailable' cloud/dev/scripts/relay-same-cap-script-census.test.mjs .github/workflows/cloud-deploy-relay-production-same-cap-job.yml

Repository: stablyai/orca

Length of output: 11158


Bind the policy flags to the replacement command.

apply contains the entire shell step. The test checks that rolling-action replace exists and separately checks that the flag sequence exists somewhere in apply. The test can therefore pass if the flags move to unrelated shell text while the replacement command uses gcloud defaults. Capture the rolling-action replace invocation and assert the three flags within that command.

ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…#21321)

* fix(relay-ops): roll a cell a wave stranded after its drain

A wave that stops any time after its drain leaves the cell migration-only and
draining on the rollback image, and nothing clears it: the drain flag is a
one-way latch on the running process, and the failsafe restarts nothing. Both
recovery modes then refuse the cell. Apply wants it general and not draining.
Rollback sees the rollback image, reads it as a resume, refuses the draining,
and would not have restarted it anyway.

The image alone cannot separate a rollback that failed after its template apply
from a wave that stopped before one. The restart can: the first left a fresh
process, the second did not. Classify on that, so the cell that never restarted
takes the rolling path instead of the resuming one.

Its template still carries the image it serves, so that is the predecessor its
plan is reviewed against, and a template already moved on to the target is
refused rather than rolled backwards under a stale review. When the reviewed
template is already in place the plan changes nothing, so the MIG is rolled
explicitly on the same replacement policy a template change uses; the existing
incarnation check is what proves the instance came back.

Every other combination of mode, live image, and drain flag keeps the value it
had, held by a census that runs the real block over all nine.

* fix(relay-ops): pin the replacement method on the explicit MIG roll

gcloud persists every rolling-action bound into the group's update policy, and
it defaults the replacement method to substitute on a group with no stateful
config. Passing surge and unavailable without the method would patch the policy
off the declared RECREATE, and the next targeted plan would then carry a MIG
change outside version.0.instance_template, which the plan validator refuses.

Pass all three so the patch is identical to the declared policy, and read the
declared values in the census instead of restating two of them. Dropping the
flag, or moving any of the three in Terraform, now fails the census.
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