Repository navigation
fix(signal): await daemon shutdown on restart - #71863
ZHOUKAILIAN wants to merge 3 commits into
Conversation
Greptile SummaryThis PR makes the Signal daemon shutdown asynchronous: Confidence Score: 4/5Safe to merge; the async stop logic and SIGKILL fallback are sound, and all new behavior is covered by tests. Only P2 style observations: a fire-and-forget void call that silently drops errors, and a hardcoded timeout constant in the test. No correctness or logic defects found. extensions/signal/src/monitor.ts (void stop() on abort) and extensions/signal/src/daemon.test.ts (hardcoded 1500 ms boundary) Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/signal/src/monitor.ts
Line: 437
Comment:
**Unhandled rejection from fire-and-forget stop**
`void daemonLifecycle.stop()` discards any rejection from the async `stop()` call. While `stop()` is unlikely to throw in practice (it only sets a flag and calls `daemonHandle?.stop()`), if it does reject the error is silently lost. The `finally` block already awaits `daemonLifecycle.stop()` for proper cleanup, so the `onAbort` call is primarily used to initiate the signal early — consider wrapping it with a `.catch` to surface unexpected errors.
```suggestion
void daemonLifecycle.stop().catch((err) => {
runtime.error?.(`daemon stop error on abort: ${String(err)}`);
});
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: extensions/signal/src/daemon.test.ts
Line: 83
Comment:
**Hardcoded timeout value tightly coupled to implementation**
`vi.advanceTimersByTimeAsync(1_501)` hard-codes knowledge of the 1500 ms kill timeout defined in `daemon.ts`. If the timeout constant is ever changed, this test will break silently (it will advance past the new threshold and the assertions may still pass, but the test no longer verifies the intended boundary). Consider exporting the timeout constant from `daemon.ts` and referencing it here, or adding a comment indicating the coupling.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(signal): await daemon shutdown on re..." | Re-trigger Greptile |
| @@ -434,7 +434,7 @@ export async function monitorSignalProvider(opts: MonitorSignalOpts = {}): Promi | |||
| } | |||
|
|
|||
| const onAbort = () => { | |||
| daemonLifecycle.stop(); | |||
| void daemonLifecycle.stop(); | |||
There was a problem hiding this comment.
Unhandled rejection from fire-and-forget stop
void daemonLifecycle.stop() discards any rejection from the async stop() call. While stop() is unlikely to throw in practice (it only sets a flag and calls daemonHandle?.stop()), if it does reject the error is silently lost. The finally block already awaits daemonLifecycle.stop() for proper cleanup, so the onAbort call is primarily used to initiate the signal early — consider wrapping it with a .catch to surface unexpected errors.
| void daemonLifecycle.stop(); | |
| void daemonLifecycle.stop().catch((err) => { | |
| runtime.error?.(`daemon stop error on abort: ${String(err)}`); | |
| }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/signal/src/monitor.ts
Line: 437
Comment:
**Unhandled rejection from fire-and-forget stop**
`void daemonLifecycle.stop()` discards any rejection from the async `stop()` call. While `stop()` is unlikely to throw in practice (it only sets a flag and calls `daemonHandle?.stop()`), if it does reject the error is silently lost. The `finally` block already awaits `daemonLifecycle.stop()` for proper cleanup, so the `onAbort` call is primarily used to initiate the signal early — consider wrapping it with a `.catch` to surface unexpected errors.
```suggestion
void daemonLifecycle.stop().catch((err) => {
runtime.error?.(`daemon stop error on abort: ${String(err)}`);
});
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in c8bf546a. onAbort now keeps the early stop trigger but logs any unexpected rejection via runtime.error before the awaited cleanup path in finally.
| it("falls back to SIGKILL if the daemon does not exit in time", async () => { | ||
| vi.useFakeTimers(); | ||
| const fake = createFakeDaemonChild(); | ||
| spawnMock.mockReturnValue(fake.child); |
There was a problem hiding this comment.
Hardcoded timeout value tightly coupled to implementation
vi.advanceTimersByTimeAsync(1_501) hard-codes knowledge of the 1500 ms kill timeout defined in daemon.ts. If the timeout constant is ever changed, this test will break silently (it will advance past the new threshold and the assertions may still pass, but the test no longer verifies the intended boundary). Consider exporting the timeout constant from daemon.ts and referencing it here, or adding a comment indicating the coupling.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/signal/src/daemon.test.ts
Line: 83
Comment:
**Hardcoded timeout value tightly coupled to implementation**
`vi.advanceTimersByTimeAsync(1_501)` hard-codes knowledge of the 1500 ms kill timeout defined in `daemon.ts`. If the timeout constant is ever changed, this test will break silently (it will advance past the new threshold and the assertions may still pass, but the test no longer verifies the intended boundary). Consider exporting the timeout constant from `daemon.ts` and referencing it here, or adding a comment indicating the coupling.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in c8bf546a. Exported SIGNAL_DAEMON_STOP_KILL_TIMEOUT_MS from daemon.ts and updated the test to advance by that shared constant instead of a hardcoded 1501ms.
|
Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 5:57 AM ET / 09:57 UTC. Summary PR surface: Source +27, Tests +165. Total +192 across 5 files. Reproducibility: yes. Current main source shows Signal daemon stop is fire-and-forget SIGTERM, and the PR plus independent discussion provide failing-before/passing-after coverage for awaiting exit and SIGKILL escalation; I did not run a live Signal account restart in this read-only review. Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land a Signal-owned lifecycle fix once maintainers are comfortable with the 1500 ms SIGKILL escalation policy and the bounded proof scope. Do we have a high-confidence way to reproduce the issue? Yes. Current main source shows Signal daemon stop is fire-and-forget SIGTERM, and the PR plus independent discussion provide failing-before/passing-after coverage for awaiting exit and SIGKILL escalation; I did not run a live Signal account restart in this read-only review. Is this the best way to solve the issue? Yes. The PR fixes the Signal-owned daemon handle and monitor cleanup instead of adding a gateway delay, while leaving the rare post-SIGKILL no-exit case as an explicit maintainer availability policy decision. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 36dd9ee3c3c1. Label changesLabel justifications:
Evidence reviewedPR surface: Source +27, Tests +165. Total +192 across 5 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Thanks, that makes sense. The PR is intentionally scoped to the Signal daemon/monitor lifecycle, and the current checks are green. I agree the remaining open point is live Signal restart validation, so I’ll keep this open for maintainer review rather than closing it as obsolete. |
Independent verification of this PR
I cherry-picked both commits from this PR ( Cherry-pickCherry-pick onto current Test resultsOn unpatched
The first two failures are exactly the symptoms reported in #22676. They are genuine regressions of the bug, not synthetic. On the patched branch: Wider Signal extension suite on the patched branch: No regressions in the Signal extension suite. Code-level review notesA few things I went looking for and was satisfied by:
What I did NOT verifyPer CONTRIBUTING.md's "Real behavior proof" guidance, I should be explicit:
If a maintainer or @UberKitten can confirm the live macOS path, that would close the remaining gap. Environment
VerdictThe fix is correct, scoped, and has tests that genuinely cover the bug (proven by their failure on unpatched Thanks @ZHOUKAILIAN for the clean implementation. |
c8bf546 to
e333a6f
Compare
232bc33 to
3fa74e9
Compare
|
ClawSweeper PR egg ✨ Hatched: ✨ glimmer Velvet Proofling Hatch commandComment Hatchability rules:
Rarity: ✨ glimmer. What is this egg doing here?
|
|
This pull request has been automatically marked as stale due to inactivity. |
# Conflicts: # extensions/signal/src/daemon.test.ts
3fa74e9 to
cb68041
Compare
|
Refreshed this PR onto current Local verification on the refreshed branch:
Both passed locally after syncing the worktree dependencies to current |
|
Superseded by #107409, landed as 5688d90. The replacement preserves current Thank you @ZHOUKAILIAN for identifying the race and contributing the original fix. |
Summary
Testing
Real behavior proof (required for external PRs)
signal-cli daemonprocesses across abort/restart paths.3fa74e98e72de378366b4dc5d48cae5f6dd21249. The machine does not have a linked Signal account orsignal-cliinstalled, so this proof used the real OpenClaw Signal monitor/daemon lifecycle code with a local signal-cli-compatible child process that exposes/api/v1/checkand/api/v1/events; no external Signal messages were sent.{ "repoHead": "3fa74e98e72de378366b4dc5d48cae5f6dd21249", "baseMain": "e0225380a7454a85db1038e495d18a28b5d918ed", "port": 20031, "pid": 34488, "aliveBeforeAbort": true, "monitorResolved": true, "resolveWaitMs": 659, "aliveAfterMonitorResolved": false, "elapsedMs": 867, "events": "START pid=34488 args=[\"daemon\",\"--http\",\"127.0.0.1:20031\",\"--no-receive-stdout\",\"--receive-mode\",\"manual\"]\nSIGTERM pid=34488 at=1778304230573\nEXIT_AFTER_SIGTERM pid=34488 at=1778304231225", "runtimeLogs": [ { "level": "log", "t": 200, "msg": "signal-cli: signal-cli shim READY pid=34488 http=127.0.0.1:20031" }, { "level": "error", "t": 867, "msg": "signal daemon exited (source=process code=0 signal=null)" } ] }aliveAfterMonitorResolved: falseconfirms there was no leftover daemon process aftermonitorSignalProviderreturned.signal-clinetwork traffic, actual inbound/outbound Signal message delivery, or the macOS LaunchAgent restart path. This proof is scoped to the changed OpenClaw daemon lifecycle behavior and avoids sending external Signal messages from the test machine.stop()returnedundefinedinstead of a promise and there was no SIGKILL escalation. The live proof above verifies the patched after-fix runtime behavior on this machine.Root Cause
stop()only sent SIGTERM and returned immediately, so monitor abort/restart could continue while the old daemon process was still shutting down.signal-clidaemon shutdown can be slow enough that immediate restart paths race with the previous process still owning resources.Regression Test Plan
extensions/signal/src/daemon.test.tsextensions/signal/src/monitor.tool-result.autostart.test.tsstop()waits for daemon exit after SIGTERM, escalates to SIGKILL after the timeout, reuses an in-flight stop promise, andmonitorSignalProviderawaits daemon stop before resolving aborted shutdown.User-visible / Behavior Changes
Signal auto-start restart/shutdown should leave fewer orphaned daemon processes. Shutdown may now wait briefly for
signal-cli daemonto exit; if it does not exit after SIGTERM, OpenClaw escalates to SIGKILL after the configured timeout.Closes #22676