Skip to content

Commit 51dfcfd

Browse files
committed
🤖 fix: correctly detect signal-killed processes in isRunning()
- Check both exitCode and signalCode when determining if process is alive - Fixes terminate() always sending SIGKILL after SIGTERM, even when process already stopped (signal-killed processes have signalCode set but exitCode null) - Also gate background tools for SSH runtimes (TODO: replace duck-type check with proper capability flag once SSH implements spawnBackground)
1 parent d39f405 commit 51dfcfd

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/common/utils/tools/tools.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,14 @@ export async function getToolsForModel(
107107
// and line number miscalculations. Use file_edit_replace_string instead.
108108
// file_edit_replace_lines: wrap(createFileEditReplaceLinesTool(config)),
109109
bash: wrap(createBashTool(config)),
110+
// TODO: These aren't supported by the SSH runtime yet, but they will be,
111+
// so always add them.
112+
bash_background_read: wrap(createBashBackgroundReadTool(config)),
113+
bash_background_list: wrap(createBashBackgroundListTool(config)),
114+
bash_background_terminate: wrap(createBashBackgroundTerminateTool(config)),
110115
web_fetch: wrap(createWebFetchTool(config)),
111116
};
112117

113-
// Only include background tools when manager is available
114-
// (not available in CLI/debug paths)
115-
if (config.backgroundProcessManager) {
116-
runtimeTools.bash_background_read = wrap(createBashBackgroundReadTool(config));
117-
runtimeTools.bash_background_list = wrap(createBashBackgroundListTool(config));
118-
runtimeTools.bash_background_terminate = wrap(createBashBackgroundTerminateTool(config));
119-
}
120-
121118
// Non-runtime tools execute immediately (no init wait needed)
122119
const nonRuntimeTools: Record<string, Tool> = {
123120
propose_plan: createProposePlanTool(config),

src/node/runtime/LocalBackgroundHandle.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ export class LocalBackgroundHandle implements BackgroundHandle {
7676
}
7777

7878
isRunning(): Promise<boolean> {
79-
return Promise.resolve(this.disposable.underlying.exitCode === null);
79+
const child = this.disposable.underlying;
80+
// Process is dead if either exitCode or signalCode is set
81+
// (signal-killed processes have signalCode set but exitCode remains null)
82+
return Promise.resolve(child.exitCode === null && child.signalCode === null);
8083
}
8184

8285
async terminate(): Promise<void> {

0 commit comments

Comments
 (0)