Skip to content

feat(infra): hosts and company boxes get a full vCPU, and the fleet runs 24 boxes - #984

Merged
allisonmahmood merged 1 commit into
mainfrom
t3/scale-fleet-vcpu
Oct 29, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
t3/scale-fleet-vcpu

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

What changed

Company boxes and hosts ran on half a vCPU, and production capped the fleet at 15 boxes with 2 warm spares. Both now get a full vCPU (memory stays 2 GiB), and the fleet can run 24 boxes with 3 warm spares. Patches should feel quicker, and more companies can be open at once before anyone waits for a box. 24 is what the account's current 30-vCPU Fargate quota allows at a full vCPU each; the budget goes to 30 once the quota is raised.

Look at

  1. The sizes and the fleet limits in apps/infra/src/AppStack.ts: exec and host task definitions go 512 → 1024 CPU units, and the hosts' PATCHY_LIMITS_JSON goes {"execution.fleet.budget":15} → {"execution.fleet.budget":24,"execution.pool.spares":3}. A new infra case pins them. It fails against main's stack and passes on this branch:

    # main's AppStack.ts with this branch's test
    × gives hosts and company boxes a full vCPU, and the fleet 24 boxes with three spares
    AssertionError: Template has 2 resources with type AWS::ECS::TaskDefinition, but none match as expected.
    Tests  1 failed | 6 passed (7)
    
    # this branch
    Test Files  1 passed (1)
         Tests  7 passed (7)
    
  2. execution.task.cpu and execution.task.memory stay, but inert and truthful. Nothing reads them: the ECS provider sends no size override, so the exec task definition sets every box's size. Their defaults now match it (1 vCPU, 2 GiB), and their measure says they aren't read and are kept so existing configuration still loads. docs/limits.md says where the size comes from. A PATCHY_LIMITS_JSON naming either id still loads, and stored override rows can still be read and removed. Removing the ids is a separate change that needs a deprecation path. The limits docs and skill snapshots are regenerated.

  3. The Fargate vCPU quota in docs/OPERATIONS.md › Production. The account's Fargate On-Demand vCPU quota must cover 24 boxes + 4 hosts mid-deploy + the promote task, which is 29 vCPUs (it was 10), inside the current 30. Fargate refuses launches past the quota, so raising the budget to 30 needs the quota raised first.

  4. Freeing budget for a promotion, a new runbook in OPERATIONS.md › Rolling back. Housekeeping never trims the current revision's surplus spares. So a rollback to an older release (budget 15, floor 2) can stall forever with no company bound once this release holds 14 or more spares. Waiting and re-running don't help. The runbook has two statements for the platform database:

    • A count query that diagnoses the stall and gives stops: max(0, live + max(0, floor − staged spares and starting) − budget). live is every starting, spare and bound task of either revision, so a fleet already over the staged budget is covered; stopping tasks are already leaving, so recounting right after a fence is correct.
    • The fence the controller itself puts on a spare before stopping it (fleet.ts, drainTask). It sets the current revision's newest spare rows to stopping with FOR UPDATE SKIP LOCKED, so it never takes a row a claim holds, and a claim never takes a row it holds. Housekeeping's reconcile stops every stopping task through ECS on its next pass, so the operator never calls ECS. That path has existed since the fleet landed (feat(execution): manage company task fleets #438), so every release production could roll back to has it.

    If stops is more than the eligible spares, the runbook says the rest must come from bound companies going idle, and to count again each round.

    A throwaway probe on this head ran both statements verbatim (placeholders filled) with the real controller and store, disposable Postgres and the memory provider:

    race A: fence in open transaction [race-spare-00]
    race A: claim while fence uncommitted no spare
    race A: claim after commit no spare   # row is stopping
    race B: claim in open transaction race-spare-01
    race B: fence while claim uncommitted []
    race B: fence after commit []         # row stays bound
    stalled [larger spare 16] promoted false
    count {live 16, stopping 0, current_spares 16, staged_spares 0, stops 3}
    fenced [larger-spare-13, larger-spare-14, larger-spare-15]
    count after fence {live 13, stopping 3, stops 0}
    pass 1 [larger spare 13] promoted false   # the controller stopped the three
    pass 2 [larger spare 13, older spare 2] promoted true
    after promotion [older spare 2]           # the surplus drains on its own
    

    This PR adds no controller test for it, because packages/execution belongs to another lane this round. The probe is the reproduction.

Docs that followed: OPERATIONS.md (promotion now needs three ready spares within 24), ADR-0012's production topology and hosting decisions 1–2, product.md's box size and cost promise (about $36 a month for an always-on box instead of $21, with the per-call figures scaled the same way), and a packages/serving comment that said "half a vCPU". ADR-0012's spike measurements still say half a vCPU on purpose: they record what was measured. The spike script keeps its own 512.

How it was verified

  • pnpm --filter @patchy/infra exec vitest run: red on main's stack, green here (above). The security-group snapshot doesn't cover task sizes, so it is unchanged.
  • packages/limits and apps/infra tests: 6 files, 32 tests pass. A probe loads {"execution.task.cpu":0.5} and {"execution.task.memory":2147483648} on this head without error, as on main.
  • pnpm check: format, lint, typecheck and synth pass. The offline tests fail locally in the packages/patchy CLI suites and LocalTaskProvider. That's stray GET / requests from another process on the shared machine reaching the tests' fake servers on random localhost ports (expected { method: 'GET', url: '/' } to match object { url: '/api/me' }). A different set fails on every run, and SdkApi.test.ts's two 5-second timeouts pass when run alone (21/21). CI is the clean run.
  • Not checked: the deploy and a real ECS rollback. The runbook's statements ran against Postgres with the real controller, not against production.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

Infrastructure sizing and production's fleet limits, which fit the account's current Fargate vCPU quota, so nothing is needed before deploying. No API, CLI, schema or configuration-format change: every limit id that loaded before still loads, and stored overrides stay readable. The deployment configuration's revision hash changes because execution.task.cpu's default moved from 0.5 to 1. It changes whenever a resolved value does, and nothing reads that value.

  • What does a revert leave behind? Nothing stored: no schema, no rows. Exec task definitions are retained on replacement, so the 1-vCPU revision stays registered, and the previous release's hosts can still launch and manage its spares until promotion.
  • Does the release before it still work with that? Yes. An older release's stacks carry their own sizes (0.5 vCPU), budget (15) and spare floor (2), and the deploy record hands its hosts this release's exec task definition as "previous". Its promotion needs two ready spares inside 15 live tasks, counting this release's bound boxes and spares. Once this release holds 14 or more spares, that never happens on its own, even with no company bound.

Rollback line for the deploy: if this release misbehaves, roll back to the live commit. If the rollback's promote step times out short of two older spares, follow OPERATIONS.md › Freeing budget for a promotion: count, fence stops of this release's newest spares with the controller's own fence, recount until the older revision has its two spares, then re-run the run. If there aren't enough spares to fence, the rest of the room comes from bound companies going idle.

Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.

@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area size:m 100-500 changed lines labels Oct 28, 2026
@allisonmahmood allisonmahmood changed the title feat(infra): hosts and company boxes get a full vCPU, and the fleet runs 30 boxes feat(infra): hosts and company boxes get a full vCPU, and the fleet runs 24 boxes Oct 29, 2026
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
)

