Skip to content

fix(cloud): pin the asia cell database pool in the same-cap plan validator - #21171

Merged
Jinwoo-H merged 2 commits into
mainfrom
relay-same-cap-pool-pin
Sep 17, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
relay-same-cap-pool-pin

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​190 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​176
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55

ELI5

Three of our relay servers live in Hong Kong, and last week we told them to open more database connections than the servers in the US do. The safety check that runs before we deploy a new version to a server compares the machine's current setup line by line against the setup the deploy is about to write, and refuses to continue if anything it wasn't told about moved. Nobody told it about the connection-count change, so it saw "10" on the machine and "16" in the deploy and stopped every deploy to those three servers. This PR tells the safety check what the reviewed number is, so it can recognise the change instead of treating it as a surprise.

What Changed

Before. Since #21163 raised database_pool_max from 10 to 16 for production-gce-c27, c28 and c29, any same-cap roll of those three cells — forward, rollback or resume — stops with cell plan does not contain the reviewed image and capacity at plan validation. Nothing is applied, so the cells cannot take a new relay image at all. The other sixteen same-cap cells are unaffected.

After. A roll of an Asia cell validates, with the pool held to exactly the reviewed 16. A roll of a US cell validates as before, and now also fails if its plan grows a pool line at all.

Mechanism. Each cell's startup script is generated from a Terraform template that emits

  printf 'ORCA_RELAY_DATABASE_POOL_MAX=%s\n' '<n>'

only when a cell's region differs from the root region or its pool is off the default of 10. So the three Asia cells carry that line and the US cells carry no line at all.

The plan validator (cloud/dev/scripts/validate-relay-capacity-plan.mjs) proves a roll changes nothing but the image by normalizing the live startup script and the planned one and requiring the two to be byte-identical. It removes a line from that comparison only when it separately pins that line to an exact value supplied on the command line — the image digest, the connection hard cap, the unobserved bound, the capacity service account, and the rehome trust lines all work this way. The pool line was in neither list, so the live '10' and the planned '16' read as unreviewed drift.

This adds the pool to both lists at once:

  • A new optional --database-pool-max <1..100>, accepted in same-cap-cell mode only and rejected elsewhere, exactly as --regional-rehome-protocol is.
  • When it is supplied, the planned script must contain that pool line with that exact value, and the line is then masked from the equality comparison.
  • When it is not supplied, the planned script must contain no pool line at all, and nothing is masked. This mirrors the existing rule that a protocol-0 cell must not grow rehome trust lines.

The same-cap job (.github/workflows/cloud-deploy-relay-production-same-cap-job.yml) resolves EXPECTED_DATABASE_POOL_MAX from the cell id next to the hard cap and region (16 for c27|c28|c29, empty for the US cells), cross-checks it against database_pool_max in the committed relay_gce_cells map the way the hard cap is already cross-checked (asserting the default 10 for the cells it leaves unpinned), and passes the flag to both validator invocations — the apply-side one and the resume one — only when it is non-empty.

verify-relay-capacity-transition.mjs is untouched: it reads the cell's live admin status, which does not report the pool.

Why

The three Asia cells are currently undeployable. The pool value itself is correct and measured (176 ms from the us-central1 Postgres saturates a pool of 10, with 94–156 waiters), so the fix belongs in the gate that reviews it, not in the value.

Alternatives considered:

  • Mask the pool line unconditionally and pin nothing. One line, and it unblocks the roll — but it turns the pool into a field no gate reads. A plan that quietly moved an Asia cell to 99, or gave a US cell a pool line it should never have, would pass. Mask-plus-pin is the shape every other exempted line in this validator already uses, and it is the reason the guard is still a guard.
  • Revert the tfvars back to 10. Restores rolls immediately and loses the connection-ceiling fix that the Asia cells need.
  • Derive the pool inside the relay app instead of the startup script. The env var wins over any in-app default (config.ts), so the startup line would still be emitted and still be unreviewed. It moves the problem rather than solving it.

One consequence worth stating: both changed files are in TRUSTED_EVIDENCE_CODE_PATHS, so any monitor evidence or canary authority sealed before this merge is no longer byte-identical and will be refused. That is the intended behaviour of that check and is not weakened here — a roll after this merge needs a fresh dry run.

Linked Issue

N/A — follow-up to #21163, no separate issue filed.

Visual Proof

N/A — no UI. This changes a CI plan-validation gate and the shell that calls it.

Testing

Ran by hand against a synthetic plan for production-gce-c27 whose before and after startup scripts differ only in the pool line, 10 → 16:

$ node dev/scripts/validate-relay-capacity-plan.mjs --mode same-cap-cell \
    --cell-id production-gce-c27 --hard-cap 3000 --unobserved-bound 60 \
    --image ...@sha256:eee... --rollback-image ...@sha256:ddd... \
    --rehome-director-service-account [email protected] \
    --rehome-audience https://relay.onorca.dev/v1/admin/host-drain \
    --regional-rehome-protocol 3 < plan.json
