Skip to content

feat(relay): watch a reserve cell and flip it back on the first step 5 stop rule - #28698

Merged
Jinwoo-H merged 10 commits into
mainfrom
relay-reserve-flip-watcher
Oct 15, 2026
Merged

Jinwoo-H merged 10 commits into
mainfrom
relay-reserve-flip-watcher

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​984 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​982
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1373 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1354

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 Flags with admitMode=db by 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 own admitMode=db write, and the run fails with a one-line verdict. dry-run mode does everything except the write: it logs the flag tool's plan. Nothing runs it except a manual dispatch, and it is behind the same ORCA_CLOUD_OPERATIONS_ENABLED gate as every relay workflow.

Mechanism:

  • cloud/dev/scripts/relay-reserve-watch-rules.mjs holds the stop rules as pure functions over one sample plus the carried state.
  • cloud/dev/scripts/watch-relay-reserve-cell.mjs does the reads and the flip back. The flip back calls operateCellFlags from operate-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).
  • The 503 baseline comes from before the flip. The operator gives 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-minute overrides that. With neither, the watch refuses to start.
  • The flag tool changes only to export readers that already existed and to mark its two generation-conflict errors with generationConflict, so the retry does not match on error text.
  • The workflow copies the flag workflow's production environment, deploy identity, ID-token audience and token masking. An ID token lasts an hour, so the watch runs in six 55-minute segments, logging in again before each one; the state carries over in a file. The segment command lives once in job env and each segment step runs it. Each segment checks the token's shape first, as the monitor job does.
  • A watch that fails, times out or is cancelled (including by the operator) without a verdict flips back like a trip in write mode, and only plans it in dry-run. Every flip-back step runs on always(), 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 end completed, stopped (someone flipped it back by hand) or refused (never in reserve, or bad inputs) do not.
  • Terraform adds the new file to the workflows the shared deploy identity trusts, and the identity, census and workflow-count tests are updated to match. This takes effect only when that Terraform is applied; until then the workflow cannot log in.

Stop rules, and which signal each one uses (in precedence order: the first one that trips names the verdict, so exact signals come first):

Rule (§9) Signal Exact or proxy
(added) Dead-man tripped runtime-status reports admitModeEffective=db while the switch file says reserve Exact. The runbook already requires the admitMode=db write within hours
Any overrun cell runtime-status: enforcedConnectionUnits over connectionCapacity.hardCap Exact, but an invariant check, not a detector: the cell's ledger already refuses past its cap, so this trips only if that refusal broke
Sticky + placement 503s > 1.5x background for 3 min Director Cloud Run request_count 503s per minute, compared with max(1.5x background, background + 20), the warn line the roll ladder already uses Proxy that can miss. It is fleet-wide, because no existing signal ties a 503 to the cell a host was headed for, so a problem on one cell can stay under the whole fleet's line. It also lags about 3 minutes, because Cloud Run publishes metrics late
Duplicate seat past its grace The ledger reconcile's orca_relay_reserve_ledger_seat_behind_row line 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 epoch Proxy that can only over-count. The line does not name the host, so two hosts that share that key read as one seat
Host drop > 5% in 5 min outside a drain cell runtime-status controls and draining Exact. Also needs a drop of at least 10 hosts, so a nearly empty cell's normal churn does not trip it
Ledger drift > 0.5% after 2 min Queued plus dropped rows in each director's newest orca_relay_reserve_ledger_summary, divided by the cell's controls, above 0.5% for 2 minutes Proxy that can only over-count. The summaries count every reserve cell together, so it is exact only while this is the only reserve cell

If a rule cannot be read, that sample counts as unverifiable, and unverifiable-limit such samples in a row (default 3) is a trip of its own, so missing data never counts as healthy. For 503s, the read groups request_count by 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 before flipped-at are published, the 503 rule is "pending" and does not add to the unverifiable count.

