Repository navigation
fix(gateway): drain root work continuations before stop process exit - #105848
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 28, 2026, 8:08 AM ET / 12:08 UTC. ClawSweeper reviewWhat this changesThis PR fences new gateway root work on direct stop signals, waits within the shutdown budget for already-admitted session-finalization continuations, and adds unit plus packaged-gateway coverage for durable Merge readinessKeep this PR open: current Priority: P2 Review scores
Verification
How this fits togetherGateway signal handling decides whether a process stops or restarts, then closes the gateway server and exits. Session reset/delete/compaction can launch detached flowchart TD
A[Session reset, delete, or compaction] --> B[Detached session_end plugin hook]
B --> C[Tracked gateway root work]
D[SIGTERM or SIGINT] --> E[Gateway stop handler]
E --> F[Close new root-work admission]
F --> G[Bounded root-work drain]
G --> H[Close gateway and exit]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +19, Tests +281. Total +300 across 3 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Refresh the branch against current Do we have a high-confidence way to reproduce the issue? Yes, at source level: a session-finalization continuation is separately tracked after the session leaves the active-session shutdown tracker, while current direct-stop handling exits without waiting for that root-work set. The PR also supplies a real packaged-gateway SIGTERM scenario that exercises this path. Is this the best way to solve the issue? Yes. Reusing the existing gateway root-work admission and bounded drain is narrower and safer than making every AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bdb3918f4dad. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (16 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
d84d46a to
2c627c6
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
2c627c6 to
674e389
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
674e389 to
c1a35a3
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
de2e1e5 to
7b163ff
Compare
7b163ff to
7189191
Compare
…05697) Preserve the original contributor branch and merge current main. Fence new root work before stopping, drain the canonical work set inside the existing watchdog budget, and verify real packaged gateway, plugin, WebSocket, and operating-system SIGTERM behavior.
|
Maintainer validation for
The fix marks root admission draining immediately and waits for admitted gateway root work before closing the gateway, bounded within the existing shutdown watchdog. |
|
Merged via squash.
|
…s exit (openclaw#105848) Co-authored-by: Peter Steinberger <[email protected]>
…ifecycle-hooks * origin/main: fix(mattermost): key private channels as group on outbound routing (#96645) fix(ci): grant Telegram QA runtime scratch access (#115659) fix(telegram): stop retrying blocked recipients (#115640) fix(tts): persist generated speech in media store (#115647) fix(gateway): preserve complete streamed chat completions (#115652) fix(mac): prevent app auth from blocking node-host startup (#115533) fix(heartbeat): keep message-tool final replies private (#115629) fix(gateway): drain root work continuations before direct-stop process exit (#105848) fix(ollama): keep active streams within their idle timeout (#115648) fix(delivery): keep session keys out of inferred message targets (#115657) fix(ci): type code mode matrix catch callback (#115674) refactor(agents): centralize bundled CLI backend auth policy (#115633) refactor: remove 3,527 lines of runtime and test duplication (#115626) [AI] fix(doctor): stop repeated bundledDiscovery migration noise on beta (#115208) # Conflicts: # scripts/code-mode-model-matrix.ts
What Problem This Solves
Close #105697
When a gateway process receives a direct stop signal (SIGTERM/SIGINT without a restart intent), any
session_endplugin hooks already started by session reset/delete/compaction may be truncated before they complete. Affected plugins may lose database writes, memory summaries, or external resource cleanups.Why This Change Was Made
Adds a bounded drain of the existing gateway root-work set to the direct-stop path. The drain uses a referenced
setTimeoutpoll (not.unref()) so the timer keeps the event loop alive. Bounded at 2 seconds; the caller always invokesexitProcess(0)after return. Per ClawSweeper clarification: the force-exit watchdog is cleared atrun-loop.ts:705beforehandleStopAfterServerCloseis entered at line 710; the drain is self-bounded by its own referenced timer.User Impact
No visible impact. Pending
session_endhooks get up to 2 seconds to complete before exit. Stuck hooks cannot block shutdown.Evidence
1. Real Gateway startup + shutdown log (PR branch, 10 production plugins, Node v22.23.1)
Gateway under this PR starts cleanly with 10 production plugins (including acpx, browser, canvas, device-pair, file-transfer, memory-core, ollama, phone-control, talk-voice), reaches ready state, and shuts down in 261ms with zero errors.
2. Drain mechanism proof (12/12 passed)
Each case: real child process, real
gateway-work-admissionmodule, real OS SIGTERM, realwaitForGatewayRootWorkDrain(). Continuations created via the sameroot.run()→runWithGatewayIndependentRootWorkContinuation()→root.release()pattern assession-reset-service.ts.3. Unit tests (62 passed)
4. Change scope: 4 files, +116 lines. No config, CLI, SDK, docs, or changelog surface. No new dependencies.