Repository navigation
fix: Gateway shutdown hangs during recovered worker provisioning - #176777
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c6e17222a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }), | ||
| ).toBe(true); | ||
| expect(child.kill("SIGTERM")).toBe(true); | ||
| expect(await gate(closed), instance.logs()).toEqual([0, null]); |
There was a problem hiding this comment.
Fix the known-red restart regression before enabling it
When this E2E reaches restart with the spawn broker enabled, the Gateway exits with code 1 because native broker cleanup fails, so this strict [0, null] assertion fails; the commit's own corrected Testbox run records exactly that outcome. Committing the test unskipped therefore leaves the restart E2E suite red in that supported environment rather than providing a green post-fix regression, so fix the cleanup failure or defer enabling this test.
AGENTS.md reference: AGENTS.md:L80-L80
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The lead has accepted this as a scope limitation for the provisioning fix. This remains an unresolved Node process-cleanup failure, not a proven baseline defect. Its source is this review (original commit 7c6e172) and the Node 24.19.0/Linux Testbox run: all six lanes and reconciliation settled in 239 ms with clean-close receipts, then the broker reported native cleanup failure about seven seconds later.
The captured aggregate omitted nested causes and PID/process-group state. Changing cleanup semantics without those facts would risk weakening ownership. The provisioning-owner discriminator is independently RED on base / GREEN with the patch. The successful Bun process test does not prove Node cleanup. We retain the strict exit-zero, no-deadline and child-extinction assertions; nothing is skipped or weakened.
Main has now been merged for fresh typechecks and CI. No fresh Node process-level base/fix comparison is claimed. The PR body records this limitation and the next evidence needed: nested cleanup errors plus PID/group state, followed by a base/fix comparison.
|
Codex review: needs maintainer review before merge. What this changesPropagates Gateway shutdown cancellation through recovered worker provisioning and node installation while preserving allocations for recovery. Example: Restart the Gateway while recovering a provisioning operation with a 300-second provider timeout.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current provisioning cancellation gap, and both prior actionable findings are resolved without introducing another lifecycle owner. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe worker-environment service owns provisioning, reconciliation, and shutdown; it passes cancellation to provider and node operations and records their outcomes in the existing environment store. flowchart TD
A[Gateway shutdown] --> B[Service owner signal]
B --> C[Provider lifecycle]
C --> D[Allocation and preparation]
C --> E[Node installation]
D --> F[Producer settlement]
E --> F
F --> G[Retained recovery state]
Technical reviewBest possible solution: Carry the existing owner signal through provisioning and installation, retain actual producer settlement, and keep destruction intent exclusive to explicit cancellation or teardown. Do we have a high-confidence way to reproduce the issue? Current main visibly omits owner cancellation on recovered provisioning and node installation, and the contributor records discriminating lifecycle-owner red/green results; this read-only review executed no target code. Is this the best way to solve the issue? The patch repairs cancellation at the existing lifecycle owner, preserves explicit Stop semantics and factual cleanup receipts, and adds no parallel state or teardown mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d8e54ec6e0e4. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +16, Tests +516, Docs +4. Total +536 across 9 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed October 19, 2026, 4:46 AM ET / 08:46 UTC (Revision 4). |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 89f387d699
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| : {}), | ||
| ...(cancellation ? { signal: cancellation.signal } : {}), | ||
| signal: workSignal, |
There was a problem hiding this comment.
Keep shutdown out of the explicit-cancel signal
When beginClose() aborts ownerSignal, this now aborts options.signal for every provider even when no request cancellation occurred. The published provider contract still states that an aborted provisioning signal means explicit cancellation (docs/plugins/sdk-overview/capabilities.md:108), so a provider following that contract may cancel or release its in-flight allocation while core deliberately leaves destroyRequestedAtMs null for restart recovery, potentially losing the retained worker during a routine restart. Introduce a distinguishable shutdown cancellation contract and migrate providers/docs together, or preserve the existing explicit-cancel semantics of this signal.
AGENTS.md reference: AGENTS.md:L55-L55
Useful? React with 👍 / 👎.
|
Fixed the scheduler-first owner-cancellation P1 in bcc6f78. The node failure handler now receives the authoritative owner signal and checks Extended the existing scheduler-first lifetime regression to node installation. On 10f3396, the new case failed because The separate, previously accepted Node spawn-broker cleanup limitation is unchanged. This repair addresses allocation destruction during owner cancellation. The stopped native landing worktree was not touched, and the PR remains unmerged. The P1 fix was verified on refreshed head |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
Coordination from #176770 at Sanitized failure diagnostics: The fixture is |
|
Fixed the SDK cancellation-contract P2 in The worker-provider guide now states that an aborted Full The prior process-cleanup limitations remain documented. No merge performed; the stopped landing worktree was not touched. |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…nclaw#176777) * fix: cancel recovered worker provisioning during gateway shutdown * test: use advertised dispatch surface in restart regression * test: expect reply-drain warning during forced restart * fix: preserve node allocations during scheduler shutdown * test: diagnose child state after gateway shutdown * docs: distinguish worker attempt aborts from destruction
What Problem This Solves
Fixes Gateway shutdown exceeding its deadline while worker provisioning or allocation recovery is in progress. Team's 2026-10-18 21:45 restart was SIGKILLed by systemd at its 90-second stop limit.
User Impact
Stop and restart cancel provisioning through the service owner's signal and wait for the actual producer to settle before closing state. Durable operation IDs, recorded leases and factual cleanup receipts remain available for recovery; shutdown does not request machine destruction. Providers that ignore cancellation remain owned and awaited.
Why This Change Was Made
Recovered provisioning runs without a caller signal. Allocation and node installation previously forwarded only that optional caller signal, so shutdown could wait for the normal 300-second provider timeout while joining reconciliation.
provider-lifecycle.ts:439now composes caller cancellation with the owner's shutdown signal and carries it through allocation, preparation and node installation (provider-node-provisioning.ts:334). Only caller cancellation records destruction intent. No timeout increase, abandoned writer, schema/config change or parallel lifecycle owner is introduced.Both missing-signal paths predate the session-controller cutover. This is separate from #172971, which was already present in the affected build
2aca4a06b2c8. The journal is consistent with this defect but does not name the exact blocked provider call or prove this was the incident's only contributor.Evidence
Sanitized journal lines from the full shutdown window (UTC):
All twelve aborted lane tasks released their active slots by 21:45:38.004; the deadline activity counts were explicitly a last-observed snapshot. Four later agent-database clean-close receipts were written. The journal does not establish which call owned the Git children.
Scheduler-first node cancellation repair
The ClawSweeper P1 was valid: scheduler shutdown aborts the work before service teardown sets
stopping. The node handler previously consulted that later flag and could treat the abort as bootstrap failure, record destruction intent and tear down the recoverable machine. The handler now takes the authoritative owner signal and checks its cancellation independently ofisStopping, matching the existing SSH bootstrap path. The shared catch covers node installation and prepared-workspace registration. Explicit request cancellation keeps its existing destruction semantics.Extended the existing scheduler-first lifetime regression to node installation. RED on
10f3396ae362: the node case calledprovider.destroyonce after scheduler cancellation, while SSH passed. GREEN with the repair: both transports preserve state, operation identity, lease facts, destroy intent and last error before service teardown. All 55 tests in the four focused lifetime/node-owner/cancellation/shutdown-replay files passed. Test run: 391.07s; wrapper including worker-build verification: 457.56s on the local host. The new node case took 1.138s and reuses the existing real service/store fixture.Targeted
tsrsproduction and gateway test typechecks, lint/format andgit diff --checkpass. Pre-commit and full committed-branch Codex reviews are scoped-clean, with no actionable P0–P2 findings. The allocation-preservation repair is commitbcc6f784f32cb42d1d8506873e5b1b063506d003. The stopped native landing worktree has not been touched. No timeout, schema, configuration or cleanup-ownership change is included.CI refresh and independent fixture repair
CI on
bcc6f784f32cpassed every job exceptcheck-test-types-core-2and its aggregate gate. Its merge result included main's #177038, which supplied the retiredloaddependency in a subscription test. The exact diagnostic wascontrol-ui.test.ts(485,7): TS2353: 'load' does not exist in type 'SubscriptionDeps'. The latest completed scheduled main run's same job passed on4278e94e48b2; that revision predates #177038, so it does not establish that the new fixture is valid.The failing graph was reproduced on current main
99f5d0f8e4e0(RED, 5.2s), then passed after removing only the unused test argument (GREEN, 4.2s). That independent one-line repair is tracked in #177111, whose exact-head CI passed; its type graph has direct local RED/GREEN proof (CI path routing skipped type jobs). This branch incorporates that main revision and repair to make its CI result meaningful. After integration, all 35 service-lifetime tests passed, including the scheduler-first SSH/node cases and main's idle-reconciliation cancellation test. The production typecheck, both affected Gateway test type graphs, lint and format also passed. The refresh head was29a5592a95418a173cd6b217211bb5a6a1a6d2ab. Its exact-head CI has a restart-process test failure under investigation: Gateway exit was zero and shutdown completed in 564ms, but the subsequent raw PID-existence assertion found a reported child PID. The log does not identify whether it was live, terminal/unreaped, or reused. No assertion or timeout has been weakened. Follow-up commit25bdbff142c1fa437adee4e350cfc0eb88f44b0arecords the failed PID and Linux process status/stat only after the original assertion fails, preserving its timing and behavior. A Testbox diagnostic lease queued and was stopped before any payload ran (cancelled run); PR CI supplies the supported diagnostic fallback. Local root-test typechecking (10.2s), targeted lint/format, precommit and committed-branch Codex review passed. The diagnostic change does not claim to fix or classify the earlier survivor. Diagnostic head:25bdbff142c1fa437adee4e350cfc0eb88f44b0a; exact-head CI and the aggregate gate are green. The restart shard passed its unchanged strict assertions (11.17s test time, 16.20s wrapper). No failure diagnostic was emitted: the prior intermittent PID-existence failure remains unexplained and is not claimed fixed. All type/UI gates on that diagnostic head passed. The PR remains READY and unmerged.SDK cancellation contract correction
The ClawSweeper P2 identified stale provider guidance that treated every aborted provisioning signal as explicit cancellation and destruction intent. The SDK capability guide and both provisioning/runtime-enrollment signal JSDoc comments now distinguish stopping an attempt from requesting machine destruction. Gateway shutdown can abort the existing signal; providers stop and settle owned work while preserving allocations for replay. Core records destruction intent for a cancelled attempt only after an explicit cancellation or destroy request. No executable code, type signature, signal API, or runtime behavior changes in this follow-up.
Commit
8f38c4e7ef4ec2a5d76de5b84bdb673dc0adf0d7: fullpnpm check:docspassed, including docs lint, formatting, MDX, glossary, 15,712 link checks, config examples and changelog checks. Targeted source lint/format andgit diff --checkpassed. Local and committed-branch Codex reviews are scoped-clean. Current head:8f38c4e7ef4ec2a5d76de5b84bdb673dc0adf0d7; exact-head CI is green (67 successful jobs, no failed jobs). The PR remains READY and unmerged.Accepted scope limitation: Node spawn-broker cleanup
The P1 review was raised by the automated Codex GitHub review of
7c6e17222a58, based on the earlier Node 24.19.0/Linux Testbox run of this new regression. That run reached real restart and settled all six lanes, then failed the strict clean-exit assertion:This is an accepted scope limitation, not a resolved broker defect or proven baseline failure. The captured aggregate omits nested causes and child/process-group state; it does not establish whether a live child, terminal process group or another native resource blocked cleanup. The separate provisioning cancellation defect has owner-level red/green proof, and the Node failure occurred after its reconciliation and lane settlement completed. Changing native process cleanup without that missing evidence would risk weakening ownership guarantees. No broker change, relaxed assertion, longer deadline or writer abandonment is included. The Bun pass does not prove Node cleanup. A follow-up needs nested cleanup causes and a PID/group census, then a process-level base/fix comparison.
Two local restart runs hit the existing 300-second no-output watchdog before Gateway startup. A second Testbox attempt never reached its payload during source preparation. These are tooling results, not product verdicts. Both task-owned leases were stopped. No fresh Node base/fix comparison is claimed after the main merge.
Delta against merged main: production source including JSDoc +30/-14 (net +16), tests +560/-44 (net +516), docs +5/-1 (net +4). The documentation follow-up adds only comments (+5/-2) and prose (+3/-1); the executable production diff remains +25/-12. The production increase carries the existing owner's cancellation across both provisioning transports and recognizes it before service teardown begins. The larger test addition is the requested real-process boundary proof; no test-only production seam was added.
Focused proof commands