mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 13:14:58 +00:00
refactor(agents): dedupe exec spawn fallback wiring
This commit is contained in:
@@ -324,6 +324,20 @@ export async function runExecProcess(opts: {
|
|||||||
let stdin: SessionStdin | undefined;
|
let stdin: SessionStdin | undefined;
|
||||||
const execCommand = opts.execCommand ?? opts.command;
|
const execCommand = opts.execCommand ?? opts.command;
|
||||||
|
|
||||||
|
const spawnFallbacks = [
|
||||||
|
{
|
||||||
|
label: "no-detach",
|
||||||
|
options: { detached: false },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleSpawnFallback = (err: unknown, fallback: { label: string }) => {
|
||||||
|
const errText = formatSpawnError(err);
|
||||||
|
const warning = `Warning: spawn failed (${errText}); retrying with ${fallback.label}.`;
|
||||||
|
logWarn(`exec: spawn failed (${errText}); retrying with ${fallback.label}.`);
|
||||||
|
opts.warnings.push(warning);
|
||||||
|
};
|
||||||
|
|
||||||
// `exec` does not currently accept tool-provided stdin content. For non-PTY runs,
|
// `exec` does not currently accept tool-provided stdin content. For non-PTY runs,
|
||||||
// keeping stdin open can cause commands like `wc -l` (or safeBins-hardened segments)
|
// keeping stdin open can cause commands like `wc -l` (or safeBins-hardened segments)
|
||||||
// to block forever waiting for input, leading to accidental backgrounding.
|
// to block forever waiting for input, leading to accidental backgrounding.
|
||||||
@@ -359,18 +373,8 @@ export async function runExecProcess(opts: {
|
|||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
windowsHide: true,
|
windowsHide: true,
|
||||||
},
|
},
|
||||||
fallbacks: [
|
fallbacks: spawnFallbacks,
|
||||||
{
|
onFallback: handleSpawnFallback,
|
||||||
label: "no-detach",
|
|
||||||
options: { detached: false },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
onFallback: (err, fallback) => {
|
|
||||||
const errText = formatSpawnError(err);
|
|
||||||
const warning = `Warning: spawn failed (${errText}); retrying with ${fallback.label}.`;
|
|
||||||
logWarn(`exec: spawn failed (${errText}); retrying with ${fallback.label}.`);
|
|
||||||
opts.warnings.push(warning);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
child = spawned as ChildProcessWithoutNullStreams;
|
child = spawned as ChildProcessWithoutNullStreams;
|
||||||
stdin = child.stdin;
|
stdin = child.stdin;
|
||||||
@@ -426,18 +430,8 @@ export async function runExecProcess(opts: {
|
|||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
windowsHide: true,
|
windowsHide: true,
|
||||||
},
|
},
|
||||||
fallbacks: [
|
fallbacks: spawnFallbacks,
|
||||||
{
|
onFallback: handleSpawnFallback,
|
||||||
label: "no-detach",
|
|
||||||
options: { detached: false },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
onFallback: (fallbackErr, fallback) => {
|
|
||||||
const fallbackText = formatSpawnError(fallbackErr);
|
|
||||||
const fallbackWarning = `Warning: spawn failed (${fallbackText}); retrying with ${fallback.label}.`;
|
|
||||||
logWarn(`exec: spawn failed (${fallbackText}); retrying with ${fallback.label}.`);
|
|
||||||
opts.warnings.push(fallbackWarning);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
child = spawned as ChildProcessWithoutNullStreams;
|
child = spawned as ChildProcessWithoutNullStreams;
|
||||||
stdin = child.stdin;
|
stdin = child.stdin;
|
||||||
@@ -453,18 +447,8 @@ export async function runExecProcess(opts: {
|
|||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
windowsHide: true,
|
windowsHide: true,
|
||||||
},
|
},
|
||||||
fallbacks: [
|
fallbacks: spawnFallbacks,
|
||||||
{
|
onFallback: handleSpawnFallback,
|
||||||
label: "no-detach",
|
|
||||||
options: { detached: false },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
onFallback: (err, fallback) => {
|
|
||||||
const errText = formatSpawnError(err);
|
|
||||||
const warning = `Warning: spawn failed (${errText}); retrying with ${fallback.label}.`;
|
|
||||||
logWarn(`exec: spawn failed (${errText}); retrying with ${fallback.label}.`);
|
|
||||||
opts.warnings.push(warning);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
child = spawned as ChildProcessWithoutNullStreams;
|
child = spawned as ChildProcessWithoutNullStreams;
|
||||||
stdin = child.stdin;
|
stdin = child.stdin;
|
||||||
|
|||||||
Reference in New Issue
Block a user