Skip to content

feat(runtime): a portal view readies its company's tier 2 tools before an open - #999

Merged
allisonmahmood merged 1 commit into
mainfrom
feat/portal-prewarm
Oct 29, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
feat/portal-prewarm

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What changed

The first open of a company's tier 2 tool waits for its server to start the tool's process: 1.8 s p50 in production for a version's first start, with first runs at p90 2.2 s. Now, when a signed-in member lands on Home or All patches, Patchy readies their company's server and the three live tier 2 tools they're likeliest to open, in the background, so the first open usually finds them running. A server it started that nobody uses is let go a few minutes later instead of after the 30-minute tail.

Look at

1. A prewarm is a short hold that runs no idle clock (fleetStore.ts, fleet.ts). lifecycle.prewarm(companyId) takes a lock of its own (execution/prewarm/<company>). The idle fence waits while it is held but doesn't restart the documents' window. It claims a spare only when it can lock one beyond the last ready spare and the fleet is under budget; otherwise it's full and takes nothing. It never waits for a launch. Its version loads go through the same ConnectedVersions keepalives as documents, admitted only on the live binding, and run neither clock. When the hold ends, a task nobody used is released at the next pass as unused; once a tool opens, the normal clocks take over. The new fleet tests pin each rule:

✓ prewarms a spare only while another stays ready, and lets a task nobody used go at once
✓ never prewarms a spare the fleet budget has no room to replace
✓ keeps a prewarmed task someone opened on the documents' clock
✓ holds a used task through a prewarm without restarting its documents' window

2. A prewarm never displaces a real tool, and an open displaces a prewarm (supervisor.ts, management.ts). A prewarm's loads are sent with a new optional speculative flag on the management bind. The supervisor loads a speculative bind only into a free residency slot and refuses it busy otherwise; it never evicts. Eviction takes speculative processes before any other, even one still initializing, so a real open displaces them instead of being refused; a demanded bind or a call makes one ordinary. A refused prewarm load counts as a full warmup on the keepalive event. Real-workerd tests at execution.residency.processes = 1:

✓ leaves a connected tool resident when a prewarm finds no free slot
✓ loads a real open at once over a prewarm still initializing
✓ evicts a speculative process before an older demanded one, until demand binds it
✓ never sends a speculative bind without its flag to a supervisor that refuses it

The first two are the review's probes with their assertions turned around: before this, the prewarm evicted the connected tool, and the real open was refused busy. Removing the "demand makes it ordinary" rule turns the third red (expected [ 'ver_new', 'ver_old' ] to deeply equal [ 'ver_guessed', 'ver_new' ]).

3. Landing to data, measured on the local fleet. Same brightline instance and database, one local-fleet host at a time, alternating this branch and main (6 opens a side per think time, each from a released company with two ready spares). Each trial: land on Home as a member, wait the think time, open New Business, and stop the clock when its first deal renders in the patch frame. Defaults throughout except execution.company.idle at 10 s and execution.prewarm.window at 20 s, so trials could repeat.

Think time Click to data, before Click to data, after Landing to data, before Landing to data, after
0.5 s 468 ms 251 ms 1000 ms 792 ms
2 s 456 ms 275 ms 2503 ms 2329 ms

Server-side, from the same runs' wide events: the opened tool's first run took a median 59 ms after versus 242 ms before, and every prewarmed open found its process resident. The local gap is about 200 ms because a local workerd start is that fast (median 201 to 206 ms here). On Fargate a version's first start is 1.8 s p50, which is what a prewarm takes off a first open once the member takes longer than that to click.

Raw runs (ms, click to data)

Quiet machine (load under 3), used in the table:

  • 0.5 s think, after: 259, 207, 259, 242, 282, 204 · before: 517, 322, 316, 589, 478, 457
  • 2 s think, after: 308, 299, 410, 251, 234, 172 · before: 535, 1176, 1070, 377, 329, 319

Earlier 2 s runs on a loaded shared machine (load 12 to 32), same direction, noisier: after 283, 360, 1068, 528, 956, 632, 896, 1850, 933 (median 896) · before 2130, 3066, 6991, 1703, 1913, 1868, 3243, 1137, 548 (median 1913).

4. What production will show. One type: "prewarm" event per prewarm, a child of the page view's request event:

{"type":"prewarm","outcome":"success","prewarm":"warmed","companyBind":"spare","versions":2,"followed":true,"durationMs":20080}

prewarm is warmed, cooldown, full (with outcome: "refused") or none. A claimed task nobody used shows on its binding event as releaseCause: "unused", without agentOnly. Keepalive events count prewarms apart from peakDocuments, and endReason: "prewarm" when a prewarm let go last. OPERATIONS › Prewarming from the portal has the queries.

How it was verified

  • New tests: four fleet cases and four residency cases (above), Prewarm.test.ts (top three by likelihood held for the window then let go, the per-company cooldown, residency cap, full, no tier 2 left), ConnectedVersions cases (a prewarm warms under its own speculative admission and counts as no document; a refused one counts full), and a portal case (Home and All patches hand over the viewer's live tier 2 tools, their opens first then visits; pages and retired tools never; nothing for a company without tier 2).
  • On a local-fleet host against pnpm dev up brightline: the measurements above; a Home view with no open afterwards bound a spare with neither clock run and released it 3 s after the window as unused; Home answered in 24 ms while the prewarm started.
  • pnpm check: format, lint, typecheck and synth pass. Its offline tests failed only in packages/patchy CLI files, which fail the same way on clean main on this shared machine (a stray GET / reaches their fake servers), and in two execution tests that pass when re-run alone. CI is the judge.
  • After the speculative fix: typecheck and lint pass, and packages/execution plus the prewarm suites pass (165 of 166). The one failure, does not reap active calls as idle…, times out on this machine right now with the supervisor from before the fix too, and passed in CI on the previous head.
  • Not checked: ECS and more than one host. Agents (Patchy MCP) and public readers never reach the portal, so they never prewarm.

Release impact

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

A new limit with a default, a new wide event type, a new release cause and an optional speculative field on the host-to-supervisor management bind. No migration, public API or CLI change. During a rolling deploy, a supervisor of the release before refuses the unknown field before any effect, so prewarms on its tasks only skip; nothing resends the bind without the flag.

  • What does a revert leave behind? Binding history rows with release_cause = 'unused' and agent_only null, and possibly a live binding a prewarm claimed with neither clock run.
  • Does the release before it still work with that? Yes. It reads the cause as text, and releases a binding whose clocks never ran at its next pass, as idle. Its hosts never send speculative, which this release's supervisors treat as absent; a process loaded speculatively before the rollback is then just an idle process. A company override for execution.prewarm.window is ignored by it, but an entry in PATCHY_LIMITS_JSON would stop it from starting (unknown limit), so set none there while a rollback past this is possible.

Rollback: if this release misbehaves, roll back to the release before it; nothing needs undoing.

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 area:ui Portal and first-party browser pages, shared rendering and styles size:l 501-1,000 changed lines size:xl Over 1,000 changed lines; review in multiple passes and removed size:l 501-1,000 changed lines labels Oct 29, 2026
…e an open

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 0f9edb4 into main Oct 29, 2026
24 checks passed
@allisonmahmood
allisonmahmood deleted the feat/portal-prewarm branch October 29, 2026 15:57
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 area:ui Portal and first-party browser pages, shared rendering and styles size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant