packages/ai: - feat: expose provider responseId on AssistantMessage - feat: lazy-load provider modules for faster startup - fix: hash foreign Responses API tool call IDs exceeding 64-char limit - fix: ignore null chunks in openai-completions streams - fix: keep image tool results inline for Gemini 3+ and Antigravity - fix: correct Bedrock Claude 4.6 context window to 200k - fix: support prompt caching for Bedrock application inference profiles - fix: add OpenRouter reasoning payload format - fix: ignore placeholder Vertex API keys - fix: skip AJV validation in restricted runtimes - fix: Anthropic OAuth client injection and responseId extraction - fix: Codex incomplete/failed response status handling packages/agent: - fix: defer steering until after tool execution completes packages/tui: - feat: namespaced keybinding IDs with KeybindingsManager conflict detection - feat: configurable select list column sizing (#2154 by @markusylisiurunen) - fix: stream truncateToWidth for large strings - fix: skip Termux height redraws - fix: stop evicting unrelated default keybindings - fix: resolve raw backspace ambiguity on Windows Terminal - fix: clear stale scrollback on session switch (#2155 by @Perlence) - fix: remove trailing markdown block spacing (#2152 by @markusylisiurunen) packages/coding-agent: - feat: add resizable share sidebar (#2435 by @dmmulroy) - feat: emit OSC 133 command-executed marker - feat: reload custom themes from disk watcher - feat: add --fork session flag - feat: file mutation queue for serialized writes - feat: initial message consolidation utility - fix: keybindings migrated to namespaced IDs - fix: resolve waitForRetry() race when auto-retry produces tool calls - fix: handle slash-delimited /model refs - fix: refresh active model after provider updates - fix: extended transient error patterns for retry
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
import type { ChildProcess } from "node:child_process";
|
|
|
|
const EXIT_STDIO_GRACE_MS = 100;
|
|
|
|
/**
|
|
* Wait for a child process to terminate without hanging on inherited stdio handles.
|
|
*
|
|
* Daemonized descendants can inherit the child's stdout/stderr pipe handles. In that
|
|
* case the child emits `exit`, but `close` can hang forever even though the original
|
|
* process is already gone. We wait briefly for stdio to end, then forcibly stop
|
|
* tracking the inherited handles.
|
|
*/
|
|
export function waitForChildProcess(child: ChildProcess): Promise<number | null> {
|
|
const { promise, resolve, reject } = Promise.withResolvers<number | null>();
|
|
|
|
let settled = false;
|
|
let exited = false;
|
|
let exitCode: number | null = null;
|
|
let postExitTimer: NodeJS.Timeout | undefined;
|
|
let stdoutEnded = child.stdout === null;
|
|
let stderrEnded = child.stderr === null;
|
|
|
|
const cleanup = () => {
|
|
if (postExitTimer) {
|
|
clearTimeout(postExitTimer);
|
|
postExitTimer = undefined;
|
|
}
|
|
child.removeListener("error", onError);
|
|
child.removeListener("exit", onExit);
|
|
child.removeListener("close", onClose);
|
|
child.stdout?.removeListener("end", onStdoutEnd);
|
|
child.stderr?.removeListener("end", onStderrEnd);
|
|
};
|
|
|
|
const finalize = (code: number | null) => {
|
|
if (settled) return;
|
|
settled = true;
|
|
cleanup();
|
|
child.stdout?.destroy();
|
|
child.stderr?.destroy();
|
|
resolve(code);
|
|
};
|
|
|
|
const maybeFinalizeAfterExit = () => {
|
|
if (!exited || settled) return;
|
|
if (stdoutEnded && stderrEnded) {
|
|
finalize(exitCode);
|
|
}
|
|
};
|
|
|
|
const onStdoutEnd = () => {
|
|
stdoutEnded = true;
|
|
maybeFinalizeAfterExit();
|
|
};
|
|
|
|
const onStderrEnd = () => {
|
|
stderrEnded = true;
|
|
maybeFinalizeAfterExit();
|
|
};
|
|
|
|
const onError = (err: Error) => {
|
|
if (settled) return;
|
|
settled = true;
|
|
cleanup();
|
|
reject(err);
|
|
};
|
|
|
|
const onExit = (code: number | null) => {
|
|
exited = true;
|
|
exitCode = code;
|
|
maybeFinalizeAfterExit();
|
|
if (!settled) {
|
|
postExitTimer = setTimeout(() => finalize(code), EXIT_STDIO_GRACE_MS);
|
|
}
|
|
};
|
|
|
|
const onClose = (code: number | null) => {
|
|
finalize(code);
|
|
};
|
|
|
|
child.stdout?.once("end", onStdoutEnd);
|
|
child.stderr?.once("end", onStderrEnd);
|
|
child.once("error", onError);
|
|
child.once("exit", onExit);
|
|
child.once("close", onClose);
|
|
|
|
return promise;
|
|
}
|