Skip to content

perf(execution): processes stay warm for ten minutes after their last call - #992

Merged
allisonmahmood merged 1 commit into
mainfrom
perf/execution-warm-window
Oct 29, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
perf/execution-warm-window

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

What changed

A tier 2 version's process was reaped after 60 seconds without a call. The same limit also capped an unfinished load. In production, a respawn costs ~470 ms (p50) plus cold patch code (guest time ~150 ms on a first run vs ~30 ms warm), so anyone back after a minute waited for both.

  • Load and idle are separate limits. execution.process.load (60 s from spawn, not company-overridable) bounds an unfinished load, with the same load_failed refusal and report cause as before. execution.process.idle now means only the ready process's idle window, and its default rises from 60 s to ten minutes. A page reopened within ten minutes of its last call or touch finds its version loaded and its code warm. The company task is already held 30 minutes after the last document lets go (execution.company.idle), so the box exists either way.
  • Local fleet tasks get the load deadline too. Execution tasks read it from PATCHY_LIMITS_JSON at startup, since no bind carries it. The local provider records the host's resolved value in each task's request, and the owner hands it to the task the same way.
  • Idle residents are cheaper to watch. The watchdog sampled /proc and probed /healthz for every resident every 250 ms. A ready process with no call in flight is now watched once its last good probe is a second old. A process that stops answering is watched every tick again, toward the same six-second stall kill. Loading processes, and processes with a call in flight, keep the 250 ms cadence and every kill line.

Memory budget

The longer window fills a budget that already existed and never exceeds it:

  • An idle process holds ~80 MiB RSS (measured here; production peaks were 82–93 MB).
  • Residency is unchanged: 12 processes and 1.5 GiB aggregate per company task, supervisor included. Twelve idle residents measured 1,120 MiB aggregate, inside the 1.5 GiB line on a 2 GiB task.
  • When a bind needs room, eviction takes idle processes first, as before: the largest under memory pressure, otherwise the one idle longest. A busy box behaves exactly as it does today. Only a quiet one keeps more versions warm.
  • No extra Fargate cost: billing is per task allocation, and the task lifetime is unchanged.

Look at

Reopening after 80 seconds, on this worktree's instance (pnpm dev up brightline, pnpm dev shot allison /brightline/new-business twice, wide events from dev.log):

main:     open → deals.board processGeneration 1 · 80 s later: process event cause "idle" · reopen → processGeneration 2 (respawn)
this PR:  open → deals.board processGeneration 1 · 80 s later: no process event          · reopen → processGeneration 1 (warm)

What a return within the window saves, real supervisor and New Business bundle at 0.5 vCPU (CFS quota on two pinned CPUs, medians of 7): a respawn is a 402 ms bind plus a first call of ~14 ms, against a warm call of ~9 ms. This machine runs about 1.5× Fargate's speed, which matches production's 468 ms respawn p50.

Watching idle residents: 12 idle residents for 20 s at 0.5 vCPU, two runs each:

supervisor CPU workerd CPU aggregate RSS
main (every 250 ms) 7.6%, 7.6% of a core 1.3%, 1.4% 1,130 MiB
this PR (once a second) 2.3%, 3.1% 0.4%, 0.4% 1,095–1,113 MiB

On a half-vCPU box, that's the difference between ~18% and ~6% of the box spent watching processes nobody is using.

How it was verified

  • New supervisor test: an idle process gets 2–4 probes in 120 ticks; one with a held call gets more than 40 in 80 ticks.
  • The load-expiry tests now set execution.process.load. One keeps the default ten-minute idle window, which shows the deadline is its own. The touched-process test sets a load deadline that passes mid-test, which shows a ready process answers to its idle window alone.
  • New local-provider test: with {"execution.process.load":1000} configured on the host, a task's never-finishing load fails load_failed within a second and reports it. Without the fix, the same bind times out as transport behind the 60 s default.
  • Supervisor, Local, Management, LocalTaskProvider, limits, API docs and ConnectedVersions suites pass locally.
  • Outside this lane, one line: packages/runtime/src/ConnectedVersions.test.ts simulated a fixed ten minutes and expected ten keepalive touches, which assumed the 60 s window. It now simulates ten idle windows, as its neighbours do.
  • Generated limit docs (docs/limits.md, the patchy-server skill table) and docs/API.md are re-rendered. ADR-0012 and OPERATIONS describe both limits and the watchdog cadence.

Release impact

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

An operating default rises and a new deployment-only limit appears. The management wire is unchanged: hosts still push only execution.process.idle to supervisors.

  • What does a revert leave behind? Nothing stored. If someone has set execution.process.load in PATCHY_LIMITS_JSON, a release without the limit refuses that configuration as unknown, so remove it before rolling back. Nothing sets it today.
  • Does the release before it still work with that? Yes. During a rollout, hosts of this release push the ten-minute idle window to the previous release's supervisors, which also apply it to unfinished loads until their tasks are replaced. A hung load there lives ten minutes instead of one, within the same residency bounds.

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 force-pushed the perf/execution-warm-window branch from 1d450bb to ec08b86 Compare October 29, 2026 15:01
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
…loop can add (#1049)

## What changed

A Fleet test failed often in CI: a refused call reported waiting 40,500
ms instead of 40,000. The call arms its 40-second wait just after it
reads the clock, and the test's loop moves the clock in 500 ms steps
alongside it. When a step lands between those two, the wait arms one
step late. The test now accepts exactly that one step. The product code
is unchanged.

Closes #1012

## Look at

- **`packages/execution/src/Fleet.test.ts`, the refused call.** `found`
and `refused` are still exact, and `waitedMs` must be 40,000 or 40,500,
never shorter than the pool wait. This is the "asserts within one step"
option from the issue.
- **Why now.** This failed on `test (24)` twice in a row on #992 (run
40897302040, both attempts), with the same diff as on #1000:
  ```
  -   "waitedMs": 40000,
  +   "waitedMs": 40500,
  ```
Neither #992 nor any of the speed PRs queued behind it touch this test
or `fleet.ts`'s wait. They each run it on three Node versions, so it
would keep blocking them.

## How it was verified

- The case passes 3 of 3 locally: `pnpm vitest run
packages/execution/src/Fleet.test.ts -t "says how a call found"`.
- `pnpm typecheck:tests`, oxlint and prettier pass on the file.
- CI on this PR runs the full suite on Node 22, 24 and 26.

## Release impact

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

Test only.

- **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]>
… call

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the perf/execution-warm-window branch from ec08b86 to c9d5cf7 Compare October 29, 2026 15:33
@allisonmahmood
allisonmahmood merged commit eed8d54 into main Oct 29, 2026
23 checks passed
@allisonmahmood
allisonmahmood deleted the perf/execution-warm-window branch October 29, 2026 15:45
allisonmahmood added a commit that referenced this pull request Oct 29, 2026
## What changed

Every bind of a tier 2 version started a fresh workerd, waited for it
and its loader worker to come up, and only then loaded the patch.
Startup is the same for every version: process exec, config, and
evaluating the 186 KiB loader (most of it Effect Schema). On half a vCPU
it was ~40% of each process start.

Execution tasks now keep one **standby process**: a workerd started
ahead of the next bind.

