Skip to content

fix(infra): production hosts cap company-database connections so a rolling deploy fits Neon's limit - #531

Merged
allisonmahmood merged 3 commits into
mainfrom
fix/infra-company-db-backend-cap
Oct 5, 2026
Merged

allisonmahmood merged 3 commits into
mainfrom
fix/infra-company-db-backend-cap

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

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.hostBackends is a legacy limit, so PATCHY_LIMITS_JSON refuses it.

Per host, from the source:

Pool Max Where
Company pools (budget) 64 PgCompanyDatabases reserves each pool's maximum against maxBackends before opening it
Platform pool 10 Sql.layer → @effect/sql-pg default maxConnections; also serves the runtime-wakes LISTEN (pool.reserve)
Placement pool 2 placementClientLayer
Admin 1 adminLayer
Provisioning data connection ≤ 2 one per ensureReady, which runs inside a placement-pool transaction, so at most 2 at once
Host total 79

Four hosts: 316. The deploy workflow's promote task (node dist/fleet.js promote, from the host task definition) opens only Sql.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 busy with 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.ts asserts the value beside the MaximumPercent: 200 check it depends on; the snapshot only pins security groups, so it does not change.

Hit every surface

  • Wire contract, CLI, dev loop, served pages, migrations, repo layout: not touched.
  • Vocabulary and product shape: no new concept; the limit is already in the registry.
  • Company resources: no new company-database caller; this only lowers an existing per-host budget.
  • Reverse states: the cap is one value in AppStack.ts, and raising it is a deploy.
  • Docs: docs/OPERATIONS.md updated.

Refs #416.

Checks: pnpm check and pnpm verify pass locally.

Made by Claude Opus 5.5 (1M context) in Claude Code, running in T3 Code.

…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]>
@github-actions github-actions Bot added area:docs Touches the docs area size:s Under 100 changed lines labels Oct 5, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

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 maximumPercent counts only running and pending tasks, so a stopping host (up to stopTimeout 120s) still holds connections that the four-host figure doesn't count. The 120 connections of headroom cover it, and docs/OPERATIONS.md now says so.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@allisonmahmood

Copy link
Copy Markdown
Owner Author

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 maximumPercent, so the doc now says only that draining or stopping hosts may still hold connections. Docs only; the cap and the test are unchanged.

@allisonmahmood
allisonmahmood merged commit 8f8a171 into main Oct 5, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the fix/infra-company-db-backend-cap branch October 5, 2026 01:21
allisonmahmood added a commit that referenced this pull request Oct 15, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Touches the docs area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant