diff --git a/docs/architecture/task-sources.md b/docs/architecture/task-sources.md index 1a4ae0d..3e06008 100644 --- a/docs/architecture/task-sources.md +++ b/docs/architecture/task-sources.md @@ -111,8 +111,8 @@ no compare-and-set, so starts under two home directories, on one machine or two, can both claim the same Task. The run baton (`Run`, the `classic-delivery` template with seats `impl` and -`review`, and the process runner) belongs to `agent-task-loop` -(`src/orchestration/`). Only the lease itself comes from +`review`, and the `ProcessRunner` port, which the caller implements) belongs to +`agent-task-loop` (`src/orchestration/`). Only the lease itself comes from `@rivus/agent-kit-collab`'s `/lease`: `createLeaseManager` with a file lease repository over the shared per-key directory, renewed by the manager's own heartbeat fiber and released when the occupancy scope closes, shared by the CLI diff --git a/packages/agent-task-loop/src/orchestration/execa-runner.test.ts b/packages/agent-task-loop/src/orchestration/execa-runner.test.ts deleted file mode 100644 index 59e4f27..0000000 --- a/packages/agent-task-loop/src/orchestration/execa-runner.test.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { mkdtempSync, readFileSync, rmSync } from 'node:fs'; -import { tmpdir } from 'node:os'; -import { join } from 'node:path'; - -import { afterEach, describe, expect, it } from 'vitest'; - -import { execaProcessRunner } from './execa-runner.js'; - -const directories: string[][] = []; - -afterEach(() => { - for (const directory of directories.pop() ?? []) { - rmSync(directory, { recursive: true, force: true }); - } -}); - -function isAlive(pid: number): boolean { - try { - process.kill(pid, 0); - return true; - } catch { - return false; - } -} - -describe('execaProcessRunner', () => { - it('kills descendant processes when the cancel signal aborts', async () => { - const directory = mkdtempSync(join(tmpdir(), 'execa-runner-')); - directories.push([directory]); - const pidFile = join(directory, 'grandchild.pid'); - - const controller = new AbortController(); - const promise = execaProcessRunner({ - cmd: 'sh', - args: ['-c', `sleep 30 & echo $! > '${pidFile}'; wait`], - cwd: directory, - env: {}, - signal: controller.signal, - }); - - // Wait until the grandchild (the background sleep) has written its pid. - let grandchildPid = 0; - for (let waited = 0; waited < 5_000; waited += 50) { - try { - grandchildPid = Number(readFileSync(pidFile, 'utf8').trim()); - if (grandchildPid > 0 && isAlive(grandchildPid)) { - break; - } - } catch { - // pid file not written yet - } - await new Promise((resolve) => setTimeout(resolve, 50)); - } - expect(grandchildPid).toBeGreaterThan(0); - expect(isAlive(grandchildPid)).toBe(true); - - controller.abort(); - const result = await promise; - expect(result.exitCode).not.toBe(0); - - // killDescendants terminates the whole process group, so the grandchild dies too. - let gone = false; - for (let waited = 0; waited < 5_000; waited += 50) { - if (!isAlive(grandchildPid)) { - gone = true; - break; - } - await new Promise((resolve) => setTimeout(resolve, 50)); - } - expect(gone).toBe(true); - }); -}); diff --git a/packages/agent-task-loop/src/orchestration/execa-runner.ts b/packages/agent-task-loop/src/orchestration/execa-runner.ts deleted file mode 100644 index 32a3f98..0000000 --- a/packages/agent-task-loop/src/orchestration/execa-runner.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { execa } from 'execa'; -import type { ProcessRunner } from './types'; - -export const execaProcessRunner: ProcessRunner = async (input) => { - const subprocess = execa(input.cmd, input.args, { - cwd: input.cwd, - env: { ...process.env, ...input.env }, - cancelSignal: input.signal, - killDescendants: true, - reject: false, - stdin: 'ignore', - }); - input.onSpawn?.(subprocess.pid); - const result = await subprocess; - return { - stdout: result.stdout, - stderr: result.stderr, - exitCode: result.exitCode ?? 1, - }; -};