Repository navigation
infra(relay): raise asia-east2 cell pools to 16 and record the measured connection ceiling - #21163
Conversation
…cells The three asia-east2 cells sit 176 ms from the Cloud SQL instance in us-central1. Server-side statement time there is 0.2 ms, so a pool slot is held by the round trip, not by the query. At a pool of 10 they measured 94-156 waiters and 2 s waits, and client accepts ran a ~4 s p95 against 222-646 ms in us-central1. Raising those three pools to 16 is the agreed first step; every other cell stays at 10. c4 and c5 join the committed fence set. Both are existing-only capacity the admission selector can never place on again, they carried ~1 connection each on 40-day-old images, and each still holds 10 Postgres connections. The fence set is the prerequisite the fence-source workflow confirms before it drains and attests a cell; it is not itself the resize. c17 and c18 are not fenced here. They are migration-only, and the runbook requires retire-migration-cell to move a migration-only cell to existing-only through a generation-bound selector CAS before it can be fenced. Terraform cannot express that step. The Cloud SQL consumer contract carried two stale numbers: auth at 2 instances when production has run a cap of 20 since 2026-09-04, and a 400-connection ceiling when the live instance reports 500. Both are corrected, and the budget now asserts its headroom in two named gates instead of one aggregate boolean. Those gates fail: auth alone accounts for 200 configured connections and a 215-connection rollout overlap, so the operating maximum is 713 against a usable ceiling of 490. Nothing here caused that, and no pool was lowered to hide it.
The contract correction (auth at its real 20-instance cap, the measured 500-connection ceiling) makes the budget gate fail for reasons that have nothing to do with asia pools or fenced cells, and it held this branch red. It moves to its own branch where the failure is the subject. production-cloud-sql-app-consumers.json returns to main unchanged. The budget test keeps main's single gate and only repins the cell figure that this branch genuinely moves: 230 -> 228, being +18 for three asia pools at 16 and -20 for fencing c4 and c5. Against main's 400-connection model that leaves an operating maximum of 383 under a usable ceiling of 390.
Terraform now sets a cell's MIG target size directly from relay_gce_fenced_cells (relay-gce-cells.tf); the lifecycle ignore that used to protect operational target_size drift is gone. So a fence entry sitting on main ahead of its fence-source run is a standing instruction that any apply reaching that cell may execute without the documented drain and attestation. Keeping the entry in the same merge as an unrelated pool change widens that blast radius for no reason. The two entries move to their own branch, to be merged immediately before fence-source runs for c4 and then c5. This branch keeps the multi-line reflow of the list, which makes that later diff two added lines instead of a rewritten one. The cell figure in the budget test follows: 230 + 18 for the three asia-east2 pools at 16, with no fenced-cell subtraction. That is 403 operating against a usable ceiling of 390, so the headroom gate now fails by 13. It fails against a ceiling of 400 that is itself wrong; the instance reports 500. See the PR body.
The budget's usable ceiling came from maxConnections: 400, described as the tier default. It is a tier default, since no max_connections flag is set, but the instance does not report 400. SHOW max_connections on it returns 500, measured 2026-09-16. On main the model sat at 385 against a usable ceiling of 390, five connections of margin, so raising the three asia-east2 pools by 18 failed the gate by 13 against a ceiling that was never checked. Against the measured one it is 403 against 490, clearing by 87. Only the ceiling and its source note change here. auth stays recorded at 2 instances, which is also wrong; PR #21165 corrects it, and with the true auth figure the budget is over by 225 for reasons that have nothing to do with these pools.
There was a problem hiding this comment.
Caution
This PR's two value changes desynchronize four production checks that still hardcode the old numbers. Raising the committed pool to 16 makes the Asia shape validators reject the cells, and the maxConnections bump makes the Asia topology workflow's live-ceiling assertion fail closed. pnpm -r test stays green because those tests use 10-valued fixtures and string-match the workflow — none evaluates the committed values. Both need to be fixed before this can merge.
Reviewed changes
- Asia cell pools 10 → 16.
production-gce-c27/c28/c29inproduction.tfvarsgetdatabase_pool_max = 16; the budget test is repinned to cells 248 / ceiling 490 / operating max 403 / headroom 87, all internally consistent withrelay-cloud-sql-connection-budget.mjs. - Connection ceiling 400 → 500.
production-cloud-sql-app-consumers.jsonnow records the measuredSHOW max_connectionsand updates the source note. relay_gce_fenced_cellsreflow only. Same six cells, one per line, plus a two-line comment; no cell added or removed.
ℹ️ Ceiling references outside the contract still say 400 / 385
The contract now records a 500-connection ceiling and the budget models a 403 operating maximum, but four operational references still cite the old figures. The alert documentation is the one with practical fallout: it describes the trip point as "80% of the 400-connection ceiling", while the threshold of 320 is now 64% of 500 — an on-call reader gets a wrong mental model of how much room is left.
Technical details
# Stale 400-connection ceiling references
## Affected sites
- `cloud/infra/terraform/relay-observability.tf:622` — alert `relay_cloud_sql_backends` documentation: "exceeded 80% of the 400-connection ceiling ... modeled 385-connection operating maximum". The condition threshold is 320 (`:607`), so the "80%" claim is no longer true.
- `cloud/docs/relay-incident-monitor.md:105` — "over 250 (62% of the verified 400-connection ceiling)"; the same sentence appears at `:216`.
- `cloud/apps/relay-ops/src/incident-monitor.ts:48` — comment "firing well before the verified 400-connection ceiling".
## Required outcome
- Every ceiling/percentage/operating-maximum reference reflects 500 / 403, or is reworded so it does not depend on the ceiling figure.
- Decide deliberately whether the `relay_cloud_sql_backends` threshold should track 80% of the raised ceiling (400) or stay at 320; either way the description must match the number.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| "apiInstances": 10, | ||
| "apiPoolMax": 5, | ||
| "maxConnections": 400, | ||
| "maxConnections": 500, |
There was a problem hiding this comment.
Bumping maxConnections also changes the value the Asia topology workflow compares against the live instance. cloud-deploy-relay-asia-topology.yml:127 hardcodes live_max=400, and line 130 asserts test "${live_max}" = "${checked_max}". With no explicit max_connections flag — exactly the case this source note asserts — that assertion becomes test 400 = 500 and the workflow aborts before it plans the cells whose pool this PR raises.
Technical details
# `live_max=400` no longer matches the checked ceiling
## Affected sites
- `.github/workflows/cloud-deploy-relay-asia-topology.yml:127` — hardcodes `live_max=400` in the `verified-shape-default` branch; `:121-122` repeats the claim in a comment.
- `.github/workflows/cloud-deploy-relay-asia-topology.yml:107-108` — `checked_max` is `.maxConnections` from the budget report, now 500.
- `.github/workflows/cloud-deploy-relay-asia-topology.yml:110-130` — production-only comparison; the `else` branch is taken when `live_flag` is empty.
- `cloud/dev/scripts/relay-cloud-sql-connection-budget.mjs:138` — feeds `apps.maxConnections` through as `maxConnections`.
## Required outcome
- The workflow's verified-shape default and the contract must state the same number. If the live measurement of 500 is correct, update the `live_max` constant and the comment (and confirm the `db-custom-4-15360` + `POSTGRES_17` default really is 500); if 400 is the verified shape default, the contract change cannot stand as written.
- `cloud/dev/scripts/relay-asia-topology-workflow.test.mjs:74,77` only string-matches the workflow, so a test that evaluates the constant against the budget's `maxConnections` is what would have caught this.| boot_image = "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/images/cos-stable-121-18867-528-21" | ||
| capacity_requests = 6000 | ||
| database_pool_max = 10 | ||
| database_pool_max = 16 # 176 ms from us-central1 Postgres saturates 10 (94-156 waiters). |
There was a problem hiding this comment.
Raising the committed pool to 16 desynchronizes the Asia cell-shape checks that still pin 10. prepare-relay-asia-topology-input.mjs:79 throws committed Asia cell differs from the reviewed topology; validate-relay-asia-topology-plan.mjs:85 rejects the startup script because it now carries ORCA_RELAY_DATABASE_POOL_MAX='16'; and prepare-relay-asia-director-cells.mjs:39 rejects the cell. The unit tests miss all three because they use 10-valued fixtures.
Technical details
# Asia shape validators still require `database_pool_max = 10`
## Affected sites
- `cloud/dev/scripts/prepare-relay-asia-topology-input.mjs:79` — expected shape pins `database_pool_max: 10`; the canonical equality check at `:90-95` then throws. Invoked from `cloud-deploy-relay-asia-topology.yml:187` with `--existing-json` built from `.variables.relay_gce_cells.value` (`:182-186`), which is now 16.
- `cloud/dev/scripts/validate-relay-asia-topology-plan.mjs:85` — `startupValue(script, 'ORCA_RELAY_DATABASE_POOL_MAX') !== '10'`; `cloud/infra/terraform/relay-gce-cells.tf:231` sets `include_database_pool_max` true for any non-`us-central1` cell, so the asia startup script emits `16`. Throws `does not have the reviewed Asia cell shape`. Invoked at `cloud-deploy-relay-asia-topology.yml:192` and `:227`.
- `cloud/dev/scripts/prepare-relay-asia-director-cells.mjs:39` — `cell.database_pool_max !== 10`; the topology comes from `terraform output relay_gce_cell_deployments` (`cloud/infra/terraform/outputs.tf:174`). Invoked at `cloud-operate-relay-asia-admission.yml:454`.
## Required outcome
- Each check accepts the reviewed pool for the environment it validates and rejects drift from it.
- These scripts are shared with staging (`validate-relay-asia-topology-plan.mjs`'s `CELL_SHAPES`, `prepare-relay-asia-topology-input.mjs`'s `SHAPES`), whose asia cell stays at 10 — do not simply flip the constant to 16.
- Update the fixtures in `prepare-relay-asia-topology-input.test.mjs`, `validate-relay-asia-topology-plan.test.mjs`, and `prepare-relay-asia-director-cells.test.mjs` so the production shape exercises the committed value.…ed connection ceiling (stablyai#21163) * infra(relay): raise asia-east2 cell pools to 16 and retire four idle cells The three asia-east2 cells sit 176 ms from the Cloud SQL instance in us-central1. Server-side statement time there is 0.2 ms, so a pool slot is held by the round trip, not by the query. At a pool of 10 they measured 94-156 waiters and 2 s waits, and client accepts ran a ~4 s p95 against 222-646 ms in us-central1. Raising those three pools to 16 is the agreed first step; every other cell stays at 10. c4 and c5 join the committed fence set. Both are existing-only capacity the admission selector can never place on again, they carried ~1 connection each on 40-day-old images, and each still holds 10 Postgres connections. The fence set is the prerequisite the fence-source workflow confirms before it drains and attests a cell; it is not itself the resize. c17 and c18 are not fenced here. They are migration-only, and the runbook requires retire-migration-cell to move a migration-only cell to existing-only through a generation-bound selector CAS before it can be fenced. Terraform cannot express that step. The Cloud SQL consumer contract carried two stale numbers: auth at 2 instances when production has run a cap of 20 since 2026-09-04, and a 400-connection ceiling when the live instance reports 500. Both are corrected, and the budget now asserts its headroom in two named gates instead of one aggregate boolean. Those gates fail: auth alone accounts for 200 configured connections and a 215-connection rollout overlap, so the operating maximum is 713 against a usable ceiling of 490. Nothing here caused that, and no pool was lowered to hide it. * infra(relay): move the Cloud SQL contract correction out of this branch The contract correction (auth at its real 20-instance cap, the measured 500-connection ceiling) makes the budget gate fail for reasons that have nothing to do with asia pools or fenced cells, and it held this branch red. It moves to its own branch where the failure is the subject. production-cloud-sql-app-consumers.json returns to main unchanged. The budget test keeps main's single gate and only repins the cell figure that this branch genuinely moves: 230 -> 228, being +18 for three asia pools at 16 and -20 for fencing c4 and c5. Against main's 400-connection model that leaves an operating maximum of 383 under a usable ceiling of 390. * infra(relay): move the c4/c5 fence entries out of this branch Terraform now sets a cell's MIG target size directly from relay_gce_fenced_cells (relay-gce-cells.tf); the lifecycle ignore that used to protect operational target_size drift is gone. So a fence entry sitting on main ahead of its fence-source run is a standing instruction that any apply reaching that cell may execute without the documented drain and attestation. Keeping the entry in the same merge as an unrelated pool change widens that blast radius for no reason. The two entries move to their own branch, to be merged immediately before fence-source runs for c4 and then c5. This branch keeps the multi-line reflow of the list, which makes that later diff two added lines instead of a rewritten one. The cell figure in the budget test follows: 230 + 18 for the three asia-east2 pools at 16, with no fenced-cell subtraction. That is 403 operating against a usable ceiling of 390, so the headroom gate now fails by 13. It fails against a ceiling of 400 that is itself wrong; the instance reports 500. See the PR body. * infra(cloud-sql): record the measured 500-connection ceiling The budget's usable ceiling came from maxConnections: 400, described as the tier default. It is a tier default, since no max_connections flag is set, but the instance does not report 400. SHOW max_connections on it returns 500, measured 2026-09-16. On main the model sat at 385 against a usable ceiling of 390, five connections of margin, so raising the three asia-east2 pools by 18 failed the gate by 13 against a ceiling that was never checked. Against the measured one it is 403 against 490, clearing by 87. Only the ceiling and its source note change here. auth stays recorded at 2 instances, which is also wrong; PR stablyai#21165 corrects it, and with the true auth figure the budget is over by 225 for reasons that have nothing to do with these pools. * test(cloud): state the cell pool arithmetic literally in the budget pin comment
…d 500-connection default (#22386) The topology workflow's Cloud SQL gate carried a hard-coded 400 for the instance's tier default while the consumer contract records the value measured on the live instance (SHOW max_connections = 500, 2026-09-16, #21163). The gate compares the two and the first production plan run (35815654836) failed silently on that mismatch before Terraform ran. The verified default now lives beside the tier and version it is verified for, as VERIFIED_DEFAULT_MAX_CONNECTIONS, so the contract and the workflow are two independent records of the same measurement and the gate keeps its cross-check. The test pins the new source and forbids a bare literal. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

ELI5
People in Asia wait about four seconds to connect. Three of our servers live in Hong Kong, but the database they have to talk to lives in Iowa. Every question they ask takes a fifth of a second just to travel there and back, and each server only has ten phone lines to Iowa. The lines are all busy, so everyone queues.
This gives those three servers sixteen lines instead of ten. It also fixes a tally that claimed the database allowed 400 connections when it actually allows 500, which is what made the extra lines look unaffordable.
What Changed
Asia cell pools, 10 -> 16. In
cloud/infra/terraform/environments/production.tfvars,production-gce-c27,c28, andc29inasia-east2getdatabase_pool_max = 16. Every other cell stays at 10.The recorded connection ceiling, 400 -> 500. In
cloud/dev/contracts/production-cloud-sql-app-consumers.json,maxConnectionsand its source note.SHOW max_connectionson the live instance returns 500, measured 2026-09-16. The old value was described as the tier default, and it is a tier default since nomax_connectionsflag is set in either environment, but it was never checked against the instance.The
relay_gce_fenced_cellslist is reflowed to one entry per line with a comment. No cell is added or removed here; the reflow is so that #21166, which does add two, reads as two added lines rather than a rewritten one.The budget test repins to the figures that follow: cells 248, a usable ceiling of 490, and an operating maximum of 403.
Before and after, as a user experiences it: an Asia client's accept currently measures a p95 near 4 s against 222-646 ms in us-central1, because its cell's connection pool is queueing. Queueing theory on the measured service time puts the wait at 382 ms today and 1.8 ms at a pool of 16. Nothing changes for us-central1 users.
Why
The mechanism is round-trip time, not query cost. The renewal query that dominates the profile finishes in 64-256 microseconds server-side with zero disk reads. What holds a pool slot is the 176 ms trip to Iowa, multiplied by the 5-6 round trips a transaction makes. Measured service time per slot is ~390 ms in Asia against 22-115 ms in us-central1, which puts pool utilization at 0.92 — squarely in the queueing knee, where small load increases produce large waits.
Alternatives considered and rejected:
capacity_requestsorconnection_hard_cap.capacity_requestsis a placement budget; raising it sends more work to a starved cell.connection_hard_capaccepts only 600, 1000, or 3000, and Asia is already at 3000.Why the ceiling correction is in this PR
On
mainthe budget model sat at 385 against a usable ceiling of 390. Five connections of margin. Adding 18 takes it to 403 and fails the gate by 13 — against a ceiling that nobody had ever compared to the instance.Correcting only that one number is a narrow, independently defensible fix: the contract claimed a tier default it had not verified, and the instance reports 500. With the measured ceiling the usable figure is 490 and this PR's 403 clears it by 87.
The alternative was to lower a pool or shrink the reserve until 390 accommodated the change, which would have made a real capacity signal quieter instead of more accurate.
Linked Issue
Fixes #
Visual Proof
N/A— infrastructure configuration and a data contract. There is no user interface surface.Testing
Run from
cloud/, with Terraform 1.15.8 locally to match theterraform_version: 1.15.8pin in the workflows.terraform fmt -check -recursiveterraform init -backend=falsethenterraform validatepnpm -r testnode --testscript listpretestscript listNo Terraform apply was run and no remote state was touched.
initused-backend=false.The arithmetic:
mainmax_connectionsAI Disclosure
Review
The auth figure in that contract is still wrong, deliberately
The same file records auth at 2 instances. Production has run
auth_max_instances = 20since 2026-09-04, when a cap of 2 starved desktop token refresh with hours of 429s. This PR does not touch it.#21165 corrects it, and when it lands this budget goes red. With auth at its real 20 instances the operating maximum is 715 against a usable ceiling of 490, of which auth is 415: 200 configured plus a 215 modelled rollout overlap. That overshoot exists today on
main, hidden behind the stale figure. It is not caused by this PR and it is not closed by it — relay cells are 248 of the 715, and no relay-side change closes a 225-connection gap. Closing it is an auth sizing decision; #21165 lays out the options and what each one costs.So read this PR's green gate as "correct against the numbers currently recorded", not as "the shared instance has room". Those become the same statement only after auth is resized.
Scope
This PR was originally three changes. The full contract correction moved to #21165 because the auth figure turns the gate red for reasons unrelated to Asia. The c4/c5 fence entries moved to #21166 because Terraform reads MIG target size straight from
relay_gce_fenced_cellswith no lifecycle ignore, so a fence entry onmainis a standing resize instruction that any apply reaching those cells may execute without the documented drain and attestation. Those entries belong in a PR merged immediately before the fence run, not carried along by a pool change.Note on the comment style
The three pool comments are trailing rather than on their own line. A standalone comment splits
terraform fmt's alignment group and reflows seven unrelated attribute lines per cell, which would triple the diff for no gain.Related
All three touch
cloud/dev/scripts/relay-cloud-sql-connection-budget.test.mjsand will conflict textually. The conflicts are the pinned figures, a few lines each.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Security: no identity, permission, or trust boundary changes. Cross-platform: Terraform, JSON, and a Node test file, no platform-dependent behavior. Remote SSH and Mobile: unaffected; the push gateway runs on its own instance and is not in this budget. Backwards compatibility:
database_pool_maxis an existing per-cell field with a default of 10; raising three cells changes no wire format or client contract. Performance: the intended effect is lower connection-accept latency for Asia clients; judge it onclientAcceptTotalMsP95per region, not on waiter counts.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)