Repository navigation
fix(gateway): interrupt worker teardown during shutdown - #183579
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. |
68a76c6 to
5c33ee1
Compare
|
Codex review: needs maintainer review before merge. What this changesPasses shutdown, suspension, and deadline cancellation through worker teardown and Crabbox commands while preserving cleanup recovery. Example: Gateway receives SIGTERM while provider destroy is hanging.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: current main still has the teardown cancellation gap, and this PR repairs it through the existing lifecycle owner. No actionable introduced defect was found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe worker-environment service serializes provider operations and persists cleanup intent; Crabbox translates teardown into capture, stop, and checkpoint cleanup commands. flowchart TD
A[Gateway shutdown or suspension] --> B[Environment lifecycle owner]
B --> C[Serialized provider destroy]
C --> D[Crabbox command chain]
D --> E[Child process settlement]
E --> F[Durable cleanup outcome]
F --> G[Startup reconciliation]
Technical reviewBest possible solution: Keep teardown cancellation in the existing lifecycle owner, retain unconfirmed cleanup for restart, and honor the author’s landing hold. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the missing signal, and the committed process fixture targets that exact path; the PR reports a failing baseline and successful candidate, but no target code was executed during this read-only review. Is this the best way to solve the issue? The patch repairs the shared teardown owner and its Crabbox consumer, preserves compensating cleanup and mutation settlement, and introduces no competing lifecycle or storage owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b24990a227eb. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +32, Tests +253, Docs +8, Other +364. Total +657 across 17 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 25, 2026, 8:54 AM ET / 12:54 UTC. |
What Problem This Solves
Fixes Gateway shutdown waiting minutes for a worker-environment teardown during reconciliation, until the service supervisor kills the process.
User Impact
Shutdown can interrupt Crabbox capture, stop, and checkpoint cleanup, retain their durable recovery state, and retry the same cleanup after restart. Pending replies, terminal persistence, and actual child-process settlement keep their existing drain obligations. There is no schema, configuration, or retention change.
Why This Change Was Made
The observed pending operation was provider
destroy, not inspection. Production traces showed it still pending after 219 seconds; another timeout had no active turns or pending owners. Both the earlier inspection cancellation fix (#180841) and cleanup-acceptance change (#182138) were already in the affected build. Crabbox's bounded stop budget is 16 minutes 45 seconds, but reconciliation dropped cancellation before reaching it.The teardown owner now supplies Gateway lifecycle cancellation for normal, failed-bootstrap, and expired-preparation cleanup, and Crabbox forwards it through its command chain. Explicit turn cancellation still runs compensating cleanup; it does not cancel teardown. The existing provider deadline also aborts destroy. The owner still joins the underlying mutation; a timeout or cancellation does not falsely declare physical teardown complete. The additive optional
destroy.signalprovider contract documents that requirement.Evidence
Acceptance declared before the process/load measurements: the real isolated dist Gateway must interrupt a hanging fixture destroy and exit cleanly within a 20-second budget, retain the exact lease, and complete cleanup after restart. Base must reproduce the blocked shutdown. Required Team-shaped load comparison uses the canonical harness, 10-minute arms, two counterbalanced timing and allocation pairs. Report server-side latency and host load, and obtain A/A controls before treating an adverse load metric as a regression.
Runtime code delta: +32 net lines for lifecycle cancellation, the existing deadline abort, and the additive provider contract. No second lifecycle owner or state store was introduced. The separate 340-line script is reproducible process proof.
Real dist-Gateway reproduction passed on base
9db139fcf842versus candidate5c33ee10cc36: baseline remained blocked at the 20,002.5 ms harness deadline and required SIGKILL; candidate aborted provider teardown and exited cleanly in 801.7 ms. Candidate retained the exact lease and operation ID with a visible interruption, and the next boot completed cleanup. Clean shutdown after replay was 640.7 ms on base and 591.0 ms on candidate. This is isolated synthetic process evidence, not a live deployment timing claim.Both full builds passed; all 281 shared compiled package files are byte-identical between builds. The initial stress attempt failed during setup because the instrumentation loader disabled source aliases but could not resolve two worker-telemetry workspace dependencies. The loader now resolves those dependencies through the measured build’s compiled exports while leaving built-runtime imports untouched. Its real-child regression fails on the original loader; all six focused harness tests and a native-subagent smoke pass, with independent review clean. No performance verdict is drawn from failed setup or smoke runs. The full canonical stress campaign below completed successfully on the same final head.
Completed load acceptance
Canonical harness from this tooling head: two AB/BA pairs for untraced timing and two separate AB/BA allocation pairs, eight fresh 10-minute measurement windows plus warmup. Each arm used 10,800 synthetic sessions, 40 enabled bundled plugins, 65 WebSocket clients, four concurrent mock-provider turns per round, real tool calls/native subagents, and list/search/history/sidebar churn. All eight arms passed workload coverage and error checks; each completed 40 reported parent turns and matching tool results. Only isolated loopback development Gateways were exercised.
Mean across the two matched pairs (percentage column is the mean of the two paired percentage deltas):
These steady-state differences do not cross the predeclared adverse gates. Total untraced GC rose by 14 ms/min, below the 50 ms/min materiality floor; no maximum GC pause exceeded 50 ms or twice its paired baseline. This is a shutdown/recovery improvement, not a steady-state throughput claim. No A/A rejection investigation was triggered; the small differences are not attributed causally to this patch.
Per-arm measurements, sample counts, and host load
CPU is main OS-thread CPU (100% = one core); allocation is sampled JS allocation, excluding native/external memory. RSS is process-wide and heap is the end-of-window main isolate, not a retained-heap claim. Allocation-pass timing/GC are diagnostic only. Each host-load window has 20–21 samples on a 32-logical-CPU Mac; no window was excluded after observing results. Achieved list/RPC rates and full workload completion were checked, rather than assuming offered load equals completed work.
Handler values use first-to-last scrape counter deltas, excluding warmup and omitting up to the final 15 seconds. Handler p99 is a histogram bucket estimate, not exact client latency. Each timing handler p99 falls in the 30–40 ms bucket and has 1,173 observations; client list tails have 1,202–1,204 samples and loop tails approximately 28,000. Major-GC per-collection percentiles are context only because each timing arm has fewer than 50 collections.
Untraced GC detail (total duration, not normalized by collection count):
GC percentiles are histogram estimates; maxima are recorded raw durations. GC p99s below 1,000 collections, p95s below 200, and major-GC tails below 50 collections are context rather than gates. All original windows are included.
Final validation
Exact head
5c33ee10cc3674437aaa4762930b811f897ce15c: CI passed, build passed, no reruns. Independent local review, GitHub Codex review, and ClawSweeper identified no remaining actionable findings. ClawSweeper's previously unfinished load-evidence item is completed above.Remaining limits: the historical trace identifies provider
destroy, not which individual Crabbox child command was pending. Tests cover all three command boundaries. Third-party providers must honor the optional signal; the owner intentionally keeps waiting for actual mutation settlement rather than falsely releasing a live write. No production restart or live deployment timing is claimed.