Repository navigation
perf(execution): warm calls stop re-sending their server bundle to the task - #773
Merged
Merged
Conversation
…bundle A version bind can name its version by `binding` (company, patch, version, SHA-256) instead of carrying its bundle. A supervisor holding a live process for it answers as a bundle bind would; one that doesn't refuses `bundle_required` before any effect, and the host sends the same bind with its bundle. Hosts bind by hash first only to supervisors of their own release. Runtime binds again once, under a fresh attempt, when an invoke is refused before dispatch with `bundle_required` or `stale_generation`. The refused invoke ran nothing, so it isn't one of the handler's attempts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s show on wide events A local task owner can outlive its host's checkout, so a restarted host may send a bind by hash to a supervisor that refuses the `binding` key with `invalid_request`. That refusal comes before any effect, so `bindByHash` now sends the bundle after it too, still never after a transport or protocol failure. Fleet hosts keep sending binds by hash only to their own release. A call or re-run that goes back to bind after a refused invoke records `rebound: true` on its wide event. The rebind no longer checks the deadline itself: every pass already does before it binds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
allisonmahmood
added a commit
that referenced
this pull request
Oct 18, 2026
…ading it (#775) The supervisor reaped a version's process 60 s (`execution.process.idle`) after its last call, whether or not anyone had the patch open. In production, 25 of 44 reaps in a week happened while a document for that version was open, so reading a page for a minute and then switching screens reloaded the process: first runs took p50 1.12 s against 0.50 s warm, and 3 of 44 hit the 3 s query deadline. The load also only started when the first query arrived, while the client was still booting. Now a host keeps the version of each connected, ready tier 2 document warm by **touching** it before each idle window ends, and a document's first stream **warms** its version as it becomes ready. ## How it works **Touch** is a new private management operation, `POST /touch { bindingEpoch, binding }`. For a ready process of exactly that version and hash at the current epoch, it restarts the idle clock and answers `touched`. A loading process answers `loading` and keeps its initialization deadline from spawn; no live process answers `absent`. It never loads, reserves, evicts or changes the epoch. Every reply also carries `idleMs`, the idle window the supervisor reaps by: its last bind's setting. A different hash is `binding_conflict`; it checks `wrong_task` and the epoch like every other operation. **Where the bookkeeping lives:** a new runtime module, `ConnectedVersions`, one per host, built beside the fleet in `FleetInvocation` and used by `RuntimeStream` (absent in no-pool dev, like `ExecutionLifecycle`). It keeps one keepalive per company + patch + version, not per document: - **Open:** when a tier 2 stream sends `ready`, it calls `connect(version, { warm })` for the stream's lifetime. The first holder starts the keepalive, whose first touch is immediate. - **Reconnect, reauthentication, resume:** the shell sends `X-Patchy-Generation` on every stream after a document's first hello, so `warm` is true only when it is absent. A document warms once; its renewals only touch, so a version evicted under pressure reloads on demand, never on renewal. No state is needed for this, and it holds across hosts. - **Last disconnect or hidden suspension:** both close the stream, which releases its hold. The last release ends the keepalive, and the process idles out as before. - **Binding changes (adoption, epoch, deployment replacement):** each touch goes through `ExecutionLifecycle.touch`, which reads the company's current *active* binding and sends to that task at that epoch. It never admits, claims a task or binds; a company without an active binding gets no touch (`unbound`). - **Pause:** each touch reads the patch's breaker first (as admission does, off in dev). A paused patch gets no touch, and its warmup doesn't bind. - **Retire and delete:** the stream's existing authority checks close those documents, which ends their keepalive. - **A new publish while open:** the document keeps its loaded version, so its keepalive keeps that version. A reload opens a new document on the new version, which warms it; the old one idles out. **Cadence:** the first touch is immediate. Each later touch starts at a random 30–40 % of the idle window after the previous one *started*, whatever that one cost, and gives up after 10 %. The window is the smaller of the company's configured `execution.process.idle` (read through `StreamLimits`) and the `idleMs` the supervisor last answered. A changed limit reaches the supervisor only with its next bind, so a raise spreads touches out only once the supervisor has it, and a cut applies from the next turn. A cut can still reap a process already idle longer than the new window, as it would without touches; demand reloads it. So a lost touch, even one that fails only at the provider's timeout, still leaves the next to land within 90 % of the window after the last that landed, and versions spread out. This is derived from the idle window, so there is no new registry tunable. **Warmups:** on a first stream, the keepalive's touch decides. `touched` or `loading` is enough (`resident`, `loading`). On `absent`, it binds the version under a normal call admission (`acquire`, then the server bundle, then `executor.bind`, which binds by hash first), concurrent with client boot, without delaying `ready`. A `paused` or `unbound` touch tries nothing. Warmups are bounded: - one per logical document; - coalesced per company, version and host: a holder joins or creates its version's keepalive in one synchronous step, and warm requests set a flag that keepalive serves, so concurrent documents share one touch and at most one bind at a time. The bind runs beside the touches, so it never delays them; - only for documents whose company task is already bound, so they never claim a task or count against the fleet budget beyond what the first call would; - the supervisor's residency and memory caps and the provider's management timeout bound the bind like a call's, and its admission stays interruptible as a call's does, so a keepalive whose last document leaves mid-admission claims and binds nothing; - a failed warmup is silent apart from the wide event. It doesn't take a subscription run slot, so it never delays the first queries. **More open versions than the process cap (13 under 12):** touches never reserve or load, so they can't cause evict/reload churn. Touched residents count as recently used in the eviction order, so versions without open documents go first. Under pressure, demand (a call or a first-stream warmup) still evicts the least recently used, and touches of the evicted version then answer `absent` until demand reloads it. Memory-pressure eviction is unchanged. **Observability:** one new wide event, `type: "keepalive"`, per company version per host when its last document leaves: `peakDocuments`, `touches` by outcome (`touched`, `loading`, `absent`, `unsupported`, `paused`, `unbound`, `failed`) and `warmups` by outcome (`resident`, `loading`, `loaded`, `bound`, `paused`, `unbound`, `failed`). This measures what the issue asks for: - `touches.absent` counts versions evicted or reaped while open; - process events with `callsServed = 0` after a `loaded` warmup are unused warmups; - `cause = "evicted"` is residency churn; - the first call per process generation against warmup timing gives the cold calls avoided. A touch per open version every ~25 s per host would be too noisy as its own event, so they are counted. OPERATIONS has a query. ## Rollout Touch is a new route, and supervisors' schemas are strict, so it follows #768/#773: - The ECS provider sends it only to tasks of its own release's task definition (`sameRelease`), and through the same verified endpoint cache. - A task of another release gets `unsupported` without a request. Its release is remembered, so later touches don't ask ECS again; a task's definition never changes, and the memory is forgotten on stop. - Older hosts never send it. - A local task owner that outlived its host's checkout answers 404, which counts as a `failed` touch: no retry before the next turn, and nothing reaches viewers. - A warmup for an older supervisor (`unsupported`) is a normal bind (`bound`). No migrations. ## Tests - `Supervisor.test.ts` (real workerd): - a touched process outlives its idle window, and a touch for a version it doesn't hold loads nothing; - hash and epoch mismatches are refused; - once untouched, the process idles out and a touch finds `absent`; - an unfinished load still expires at its deadline from spawn while touches arrive; - one more touched version than the process cap: no evictions and no reloads across two idle windows; a demand bind then evicts once, and that version's touches find `absent` without reloading it. This runs at a cap of 2 rather than 12: touches never reserve, so the property doesn't depend on the cap, and twelve workerd processes would dominate the suite. - `Management.test.ts`: `/touch` authenticates before reading the body and refuses `wrong_task` before any effect. - `EcsTaskProvider.test.ts`: an older-release supervisor is never sent a touch, and ECS is asked once about it; a same-release touch reuses the cached endpoint. - `Fleet.test.ts`: a touch claims nothing for an unbound company, follows adoption's new epoch, and sends nothing for a paused patch. - `ConnectedVersions.test.ts` (TestClock, injected ports): - warms once per document and coalesces documents; - a renewal of an evicted version only touches; - a paused version is neither loaded nor woken; - each version gets one touch per turn within 40 % of the idle window, however many documents hold it; - with the widest jitter and every other touch lost, failing only at the provider's 10 s timeout, each landing still follows the last within the idle window; - four concurrent first holders, interleaved by a small scheduler budget, share one keepalive; - touches keep to the supervisor's acknowledged window while a raised limit hasn't reached it, spread out once it has, and tighten from the next turn after a cut; - a warmup waiting for admission is cancelled when its last document leaves: nothing is admitted afterwards, and the keepalive reports once; - the last document leaving stops touches. - `RuntimeStream.test.ts`: a ready document holds its version until disconnect, with `warm` only on its first stream. ## Numbers I measured on the local fleet (`pnpm dev up brightline`, `EXECUTION_PROVIDER=local-fleet` via a temporary, uncommitted runner edit) with `PATCHY_LIMITS_JSON={"execution.process.idle":20000}`. Each pass, as a member: 1. open the New Business board cold; 2. keep it open 30 s; 3. open a deal (a new `deals.timeline` query on the same version); 4. close the page. There were three passes each, on `origin/main` and this branch. | | main | this branch | | --- | --- | --- | | Open → board shows deals (browser) | 311, 313, 323 ms | 215, 216, 221 ms | | Stream open → first board answer (server) | 160–168 ms | 130–137 ms | | Process reaped while the board was open | yes, 20.1 s after the first call | no | | Deal opened after 30 s: its run | 115–124 ms, **new process generation** | 28–30 ms, same generation | | Deal opened: click → timeline shows (browser) | 217–231 ms | 120–128 ms | | After closing | reaped 20 s after the last call | reaped 20 s after close (lifetime 50.4 s = 30.3 s open + 20 s) | | `keepalive` event per pass | none | `touches {touched: 3, absent: 1}`, `warmups {loaded: 1}` | A local load costs ~90 ms; in production the first run was p50 1.12 s, so the gap there should be correspondingly larger. The open-time gain is small locally because the client boots in ~100 ms here, against ~1 s in production. `pnpm verify` passes. Closes #753 Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 18, 2026
allisonmahmood
added a commit
that referenced
this pull request
Oct 19, 2026
…ng Reconnecting (#783) Release 14's What's new entry, written from \`7694bab\`. It covers everything merged since release 13's \`through\` (\`c9b8fc4\`), and sets the \`patchy\` release to \`0.14.0\` (\`packages/patchy/package.json\` and \`CURRENT_RELEASE\`). | Change | PRs | | --- | --- | | Improved: Tools with server code answer faster | #756, #764, #768, #769, #771, #772, #773, #775, #778 | | Improved: Your company's tools and pages open sooner | #759, #761, #766, #770 | | Fixed: Tools stop flashing Reconnecting while they load | #755, #776, #780 | | Improved: Publishing is quicker | #729 | | Improved: New tools start with a tidy layout | #763 | | Improved: Your usual is easier to scan | #721 | | Fixed: A page that isn't there says what to do | #762 | | Fixed: A logo Patchy can't read is refused, not a crash | #728 | | Behind the scenes: richer logs for live data | #758 | #720 is release 13's own entry, so it's left out. Made by Claude Opus 5.5 via Claude Code. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every top-level tier 2 call sent the version's whole server bundle (about 216 KB in production) in
POST /bind. When the version was already loaded with the same hash, the supervisor returned the existing process and never used the bytes, so on a warm call the upload, its JSON encoding and the supervisor's two strict decodes were pure waste.The fix
A bind by hash.
BindRequestgains an optionalbinding(company, patch, version and SHA-256) that names the version without its bytes. A request carriesbundleorbinding, never both; the schema refuses both asinvalid_request.The supervisor makes the same checks as for a bundle bind: company, epoch, limits and callback URLs.
binding_conflict.bundle_required(409). It looks the version up before changing anything, so this refusal comes before any effect: no company is reserved, no epoch adopted, no limits or callback URLs applied. That is why the host can safely send the same bind again with its bundle.The host binds by hash first.
TaskProvider.bindByHashsends the bind by hash. Only after a decoded refusal that proves it had no effect does it send the same bind with its bundle:bundle_required, orinvalid_request, which a supervisor from before this change gives the unknownbindingkey. It never sends a second bind after a transport or protocol failure.EcsTaskProviderdoes this only for same-release supervisors (see Rollout), inside its per-taskanswer, so both requests reach the same resolved task. Abundle_requiredis answered after the supervisor's identity check and recovered there. It neither forgets a cached endpoint nor triggers anotherDescribeTasks. Every other perf(execution): calls reuse a verified task address instead of asking ECS twice #768 rule is unchanged: identity first, re-sends only afterunauthorized,invalid_requestorwrong_task, never after a transport failure, and reply decoding inside the endpoint-cache boundary.LocalTaskProviderand the in-processlocal.tsexecutor always bind by hash first. A local task owner can outlive its host's checkout, so a host restarted after an update may reach an older supervisor; it answersinvalid_requestand gets the bundle. In process no bytes move, butpnpm dev,patchy devand the runtime suites now run the fleet's path.The host's own bundle read is unchanged. Runtime still loads the bundle before binding. Since #764 that is a retention check plus a memory hit (
bundleLoad: cached). Loading only afterbundle_requiredwould need a hash-only lookup onServerBundles, which isContent.ts(#746's lane), and would save a read only when the host's cache missed but the supervisor was warm. I left it out.Eviction between bind and invoke recovers. Before, an invoke refused
bundle_requiredorstale_generationsurfaced ashandler_failed. Now Runtime's attempt loop binds again once, under a fresh attempt and capability, and invokes the current generation. It does this only when all of these hold:invokerefusal with one of those two codes;Every pass checks the call's deadline before it binds, so a call refused at its deadline times out instead of binding again.
What proves nothing ran:
selectrefuses both codes before it registers the attempt or calls the engine.bundle_requiredrefuses before any handler runs.transport, which is never retried, so an invocation is never replayed after uncertain transport loss.Each pass takes its generation from its own bind reply, so a stale generation is never reused. A second refusal fails the call as before. The refused invoke ran no handler, so it doesn't count toward
tier2.mutation.attempts: a recovered mutation still gets its three conflict attempts. The call's request or re-run event recordsrebound: true, whatever came of the rebind, so a rebind that then failsbusystill shows the refusal behind it.Nested calls are unaffected. They reuse their parent's bundle and bound version, never bind, and never take the recovery path: their parent is running in that process, so if it's gone, the parent fails too.
Wire shape
I chose an optional
bindingonbindover a new route. The reply, the checks and the epoch semantics are bind's own, so a second route would duplicate them. An older supervisor would also answer an unknown route with a router 404 rather than a typed refusal. Abindwithoutbundlealready means a company bind (claim, adoption, limit updates), so the version has to be named. Strict decoding stays meaningful: unknown keys are still refused, andbundlewithbindingis refused by the schema.Rollout
Management schemas are strict, so an older supervisor refuses
bindingas an unknown key, just as it refuses #768'staskId. I reused #768's gate and renamed it fromchecksIdentitytosameRelease: a task on the host's own exec task definition runs the host's own image, pinned by digest, so its supervisor speaks the host's management wire.bundle_requiredbindinginvalid_requestbefore any effect, then the full bindThe recovery needs nothing from the supervisor: both refusals predate this change and come before dispatch in every release. One PR is enough, because host and supervisor ship in one image.
One behaviour change for every host: a bundle bind whose hash conflicts with a live process of the same version is now refused before it adopts its epoch and limits, where before it was refused after. Versions are immutable, so this doesn't happen outside tests.
Tests
Management.test.ts(real listener, supervisor and workerd): a bind by hash to a version not held gets 409bundle_requiredand leaves the task an unreserved spare. After a bundle bind, a bind by hash returns the same reply. A different hash isbinding_conflict, andbundlewithbindingis 400invalid_request.Supervisor.test.ts: a bind by hash waits for a loading version and returns its generation. When adoption raises the epoch during the wait, both waiting binds failstale_epoch.EcsTaskProvider.test.ts. The fake supervisors now hold versions, and the previous release refusesbinding:DescribeTasks;LocalTaskProvider.test.ts, with a real task and a transport layer that answers like an older supervisor: each version bind is refused by hash and then sent with its bundle, and a bind by hash whose reply was lost is never followed by the bundle.Invocation.test.ts:bundle_requiredorstale_generationrebinds and succeeds on the new generation, with a new attempt id; its event reports one attempt andrebound: true;rebound; a lost invoke reply (transport) is never re-sent and isn't;MutationTransaction.postgres.test.ts, realSERIALIZABLEPostgres: after a rebind, a contended mutation still gets three handler attempts beforewrite_conflict(eventattempts: 3,rebound: true), and a committed mutation's key replays its stored reply without running the handler again.parentand once-only guards, and leaving the refused attempt counted (in both the unit and the Postgres test)bundle_requiredoutside the endpoint-cache boundary (that one breaks both provider tests)invalid_requestfrom the fallback (the previous-wire local test)Validation
On this worktree's
pnpm dev up brightline, I ran a second host on the same database with tier 2 on the local task provider (EXECUTION_PROVIDER=local-fleet). Calls went through real supervisor and workerd processes. New Business's server bundle is 196 KB; production's is about 216 KB.Bytes sent to
/bindper warm call (temporary request logging, not committed; 40 warmdeals.boardcalls each):mainWarm call latency, without the logging: 100 sequential calls per run after 10 warm-ups, at load ≈3, alternating main and branch:
main, two runsThat's about 2.8 ms (11%) off each warm call on loopback.
Cold, reaped and evicted versions still load:
bundle_requiredin 4.4 ms, then the full bind loads the version and the call succeeds.bundle_requiredbefore dispatch.busyon the rebind (429 withretryAfter), because the tiny cap had no idle process to evict.handler_failed, which is the bound.main, all 28 would have failedhandler_failed.attempts: 2on those queries. That run came before I stopped counting the refused attempt, which changes only the count.Expected production effect:
durationMsafter the deploy, as Tier 2 pages take about 7 s to show all their data: diagnosis and fixes #754 plans.busy, instead of failinghandler_failed.Known gaps
Closes #751
Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.