Repository navigation
fix(relay): bound the same-cap shadow gate in time and apply a resumed backend update - #21865
Merged
Merged
Conversation
…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
Contributor
|
This run was cancelled 🛑 The workflow was cancelled before completion. Please check the link below for details. |
…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
Contributor
✨ Finishing Touches📝 Generate docstrings
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. Comment |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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, stepShadow health gate (report only), hadcontinue-on-error: trueand notimeout-minutes. The job's only bound was its owntimeout-minutes: 75.continue-on-errorbounds 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 costsREAD_ATTEMPTS = 3attempts atreadTimeoutMs = 60_000plus 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 + 2forSten-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, socontinue-on-errorcannot absorb it: thefailure() && 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: 8on the gate step. Per GitHub Actions semantics a step that exceedstimeout-minutesis failed, not cancelled, andcontinue-on-error: trueon the same step marks it as passed for the job's conclusion — so the job stays green and thefailure()-gated cleanup does not fire. (Job-level cancellation, which is what we are avoiding, is the casecontinue-on-errorcannot cover.)timeout-minutes: 2on thePublish the shadow health gate verdictupload step. One small JSON file; a retrying upload must not spend the wave's minutes either.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 asunverifiedand which can never settle toPASS. Each read is also givenmin(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.overallDeadlineMslives besidereadTimeoutMsinrelay-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 whenROLLBACK_RESUME == 'true') applies nothing — the apply step is skipped byenv.ROLLBACK_RESUME != 'true'. Its acceptance predicate was:changesdeliberately excludes the backend, sochanges == 0with a non-emptybackendUpdatemeans "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:The exact before/after of the three reachable states:
length == 0check; proceedschanges: 0,backendUpdatenon-empty)changes: 2)jq -efails the step, failsafe firesApplying 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 classifiedstrandedat the precheck), takes the drain-and-apply path, and itsROLLBACK_STAGE = stranded && .changes == 0branch still issues the explicitrolling-action replace— which is the only thing that clears the drain flag. Because a pending backend update is not counted inchanges, it cannot suppress that roll.Why
Both fixes are one-line-shaped in effect and keep the existing structure rather than reworking it.
WARNwithunverifiedchecks — which is information — and the runner bound is left as a backstop.changesto 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
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 insideoverallDeadlineMs, 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; withoverallDeadlineMsraised out of the way it makes 22 (which at 190 s each is the 70-minute case this fixes).timeout-minutes: 8on the gate step,timeout-minutes: 2on the upload step, and assertsoverallDeadlineMs < stepTimeoutMinutes * 60_000so 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 thechanges == 0test from the workflow text and runs them underbashagainst 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.rolls a stranded MIG on the shipped predicate, backend update or not: same technique on the apply step's stranded condition, proving a pendingbackendUpdatedoes not suppress therolling-action replaceand 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 oneterraform apply.Commands (macOS).
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_modulesis absent in this worktree), unrelated to these files; CI installs the workspace.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.
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.tsemits its checked-out-client failure throughconsole.warnwith a bare template string, while every other operator-facing relay log isJSON.stringifywith aneventfield (comparedatabase.ts,orca_relay_postgres_transaction_retry). A plain string lands intextPayload. That matters this week in particular because the shadow gate's own cell scope filters onjsonPayload.*, and its own comment inrelay-same-cap-shadow-gate.mjssays atextPayloadfilter "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 anorca_relay_postgres_checked_out_client_failedevent object. Separate PR: it is a different file, a different owner, and a different test suite.The backend now sits after the MIG in the apply graph, which is a new stranding path.
google_compute_backend_servicedepends on the MIG throughbackend { group = ...instance_group }, so Terraform orders MIG before backend. A failed backend patch now failsterraform applywith the recreate already in flight; the restore step issuccess()-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 inmode: rollback, which classifiesstrandedand 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.60 s LB drain versus the 75 s control-silence timeout.
cloud/packages/relay-contract/src/protocol-limits.ts:21-22givescontrolPingIntervalMs: 15 * 1000andcontrolSilenceTimeoutMs: 75 * 1000, so the new 60-secondconnection_draining_timeout_seccuts 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 onverify-relay-capacity-transition.mjs --activity restart-safe --draining requiredwith a 17-minute timeout and fails the step rather than proceeding, so Terraform never runs against an undrained cell.restart-saferequires 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
unverifiedtails 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 showingunverifiedon healthy cells, raise both numbers together rather than only the deadline; the census only pins the relation, not the values.Agent skill upstream boundary
Notes
No security surface change. The resume apply is bounded by the same reviewed validator the normal apply uses and by the same
-targetset, 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
N/Awith reason for visuals