cell plan does not contain the reviewed image and capacity
exit=1

$ # ... same command with --database-pool-max 16
{"event":"relay_capacity_plan_verified","mode":"same-cap-cell","changes":2}
exit=0

$ # ... same command with --database-pool-max 12
cell plan does not contain the reviewed image and capacity
exit=1

The first of those is the exact failure a real c27 roll hits today.

Automated:

  • node --test dev/scripts/*.test.mjs from cloud/ — 711 pass, 1 pre-existing failure (relay-load-control-peer.test.mjs cannot resolve @orca-cloud/relay-contract without a workspace install; it fails the same way on origin/main).
  • New cases in validate-relay-capacity-plan.test.mjs: pin matching passes; pin against a different value fails; no pin with a pool line present fails; no pin with a pool line unchanged on both sides still fails; a pin the plan does not satisfy fails; out-of-range pins are rejected; before 10 / after 16 with the pin passes the equality check; the flag is rejected outside same-cap-cell.
  • relay-same-cap-script-census.test.mjs now resolves the pool from the job's own shell block for every wave cell, cross-checks it against production.tfvars, requires both validator invocations to carry the flag and both steps to build it conditionally, and validates a plan per cell where the live template still says 10 — plus a negative that dropping the pin rejects an Asia cell and adding one rejects a US cell.
  • relay-regional-rehome-workflow.test.mjs's pin on the resume invocation's argument list updated for the added argument.
  • Mutation-checked the three new rules by deleting each in turn: removing the pin fails 2 tests, removing the absent-line rule fails 1, removing the mask fails 2.

Shell behaviour checked directly: with EXPECTED_DATABASE_POOL_MAX=16 the array expands to --database-pool-max 16; empty, it expands to zero arguments. Both changed run: blocks pass bash -n.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Platforms: CI-only change (Ubuntu runner, bash). No Orca client code touched, so macOS/Linux/Windows/SSH behaviour is unchanged.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: the flag is bounded to 1..100 and reaches the validator only from a case branch keyed on the cell id, cross-checked against the committed Terraform map — an operator cannot supply it. The change strictly narrows what the validator accepts for US cells and keeps Asia cells pinned to a reviewed constant. No production or cloud resource was touched and no Terraform ran against remote state. Mobile, remote-SSH and backwards compatibility: not reachable from this code.

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)

…dator

Raising `database_pool_max` from 10 to 16 for production-gce-c27, c28 and c29
made every same-cap roll of those three cells fail closed at plan validation.
The cell startup template emits `ORCA_RELAY_DATABASE_POOL_MAX` only for a cell
whose region differs from the root region or whose pool is off the default, so
the asia cells carry that line while the us-central1 cells do not. The plan
validator requires the before and after startup scripts to normalize to the
same text, masking only the lines it independently pins to a reviewed value.
The pool line was neither masked nor pinned, so the live template's `'10'` and
the plan's `'16'` were read as unreviewed drift.

The validator gains an optional `--database-pool-max`, accepted in
`same-cap-cell` mode alone. When it is supplied the after-script must contain
exactly that pool line and the line is masked from the equality check; when it
is not supplied the after-script must contain no pool line at all. Masking
without the pin would have removed the guard rather than moved it.

The same-cap job resolves the expected pool next to the hard cap, cross-checks
it against the committed `relay_gce_cells` map (asserting the default 10 for
the us-central1 cells), and passes the flag to both validator invocations only
for the cells that emit the line.
@Jinwoo-H
Jinwoo-H marked this pull request as ready for review September 17, 2026 06:30
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Opus review: GO (7/7 checks, no reproduced defects). Merge is deliberately held until the in-flight US same-cap roll finishes: this PR edits a TRUSTED_EVIDENCE_CODE_PATHS file, so landing it now would invalidate the sealed c7 canary authority and fail the remaining batches. Merge right after the US roll, before the Asia cells.

@pullfrog

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

@Jinwoo-H
Jinwoo-H merged commit 560c42e into main Sep 17, 2026
46 of 47 checks passed
@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The deployment workflow now derives database pool expectations per cell. The capacity-plan validator accepts and enforces --database-pool-max for same-cap-cell plans. Startup-script comparisons handle pinned and unpinned pool values. Tests cover pool resolution, plan transitions, invalid values, command arguments, and regional rehome workflow assertions.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 40861

An unpinned cell can retain an unexpected database-pool setting when its startup script uses noncanonical indentation. Broaden pool-line detection before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed and covers the change, reason, mechanism, testing, scope, and checklist. However, the required Linked Issue section says "N/A" even though the template requires an issue li… Add the linked issue reference, such as Fixes #21163`` or the correct follow-up issue number. Do not use N/A for the Linked Issue section.
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: pinning the database pool for the Asia cell in the same-cap plan validator.
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: Description check

Explanation

The description is detailed and covers the change, reason, mechanism, testing, scope, and checklist. However, the required Linked Issue section says "N/A" even though the template requires an issue link.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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: 79414b15-ff98-453f-9183-033b8a64d08f

📥 Commits

Reviewing files that changed from the base of the PR and between 01a1b6b and 40861cf.

📒 Files selected for processing (5)
  • .github/workflows/cloud-deploy-relay-production-same-cap-job.yml
  • cloud/dev/scripts/relay-regional-rehome-workflow.test.mjs
  • cloud/dev/scripts/relay-same-cap-script-census.test.mjs
  • cloud/dev/scripts/validate-relay-capacity-plan.mjs
  • cloud/dev/scripts/validate-relay-capacity-plan.test.mjs

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

const REHOME_CONFIG =
/^ printf 'ORCA_RELAY_REHOME_(?:DIRECTOR_SERVICE_ACCOUNT|AUDIENCE)=%s\\n' '[^'\n]+'$/

const DATABASE_POOL_MAX = /^ printf 'ORCA_RELAY_DATABASE_POOL_MAX=%s\\n' '[0-9]+'$/

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,120p' cloud/dev/scripts/validate-relay-capacity-plan.mjs
sed -n '185,295p' cloud/dev/scripts/validate-relay-capacity-plan.mjs
sed -n '430,485p' cloud/dev/scripts/validate-relay-capacity-plan.mjs
rg -n -C 3 'ORCA_RELAY_DATABASE_POOL_MAX|DATABASE_POOL_MAX|unexpectedDatabasePoolMax|normalizedStartupScript' cloud/dev/scripts/validate-relay-capacity-plan.mjs cloud/dev/scripts/validate-relay-capacity-plan.test.mjs cloud/dev/scripts/relay-same-cap-script-census.test.mjs

Repository: stablyai/orca

Length of output: 19872


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- validator tests around startup scripts and pool cases ---'
sed -n '680,870p' cloud/dev/scripts/validate-relay-capacity-plan.test.mjs
printf '%s\n' '--- all test references to database pool and same-cap validation ---'
rg -n -C 5 'database-pool-max|DATABASE_POOL_MAX|same-cap-cell|metadata_startup_script|startup script' \
  cloud/dev/scripts/validate-relay-capacity-plan.test.mjs \
  cloud/dev/scripts/relay-same-cap-script-census.test.mjs
printf '%s\n' '--- candidate startup-script fixtures ---'
rg -n -l 'ORCA_RELAY_DATABASE_POOL_MAX|metadata_startup_script' cloud/dev cloud | head -80

Repository: stablyai/orca

Length of output: 50369


Match pool assignments independent of leading whitespace.

DATABASE_POOL_MAX requires exactly two leading spaces. Shell accepts an unindented printf command. For an unpinned same-cap-cell, the validator does not detect a pool assignment with different indentation when the line appears in both the before and planned scripts. The normalized scripts then compare equal, so the plan can pass.

Broaden this detection pattern. hasExactSingleAssignment still requires the expected assignment string exactly for pinned pools.

Proposed fix
-const DATABASE_POOL_MAX = /^  printf 'ORCA_RELAY_DATABASE_POOL_MAX=%s\\n' '[0-9]+'$/
+const DATABASE_POOL_MAX = /^\s*printf 'ORCA_RELAY_DATABASE_POOL_MAX=%s\\n' '[^'\n]+'$/
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const DATABASE_POOL_MAX = /^ printf 'ORCA_RELAY_DATABASE_POOL_MAX=%s\\n' '[0-9]+'$/
const DATABASE_POOL_MAX = /^\s*printf 'ORCA_RELAY_DATABASE_POOL_MAX=%s\\n' '[^'\n]+'$/

ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…dator (stablyai#21171)

* fix(cloud): pin the asia cell database pool in the same-cap plan validator

Raising `database_pool_max` from 10 to 16 for production-gce-c27, c28 and c29
made every same-cap roll of those three cells fail closed at plan validation.
The cell startup template emits `ORCA_RELAY_DATABASE_POOL_MAX` only for a cell
whose region differs from the root region or whose pool is off the default, so
the asia cells carry that line while the us-central1 cells do not. The plan
validator requires the before and after startup scripts to normalize to the
same text, masking only the lines it independently pins to a reviewed value.
The pool line was neither masked nor pinned, so the live template's `'10'` and
the plan's `'16'` were read as unreviewed drift.

The validator gains an optional `--database-pool-max`, accepted in
`same-cap-cell` mode alone. When it is supplied the after-script must contain
exactly that pool line and the line is masked from the equality check; when it
is not supplied the after-script must contain no pool line at all. Masking
without the pin would have removed the guard rather than moved it.

The same-cap job resolves the expected pool next to the hard cap, cross-checks
it against the committed `relay_gce_cells` map (asserting the default 10 for
the us-central1 cells), and passes the flag to both validator invocations only
for the cells that emit the line.

* test(cloud): require the pool pin for a line the live template already carries
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