Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): keep subagent steering available during retries
zqchrisb3631207cbcb
diff --git a/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts b/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.tsindex 81430a3e22..8d58846c45 100644--- a/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts@@ -228,6 +228,7 @@ async function makeFixture(options: {approvalMethod?: 'confirm' | 'input';modelError?: boolean;retryThenSucceed?: boolean;+ retryThenHang?: boolean;outputThenHang?: boolean;commentaryThenHang?: boolean;hangOnMessage?: string;@@ -337,13 +338,13 @@ setTimeout(() => process.exit(0), 60000).unref();? `process.stdout.write(JSON.stringify({ type: 'message_end', message: { role: 'assistant', content: [], stopReason: 'error', errorMessage: 'socket closed before response', usage: { input: 0, output: 0 } } }) + '\\n');process.stdout.write(JSON.stringify({ type: 'agent_end' }) + '\\n');process.stdout.write(JSON.stringify({ type: 'agent_settled' }) + '\\n');`- : options.retryThenSucceed+ : options.retryThenSucceed || options.retryThenHang? `process.stdout.write(JSON.stringify({ type: 'message_end', message: { role: 'assistant', content: [], stopReason: 'error', errorMessage: 'temporary socket failure', usage: { input: 1, output: 0 } } }) + '\\n');process.stdout.write(JSON.stringify({ type: 'agent_end' }) + '\\n');process.stdout.write(JSON.stringify({ type: 'auto_retry_start', attempt: 1, maxAttempts: 2, delayMs: 0, errorMessage: 'temporary socket failure' }) + '\\n');- process.stdout.write(JSON.stringify({ type: 'message_end', message: { role: 'assistant', content: [{ type: 'text', text: ${fixtureOutput} }], usage: { input: 3, output: 2, cost: { total: 0.01 } } } }) + '\\n');+ ${options.retryThenHang ? '' : `process.stdout.write(JSON.stringify({ type: 'message_end', message: { role: 'assistant', content: [{ type: 'text', text: ${fixtureOutput} }], usage: { input: 3, output: 2, cost: { total: 0.01 } } } }) + '\\n');process.stdout.write(JSON.stringify({ type: 'agent_end' }) + '\\n');- process.stdout.write(JSON.stringify({ type: 'agent_settled' }) + '\\n');`+ process.stdout.write(JSON.stringify({ type: 'agent_settled' }) + '\\n');`}`: `process.stdout.write(JSON.stringify({ type: 'message_end', message: { role: 'assistant', content: [{ type: 'text', text: ${fixtureOutput} }], usage: { input: 3, output: 2, cost: { total: 0.01 } } } }) + '\\n');process.stdout.write(JSON.stringify({ type: 'agent_end' }) + '\\n');process.stdout.write(JSON.stringify({ type: 'agent_settled' }) + '\\n');`;@@ -677,6 +678,30 @@ describe('Cindy durable PI Subagent runner', () => {await waitForClose(fixture.child, fixture.stderr);});+ it('accepts steering while a child is backing off for automatic retry', async () => {+ const fixture = await makeFixture({ retryThenHang: true });+ try {+ const retrying = await waitFor(async () => {+ const [run] = await listPiSubagentRuns(fixture.root);+ if (run?.totalTokens !== 1 || run.state !== 'running') return null;+ const transcript = await readFile(path.join(fixture.runDir, 'transcript.jsonl'), 'utf8');+ return transcript.includes('auto_retry_start') ? run : null;+ });+ expect(retrying.tasks[0]?.resultReady).toBe(false);+ await expect(controlPiSubagentRuns(fixture.root, retrying.runId, 'steer', {+ childId: retrying.tasks[0]?.childId, message: 'Use the corrected request after retry',+ })).resolves.toBe(1);+ await waitFor(async () => {+ const commands = await readCommandsIfPresent(fixture.commandsFile);+ return commands?.some(command => command.type === 'steer'+ && command.message === 'Use the corrected request after retry') ? true : null;+ });+ } finally {+ await controlPiSubagentRuns(fixture.root, fixture.runId, 'stop');+ await waitForClose(fixture.child, fixture.stderr);+ }+ });+it('rejects controls after the child RPC input has closed but before process exit', async () => {const fixture = await makeFixture({ holdExitAfterInputEnd: true });try {diff --git a/packages/maker-core/src/agents/pi/cindy-subagent-runner-source.ts b/packages/maker-core/src/agents/pi/cindy-subagent-runner-source.tsindex 89121bd52a..fcee9accb6 100644--- a/packages/maker-core/src/agents/pi/cindy-subagent-runner-source.ts+++ b/packages/maker-core/src/agents/pi/cindy-subagent-runner-source.ts@@ -958,6 +958,10 @@ function main() {}if (event.type === 'auto_retry_start') {terminalError = '';+ // A failed attempt is not the generation's final answer. Pi keeps+ // stdin open during retry backoff so corrections must stay eligible.+ task.resultReady = false;+ scheduleStatus();return;}if (event.type === 'agent_end') {