Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d6f324f1e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (child.killed || exited) { | ||
| return; |
There was a problem hiding this comment.
Return in-flight stop promise when already signaled
After stop() became async, this early return means a second caller does not wait for shutdown if another caller already sent SIGTERM. In monitor.ts, abort triggers a fire-and-forget daemonLifecycle.stop(), then finally does await daemonLifecycle.stop(); with this guard, that awaited call can return immediately while the first stop is still waiting, so the monitor can exit before the daemon is actually gone (the exact orphan/restart race this change is trying to prevent). Make stop() idempotent by reusing/returning an in-flight stop promise instead of returning early on child.killed.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR converts
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/signal/src/monitor.ts
Line: 407-409
Comment:
**`await` in `finally` bypassed when abort fires first**
When `opts.abortSignal` is aborted, `onAbort` calls `void daemonLifecycle.stop()` (fire-and-forget), which immediately invokes `child.kill("SIGTERM")` and sets `child.killed = true`. When the `finally` block later runs `await daemonLifecycle.stop()`, the inner guard `if (child.killed || exited) { return; }` causes it to return instantly — without waiting for the process to actually exit. As a result, `monitorSignalProvider` can return while the child is still alive for up to 5 s (until the background SIGKILL fires), defeating the fix for port/lock contention on restart.
One way to resolve this is to change the early-exit guard in `spawnSignalDaemon`'s `stop()` so that an already-signalled-but-not-yet-exited process is still awaited:
```ts
// daemon.ts
stop: async () => {
if (!exited && !child.killed) {
child.kill("SIGTERM");
}
if (exited) return; // already gone, nothing to await
await new Promise<void>((resolve) => {
const t = setTimeout(() => {
try { child.kill("SIGKILL"); } catch {}
resolve();
}, 5000);
child.once("exit", () => { clearTimeout(t); resolve(); });
if (child.exitCode !== null) { clearTimeout(t); resolve(); }
});
},
```
With this change, the second call from `finally` still awaits the exit even when SIGTERM was already sent by the abort handler, so `monitorSignalProvider` only returns once the subprocess has truly stopped.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/hooks/gmail-ops.ts
Line: 329-345
Comment:
**Mutable `child` captured by closure inside SIGKILL timeout**
`shutdown()` closes over the `let child` variable. Inside the 5 s `setTimeout` callback, `child.kill("SIGKILL")` resolves the variable at callback-fire time, not at the time `shutdown()` was invoked. While the `shuttingDown` guard prevents reassignment in the happy path, this differs from the pattern used in `client.ts` (which correctly snapshots `const child = this.child` before any async work).
A safer approach is to capture a local constant at the start of `shutdown()`:
```suggestion
const currentChild = child;
currentChild.kill("SIGTERM");
await new Promise<void>((resolve) => {
const t = setTimeout(() => {
try {
currentChild.kill("SIGKILL");
} catch {}
resolve();
}, 5000);
currentChild.once("exit", () => {
clearTimeout(t);
resolve();
});
if (currentChild.exitCode !== null) {
clearTimeout(t);
resolve();
}
});
```
This matches the explicit snapshot pattern in `client.ts` (`const child = this.child; this.child = null;`) and removes the implicit dependency on `shuttingDown` to keep the closure variable stable.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 2d6f324 |
| const onAbort = () => { | ||
| daemonLifecycle.stop(); | ||
| void daemonLifecycle.stop(); | ||
| }; |
There was a problem hiding this comment.
await in finally bypassed when abort fires first
When opts.abortSignal is aborted, onAbort calls void daemonLifecycle.stop() (fire-and-forget), which immediately invokes child.kill("SIGTERM") and sets child.killed = true. When the finally block later runs await daemonLifecycle.stop(), the inner guard if (child.killed || exited) { return; } causes it to return instantly — without waiting for the process to actually exit. As a result, monitorSignalProvider can return while the child is still alive for up to 5 s (until the background SIGKILL fires), defeating the fix for port/lock contention on restart.
One way to resolve this is to change the early-exit guard in spawnSignalDaemon's stop() so that an already-signalled-but-not-yet-exited process is still awaited:
// daemon.ts
stop: async () => {
if (!exited && !child.killed) {
child.kill("SIGTERM");
}
if (exited) return; // already gone, nothing to await
await new Promise<void>((resolve) => {
const t = setTimeout(() => {
try { child.kill("SIGKILL"); } catch {}
resolve();
}, 5000);
child.once("exit", () => { clearTimeout(t); resolve(); });
if (child.exitCode !== null) { clearTimeout(t); resolve(); }
});
},With this change, the second call from finally still awaits the exit even when SIGTERM was already sent by the abort handler, so monitorSignalProvider only returns once the subprocess has truly stopped.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/signal/src/monitor.ts
Line: 407-409
Comment:
**`await` in `finally` bypassed when abort fires first**
When `opts.abortSignal` is aborted, `onAbort` calls `void daemonLifecycle.stop()` (fire-and-forget), which immediately invokes `child.kill("SIGTERM")` and sets `child.killed = true`. When the `finally` block later runs `await daemonLifecycle.stop()`, the inner guard `if (child.killed || exited) { return; }` causes it to return instantly — without waiting for the process to actually exit. As a result, `monitorSignalProvider` can return while the child is still alive for up to 5 s (until the background SIGKILL fires), defeating the fix for port/lock contention on restart.
One way to resolve this is to change the early-exit guard in `spawnSignalDaemon`'s `stop()` so that an already-signalled-but-not-yet-exited process is still awaited:
```ts
// daemon.ts
stop: async () => {
if (!exited && !child.killed) {
child.kill("SIGTERM");
}
if (exited) return; // already gone, nothing to await
await new Promise<void>((resolve) => {
const t = setTimeout(() => {
try { child.kill("SIGKILL"); } catch {}
resolve();
}, 5000);
child.once("exit", () => { clearTimeout(t); resolve(); });
if (child.exitCode !== null) { clearTimeout(t); resolve(); }
});
},
```
With this change, the second call from `finally` still awaits the exit even when SIGTERM was already sent by the abort handler, so `monitorSignalProvider` only returns once the subprocess has truly stopped.
How can I resolve this? If you propose a fix, please make it concise.| child.kill("SIGTERM"); | ||
| await new Promise<void>((resolve) => { | ||
| const t = setTimeout(() => { | ||
| try { | ||
| child.kill("SIGKILL"); | ||
| } catch {} | ||
| resolve(); | ||
| }, 5000); | ||
| child.once("exit", () => { | ||
| clearTimeout(t); | ||
| resolve(); | ||
| }); | ||
| if (child.exitCode !== null) { | ||
| clearTimeout(t); | ||
| resolve(); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Mutable child captured by closure inside SIGKILL timeout
shutdown() closes over the let child variable. Inside the 5 s setTimeout callback, child.kill("SIGKILL") resolves the variable at callback-fire time, not at the time shutdown() was invoked. While the shuttingDown guard prevents reassignment in the happy path, this differs from the pattern used in client.ts (which correctly snapshots const child = this.child before any async work).
A safer approach is to capture a local constant at the start of shutdown():
| child.kill("SIGTERM"); | |
| await new Promise<void>((resolve) => { | |
| const t = setTimeout(() => { | |
| try { | |
| child.kill("SIGKILL"); | |
| } catch {} | |
| resolve(); | |
| }, 5000); | |
| child.once("exit", () => { | |
| clearTimeout(t); | |
| resolve(); | |
| }); | |
| if (child.exitCode !== null) { | |
| clearTimeout(t); | |
| resolve(); | |
| } | |
| }); | |
| const currentChild = child; | |
| currentChild.kill("SIGTERM"); | |
| await new Promise<void>((resolve) => { | |
| const t = setTimeout(() => { | |
| try { | |
| currentChild.kill("SIGKILL"); | |
| } catch {} | |
| resolve(); | |
| }, 5000); | |
| currentChild.once("exit", () => { | |
| clearTimeout(t); | |
| resolve(); | |
| }); | |
| if (currentChild.exitCode !== null) { | |
| clearTimeout(t); | |
| resolve(); | |
| } | |
| }); |
This matches the explicit snapshot pattern in client.ts (const child = this.child; this.child = null;) and removes the implicit dependency on shuttingDown to keep the closure variable stable.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/hooks/gmail-ops.ts
Line: 329-345
Comment:
**Mutable `child` captured by closure inside SIGKILL timeout**
`shutdown()` closes over the `let child` variable. Inside the 5 s `setTimeout` callback, `child.kill("SIGKILL")` resolves the variable at callback-fire time, not at the time `shutdown()` was invoked. While the `shuttingDown` guard prevents reassignment in the happy path, this differs from the pattern used in `client.ts` (which correctly snapshots `const child = this.child` before any async work).
A safer approach is to capture a local constant at the start of `shutdown()`:
```suggestion
const currentChild = child;
currentChild.kill("SIGTERM");
await new Promise<void>((resolve) => {
const t = setTimeout(() => {
try {
currentChild.kill("SIGKILL");
} catch {}
resolve();
}, 5000);
currentChild.once("exit", () => {
clearTimeout(t);
resolve();
});
if (currentChild.exitCode !== null) {
clearTimeout(t);
resolve();
}
});
```
This matches the explicit snapshot pattern in `client.ts` (`const child = this.child; this.child = null;`) and removes the implicit dependency on `shuttingDown` to keep the closure variable stable.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e06d0a9a02
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const closedOrTimeout = await Promise.race([ | ||
| this.closed.then(() => "closed" as const), |
There was a problem hiding this comment.
Recreate close promise on each iMessage child start
stop() now decides whether to escalate based on this.closed, but this.closed is a single promise created in the constructor and never reset per spawned child. After one start() → stop() cycle, that promise stays resolved, so a later stop() on the same IMessageRpcClient instance will take the "closed" branch immediately and skip SIGTERM/SIGKILL, which can leave the new imsg process alive when stdin EOF is insufficient to terminate it. Because this class exposes reusable start()/stop() methods, this is a real restart-path orphan risk.
Useful? React with 👍 / 👎.
…loses openclaw#22676) Signal daemon stop() was fire-and-forget: it sent SIGTERM but did not wait for the process to exit. On SIGUSR1 restart the new signal-cli spawned before the old one released its port/lock, causing orphaned processes and send failures. The same pattern existed in the iMessage RPC client and Gmail ops shutdown. Apply the SIGTERM → wait (5 s) → SIGKILL escalation pattern already used in src/infra/ssh-tunnel.ts to all three call sites: - extensions/signal/src/daemon.ts (SignalDaemonHandle.stop) - extensions/imessage/src/client.ts (IMessageRpcClient.stop) - src/hooks/gmail-ops.ts (shutdown in runGmailService) Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3cc1c300b1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| id === defaultSlotIdForKey("contextEngine") && | ||
| normalizedOwner !== CORE_CONTEXT_ENGINE_OWNER | ||
| ) { |
There was a problem hiding this comment.
Permit built-in registration of the default context engine
This guard blocks registration of the default slot id (legacy) for any non-core owner, but built-in startup still registers legacy via registerContextEngine("legacy", ...) (the public path) and ignores the { ok: false } return, so default initialization no longer installs a factory for legacy. In the default configuration, resolveContextEngine() will then throw that legacy is not registered, which breaks normal agent/context-engine resolution paths.
Useful? React with 👍 / 👎.
|
Closing to manage active PR count. Will reopen when slot is available. |
Summary
Change Type
Scope
Linked Issue/PR
Security Impact
Evidence
Human Verification
Compatibility / Migration
Failure Recovery
This PR was AI-assisted (fully tested with pnpm build/check/test).