Repository navigation
perf(execution): an open patch keeps its process warm instead of reloading it - #775
Merged
Merged
Conversation
…ading it The supervisor reaped a version's process 60 s after its last call even while its patch was open, so the next screen reloaded it, and the first query after open waited for a load that only started when it arrived. A host now touches the version of each connected, ready tier 2 document before its idle window ends: a new management operation that restarts a ready process's idle clock and never loads, reserves or evicts. A document's first stream also warms its version as it becomes ready. Touches go only to supervisors of the host's own release. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ncurrent holders share one keepalive Each touch now starts 30-40 % of the idle window after the previous one started, whatever that one cost, and gives up after 10 %, so a lost touch still leaves the next to land within 90 % of the window. Warmup binds run beside the touches instead of in their way. A holder now joins or creates its version's keepalive in one synchronous step, and a keepalive removes only its own entry when its last holder leaves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a closing keepalive cancels its warmup's admission Every touch reply now carries `idleMs`, the idle window the supervisor enforces, and touches are spaced by the smaller of that and the configured limit, so a raised limit the supervisor hasn't taken yet can't let an open version idle out. A cut applies from the next turn. A warmup's admission is interruptible, as a call's is, so a keepalive whose last document leaves while it waits claims and binds nothing. 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 18, 2026
…t once (#776) When a subscription POST is refused as `409 invalid_request` but still names the current stream generation and latest sequence, the stream has been lost: a **current-generation loss**. The shell tears it down, then waited its jittered backoff (250–500 ms right after a `hello`) before reconnecting. In the traced production load on #754, that wait sat in front of the first query. Two refusals produce this loss: - `StreamReplaced`, from a host that doesn't hold the stream, such as a misrouted POST; - `StaleSequence`, from a document that just closed. ## Fix - **One immediate reconnect.** On a 409 the shell reads the body. If it is `invalid_request` and the POST still names the current generation and latest sequence, the stream reconnects at once instead of waiting for the backoff. - **The allowance comes back only when the document reconciles.** A new `hello` doesn't restore it. A second loss before then waits for the backoff, as on main, so a persistent misroute can't loop faster than it does today. - **Everything else keeps its handling:** - a stale-generation or stale-sequence refusal is ignored; - `401`, a `409 principal_changed` and `429` tear the stream down and wait for the backoff; - a pending tier 2 bind deadline still wins; - the reconnect still sends `X-Patchy-Generation`, so #775 only touches the version and doesn't warm it again. - **ADR-0010 is updated.** The stickiness cookie lasts one day (`duration_seconds=86400`), which is what `AppStack.ts` sets. The new reconnect rule is recorded next to the backoff. ## What "reconciled" means This uses the shell's existing `reconciled` state: the server has admitted this stream's latest sequence, and every desired subscription has been answered past its fence, by a snapshot, an up-to-date or a refusal. It is the state that already clears the Reconnecting pill. It's the first point where the shell has proof that its POSTs reach the stream's host. A `hello` only proves the GET landed somewhere, and an empty set still needs its replace admitted. So between any two immediate reconnects there is at least one full, successful round trip through the stream's host. ## Tests `stream.spec.ts`, with the page clock paused so that no backoff timer can fire unless the test runs the clock: - **Allowance.** - A current-generation loss reconnects at once. - The new stream admits its replace while its answers are held, so it hasn't reconciled; a loss there waits for the backoff. - Once the answers arrive, the next loss reconnects at once again. - Every reconnect carries the generation it replaces. - **Fails on main**: no second `hello` arrives without the clock. - **Other refusals.** - A stale-sequence `409` leaves the stream alone. - `401 session_refresh_required`, `409 principal_changed` and `429 rate_limited` each tear the stream down and wait for the backoff. - The unreconciled replacement's own current-generation loss then still reconnects at once, so these refusals didn't spend the allowance. - Passes on main and here. I checked that each test catches the bug it pins: - restoring the allowance on `admitted` fails the first test; - spending it on any refusal fails the second. `pnpm verify` passes locally: check, postgres-concurrency, cli-smoke, tier2-smoke and browser. ## Numbers Setup: - a local brightline instance, opening New Business (tier 2) as a persona; - a temporary, uncommitted server hook that refused every subscription POST of a document's first generation as `StreamReplaced`; - 10 loads each, timed in the shell from the `409` response. | From the refusal to… | main (backoff) | this branch | | --- | --- | --- | | the new stream's request | median 358 ms (274–473) | 15 ms (14–18) | | its `hello` | 368 ms (282–480) | 24 ms (21–30) | | the first query answer | 410 ms (317–781) | 51 ms (49–59) | With every POST refused, a persistent misroute, over 10 s: - main reconnected 23 times, 300–570 ms apart; - this branch reconnected 27 times: the first after 23 ms, then 294–498 ms apart. The allowance adds one immediate reconnect per unreconciled streak. Jitter alone moves the count over a 10 s window, so the totals don't measure that exactly. **Unchanged here.** On main, `hello` resets the backoff's failure count, so a persistent misroute already reconnects every 0.25–0.5 s indefinitely instead of backing off further. Part of #749. Steps 1 and 2, diagnosing the cause from #758's wide events and fixing it, need production data. 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 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.
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 answerstouched. A loading process answersloadingand keeps its initialization deadline from spawn; no live process answersabsent. It never loads, reserves, evicts or changes the epoch. Every reply also carriesidleMs, the idle window the supervisor reaps by: its last bind's setting. A different hash isbinding_conflict; it checkswrong_taskand the epoch like every other operation.Where the bookkeeping lives: a new runtime module,
ConnectedVersions, one per host, built beside the fleet inFleetInvocationand used byRuntimeStream(absent in no-pool dev, likeExecutionLifecycle). It keeps one keepalive per company + patch + version, not per document:ready, it callsconnect(version, { warm })for the stream's lifetime. The first holder starts the keepalive, whose first touch is immediate.X-Patchy-Generationon every stream after a document's first hello, sowarmis 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.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).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 throughStreamLimits) and theidleMsthe 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.
touchedorloadingis enough (resident,loading). Onabsent, it binds the version under a normal call admission (acquire, then the server bundle, thenexecutor.bind, which binds by hash first), concurrent with client boot, without delayingready. Apausedorunboundtouch tries nothing. Warmups are bounded: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
absentuntil 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,touchesby outcome (touched,loading,absent,unsupported,paused,unbound,failed) andwarmupsby outcome (resident,loading,loaded,bound,paused,unbound,failed). This measures what the issue asks for:touches.absentcounts versions evicted or reaped while open;callsServed = 0after aloadedwarmup are unused warmups;cause = "evicted"is residency churn;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:
sameRelease), and through the same verified endpoint cache.unsupportedwithout 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.failedtouch: no retry before the next turn, and nothing reaches viewers.unsupported) is a normal bind (bound).No migrations.
Tests
Supervisor.test.ts(real workerd):absent;absentwithout 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:/touchauthenticates before reading the body and refuseswrong_taskbefore 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):RuntimeStream.test.ts: a ready document holds its version until disconnect, withwarmonly on its first stream.Numbers
I measured on the local fleet (
pnpm dev up brightline,EXECUTION_PROVIDER=local-fleetvia a temporary, uncommitted runner edit) withPATCHY_LIMITS_JSON={"execution.process.idle":20000}. Each pass, as a member:deals.timelinequery on the same version);There were three passes each, on
origin/mainand this branch.keepaliveevent per passtouches {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 verifypasses.Closes #753
Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.