## What changed

A box's first tier 2 process took 1.8 s to start in production (p50),
while a respawn of the same version took 0.5 s. Most of the gap was the
supervisor bundling its own loader worker with esbuild the first time it
started a process. On half a vCPU, esbuild's threads exhaust the CFS
quota and stall. The CLI already shipped this worker prebuilt; services
didn't.

The execution package's build now bundles the loader into
`dist/loader.js` (`scripts/build-execution-loader.mjs`, run after `tsc`,
like the serving broker's build), and built code always reads it. Only a
source checkout (dev and tests) still bundles on first use. That makes
the `__PATCHY_PACKED_LOADER__` define the CLI build set unnecessary, so
it's removed. esbuild and es-module-lexer become dev dependencies and
leave the server image. The image build now checks that the staged
loader's only import is `cloudflare:workers`, so an unbundled loader
can't ship.

This also speeds up the host's first bundle inspection, which starts a
workerd through the same path.

## Look at

The real supervisor (compiled, as the image runs it) binding a real tier
2 bundle (New Business from `brightline`, 226 KiB) under a CFS quota on
two pinned CPUs. Medians of 7 interleaved runs each:

| | main | this PR |
| --- | --- | --- |
| First process on a box, 0.5 vCPU | 1,283 ms | **419 ms** |
| Respawn, 0.5 vCPU | 402 ms | 407 ms |
| First process on a box, 1 vCPU | 633 ms | **199 ms** |
| Respawn, 1 vCPU | 202 ms | 217 ms |

A box's first process now costs the same as any other. This machine's
cores are about 1.5× Fargate's (main's 402 ms respawn here vs 468 ms p50
in production), so production should see the first process drop from
~1.8 s to ~0.5 s on today's 0.5 vCPU boxes, and to ~0.3 s on 1 vCPU
(#984).

The esbuild step alone, timed from a cold Node process the way a box
runs it:

```
CPUQuota=50%, 2 CPUs:  build 403 / 449 / 460 ms
CPUQuota=100%, 2 CPUs: build 207 / 239 / 263 ms
```

## How it was verified

- Staged the image runtime (`node scripts/build-server-image.mjs
--stage`) with no esbuild in it, then bound both brightline tier 2
bundles through its supervisor: first process 225 ms, second version 252
ms, respawn 208 ms (unthrottled).
- The staging check rejects tsc's unbundled `loader.js` and accepts the
built one.
- `Process`, `Engine` and `Inspection` tests pass from source (the dev
path, which still bundles).
- CI's packed CLI e2e covers the CLI's own `dist/loader.js`, which it
now reads without the define.

Not measured: production's cold page cache for the 133 MB workerd
binary. It cost 10–20 ms here on local NVMe.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Build output only: the image ships the loader prebuilt instead of the
bundler that made it.

- **What does a revert leave behind?** Nothing. The previous image
bundles at first use, as it always did.
- **Does the release before it still work with that?** Yes. No wire,
schema or configuration change.

Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…uns 24 boxes

Rebased onto main after the TypeScript 7 stack (#985).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit ee167e1 into main Oct 29, 2026
39 of 40 checks passed
@allisonmahmood
allisonmahmood deleted the t3/scale-fleet-vcpu branch October 29, 2026 16:36
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
…orecast passes $600 (#990)

## What changed

The production budget emails when the month's forecast passes $300. With
full-vCPU hosts and company boxes (#984), idle infrastructure alone is
about $180 a month, so that alert will fire on ordinary busy weeks. This
keeps the $300 alert exactly as it is and adds a second one, a new
budget that emails when the forecast passes $600.

## Look at

- **Two budgets, not two notifications on one.** CloudFormation replaces
an `AWS::Budgets::Budget` to change its notifications, and the
replacement would collide with the fixed `patchy-monthly` name and fail
the base stack deploy (caught in review). The $600 alert is its own
budget, `patchy-monthly-600`; `apps/infra/src/BaseStack.ts` builds both
from one helper.
- **The $300 budget doesn't change at all.** Synthesizing the production
base stack on main and on this branch gives an identical `Spend`
resource, so the deploy only creates `SpendHigh`:

  ```
  main ids: ['Spend']  branch ids: ['Spend', 'SpendHigh']
  Spend identical on branch: True
  ```

- **Email verification.** AWS Budgets emails a newly added address only
once it is verified in the account, and one verification covers every
budget. Addresses already verified in the account are active at once,
and recipients added before AWS introduced verification keep receiving
alerts unchanged. So the alert addresses may get a verification email
from an `@aws.com` sender when the new budget appears; open its link
while signed in to the account. `docs/OPERATIONS.md` records both
budgets, why each alert is its own budget, and the verification step.

## How it was verified

- `vitest run src/stacks.test.ts` in `apps/infra`: 7 passed. The new
case pins exactly two budgets, each one's name, type, period, amount,
its forecast-above-100% notification and its email subscriber.
- The identical-`Spend` comparison above, from the synthesized
templates.
- Prettier, ESLint and `tsc` on the infra package.
- Not checked: the deploy itself and the email; both happen on the next
release.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Infrastructure only: one new AWS budget in the production base stack.
The existing budget is untouched.

- **What does a revert leave behind?** Nothing: the base stack deletes
`patchy-monthly-600` on its next deploy, and `patchy-monthly` is
unchanged either way.
- **Does the release before it still work with that?** Yes. Releases
don't read budgets.

Made by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, running in
T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
## What changed

This adds release 23's What's new entry, written from `ed80fc7`. It
covers everything merged since release 22's `through` (`a2d1331`), and
sets the `patchy` release to `0.23.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`. This is the speed and capacity release: patches
that run server code open faster, and the fleet has room for more
companies at once.

| Change | PRs |
| --- | --- |
| Improved: Patches with server code open faster. Landing on Home or All
patches readies the company's server and its three most-opened patches,
a patch stays ready for ten minutes after use instead of one, loading a
patch takes a third of the time, and each company server has twice the
CPU | #991, #992, #997, #999, #984 |
| Behind the scenes: Patchy can run patches for more companies at the
same time (24 company boxes instead of 15, and 64 companies per host
instead of 16) | #984, #993 |

Two merged PRs get no line, because nobody using Patchy would notice
them: #990 (a second AWS cost alert, at $600) is operations tooling, and
#1049 (a test fix for flake #1012) is test churn. #1046 is release 22's
own entry.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`.
- **Rollback safety, from the live commit `eb414ed` (release 22) to
`ed80fc7`:**
  - No PR in the range is labelled `one-way`, and none adds a migration.
- #984 and #990 change infrastructure. A rollback redeploys release 22's
stacks: 0.5 vCPU tasks, a fleet budget of 15 with two spares, and no
`patchy-monthly-600` budget (the base stack deletes it; `patchy-monthly`
is untouched). Exec task definitions are retained, so release 22's hosts
can still manage this release's boxes until promotion.
- #984's one rollback hazard: once this release holds 14 or more spare
boxes, release 22 can't fit its two spares inside its budget of 15, and
its promote step times out. The fix is the runbook in
`docs/OPERATIONS.md` › Freeing budget for a promotion.
- #999 leaves binding history rows with release cause `unused`, which
release 22 reads as text. #999's new `speculative` bind field is refused
by release 22's supervisors before they act, so prewarms on those boxes
are skipped during a rolling deploy.
- Neither `execution.process.load` (#992) nor `execution.prewarm.window`
(#999) is set in production's `PATCHY_LIMITS_JSON`, so release 22 loads
the configuration unchanged.

**Rollback line:** If this release misbehaves, roll back to `eb414ed`
(release 22). If that rollback's promote step times out short of two
spares, follow `docs/OPERATIONS.md` › Freeing budget for a promotion,
then re-run it.

## How it was verified

- **Tests.** `whatsNew.test.ts`, `WhatsNewPages.test.ts` and
`schemas.test.ts` pass (21 tests), and prettier passes on the changed
files.
- **The range.** Each PR was Sol-reviewed with every finding fixed.
After the TypeScript 7 stack (#985), all seven were rebuilt on one
integration branch, with each conflict and each TypeScript 7 fix kept in
the PR it belongs to. `pnpm check` passed there, apart from local-only
CLI and supervisor test failures caused by T3 probing this machine's
ports. Each PR then landed with all 12 required checks green on its
rebased head, and main's tree after #990 equals the integration tip.
Re-runs: `clerk-live` once on #984 (a sign-in handshake flake). On #992,
flake #1012 failed twice and was fixed by #1049 instead of re-running.
- **Deploy state.** The live commit, pinned from `/healthz/deep`, is
`eb414ed` (release 22). The Deploy run updated last succeeded, and none
is unfinished.
- **Quota.** #984 peaks at 29 vCPUs during a deploy (24 boxes, 4 rolling
hosts, the promote task), inside the account's current 30.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Text and version numbers only. The `0.23.0` bump tells CLIs and patch
repos installed before this deploy to upgrade, as every release does.

- **What does a revert leave behind?** Nothing.
- **Does the release before it still work with that?** Yes.

Made by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, running in
T3 Code.

Co-authored-by: Claude Opus 5.5 <[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 area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant