Repository navigation
fix(infra): production hosts cap company-database connections so a rolling deploy fits Neon's limit - #531
Conversation
…lling deploy fits Neon's limit Each host may hold 200 company-database connections by default, and a rolling deploy runs up to four hosts against a Neon compute that allows 446 non-superuser connections. Production now sets PATCHY_COMPANY_DB_MAX_BACKENDS to 64: four hosts at 79 connections each plus the promote task's platform pool is 326. Refs #416 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Codex review (GPT 6.1 Sol, high): safe to merge, high confidence. It confirmed 79 connections per host, and 4 × 79 + 10 for the promote task = 326 of 446, against the source. One low finding, fixed in b701410: ECS's |
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Codex round 2 (GPT 6.1 Sol, high) on b701410: safe to merge, high confidence. The round-1 finding is resolved and nothing new turned up. It left one optional nit, applied in 34b8aa5 using its suggested wording: AWS's API reference and developer guide disagree on whether stopping tasks count toward |
A pull request that touches only `packages/execution`, `apps/infra`, the dev `scenarios/`, `t3.json` or `favicon.svg` gets no area label, because `.github/labeler.yml` names none of them (#471, #531 and #532 went out with no area or only `area:docs`). Triage reads the matching table in `docs/agents/triage-labels.md`, which had the same gaps. Nothing enforced the "change both together" note at the top of the labeler config, so the next package would slip through the same way. ## What changed - `packages/execution/**` and `apps/infra/**` join `area:server`. Execution is part of the Runtime context and infra is the hosting side. - `scenarios/**`, `t3.json` and `favicon.svg` join `area:ci`. These are the seeds `pnpm dev up` builds environments from, plus T3 Code's project config and icon. - The triage table's `area:server` and `area:ci` rows now match the globs line for line. The whole table is rewrapped because prettier pads its columns. - `scripts/labeler.test.ts`, which runs in `pnpm test`, reads the labeler config's `area:*` globs. It matches each directory git lists under `apps/` and `packages/` with minimatch and `dot: true`, the way actions/labeler v7 does, and fails naming any directory with no area. It probes each directory with `<dir>/package.json`: #471 touched only that and the lockfile, and a Markdown probe would always match `area:docs`. `minimatch` and `yaml` become root devDependencies; both were already in the lockfile. ## What I checked by hand The test, against deliberately broken configs: | Change | Result | | --- | --- | | None | passes | | Delete the `packages/execution/**` glob | fails: `expected [ 'packages/execution' ] to deeply equal []` | | Delete the `apps/infra/**` glob | fails: `[ 'apps/infra' ]` | | Rename `area:server` to `server` | fails, naming its 15 directories | | Add an untracked, unignored `packages/zz-scratch/package.json` | fails: `[ 'packages/zz-scratch' ]` | | Add an untracked `packages/core/zz-café.txt` (git quotes non-ASCII paths unless `-z`) | passes | I also ran actions/labeler's own code (`getLabelConfigs` and `checkMatchConfigs` with `dot: true`, from its source at the SHA pinned in `pr-labels.yml`) over `main`'s config and this branch's: | Changed files | `main` | this branch | | --- | --- | --- | | `scenarios/team/scenario.json` | none | `area:ci` | | `scenarios/brightline/patches/kudos/index.html` | none | `area:ci` | | `t3.json` | none | `area:ci` | | `favicon.svg` | none | `area:ci` | | `packages/execution/src/index.ts` | none | `area:server` | | `packages/execution/package.json` + `pnpm-lock.yaml` | none | `area:server` | | `apps/infra/src/index.ts` | none | `area:server` | | `pnpm-lock.yaml` alone | none | none (as the table says) | The label workflow runs on `pull_request_target` and reads `labeler.yml` from `main`, so this PR's own labels come from the old config. The new globs apply to PRs opened after this merges. ## Hit every surface Applied: the labeler config and triage table pair. They agree on every area changed here. Did not apply: the wire contract, CLI, dev loop (no runner or seed change), vocabulary, migrations, company resources, served pages, reverse states and repo layout. Closes #498 Made by Claude Opus 5.5 in Claude Code, running in T3 Code. --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Each production host may hold 200 company-database connections by default (
PATCHY_COMPANY_DB_MAX_BACKENDS). A rolling deploy runs up to four hosts (maxHealthyPercent: 200), which could ask the Neon compute for about 800 connections when it allows 446 non-superuser ones. See the connection budget note on #416.Fix
The host container sets
PATCHY_COMPANY_DB_MAX_BACKENDS: "64". The env var is the only knob:company.connections.hostBackendsis alegacylimit, soPATCHY_LIMITS_JSONrefuses it.Per host, from the source:
PgCompanyDatabasesreserves each pool's maximum againstmaxBackendsbefore opening itSql.layer→@effect/sql-pgdefaultmaxConnections; also serves the runtime-wakesLISTEN(pool.reserve)placementClientLayeradminLayerensureReady, which runs inside a placement-pool transaction, so at most 2 at onceFour hosts: 316. The deploy workflow's promote task (
node dist/fleet.js promote, from the host task definition) opens onlySql.layer: +10, so 326 of 446, leaving 120 for operator sessions and connections still closing. The exec task has no environment or secrets and never connects to Postgres. The cap allows up to 94 per host before four hosts plus promote would exceed 446. 64 keeps a margin and matches the number in #416.What this means for users: a host holds at most 16 companies' four-connection pools at once. Pools stay reserved for 60 seconds after their last use, and past the cap requests get a
busywith retry metadata. Across two hosts that is about 32 recently active companies, well above beta load. Raise the cap together with the compute's connection ceiling.docs/OPERATIONS.md(Production) now records the cap and when to raise it.apps/infra/src/stacks.test.tsasserts the value beside theMaximumPercent: 200check it depends on; the snapshot only pins security groups, so it does not change.Hit every surface
AppStack.ts, and raising it is a deploy.docs/OPERATIONS.mdupdated.Refs #416.
Checks:
pnpm checkandpnpm verifypass locally.Made by Claude Opus 5.5 (1M context) in Claude Code, running in T3 Code.