Repository navigation
feat(execution): stop runaway patch processes - #428
Conversation
Opus reviewReviewed Blocking1. A sampling race in the watchdog tick can stop the whole supervisor.
2. The aggregate-memory-pressure test is flaky. It failed in 3 of 4 runs here: once in the full-file run and twice in three isolated runs ( 3. In local mode the host process's RSS counts against the 1.5 GiB residency ceiling.
4. YAGNI: Only Judgment on the Dockerfile and exec entrypoint (not blocking)The Dockerfile line is correct wherever Checked and fine
|
Astra reviewReviewed StandardsNo merge-blocking method or YAGNI findings. Spec
Verification also exercised a deadline kill in 1.276 seconds, a surviving sibling invocation, capability rejection with 401, and stale-epoch rejection with 409. The isolated supervisor and its children were stopped. No repository files changed. Standards: 0 blockers. Spec: 1 P1 blocker, unfinished loads permanently exhaust residency. |
|
Reviewed One workerd per loaded version, a private four-route listener, and a local executor that only binds and invokes is the right size. The five done-when checks in #396 are implemented and covered by live tests. Two behaviors are wrong. StandardsEffect servicesHard. The load fiber in
Judgement. Left alone after checking: Docs and the wireHard. Judgement.
Left alone after checking: management schemas live in SmellsJudgement only.
Looked for a split of the one-file Effect service, a second RPC layer, a middle man in SpecIssue #384, sections 3, 5, 14, 15, and 19, judged only for the supervisor ticket. Fleet, mutations, subscriptions, and public admission belong to later tickets. What matches: one workerd process per loaded version. Private bind, invoke, stop, and stats, accepting the current or previous deployment secret. Generation fence on callbacks. Kill at the caller deadline plus 1 second, after 6 seconds without a healthy probe, and at 512 MiB. Idle reap and the 12-process cap. Bundles pushed by the host. Process reports carry CPU seconds, peak RSS, interrupted attempt identities, and the process event. No analytics sink and no Postgres process rows. The local executor has no pool, and production construction is refused. ADR-0012, the Runtime glossary, Partial. Section 5 says at most 12 processes and 1.5 GB aggregate, enforced continuously, and past that the idle process goes first, with Bind and the watchdog do that. if (aggregateRss() >= limit("execution.residency.bytes"))
return yield* new SupervisorError({
operation: "invoke",
reason: "busy",
limit: limitRefusal("execution.residency.bytes", limit("execution.residency.bytes"))
});An idle sibling stays loaded. Scope. The process event on Wrong. Section 5 kills at the caller deadline plus 1 second when the invocation is still running, and reaps a process after 60 seconds idle. Any failed if (resident.alive && Exit.isFailure(exit)) {
// Transport loss cannot prove execution ended. Keep its deadline and identity until reap.
yield* Deferred.done(result, exit);
return;
}The comment describes transport loss. The condition keeps every failure. Issue 396The done-when list is met in code and in live tests.
A few ticket lines are implemented narrowly, and the code says so. Distinct uids are applied only when The residency sentence is only partly met. "Past it the idle process goes first, busy if none is idle" is the invoke gap above. The largest-first comparator is in
This earns Closes #396 after MethodOne workerd per loaded version is the smallest model that keeps a spinning or leaking handler off its siblings. Isolates inside one process do not survive a synchronous spin. The stall test loads a wedged module and still invokes a sibling. A process per invocation would blow the 12-process cap. The watchdog and the callback proxy belong in this design. A wedged workerd cannot police itself. An epoch or generation check inside the loader can be skipped by anything that can open the callback socket. The proxy checks the attempt, the capability, the deadline, the epoch, and the generation. Epoch and generation stay distinct. Bind adopts the host epoch when the request is greater than or equal to the current epoch, and every management call checks it. Generation is a counter inside the supervisor, and invoke requires it. Management is four POST routes, schemas in Two changes to the method:
Sampled RSS is the right kill signal. The same loop has to report CPU seconds and peak RSS, so a cgroup limit would be a second mechanism. Linux uses VmRSS for the kill and VmHWM for the peak. macOS The watchdog reads the query kill and deadline to get its 1 second grace. Mutation and action have their own kill limits, both also 1 second today. A later change to one kind's grace will leave the watchdog on the query pair. A named 1000 ms next to the tick, or the grace for the attempt's own kind, would keep the rule visible. YAGNIKeep one The process-event fields are the section 14 process event, carried on the management report because this ticket has no analytics sink and no database. Keep the cause, CPU seconds, peak RSS, calls served, interrupted attempts, and What does not earn its place:
Tests that earn their cost: the spinning sibling and its exact report, the 512 MiB leak, the 13th process, the epoch and generation fence, management auth before the body is read, and local rebind without replay. The occupied-port test only checks that listen failure becomes SummaryStandards: 2 hard findings, plus judgement calls. Worst: the load fiber turns Spec: 2 findings. Worst: |
|
Fixed in Reviewed the conversation comments from Opus, Astra and Grok, plus the Reviews tab APIs. There were no submitted review bodies or inline review comments. Fixed
Kept as is
Verification
Surface audit for the review fixes: wire/API contract, executor consumers, limits and generated skill mirrors, product/domain/development docs, and tests applied. CLI flags/JSON, dev-runner/seed, migrations, company resources, served UI and package layout are unchanged. Load expiry/rebind and scope-shutdown scenarios cover the reverse lifecycle. |
b10524a to
0a9559b
Compare
Add residency eviction, runaway termination, generation fencing and process reports. Expose private management and a supervised local Executor while keeping production admission closed. Closes #396
Bound responsive unfinished loads, isolate sampling and cleanup failures, and evict idle siblings before invocation refusal. Release completed refused attempts, preserve shutdown reports, and remove unwired executor guards. Stabilize real memory-pressure and reconnect scenarios and give multi-process CLI checks their existing integration-test budget.
b1e39ba to
3b18121
Compare
…g ECS twice (#768) Each tier 2 call asked ECS where its task was twice: one `DescribeTasks` before bind and another before invoke. For a resource-backed query, the second lookup runs after the company snapshot opens, so it also lengthens how long the company connection is held. Caching the address alone wasn't safe. A stopped task's private IP can be reassigned to a fresh spare that holds the same management secret, and nothing in a management request said which task it was meant for. ## The fix 1. **The supervisor checks who it is.** Every management request (`bind`, `invoke`, `stop`, `stats`) can carry `taskId`, the task the host resolved. Before anything else, the supervisor compares it with its `EXECUTION_TASK_ID`. If they differ, or the supervisor has no task id, it refuses with 421 `wrong_task` and does nothing else. 2. **The host reuses the endpoint.** `EcsTaskProvider` keeps each task's resolved endpoint (address, ARN, revision) once a request through it succeeds and its reply decodes, and reuses it for `execution.endpoint.lifetime`, a new host-scoped operating limit, one minute by default. - The cache holds at most `execution.fleet.budget` entries; expired entries are swept on insert. - Any failed, interrupted or undecodable request forgets the entry, without re-sending, and so does any ECS response that shows the task stopped. - A request refused before it took effect (`unauthorized`, `invalid_request` or `wrong_task`) is sent once more, after resolving the task again. - `Fleet.route`'s live binding checks are unchanged. 3. **No replay.** A transport failure through a cached endpoint is never re-sent, because an invoke may already have run. It fails exactly as before, and the next call resolves again. The local fleet provider now names the task on every request too. Its child supervisors always run the same checkout as the host, and this is the path where the identity check runs end to end against real supervisor processes. ## Rollout During a deploy, old and new hosts run side by side, and tasks of both releases keep serving. - **Old hosts** never send `taskId` and never cache. The field is optional, so new supervisors still accept their requests. - **Old supervisors** decode request bodies strictly (`onExcessProperty: "error"`). They have done so since the listener first landed in #428, before the first production deploy. A request that carries `taskId` therefore gets 400 `invalid_request` before the supervisor runs. So a new host must not send the field to them. - **The signal is the task's exact task-definition ARN.** A new host sends the field, and caches the endpoint, only for tasks running its own exec task definition (`ECS_EXEC_TASK_DEFINITION`). ECS reports that ARN for every task. Task definitions never change once registered, and `apps/infra` pins the release image by digest in each one. A task on the host's own definition therefore runs the same image as the host, and its supervisor checks identity. Every other task is resolved on every call, as today. - **Considered and rejected:** a protocol version echoed in bind or stats replies. The host would have to send a request without the field first to learn it, while the definition ARN is known before the first request. - **One PR is enough.** A release ships the host and the exec supervisor as one image, and the host caches only for supervisors from that same image. No deploy has to land first. **The reused-address hazard is closed at every stage of a rollout.** The management secret stays the same across releases, so a cached address that now reaches another task fails in one of these ways, each before any effect: | Who answers at the cached address | Result | | --- | --- | | A spare from this release | 421 `wrong_task` | | An older release's spare | 400 `invalid_request`: it doesn't know the key | | Nothing | Transport failure, not re-sent | In the first two cases the host resolves again and gets `stopped`, the same answer a fresh lookup gives today. ## Lifetime and bounds `execution.endpoint.lifetime` goes in the limits registry as a host-scoped operating limit, the precedent from #764's bundle-cache bounds. That makes it tunable through `PATCHY_LIMITS_JSON` without a release. The entry bound reuses `execution.fleet.budget`: live tasks can't exceed it, so the cache doesn't need a number of its own. The identity check makes a stale entry safe, so the lifetime only sets how often a host re-checks ECS on its own. At one minute, the burst of queries when a screen opens costs one lookup, and an open page costs at most one lookup per task per host per minute. ## What invalidates an entry | Event | How the cache learns, or why a stale entry is still safe | | --- | --- | | This host stops a task (release, drain, deploy retirement) | `stop` polls `DescribeTasks` until `STOPPED`, and any described stopped task is dropped | | Another host stops it, or it crashes | The lease holder's housekeeping `list` drops it, or any later lookup does. Until then, a request either gets an identity refusal or a transport failure (forgotten, not re-sent), or the entry expires | | Address reused by a fresh spare | `wrong_task` or `invalid_request` before any effect, then a fresh lookup returns `stopped` | | Rebind, adoption, epoch change | Same task, same address. The supervisor still checks the epoch on every request | | Spare recycling | A released task is stopped, never handed to another company. Its address reuse is the row above | | Deploy or host replacement | The cache is in memory and starts empty. Tasks of other definitions are never cached | | Any failed or interrupted request through the entry | Forgotten | Housekeeping reads final stats right after listing a task as stopped, and accepts only `stopped`. Because the listing itself drops the entry, those stats calls still get `stopped`, not `transport`. ## Tests - `Management.test.ts`, with a real listener, supervisor and workerd: a misdirected `bind` reserves nothing and loads nothing. A misdirected `invoke`, `stop` or `stats` leaves `callsServed: 0` and the task running. Requests without `taskId`, as an older host sends them, still work. A supervisor without a task id refuses any request that names one. - `EcsTaskProvider.test.ts`. The ECS fake now models each supervisor with the secrets its host injected, models the previous release as refusing `taskId`, and returns fresh task copies, as the SDK does: - a cached endpoint serves seven management requests with one `DescribeTasks`, and is looked up again after its lifetime; - a previous-release supervisor is resolved on every call and never sent the field; - a stopped task's address, reused by a spare from either release, is refused before any effect and re-resolved to `stopped`; - ECS reporting the task stopped drops the entry; - an invoke whose reply was lost is sent once, not re-resolved, and the next call looks up again. - Mutation checks: removing each of the four mechanisms (the field, stop invalidation, caching other definitions, re-sending after a transport failure) fails exactly its test. Sending a wrong task id from the local provider fails the local fleet journey in `DevelopmentExecution.test.ts`. ## Numbers ECS can't be faked outside the unit fake, so these counts come from that test. The sequence is one bind, then three calls of bind and invoke: | | `DescribeTasks` | | --- | ---: | | `main` | 7, one per management request | | This branch | 1 | Expected production effect: - **Lookups.** One or two `DescribeTasks` round trips removed per call: two for a top-level call (bind and invoke), one for a nested call that reuses its parent's bind. - **Connection hold.** For resource-backed queries, the company connection is held for less time, because the lookup before invoke used to run after the snapshot opened. - **ECS load.** Lookups fall to about one per task per host per minute. The lookup's own latency was never measured, so re-measure `dbMs` and `durationMs` after the deploy, as #754 plans. ## Known gaps - A task that dies without any host observing it can leave its address cached until the first failure or ECS observation. If nothing answers at that address, the first request may wait for its connect timeout or call bound instead of failing at once with `stopped`. - A narrow race: a call can cache a running task just as housekeeping lists it stopped. That housekeeping pass then fails its final stats with `transport`. The next pass resolves again and finishes. Closes #752 Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
A spinning or leaking tier 2 handler must not take down other loaded versions. The host also needs process measurements and interrupted attempt identities when a process dies.
Run one workerd process per loaded version with bounded residency, watchdog termination and fenced callbacks. Add private management endpoints and a supervised local Executor. Process reports carry CPU, peak RSS and interrupted attempts without claiming a transaction rollback. Public tier 2 admission remains closed.
Stacked on
tier2/395-execution-engine. This PR contains only the supervisor work for #396.Closes #396.
Verification
Implemented with OpenAI GPT-6 Astra in the omp harness.