Repository navigation
feat(relay): drain pace window as a reviewed same-cap input, with drain-aware 503 gates - #25639
Conversation
…in-aware 503 gates The same-cap roll drained every cell over a fixed 300 s window, so a US roll re-placed hosts at ~2/s and spent ~10 minutes draining and waiting for quiet. The window is now a dispatch input from a closed set (300000, 60000, 30000), defaulting to today's 300000. - Below the default is refused for anything but US general cells; Asia drains are bound by their targets' accept rate, and migration-only cells hold no hosts. - A non-default window must be named in the confirmation, the canary authority records it (v2), and a batch may run at its canary's window or slower only. - Each cell job re-checks the window, scales the restart-safe timeout with it (15-min lease + window, unchanged at the default), and records what the cell applied and when it settled. - The report-only shadow gate takes the director's drain-return deferrals out of the 503 count (window and baselines), adds the rung's 5-min non-drain 503 budget and a Retry-After check, and reports the measured re-placement rate. - relay-workflows.md documents the pace ladder and what each rung records.
|
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
📒 Files selected for processing (7)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe same-cap deployment accepts drain pace windows of 300,000, 60,000, or 30,000 ms. Validation restricts faster windows to eligible cells, requires confirmation, and records the pace in canary authority. Cell jobs apply the selected pace and pass drain results and timing data to the shadow health gate. The gate evaluates drain-return deferrals separately from non-drain 503s and reports the associated judgments and drain metadata. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to This change adds opt-in faster drain pacing, gated by cell eligibility, confirmation, and canary-sealed evidence. The default pace is unchanged. No actionable merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Faster drains have explicit cell, confirmation, and canary restrictions. However, reusable canary approval does not track changes to the health logic that now grants that approval. A later rollout can therefore reuse a stale passing result after those checks change. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 35.42% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 48 functions across 6 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches 💡 1📝 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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Drain-pace input and its binding.
drain-pace-window-ms(300000default /60000/30000) is admitted only from that closed set, refused below default for anything outsideSAME_CAP_FAST_DRAIN_PACE_CELLS(US general), and a non-default pace must be named at the end of the confirmation for canary, batch, and rollback. - Canary authority v2. The authority records its pace; a batch may run at the canary's pace or slower, never faster, and a v1/unpaced authority is refused. This is what makes falling back to
300000mid-ladder need no new canary. - Workflow plumbing. The input reaches
validate,verify-canary,create-canary, and all ten cell jobs; each cell job re-checks the pace viacell-classbefore reading production; the drain step records the applied pace (0 on an older unpaced image) and the restart-safe settle stamp; the transition timeout scales as900000 + pace(exactly today's1200000at the default). - Drain-aware shadow gate.
drainReturnByMinutereads the director's own counters,withoutDrainDeferralstakes them out of the 503 count in the window and both baselines, and the newnonDrain503Budget/drainDeferralschecks plus thedrainreport block record the rung. The subtraction is sound:drain-return-deferredis recorded exactly once per deferred request and always returns HTTP 503 (deferDrainReturn), so the counter is 1:1 with thehttp.request.status=503entries it is removed from. - Tests and docs. New coverage is exact (closed set with rejected values, US-only fast pace, confirmation binding both directions, canary pace ordering, workflow/script agreement, the rung budget thresholds, and an end-to-end fast-drain PASS versus the same 503s as WOULD_BLOCK). All changed and adjacent cloud suites pass locally.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…minutes, and seal the canary's pace verdict Review of #25639 replayed the shadow gate: it read 10-01 c29 as unverified (the log read stopped at 20k entries), false-blocked 10-02 c22, and was blind on four cells whose 24 h/48 h baseline held an incident. - Director 503s now come from Cloud Run's request_count, aligned per minute by Cloud Monitoring, so volume cannot truncate the count. - The background is the median of the 10 same-day minutes before the drain; the 24 h/48 h baselines are gone. - Scheduled 503s come out: drain-return deferrals and sticky/placement answers to a host's own early retry (host-rate-limited, host-in-flight), each split across the minutes its 30 s sample covers. - The rung budget counts only sustained breaches: two straight minutes over max(1.5x, +20) warn, over max(2x, +40) would-block. - The report carries a paceVerdict over the three pace checks. seal_canary downloads the canary cell's report and seals that verdict; a batch below the default pace needs PASS, from a report on the same cell that drained at that pace. - Docs: the step-down rule reads paceVerdict, 30 s waits for the lane service time (#25645), and the staging step is dropped since staging drains unpaced. Replayed read-only: 10-01 c29 would-block (9 minutes over 41.5/min); all nine 10-02 cells and 10-01 c25 paceVerdict PASS.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Reject below-default applies when the cell… · cloud-deploy-relay-production-same-cap-job.yml:541-548
.github/workflows/cloud-deploy-relay-production-same-cap-job.yml:541-548
🩺 Stability & Availability | 🟠 Major | ⚡ Quick winReject below-default applies when the cell falls back to an unpaced drain.
An older predecessor image can reject
paceWindowMswith HTTP 400. The drain helper then sends{v: 1, graceMs: 0}and reports an applied pace of0. This job exports that value but does not compare it with the requested pace. The transition verifier uses the requested pace only to require a quiet window, so the cell can proceed through apply and restore after an unpaced drain. A valid canary on another cell does not prevent this; the later shadow gate is report-only.HostSessionRegistry.drainsends every target immediately when the pace is0, and the rollout notes record an approximately 800-host unpaced drain pinning the director at its 400 in-flight cap.For non-default applies, fail before continuing when the applied pace differs from the requested pace.
Suggested fix
echo "drain-applied-pace-window-ms=$(jq -er '.paceWindowMs' <<< "${DRAIN_RESULT}")" \ >> "${GITHUB_OUTPUT}" + if test "${DEPLOY_MODE}" = apply \ + && test "${DRAIN_PACE_WINDOW_MS}" != 300000 \ + && test "$(jq -er '.paceWindowMs' <<< "${DRAIN_RESULT}")" != \ + "${DRAIN_PACE_WINDOW_MS}"; then + echo "cell did not apply the requested drain pace" >&2 + exit 1 + fi # Restart-safe means an empty runtime for a whole pace window after the drain; leases
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
f81b7147-3e25-42b6-ba94-c1fd77688eb7
📒 Files selected for processing (7)
.github/workflows/cloud-deploy-relay-production-same-cap.ymlcloud/dev/scripts/relay-production-same-cap-wave.mjscloud/dev/scripts/relay-production-same-cap-wave.test.mjscloud/dev/scripts/relay-same-cap-shadow-gate-verdict.mjscloud/dev/scripts/relay-same-cap-shadow-gate.mjscloud/dev/scripts/relay-same-cap-shadow-gate.test.mjscloud/docs/relay-workflows.md
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline.
Reviewed changes
- Rebuilt the shadow gate's 503 accounting: director 503s now come from Cloud Monitoring's
run.googleapis.com/request_count(per-minuteALIGN_DELTA/REDUCE_SUM) instead of a log read that truncates, and scheduled 503s (drain-return deferrals plus sticky/placementhost-rate-limited/host-in-flight) are split across the minutes their 30s intervals cover and subtracted from the observed and background counts. - Replaced the 24h/48h baselines with the same day's 10 pre-drain minutes:
nonDrain503Budgetjudges against their median with a two-consecutive-minute rule,director503against their peak, and both thresholds were re-tuned with replay evidence. - Added a
paceVerdictover the three pace-movable checks (director503,nonDrain503Budget,drainDeferrals); the canary authority (v2) seals it, and a batch below the default pace now requiresPASS. - Bound the sealed verdict to the canary cell's own report (
canaryPaceVerdict): a report from another cell or pace, or an unpaced fallback, sealsUNVERIFIED;seal_canarydownloads the artifact and passes--shadow-report. - Extended the shadow gate arguments and report with the applied pace, settle time, host count, and the pre-drain background; updated the ladder procedure and tests.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| continue-on-error: true | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: relay-same-cap-shadow-gate-${{ inputs.cell-ids }}-${{ github.run_id }}.json |
There was a problem hiding this comment.
The canary's shadow artifact is uploaded under the normalized cell id (inputs.target-cell-id = fromJSON(needs.gate.outputs.cells)[0]) but downloaded here under the raw inputs.cell-ids. When those differ — a trailing space or comma in the dispatch input, which validateSameCapWave trims and accepts — the download misses silently (continue-on-error), create-canary seals UNVERIFIED, and a non-default batch is then refused even though the canary's paceVerdict was PASS.
Technical details
# Canary shadow artifact name uses the raw cell input; the upload uses the normalized cell
## Affected sites
- `.github/workflows/cloud-deploy-relay-production-same-cap.yml:372` — download `name:` uses `inputs.cell-ids`.
- `.github/workflows/cloud-deploy-relay-production-same-cap-job.yml:864` — upload `name:` uses `inputs.target-cell-id`.
- `.github/workflows/cloud-deploy-relay-production-same-cap.yml:384` — `--shadow-report` path also uses `inputs.cell-ids`.
## Required outcome
- The download name and the `--shadow-report` path must use the same cell token the job uploaded under, so a normalized-but-not-byte-identical `cell-ids` input cannot silently miss the artifact.
## Suggested approach (optional)
- `seal_canary` already declares `needs: [gate, cell_1]`, so it can use `${{ fromJSON(needs.gate.outputs.cells)[0] }}` (or a dedicated job output) for the artifact name and the `--shadow-report` path.…shadow gate's Cloud SQL and pool checks A truncated FATAL count is a floor, and one runtime sample over the SQL-failure line is a fact, so neither waits for a complete read. The waiter-run rule still needs a complete run, since holes can join two runs into one.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit since the prior pullfrog review (c6505e2 → ffc84e66), a fix to the shadow gate's verdict helpers.
- Partial counts past a block line now block.
judgeCloudSqlFataltests the Cloud SQL FATAL count against the block line before its truncation/failure guard, andjudgePooltests a sample over the SQL-failure line before its truncation guard, so a read that is only a lower bound and already over the line blocks instead of reportingunverified. - The consecutive-sample rule stays on complete runs only. The pool waiters rule is unchanged — a hole reads as a recovery, so it is still judged only when the run is whole.
- Tests cover both directions. A truncated count over the line blocks while one under it stays
unverified; the new pool cases add a run read across holes and a single over-line sample. The changed suite passes 26/26 locally.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…y; one median-based 503 check From the final review of #25639: - canaryPaceVerdict seals PASS only from a report that drained at least 400 hosts (about half a 10-02 US cell), so a near-empty canary cannot authorize a fast batch. - A director-metrics sub-window with fewer samples than one instance emits is unverified, so an empty or short Logging answer is never a calm drain. - seal_canary names the shadow artifact, report path and cell from the gate's normalized cell list, as cell_1 uploads it. - director503 folds into nonDrain503Budget as a single-minute spike rule, max(10x median, 200), dropping the pre-drain peak statistic. All 30 replayed windows keep their verdicts.

