Repository navigation
fix(gateway): stop optional placement work from delaying shutdown - #172971
Conversation
Cancel read-only placement preparation and stop maintenance between candidates when the Gateway drains. Keep accepted retirement, recovery, and publication effects joined, and name the pending reconciliation phase in shutdown diagnostics.
|
🦞👀 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: 5db4e20010
ℹ️ 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".
| Optional session-evidence reads, disk probes, and node-retention preparation are | ||
| canceled; an accepted retirement, workspace recovery, reclaim, or publication |
There was a problem hiding this comment.
Qualify uncancelable node-retention preparation
When shutdown starts while bundleRetention.currentBuild() is already running, node-workspace-retain-coordinator.ts awaits that producer without passing a cancellation signal, and stop() then waits for the owning operation to settle. The statement that node-retention preparation is canceled is therefore inaccurate for exactly the slow-build shutdown scenario operators need this page to explain; clarify that new preparation and cancellable node requests stop, while an in-progress shared bundle build may still delay shutdown.
Useful? React with 👍 / 👎.
|
Codex review: needs changes before merge. What this changesThis PR stops optional worker-placement preparation during Gateway shutdown while joining accepted effects through settlement. Example: Shutdown begins while retiring placement shutdown-first, with shutdown-next still requested.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it addresses a concrete shutdown problem still present on main, with one documentation correction identified. Priority: P1 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Gateway placement runtime coordinates session evidence, worker recovery, idle suspension, publication, and retention; shutdown must stop optional preparation while preserving database and transport access for accepted effects. flowchart TD
A[Gateway drain] --> B[Placement runtime]
B --> C[Cancel optional preparation]
C --> D[Session readers and disk probes]
B --> E[Join accepted effects]
E --> F[Durable settlement]
F --> G[Close databases and transports]
Technical reviewBest possible solution: Preserve the cancellation and settlement boundaries, and document that an in-progress shared bundle build can still delay shutdown. Do we have a high-confidence way to reproduce the issue? Current-main source permits whole candidate loops and optional read admission to continue after drain begins; the supplied regression reports a matching base failure, but no target code was executed during this review. Is this the best way to solve the issue? The implementation addresses the owning lifecycle boundary without increasing deadlines or abandoning accepted writers; the shared-build exception is deliberate and should be reflected in the docs. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 12c076d9d63e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +231, Tests +302, Docs +11. Total +544 across 33 files. Added test files: 0. 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 Reviewed October 15, 2026, 5:15 AM ET / 09:15 UTC. |
|
Merged via squash.
|
…enclaw#172971) * fix(gateway): stop optional placement work during shutdown Cancel read-only placement preparation and stop maintenance between candidates when the Gateway drains. Keep accepted retirement, recovery, and publication effects joined, and name the pending reconciliation phase in shutdown diagnostics. * test(gateway): complete placement shutdown fixtures * test(gateway): assert deferred retirement during shutdown * docs(gateway): clarify shared build shutdown settlement
Release adaptation: frozen candidate C=df22eeb1f74e935ab3d7877742a1332779cdb1b6. Join the existing physical owner preparation before session discovery. Include only the scoped history-discovery cancellation prerequisite from #172971; retain candidate startup FTS and read-open retirement repairs. Do not import the unrelated placement migration. Main-origin: 55d9dab Main-origin: 593176c Reviewed-patch: heartbeat-firstbirth-backport.patch Reviewed-patch-SHA256: ebb37dcede8e1f2b45e2be7eba30ef366f681c430aacd9f15dd450f5b4a77bcf The independently reviewed patch bytes are unchanged. Proof: Final signal-corrected public RPC and worker-lane/target selection: 28 passed; native-idle siblings: 6 passed. Exact eight-file independent review found no actionable findings. No credentialed live-heartbeat pass is claimed. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit e2f2f857eac2fbe5f92eb6a9cc426b14051762f0)
What Problem This Solves
Fixes Gateway shutdown spending its remaining stop budget on optional worker-placement maintenance after restart drain has begun.
User Impact
Draining Gateways stop optional scans and preparation instead of starting more maintenance candidates, while accepted durable effects finish before their database or transport closes. This reduces the risk of reaching the supervisor's stop deadline on loaded Gateways without increasing timeout budgets or abandoning writers.
Why This Change Was Made
On the base revision,
src/gateway/server-worker-placement-startup.ts:467checks stopping only between whole reconciliation phases and:568joins the complete running operation. The retirement loop atsrc/gateway/worker-environments/placement-session-retirement.ts:185can continue through every candidate. Optional evidence reads can also wait behind writer admission without observing shutdown.The placement owner now carries the existing drain/scheduler cancellation signal through optional session discovery, identity reads, exact idle-session reads, and disk probes. Recovery, retirement, retention, and publication owners stop before new candidates or effects. Once a retirement, recovery, reclaim, or publication effect is accepted, its existing settlement path remains joined. Node-retention stop starts alongside the reconciliation joins. Pending-close diagnostics identify the reconciliation subphase.
The shutdown ordering stays intact: sidecars need worker transports and shared state to settle accepted effects; terminal-session disposal handles PTYs, not chat persistence. Agent database sealing already runs independently while sidecars drain. The restart-marker join and hard-exit watchdog are unchanged.
A shared worker-bundle artifact build already in progress still settles: its producer performs staged filesystem writes and has no cancellation contract. Caller-only cancellation would abandon that producer or disrupt another consumer. This change does not guarantee completion within 90 seconds for an arbitrarily slow accepted effect.
Evidence
The supplied Team journal covers 61 hours: 40 stops, 22 recorded SIGKILL exits, and connection-dependent sidecars named in 20 of 23 deadline warnings. Sanitized evidence from October 15, 2026 (UTC; decompressed journal line numbers):
The journal identifies the owning reconciliation phase, not its exact leaf await; the new diagnostic narrows future stalls to a named reconciliation subphase.
The new owner-boundary regression passed with the fix. Reverting the placement runtime to the base revision made the same test fail at the intended assertion: shutdown retired the next candidate instead of leaving it requested. The regression holds an actual SQLite retirement, starts shutdown mid-candidate, verifies the accepted writer is not aborted, releases it, and checks both durable rows and the exact pending subphase.
Separate regressions passed for cancellation during discovery/identity admission behind a writer, idle-read cancellation, disk-probe cancellation, and stopping between accepted local/repository publications. Existing startup, recovery, maintenance, retirement, and node-retention contracts were exercised. A former startup expectation that retirement must start after shutdown during an unresolved evidence read is updated to the new pre-effect deferral contract; accepted-effect settlement has independent real-SQLite coverage.
Cold worker compilation and source verification dominate the long invocations on the loaded development host. The database-backed suites exercise actual admission, SQLite settlement, and Git/worktree publication custody, which a cheaper mocked assertion would not prove.
Focused commands
Core typecheck, the targeted gateway-root/server/other test graphs (
run-tsgo-core-test-shards.mjs), targeted type-aware lint (run-oxlint.mjs), formatting (oxfmt --check), and whitespace checks passed. The repository test wrapper and canonical owning project configs were used after aggregate test preparation stalled; no aggregate run is counted as passing proof.The Linux-only managed-SIGTERM integration test cannot run on this macOS host. The requested remote allocation queued and was stopped before test execution; no remote pass is claimed. The portable full-close harness passed: an accepted retirement survives the close prelude, persists its outcome, and finishes before shared-state teardown. This proves ordering and custody, not a real-time 90-second bound; the harness uses controlled timers. Codex branch autoreview on final head
3dd8269e193d1c49d91e7e2452e16c0dc5a16fbb: scoped-clean, no accepted/actionable P0–P2 findings. The automated P3 documentation finding was fixed: node retention stops new preparation and cancellable requests, but joins an in-progress shared bundle build. The focused documentation review was also clean; formatting, whitespace checks, andpnpm docs:check-linkspassed (15,523 internal links; zero broken).CI on runtime head
5db4e20010ed6afe90f05d78183782a0bb6a83ecfailed one selected test in run 38709674325:checks-node-changed-5,test/e2e/qa-lab/runtime/node-worker-launch-wire.e2e.test.ts, “transfers and reconciles a gateway-push workspace through a device runner,” exceeded its 240-second budget. The classifier reported unknown, with no matching main job. That run reached fixture cleanup after the post-restart audit assertions, began cleanup at 249.024 seconds, and completed with no pending cleanup owners.The required
pnpm test:ci-failed 172971 --runreplay also timed out, this time during load wave 2/3 finalization. It began cleanup at 240.043 seconds and reported failure after 269.704 seconds, with no pending cleanup owners. The Gateway completed its drain and logged a clean close in 92 ms. The replay did not reach the post-restart assertions. Its cold runtime build took 17m03s outside the test budget; Vitest took 651.18 seconds including worker compilation. This reproduces a broader E2E duration problem, but does not establish a cause or a baseline attribution. No timeouts, assertions, or retry policy were changed. After two ambiguous failures, investigation of that timeout stops here for maintainer follow-up.Final-head CI at lane closeout: run 38714066515 on
3dd8269e193d1c49d91e7e2452e16c0dc5a16fbbremains in progress: 33 successful jobs, no failed jobs, 31 pending jobs. The two ambiguous timeout attempts reached this lane's stop condition. The task-owned watcher was stopped; GitHub jobs continue. The final-head run is not claimed green.LOC against the base: production +563/-332 (net +231), tests +318/-16 (net +302), docs +12/-0. The production growth propagates cancellation through existing owners; it adds no new persistence, ownership, or timeout mechanism. Release-note context is retained here; the release-owned changelog is unchanged.