Why

  • Reusing the flag tool rather than writing a second write path. Every safety property of a flip back already lives in operateCellFlags. A copy would drift away from it.
  • No shared concurrency group; the CAS orders writes instead. GitHub keeps only one pending run per concurrency group, and a newer pending run cancels the older one. If the flip back waited in the flag workflow's relay-production-cell-flags group, 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.
  • A baseline from before the flip. A watch starts after the cell is already in reserve, so "the minutes before the watch" would measure the reserve cell itself. flipped-at makes the baseline window explicit.
  • Using proxies instead of adding new cell or director telemetry. New telemetry would need new images and deploys before a single watch could run. The proxies are named in the code, the JSON lines, the docs and the table above. Two of them can only over-count, which errs toward flipping back (by §7 that disconnects nobody). The 503 rule can miss a cell-local problem; the exact cell-side rules (overrun, host drop, dead-man) are what cover that cell.

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-at checked 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, including always() on every flip-back step.

  • The whole cloud/package.json node --test list: 835 pass, 0 fail; the pretest list: 216 pass.

  • actionlint on 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-at aging 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Before the first dispatch: the Terraform list change must be applied with a targeted plan on the deploy provider's attribute condition. Until then the workflow cannot log in, which keeps it inert.
  • A director restart (new instance id) restarts the duplicate-seat first-seen clock, since the key includes the instance.
  • Cross-platform, SSH and mobile: not affected. Ubuntu runner 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)

…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
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 407eb893-73f8-465b-94f8-cc49da87db81
📥 Commits

Reviewing files that changed from the base of the PR and between f2ce633 and 1a16840.

📒 Files selected for processing: 5
  • .github/workflows/cloud-operate-relay-production-reserve-watch.yml
  • cloud/dev/scripts/relay-reserve-watch-rules.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.test.mjs
  • cloud/docs/relay-workflows.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

📝 Walkthrough

Adds a manually triggered workflow to watch a production relay cell in dry-run or write mode. The watch samples runtime and director signals, evaluates rules, and persists state across segments. The workflow can run a flip-back operation after a trip or when the watch stops before a verdict. The change also updates workflow identity allowlists, documentation, and tests, and removes one test file from the package test command.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 1a168

The workflow remains mergeable with a wording correction: operators should not read its cancellation comment as a guarantee that force-cancel will flip the cell back.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 46 functions across 8 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: watching a reserve relay cell and flipping it back when a stop rule trips.
Description check Passed The description follows the repository template and covers the user impact, implementation, rationale, linked-issue exception, testing, risks, and checklist. It also documents known cancellation limit…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 54.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 46 functions across 8 files. (2 skipped: 2 unsupported.)

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: 4b3ad46a-a8e8-4295-9fcf-346c664b9a6f
📥 Commits

Reviewing files that changed from the base of the PR and between 04e8cd9 and b862378.

📒 Files selected for processing: 12
  • .github/workflows/cloud-operate-relay-production-reserve-watch.yml
  • cloud/dev/scripts/operate-relay-cell-flags.mjs
  • cloud/dev/scripts/relay-production-identity-boundaries.test.mjs
  • cloud/dev/scripts/relay-public-workflow-contract.test.mjs
  • cloud/dev/scripts/relay-reserve-watch-rules.mjs
  • cloud/dev/scripts/relay-same-cap-shadow-gate.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.test.mjs
  • cloud/dev/scripts/workload-identity-attribute-conditions.test.mjs
  • cloud/docs/relay-workflows.md
  • cloud/infra/terraform/relay-github-actions.tf
  • cloud/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

@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: 5b14055e-f10b-4417-adb2-2797ff81f99d
📥 Commits

Reviewing files that changed from the base of the PR and between b862378 and 297f6a8.

📒 Files selected for processing: 6
  • .github/workflows/cloud-operate-relay-production-reserve-watch.yml
  • cloud/dev/scripts/operate-relay-cell-flags.mjs
  • cloud/dev/scripts/relay-reserve-watch-rules.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.test.mjs
  • cloud/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

@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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1459d239-7221-4dc4-a7a6-a07f77078875
📥 Commits

Reviewing files that changed from the base of the PR and between 297f6a8 and be7e1cc.

📒 Files selected for processing: 6
  • .github/workflows/cloud-operate-relay-production-reserve-watch.yml
  • cloud/dev/scripts/relay-reserve-watch-rules.mjs
  • cloud/dev/scripts/relay-same-cap-shadow-gate.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.test.mjs
  • cloud/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

@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: d9b772e7-98f8-4280-bfb8-94aabd1c51c4
📥 Commits

Reviewing files that changed from the base of the PR and between be7e1cc and f2ce633.

📒 Files selected for processing: 4
  • .github/workflows/cloud-operate-relay-production-reserve-watch.yml
  • cloud/dev/scripts/watch-relay-reserve-cell.mjs
  • cloud/dev/scripts/watch-relay-reserve-cell.test.mjs
  • cloud/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
@Jinwoo-H
Jinwoo-H merged commit 6e46d5e into main Oct 15, 2026
23 checks passed
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