ELI5
When we update a relay server, it first moves every connected computer to another server. Today it always spreads those moves over 5 minutes, even for US servers that could take them much faster. This PR lets the operator choose 5 minutes, 1 minute or 30 seconds when they start the roll. The default stays at 5 minutes, and the choice has to be typed into the confirmation, so nobody can pick a faster pace by accident.
What Changed
Before: the same-cap roll hard-coded
DRAIN_PACE_WINDOW_MS: '300000'. A US cell's hosts came back to the director at about 2 per second. The roll then waited about 10 minutes for the drain and the quiet period after it. The post-roll health gate also counted every director 503. That included the drain-return lane's scheduled "come back in N seconds" answers, so a faster drain would have looked like an outage.After:
Deploy Relay Production Same-Caphas adrain-pace-window-msinput with three choices:300000(default),60000and30000. The wave script checks it against that closed list.300000is refused for Asia cells and migration-only cells. Asia drains are limited by how fast the receiving cells can accept hosts, not by the pace.ROLL_RELAY_SAME_CAP <digest> <cells> drain-pace-window-ms=60000. A confirmation with no pace means300000. Default rolls keep today's confirmation unchanged.300000mid-ladder needs no new canary.ceil(pace / 5 s) + 1samples inverify-relay-capacity-transition.mjs.run.googleapis.com/request_count, code 503). Cloud Monitoring aligns it per minute, so a brownout cannot truncate the count. A log read stopped at 20k of 10-01 c29's ~31k.host-rate-limited,host-in-flight). Each 30 s sample is split across the minutes it covers.nonDrain503Budget: two straight minutes over max(1.5×, +20) warn; over max(2×, +40) would-block. One minute over max(10×, 200) would-block on its own; any other single minute is a transient. This replaces the earlier separate peak check, which needed the pre-drain peak. That peak was its blind spot when a brownout was already under way.drainDeferrals: Retry-After over 30 s warns, over 60 s would-block.unverified. An empty answer is not a calm director.paceVerdict. The other checks (Cloud SQL, Asia pools, boot) stay as context.seal_canarydownloads the canary cell's shadow report and seals itspaceVerdict. It trusts PASS only from a report on the same cell that drained at least 400 hosts at that pace; anything else sealsUNVERIFIED. A batch below 300000 requiresPASS; a 300000 batch is unaffected.cell_1uploads under. A paddedcell-idsinput can no longer silently miss the artifact.cloud/docs/relay-workflows.mdhas the ladder procedure: 300 → 60 → 30 s, onecanary-applyper rung, stepping down only after the canary'spaceVerdictis PASS. 30 s also waits for the drain-return lane service time (feat(relay): report lane service times, 503 causes, per-site hold p99 and a director-vs-cell lock-wait split #25645). Each step records the drain rate, non-drain 503s per minute, lane deferrals and roll time. Four of the rung's bars cannot be read from this job and are listed there as such. Staging cannot rehearse a paced drain today (its capacity proof drains unpaced), so each rung's first use is one production canary.Where the 503 gates live. The only gate that counted drain deferrals is the shadow gate in this job, and this PR rebuilds its 503 checks. The pre-drain sample's 500/min rule (
apps/relay-ops/src/pre-drain-sample.ts) only looks at the 10 minutes before a drain, so it never sees one. The incident monitor already leaves 503s out of its director 5xx rule (incident-monitor-sources.ts:136). The "assign 503s above 1.5× background" auto-abort that the ops review criticised was in the superseded step-1 design, not in code.Cell side.
/v1/admin/drainaccepts 0 to 300000 ms with no minimum (app.ts:577), and the cell spaces sendswindow / (hosts − 1)apart. Both 60000 and 30000 are therefore in range. No cell or director image change is needed.Why
Per the step-1 decision (item 3), US drains are slow because of this fixed 300 s window, not because of the director's lock: the 10-02 wave drained at 2.2–2.8 hosts/s with the drain lane idle. At 60 s a US roll should drop from about 26 to about 18 minutes. Each step down also measures the drain lane under real load, which no canary can do.
Alternatives considered:
300000.Linked Issue
Internal relay redesign, step 1 (revised), item 3. No issue.
Visual Proof
N/A: workflow and ops-script change with no UI.
Testing
node --teston every cloud script suite inpackage.jsontestandpretest: 852/853 pass (top-level tests). The one failure,relay-load-control-peer.test.mjs, needs a built@orca-cloud/relay-contractdist in this worktree and is unrelated.actionlinton both workflows: clean apart from the custom runner label.Replays (read-only). These reuse the review's harness (
~/orca-lanes/rv-25639-data/replay.mjs). The cases are its1002/cases.jsonandcases2.json(the final review's 19 windows), plus 10-01 c29 and c25. Run unchanged, the harness reports the 503 checksunverified, because its guard refusesgcloud auth print-access-token, which the Monitoring read needs. The copy used here differs only by also allowing that token call and GET requests to MonitoringtimeSeries.Results at the current head. All 30 overall verdicts and pace verdicts are identical to the runs before the per-minute peak check was folded into the budget:
nonDrain503BudgetdrainDeferralspaceVerdictcloudSqlFatalandfleetPool:*. That is why the ladder readspaceVerdict.Calibration, stated plainly: the +20/+40 margins and the two-minute rule were chosen with these replays in view. Clean rolls had single minutes up to 87 but never two consecutive minutes over +20.
Not done here (by design: no workflow dispatch from this PR): a paced roll. Staging has no paced-drain path, so the first
60000rung is one production canary.Review
One self-review pass on correctness, binding gaps, and backwards compatibility.
Agent skill upstream boundary
Notes
Evidence code: merging invalidates a running monitor. Both same-cap workflows and
relay-production-same-cap-wave.mjsare inTRUSTED_EVIDENCE_CODE_PATHS(relay-evidence-code-provenance.mjs). Merging this PR invalidates:Merge between rolls, with no monitor running or about to be consumed, then run a fresh canary. The shadow gate scripts are not in that set.
Default behaviour is unchanged: 300000, the same confirmation, and the same 20-minute timeout.
Shadow gate cost. The 24 h/48 h baseline reads are gone, replaced by one Monitoring read and a few director-metrics log reads; the gate took 15–31 s per cell in the replays. If a read fails, the 503 checks report
unverifiedrather than guessing. The Monitoring read uses the job's deploy identity, the same one the pre-drain sample already uses for Monitoring.coderabbit's "reject below-default applies when the cell falls back to an unpaced drain" (job
:541-548): not applied. The fallback ignores the requested pace at every value, which is today's behaviour on an old image. A fast batch cannot reach it: it needs a PASS canary, which requires applied pace = requested pace on the same predecessor image every batch cell runs. The suggested exit would fire after the isolate and the unpaced drain, leaving a drained migration-only cell mid-wave with no apply resume. That is worse than the drain it objects to.Not done (optional in the final review):
rollbackto the default pace;30000from the choice until feat(relay): report lane service times, 503 causes, per-site hold p99 and a director-vs-cell lock-wait split #25645 ships (the docs already forbid it until then);paceWindowMsinstead of inferring it from a 2xx.Not reported by this job: drain-to-reconnected p95, the drain-return lane's service time, over-cap cells, and selector compare-and-swap retries. These wait for the director observability work (revised step 1, item 1). The docs say to record them as unmeasured until then.
Checklist
N/Afor visuals, with reason