- It starts while the task is a spare, so a company's first bind finds
it ready. After a bind adopts it, the replacement starts once the task
has been quiet for a second, with no load or call in flight, so it never
competes with the version being loaded or the call that follows.
- A bind adopts it and only loads its version. From then on it is that
version's process, with a fresh generation and its own report, exactly
as if spawned for it. It never serves another version.
- Security properties are unchanged (ADR-0012). The standby has its own
uid, an empty environment and `globalOutbound: null` for guests. Its
callback route exists in its config, but no resident serves it until a
bind adopts the standby. Epochs, generations and every watchdog kill
line apply from adoption on. No version code runs in it before the bind
that owns it.
- Residency: the process-count limit counts loaded versions, so a full
task runs 12 versions **plus** the standby. The standby counts toward
aggregate RSS (~58 MiB idle), memory pressure discards it before
evicting any version, and a replacement waits for room.
- Health: the watchdog samples and probes the standby as it does an idle
resident. When it exits, can't be sampled, crosses the RSS kill line or
stalls for six seconds, the watchdog discards it without a report, since
no version ran in it. A bind passes over a standby that has missed two
probes and starts its own process. An adopted standby keeps its health
clock rather than a fresh grace window. After a failure or any discard,
memory pressure included, the next standby starts ten seconds later at
the earliest.
- Stop: a task-wide stop takes the admission a bind registers under, so
a bind racing it is refused or has its process reaped. Nothing it loads
outlives the stop. Once admitted, the stop checks its epoch again, so an
older host's stop that waited while a newer host bound the task gets
`stale_epoch`. Binds, invokes, touches and stats already check their
epoch inside admission or never wait on it. The decision to start a
replacement standby is made inside that same admission too, so a stopped
task never gets one.
- `startMs` on process events, and a report's start time, now run from
the bind, which is what a call waits for, so production's p50 will show
the gain directly. CPU seconds and peak RSS stay whole-process counters,
so an adopted standby's include the trusted loader's start before the
bind.

`dist/exec.js` and the local fleet's tasks turn it on. The local no-pool
executor (dev and tests) still spawns on demand.

## Look at

The real supervisor binding New Business (226 KiB) from `brightline`,
with a fake host answering its callbacks. CFS quota on two pinned CPUs,
same build with and without a standby, 7 interleaved runs each, medians
in ms, machine quiet (load ~4):

| | without standby | with standby |
| --- | --- | --- |
| Respawn bind, 0.5 vCPU | 211 | **125** |
| Respawn bind, 1 vCPU | 112 | **61** |
| First process on a box, 0.5 vCPU | 1,080 | **176** |
| First process on a box, 1 vCPU | 455 | **67** |

First calls after the bind are unchanged (9–16 ms). The "first process"
row also includes the runtime loader bundle that #991 removes; with a
standby, a spare task pays that before any bind. Production's respawn is
468 ms p50 on 0.5 vCPU today, about 2.2× this machine's 211 ms.

## How it was verified

- New supervisor test (Linux): a standby workerd exists before any
company binds. A bind adopts that exact pid and serves a callback
through the standby's route. After a quiet second a replacement appears
and stays nobody's until the next bind, which adopts it. Stopping the
task leaves no workerd children.
- Four more supervisor tests for review findings. A task-wide stop
racing a bind that finds its standby dead leaves nothing running. A
standby stopped with SIGSTOP is passed over, and the bind starts its own
process within 3 s instead of failing six seconds later. A standby that
exits is discarded with no report. Memory pressure gives back the
standby first, and even with room restored at once, no replacement
starts for ten seconds. An older host's task-wide stop, queued behind a
newer host's bind, gets `stale_epoch` and leaves the task bound at the
new epoch. A task stopped as it starts, with the watchdog forced to
yield every eight operations, never gets a standby. All but one fail on
the head before each fix. The memory-pressure test only failed once the
restored-room check was added; discard-first already worked. The
reviewer's race, stall, epoch-stop and pressure-backoff probes now pass:
the replacement standby came 10,043 ms after a pressure discard.
- `Supervisor`, `Local`, `LocalTaskProvider` (real local tasks, now with
standbys), `Management`, `Inspection` and `Process` suites pass. One
fencing test read the old `/callback/<generation>/<uuid>` route shape
from config. Routes are now `/callback/<uuid>`, since a standby's route
exists before its generation does.
- This conflicts textually with #992 (adjacent constants in
`supervisor.ts`). I merged #991, #992 and this branch locally, resolved
it and ran the suites together. Whichever lands second needs a one-line
rebase.

## Release impact

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

Supervisor-internal: no wire, schema or configuration change. Each
execution task holds one more idle workerd, which counts toward
aggregate RSS but not the 12-version process count.

- **What does a revert leave behind?** Nothing. Tasks from this release
keep their standby until they're replaced, and hosts don't know it
exists.
- **Does the release before it still work with that?** Yes.

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

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