fix: bridge respawned child signals (#933) (thanks @roshanasingh4)
Co-authored-by: Roshan Singh <roshanasingh4@users.noreply.github.com>
This commit is contained in:
17
src/entry.ts
17
src/entry.ts
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawn } from "node:child_process";
|
||||
import process from "node:process";
|
||||
|
||||
import { applyCliProfileEnv, parseCliProfileArgs } from "./cli/profile.js";
|
||||
import { spawnWithSignalForwarding } from "./process/spawn-with-signal-forwarding.js";
|
||||
import { attachChildProcessBridge } from "./process/child-process-bridge.js";
|
||||
|
||||
if (process.argv.includes("--no-color")) {
|
||||
process.env.NO_COLOR = "1";
|
||||
@@ -24,7 +25,7 @@ function ensureExperimentalWarningSuppressed(): boolean {
|
||||
process.env.CLAWDBOT_NODE_OPTIONS_READY = "1";
|
||||
process.env.NODE_OPTIONS = `${nodeOptions} ${EXPERIMENTAL_WARNING_FLAG}`.trim();
|
||||
|
||||
const { child } = spawnWithSignalForwarding(
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[...process.execArgv, ...process.argv.slice(1)],
|
||||
{
|
||||
@@ -33,7 +34,9 @@ function ensureExperimentalWarningSuppressed(): boolean {
|
||||
},
|
||||
);
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
attachChildProcessBridge(child);
|
||||
|
||||
child.once("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
@@ -41,6 +44,14 @@ function ensureExperimentalWarningSuppressed(): boolean {
|
||||
process.exit(code ?? 1);
|
||||
});
|
||||
|
||||
child.once("error", (error) => {
|
||||
console.error(
|
||||
"[clawdbot] Failed to respawn CLI:",
|
||||
error instanceof Error ? (error.stack ?? error.message) : error,
|
||||
);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Parent must not continue running the CLI.
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user