fix(agent): return collected output when exec auto-backgrounds

Previously, when a command exceeded yieldMs (default 5s) and was
auto-backgrounded, exec returned an empty output string. This caused
agents to misinterpret slow commands (like curl) as failed, leading
to infinite retry loops.

Changes:
- Implement three-layer buffer system (pending 30KB + aggregated 200KB + tail 1KB)
- Return collected output snapshot when backgrounding instead of empty string
- Increase default yieldMs from 5s to 10s for better coverage
- Add auto sweeper for terminated process cleanup (30min TTL)
- Register process immediately on spawn to capture all output

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jiayuan 2026-01-31 18:12:00 +08:00
parent a5f979fceb
commit cbb13b26d1
3 changed files with 172 additions and 56 deletions

View file

@ -6,6 +6,7 @@ import {
PROCESS_REGISTRY,
registerProcess,
cleanupTerminatedProcesses,
getFullOutput,
} from "./process-registry.js";
const ProcessSchema = Type.Object({
@ -138,10 +139,10 @@ export function createProcessTool(defaultCwd?: string): AgentTool<typeof Process
details: { id, running: false },
};
}
const output = entry.outputBuffer.join("");
const { output, truncated } = getFullOutput(entry);
const running = entry.exitCode === null;
return {
content: [{ type: "text", text: output || "(no output)" }],
content: [{ type: "text", text: (output || "(no output)") + (truncated ? "\n[output truncated]" : "") }],
details: { id, running, exitCode: entry.exitCode, output },
};
}