Repository navigation
feat(relay): watch a reserve cell and flip it back on the first step 5 stop rule - #28698
Conversation
…5 stop rule A manual, inert-until-dispatched workflow samples one reserve cell every minute for up to 300 minutes against the step 5 §9 stop rules, logs one JSON line per sample, and on the first trip (or N unreadable samples in a row) runs the flag tool's own admitMode=db write under the flag workflow's concurrency group. dry-run logs the flag tool's plan instead. Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4b3ad46a-a8e8-4295-9fcf-346c664b9a6f
📒 Files selected for processing: 12
.github/workflows/cloud-operate-relay-production-reserve-watch.ymlcloud/dev/scripts/operate-relay-cell-flags.mjscloud/dev/scripts/relay-production-identity-boundaries.test.mjscloud/dev/scripts/relay-public-workflow-contract.test.mjscloud/dev/scripts/relay-reserve-watch-rules.mjscloud/dev/scripts/relay-same-cap-shadow-gate.mjscloud/dev/scripts/watch-relay-reserve-cell.mjscloud/dev/scripts/watch-relay-reserve-cell.test.mjscloud/dev/scripts/workload-identity-attribute-conditions.test.mjscloud/docs/relay-workflows.mdcloud/infra/terraform/relay-github-actions.tfcloud/package.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
… and baseline 503s before the flip - The flip back holds no concurrency group: GitHub keeps one pending run per group and a newer one cancels it. The flag tool's CAS orders it instead; a generation conflict is re-read and retried (5 tries, backoff) while the switch file still says reserve. - The 503 background comes from the 10 minutes before a required flipped-at, or an explicit value; neither is refused. - A failed or cancelled write-mode watch flips back too. An unreachable cell fails with the exact break-glass inputs. - Missing 503 data (empty series, unpublished minute, unparseable time) is unverifiable. - Seat-behind-row key adds the director instance and cell; six segments share one command. Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
5b14055e-f10b-4417-adb2-2797ff81f99d
📒 Files selected for processing: 6
.github/workflows/cloud-operate-relay-production-reserve-watch.ymlcloud/dev/scripts/operate-relay-cell-flags.mjscloud/dev/scripts/relay-reserve-watch-rules.mjscloud/dev/scripts/watch-relay-reserve-cell.mjscloud/dev/scripts/watch-relay-reserve-cell.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.
…response code A quiet fleet has no 503 series, so the watch read it as unverifiable and flipped a healthy cell back within minutes. The 503 read now groups request_count by response code in one query; the newest minute any code has a point for is how far the series is published, so a 503 minute at or before it with no point is zero and minutes past it are left out. Also: the flip-back job's steps run on always(), flipped-at ages against the watch's start in later segments, a pending pre-flip background no longer adds to the unverifiable streak, the flip back retries runtime-status before calling for break glass, and the concurrency rationale lives once in the docs. Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1459d239-7221-4dc4-a7a6-a07f77078875
📒 Files selected for processing: 6
.github/workflows/cloud-operate-relay-production-reserve-watch.ymlcloud/dev/scripts/relay-reserve-watch-rules.mjscloud/dev/scripts/relay-same-cap-shadow-gate.mjscloud/dev/scripts/watch-relay-reserve-cell.mjscloud/dev/scripts/watch-relay-reserve-cell.test.mjscloud/docs/relay-workflows.md
🚧 Files skipped from review as they are similar to previous changes: 3
- cloud/docs/relay-workflows.md
- cloud/dev/scripts/relay-same-cap-shadow-gate.mjs
- cloud/dev/scripts/relay-reserve-watch-rules.mjs
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
…leave, and the 503 publish-skew assumption Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
…keep no checkout token on disk Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d9b772e7-98f8-4280-bfb8-94aabd1c51c4
📒 Files selected for processing: 4
.github/workflows/cloud-operate-relay-production-reserve-watch.ymlcloud/dev/scripts/watch-relay-reserve-cell.mjscloud/dev/scripts/watch-relay-reserve-cell.test.mjscloud/docs/relay-workflows.md
🚧 Files skipped from review as they are similar to previous changes: 2
- cloud/docs/relay-workflows.md
- cloud/dev/scripts/watch-relay-reserve-cell.test.mjs
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
…ut lease, wait for reserve to apply, and control the duplicate read - A flip back whose write or plan never finished (no ID token, a failed login, a silent cell) raises an ::error:: annotation and a FLIP BACK FAILED summary, as the clock-skew monitor does. - The first segment reads the Cloud SQL rollout lease through the lease action's own reader and refuses to start while any run holds it, or when it cannot be read. - A cell not yet reporting reserve is waited on for up to 10 minutes, judging nothing, before the watch ends refused without a write. - The duplicate-seat read takes the per-minute ledger summary in the same query and window; with no fresh summary in it the sample is unverifiable, not zero duplicates. Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
A refused watch can leave a cell in reserve and unwatched, the same as a flip back that did not land. Both now raise an escaped ::error:: annotation through one `alarm` command, and in write mode write orca_relay_reserve_watch_alarm with gcloud logging write. A new log-based metric and alert policy page on any such line, per cell, through relay_alert_notification_channels, and the deploy identity gets roles/logging.logWriter in production to write it. Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
…say a failed login cannot page Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
…tcher # Conflicts: # cloud/package.json
ELI5
When a relay cell is switched to the new "reserve" placement mode (step 5), someone has to watch it and switch it back to the old database mode if anything goes wrong. Today that someone is a person reading dashboards. This adds a watcher that does it: it checks the cell once a minute and, the first time a stop rule is hit, switches the cell back with the same tool operators already use.
What Changed
Before: after a reserve flip, the §9 "auto-abort per flip" rules in the step 5 design existed only on paper. A bad flip lasted until an operator noticed it and ran
Operate Relay Production Cell FlagswithadmitMode=dbby hand.After: a new manual workflow,
Operate Relay Production Reserve Watch, watches one cell already in reserve mode for a set time (5 to 300 minutes). Each minute it reads the cell and the director signals and writes one JSON line. On the first trip, or if the watch itself dies or is cancelled before a verdict, it runs the flag tool's ownadmitMode=dbwrite, and the run fails with a one-line verdict.dry-runmode does everything except the write: it logs the flag tool's plan. Nothing runs it except a manual dispatch, and it is behind the sameORCA_CLOUD_OPERATIONS_ENABLEDgate as every relay workflow.Mechanism:
cloud/dev/scripts/relay-reserve-watch-rules.mjsholds the stop rules as pure functions over one sample plus the carried state.cloud/dev/scripts/watch-relay-reserve-cell.mjsdoes the reads and the flip back. The flip back callsoperateCellFlagsfromoperate-relay-cell-flags.mjs, so it keeps the CAS write, the 15 s read-back, the dead-man check, the re-registration wait and the Postgres record. It reads the current generation first. If another write lands in between (a generation conflict), it reads again and retries, up to 5 times with backoff, as long as the switch file still says reserve. If the file already says db, it stops without writing. If the cell still does not answer after 4 runtime-status tries with backoff, the ordinary flip back cannot work, so the run fails and prints the exact break-glass inputs for the flag workflow (set=admitMode=default,break-glass=BREAK GLASS <cell>, the current generation, the confirmation).flipped-at(when the reserve write applied), and the background is the median of the 10 minutes before it, read once Cloud Run has published them.background-503-per-minuteoverrides that. With neither, the watch refuses to start.generationConflict, so the retry does not match on error text.writemode, and only plans it indry-run. Every flip-back step runs onalways(), so a cancel does not skip the switch-file write. A cancel during the lease wait can still kill the process before Postgres records db, leaving the file at db and Postgres at reserve, and a force-cancel can stop it outright. Watches that endcompleted,stopped(someone flipped it back by hand) orrefused(never in reserve, or bad inputs) do not.Stop rules, and which signal each one uses (in precedence order: the first one that trips names the verdict, so exact signals come first):
runtime-statusreportsadmitModeEffective=dbwhile the switch file says reserveadmitMode=dbwrite within hoursruntime-status:enforcedConnectionUnitsoverconnectionCapacity.hardCaprequest_count503s per minute, compared with max(1.5x background, background + 20), the warn line the roll ladder already usesorca_relay_reserve_ledger_seat_behind_rowline for the cell, seen again more than 90 s after it was first seen (60 s demotion close + 30 s for the map to catch up), matched by director instance, cell, epoch and row epochruntime-statuscontrolsanddrainingorca_relay_reserve_ledger_summary, divided by the cell's controls, above 0.5% for 2 minutesIf a rule cannot be read, that sample counts as unverifiable, and
unverifiable-limitsuch samples in a row (default 3) is a trip of its own, so missing data never counts as healthy. For 503s, the read groupsrequest_countby response code in one query, and the newest minute any code has a point for marks how far the data is published. A 503 minute at or before that mark with no point had no 503s, so a quiet fleet reads zero; minutes after it are left out until published. Only no request series at all, too few published minutes, or an unparseable timestamp is unverifiable. Until the minutes beforeflipped-atare published, the 503 rule is "pending" and does not add to the unverifiable count.Why
operateCellFlags. A copy would drift away from it.relay-production-cell-flagsgroup, any later flag dispatch (a second trip, a dry run, a manual write) could cancel it and leave the cell in reserve after a trip. Holding that group for the whole watch would block every manual flag write, including a manual flip back, for hours. The flag tool's generation check already refuses a write that lands after someone else's, so the flip back simply re-reads and retries on a conflict.flipped-atmakes the baseline window explicit.Linked Issue
N/A (maintainer change; step 5 design §9 "Auto-abort per flip").
Visual Proof
N/A: no UI. It is a manual operations workflow and script.
Testing
node --test cloud/dev/scripts/watch-relay-reserve-cell.test.mjs: 33 pass. Each rule's trip and no-trip edges; a quiet fleet with zero 503s that never trips; the publishing front (minutes past it left out, sparse 503s read as zero, no request series unverifiable); the pending pre-flip background not adding to the streak;flipped-atchecked against the watch start in later segments; the flip back through the real flag tool in write and dry-run, conflicts, a slow runtime-status retried, an unreachable cell's break-glass inputs; workflow shape, includingalways()on every flip-back step.The whole
cloud/package.jsonnode --testlist: 835 pass, 0 fail; thepretestlist: 216 pass.actionlinton the new workflow: clean.Not run against staging or production: this PR dispatches nothing.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Two Opus review rounds. Round 1 fixed a cancellable flip back, a post-flip baseline, an unwatched dead watcher, the break-glass path and the duplicate-seat key.
Round 2 fixed a quiet fleet reading as unverifiable (now judged against the request series' publishing front), cancel-skipped flip-back steps,
flipped-ataging out in later segments, a pending baseline counting as a gap, and a single slow runtime-status reply sending the operator to break glass.Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)