Skip to content

fix(relay): bound the same-cap shadow gate in time and apply a resumed backend update - #21865

Merged
Jinwoo-H merged 2 commits into
mainfrom
relay-same-cap-gate-timeout-and-resume
Sep 21, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
relay-same-cap-gate-timeout-and-resume

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​134 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​132
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​49

ELI5

Two safety problems in the machinery that rolls Relay servers one at a time.

First, a monitoring step that is supposed to be harmless ("just look at the logs and write a report") had no time limit. If logging is having a bad day, each lookup takes its full three minutes of retries, and it does them one after another. It can run long enough that the whole rollout job hits its own 75-minute limit and gets killed — and a killed job stops every remaining server from rolling. Now the step gives up after five minutes, and the script itself stops looking after four and just says "couldn't check", which is a report, not a crash.

Second, when an interrupted rollout is resumed, the job checks "is there anything left to do?". It was answering "no, we're done" in a case where there was something left: the load balancer settings. The resumed server quietly kept the old 5-minute drain and no request logging while the operator read a green tick. Now that case applies the one remaining change and then continues.

What Changed

Both findings are from tonight's two independent adversarial reviews of the merged set (#21840, #21848, #21849, #21860); both reviewers raised both, and both rated them P0 for the next roll.

Fix 1 — the shadow health gate is now bounded in time, not just in outcome

Before. .github/workflows/cloud-deploy-relay-production-same-cap-job.yml, step Shadow health gate (report only), had continue-on-error: true and no timeout-minutes. The job's only bound was its own timeout-minutes: 75.

continue-on-error bounds a step's contribution to the job outcome; it does not stop a step from running. The gate's reads are serialised on purpose (a burst of concurrent reads is what earns a Logging 429). Each read costs READ_ATTEMPTS = 3 attempts at readTimeoutMs = 60_000 plus two 5-second retry delays = 190 s when gcloud answers nothing rather than answering slowly — an expired credential, a project-wide Logging 429 storm, a Cloud Logging incident. All three make every read cost the full budget, not one.

The read count scales with the roll window: 8S + 2 for S ten-minute sub-windows (3S director 503 observed-plus-two-baselines, 2 cell-serving, S Cloud SQL, S cell metrics, 3S fleet pools). A routine 25-minute window is ~26 reads (~82 min); a slow 40-minute one ~34 reads (~108 min). Past 75 minutes GitHub cancels the job. Cancellation is not a step failure, so continue-on-error cannot absorb it: the failure() && inputs.mode != 'verify' cleanup fires and re-isolates a cell that had already passed restore, and the strict chain (needs: [gate, cell_N]) stops every later cell.

After.

  • timeout-minutes: 8 on the gate step. Per GitHub Actions semantics a step that exceeds timeout-minutes is failed, not cancelled, and continue-on-error: true on the same step marks it as passed for the job's conclusion — so the job stays green and the failure()-gated cleanup does not fire. (Job-level cancellation, which is what we are avoiding, is the case continue-on-error cannot cover.)
  • timeout-minutes: 2 on the Publish the shadow health gate verdict upload step. One small JSON file; a retrying upload must not spend the wave's minutes either.
  • An overall seven-minute deadline inside cloud/dev/scripts/relay-same-cap-shadow-gate.mjs. Every read short-circuits once the budget is gone and returns a failed read, which the verdict layer already renders as unverified and which can never settle to PASS. Each read is also given min(readTimeoutMs, remaining) so one read cannot overshoot the deadline. The normal outcome is therefore a written verdict, and the step timeout exists only for a genuinely hung process. SHADOW_GATE_THRESHOLDS.overallDeadlineMs lives beside readTimeoutMs in relay-same-cap-shadow-gate-verdict.mjs.

This is deliberately small: it does not change what the gate judges or how, only how long it may take to say so.

Fix 2 — a resumed cell now applies its pending backend update

Before. The resume step (Require converged Terraform state and a stable MIG on resume, which runs only when ROLLBACK_RESUME == 'true') applies nothing — the apply step is skipped by env.ROLLBACK_RESUME != 'true'. Its acceptance predicate was:

.changes == 2 or (.changes == 0 and ((.backendUpdate // []) | length) > 0)

changes deliberately excludes the backend, so changes == 0 with a non-empty backendUpdate means "template and MIG converged, this cell's reviewed backend update still pending". That predicate passed and the job walked straight on to stability verification. The cell kept the 300-second drain and never got request logging, and nothing said so; the operator read a green resume.

After. The verdict is captured once (RESUME_REVIEW), echoed for the operator, still gated by the same predicate, and then:

if test "$(jq -er '.changes' <<< "${RESUME_REVIEW}")" = 0; then
  terraform -chdir=infra/terraform apply -auto-approve \
    "${RUNNER_TEMP}/relay-same-cap-resume.tfplan"
fi

The exact before/after of the three reachable states:

Plan shape Before After
Everything converged (all no-op) short-circuits at the earlier length == 0 check; proceeds unchanged
Template + MIG converged, backend pending (changes: 0, backendUpdate non-empty) accepted as complete, applies nothing applies the saved resume plan, then proceeds
Template-and-MIG drift (changes: 2) accepted, applies nothing unchanged — a resume still applies nothing here
Anything else jq -e fails the step, failsafe fires unchanged

Applying is safe here because the saved plan is the one the validator has already bounded: it is -targeted to this cell's template, MIG, and backend, the first two are no-ops in this shape, and the validator refuses any backend change outside {connection_draining_timeout_sec → the constant, log_config.0 → enable=true at the reviewed sample rate}. Neither attribute restarts an instance, so the incarnation check downstream stays honest.

A genuinely stranded cell is untouched. Stranded routes through ROLLBACK_RESUME=false (a draining-but-not-restarted cell is classified stranded at the precheck), takes the drain-and-apply path, and its ROLLBACK_STAGE = stranded && .changes == 0 branch still issues the explicit rolling-action replace — which is the only thing that clears the drain flag. Because a pending backend update is not counted in changes, it cannot suppress that roll.

Why

Both fixes are one-line-shaped in effect and keep the existing structure rather than reworking it.

  • Gate timeout over reverting feat(relay): report a post-wave health verdict on each same-cap cell, without gating on it #21849. The gate's placement (after restore, so the cell is back in admission before any log reading) is correct and worth keeping; the defect is purely the clock. A step timeout plus a script deadline fixes the clock without touching the judgement.
  • Script deadline as well as the step timeout. The step timeout alone would kill the process mid-read with no artifact and no summary. The seven-minute internal deadline means the normal bad case produces a verdict of WARN with unverified checks — which is information — and the runner bound is left as a backstop.
  • Apply the pending backend rather than warn about it. One reviewer suggested a warning; the other rated the silent skip release-blocking. A warning still leaves a cell configured differently from every other rolled cell, and the resume path is exactly where nobody is watching. The plan is already reviewed and bounded, so applying it is both cheaper and more honest than reporting it.
  • Not bumping changes to include the backend. That would break the stranded branch (changes == 0 → MIG replace) and the drift branch (changes == 2), both of which are about instance restarts, which a backend attribute never causes.

Linked Issue

N/A — corrective follow-up to #21849 and #21860, from the two adversarial reviews of tonight's merged set.

Visual Proof

N/A — CI workflow and Node script changes; no user-visible UI.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

New tests.

  • cloud/dev/scripts/relay-same-cap-shadow-gate.test.mjs, the gate stops reading at its own deadline and still reports a verdict: drives the gate with a clock where every read costs its full retry budget, asserts the reads actually attempted fit inside overallDeadlineMs, that the report is still a verdict (WARN, cellServing: unverified), and that no read is given more time than the budget has left. Control: with the deadline it makes 2 reads; with overallDeadlineMs raised out of the way it makes 22 (which at 190 s each is the 70-minute case this fixes).
  • Same file, extended workflow census: pins timeout-minutes: 8 on the gate step, timeout-minutes: 2 on the upload step, and asserts overallDeadlineMs < stepTimeoutMinutes * 60_000 so the script always has room to write its verdict.
  • cloud/dev/scripts/relay-same-cap-script-census.test.mjs, decides refuse, apply, or skip on resume from the shipped predicate: extracts the acceptance filter and the changes == 0 test from the workflow text and runs them under bash against eight verdicts, covering converged-with-backend-pending → apply, template-and-MIG drift → skip, and every refused shape. Extracting rather than restating is what stops the test and the job drifting apart.
  • Same file, rolls a stranded MIG on the shipped predicate, backend update or not: same technique on the apply step's stranded condition, proving a pending backendUpdate does not suppress the rolling-action replace and that a real template replacement does.
  • cloud/dev/scripts/relay-regional-rehome-workflow.test.mjs: updated for the restructured resume pipeline and now pins the resume apply, plus asserts the resume step contains exactly one terraform apply.

Commands (macOS).

node --test dev/scripts/relay-same-cap-shadow-gate.test.mjs
  → tests 19, pass 19, fail 0

# cloud "pretest" list (18 files)
  → tests 157, pass 157, fail 0

# cloud "test" dev-scripts list (53 files)
  → tests 631, pass 630, fail 1

The one failure is dev/scripts/relay-load-control-peer.test.mjs: Cannot find module '@orca-cloud/relay-contract' — a pre-existing local install gap (cloud/node_modules is absent in this worktree), unrelated to these files; CI installs the workspace.

actionlint .github/workflows/cloud-deploy-relay-production-same-cap-job.yml

Byte-identical to the same command on origin/main's copy of the file: one pre-existing finding, label "blacksmith-2vcpu-ubuntu-2204" is unknown [runner-label].

Platforms: a GitHub Actions workflow (ubuntu runner) and Node scripts; no platform-dependent code. SSH/remote, mobile, and renderer untouched.

AI Disclosure

Review

Not done here, recorded as follow-ups.

  1. The fix(relay): stop a terminated checked-out PostgreSQL client from killing the cell #21840 warning is a plain string. cloud/apps/relay/src/postgres-pool-pressure.ts emits its checked-out-client failure through console.warn with a bare template string, while every other operator-facing relay log is JSON.stringify with an event field (compare database.ts, orca_relay_postgres_transaction_retry). A plain string lands in textPayload. That matters this week in particular because the shadow gate's own cell scope filters on jsonPayload.*, and its own comment in relay-same-cap-shadow-gate.mjs says a textPayload filter "matches nothing here and returns zero without saying so". The one signal that a checked-out client died is invisible to the new gate. It wants an orca_relay_postgres_checked_out_client_failed event object. Separate PR: it is a different file, a different owner, and a different test suite.

  2. The backend now sits after the MIG in the apply graph, which is a new stranding path. google_compute_backend_service depends on the MIG through backend { group = ...instance_group }, so Terraform orders MIG before backend. A failed backend patch now fails terraform apply with the recreate already in flight; the restore step is success()-gated and skipped, and the failure cleanup deliberately keeps the cell migration-only and draining. Recovery is the documented one for any failed apply — re-run in mode: rollback, which classifies stranded and clears the drain flag with the explicit MIG replace. Both reviewers rated this a follow-up rather than a blocker, and it is not made worse by this PR.

  3. 60 s LB drain versus the 75 s control-silence timeout. cloud/packages/relay-contract/src/protocol-limits.ts:21-22 gives controlPingIntervalMs: 15 * 1000 and controlSilenceTimeoutMs: 75 * 1000, so the new 60-second connection_draining_timeout_sec cuts a control socket 15 seconds before its own silence detector fires. Does it matter? Almost never, and not because of the drain ordering alone. The application drain runs first and to completion: the job's isolate-and-drain step blocks on verify-relay-capacity-transition.mjs --activity restart-safe --draining required with a 17-minute timeout and fails the step rather than proceeding, so Terraform never runs against an undrained cell. restart-safe requires zero control connections. The exposure is therefore only a control socket opened in the gap between the drain finishing and the apply landing; such a socket gets cut at 60 s instead of surviving, which the client sees as a reconnect, not an error, and recovers by its own retry. It is the one case where 300 s was doing something and 60 s is not, and it is narrow enough that neither reviewer asked for a change. Worth knowing if a future change widens the drain-to-apply gap.

One thing to push on in this PR: the seven-minute deadline and the eight-minute step timeout are a pair, and only the relation between them is asserted (deadline < step timeout). Neither number is derived from a measured worst case: the happy path is ~26 reads at roughly ten seconds each, about four minutes on a 2-vcpu runner, so both bounds are set clear of that rather than on top of it — a first pass at four and five would have reported unverified tails on ordinary days, which would stop the shadow roll measuring the very comparison it exists for. Eight minutes on top of a ~14-minute cell is still far inside the job's 75. If the artifact ever does start showing unverified on healthy cells, raise both numbers together rather than only the deadline; the census only pins the relation, not the values.

Agent skill upstream boundary

  • Not applicable.

Notes

No security surface change. The resume apply is bounded by the same reviewed validator the normal apply uses and by the same -target set, and it can only run in the one shape where the template and MIG are already converged. The gate change strictly reduces what the job may spend. No wire, mobile, cross-platform, or backwards-compatibility impact.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A with reason for visuals
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (N/A)
  • Tests and actionlint run locally; CI covers the rest

…d update

Two findings both adversarial reviews of tonight's merged set agree on.

The report-only shadow health gate (#21849) had `continue-on-error: true` but
no step timeout. That bounds the step's contribution to the job outcome, not
its clock. Its reads are serialised, and a failure that answers nothing slowly
— an expired credential, a project-wide Logging 429 storm — makes every read
cost its full 3 x 60 s retry budget, so the cost scales with the roll window:
roughly 8S + 2 reads for S ten-minute sub-windows. A 40-minute window is about
34 reads, or 108 minutes, against the job's `timeout-minutes: 75`. A cancelled
job cannot be absorbed by continue-on-error, fires the failure-gated cleanup
isolation on an already-restored cell, and stops the strict next-cell chain.

Give the step `timeout-minutes: 5` and the artifact upload `timeout-minutes: 2`.
A timed-out step is a failed step, which continue-on-error covers, so the job
stays green. Inside the script, stop reading after an overall four-minute
deadline and report the remaining checks unverified, so the normal outcome is a
written verdict rather than a killed process; the step timeout is then only for
a hung process. The census test pins both timeouts and that the deadline leaves
the step time to write its verdict.

The resume branch (#21860) accepted `changes == 0` with a non-empty
`backendUpdate` as complete and applied nothing, so a resumed cell silently
kept the 300-second drain and no request logging behind a green resume. That
shape means the template and MIG are converged and only this cell's reviewed
backend update is left, so apply the saved resume plan — the validator has
already bounded it to this cell's backend and neither attribute restarts an
instance — then continue as converged. Template-and-MIG drift still applies
nothing, which is what a resume means, and a stranded cell's explicit MIG
replace is unchanged.

Claude-Session: relay-same-cap-gate-timeout-and-resume
@pullfrog

pullfrog Bot commented Sep 21, 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 | 𝕏

…ad time

A healthy gate is already minutes of serial reads on the 2-vcpu runner, so a
four-minute deadline would report unverified tails on ordinary days and stop
the shadow roll measuring the comparison it exists for. Raise both together:
the step to eight minutes and the script's own deadline to seven, keeping the
census pin that the deadline leaves the step room to write its verdict. The
job budget is unaffected: a ~14-minute cell plus eight is well inside 75.

Claude-Session: relay-same-cap-gate-timeout-and-resume
@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

✨ Finishing Touches
📝 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.

@Jinwoo-H
Jinwoo-H merged commit e476193 into main Sep 21, 2026
25 checks passed
@Jinwoo-H
Jinwoo-H deleted the relay-same-cap-gate-timeout-and-resume branch September 21, 2026 01:35
Jinwoo-H added a commit that referenced this pull request Sep 22, 2026
…pacity role cannot update it (#22140)

The capacity role the same-cap wave authenticates as, orcaRelayProductionCapacity,
has no compute.backendServices.update. Since #21860 added
`google_compute_backend_service.relay_gce_cell["${TARGET_CELL_ID}"]` to both of the
job's plan invocations, every wave has therefore created the new instance template,
modified the MIG, and then failed 403 on the backend, leaving the cell isolated with
its trust probe, admission restore, and shadow gate all skipped. Run 35684694704 on
production-gce-c7 is the first one that hit it in production.

Drop the backend target from both plans and restore the resume gate to exactly
`.changes == 2` (the template-and-MIG rollback-image drift) or a converged plan,
removing the backend-only resume apply #21865 added on top. A resume applies nothing
again, which is what a resume means.

The validator keeps its bound on a cell backend update, so it still reports one and
refuses anything wider, but a wave plan can no longer contain one. The drain timeout
from #21848 and the log_config from #21860 need a root apply by a principal that holds
the permission; granting the capacity role that permission is itself a root apply, so
it can follow as its own change rather than blocking every wave in the meantime.

Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
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