Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(maker-core): 豁免 Codex 子 agent 等待的循环误判 (#4929)

Dash6bba06150735
diff --git a/packages/maker-core/src/agents/shared/loop-guard.test.ts b/packages/maker-core/src/agents/shared/loop-guard.test.ts
index 054fc1f73b..7883977302 100644
--- a/packages/maker-core/src/agents/shared/loop-guard.test.ts
+++ b/packages/maker-core/src/agents/shared/loop-guard.test.ts
@@ -59,13 +59,36 @@ describe('ToolLoopGuard', () => {
}
});
- it.each(['write_stdin', 'wait', 'sleep', 'subagent'])('keeps %s polling out of loop fingerprints', (name) => {
+ it.each(['write_stdin', 'wait', 'sleep', 'subagent', 'collab:wait'])('keeps %s polling out of loop fingerprints', (name) => {
const guard = new ToolLoopGuard();
for (let i = 0; i < 150; i++) {
expect(feed(guard, String(i), name, { action: 'status' }, 'running').kind).toBe('ok');
}
});
+ it('does not let collab waits erase ordinary repeated calls', () => {
+ const guard = new ToolLoopGuard();
+ for (let i = 0; i < 4; i++) {
+ expect(feed(guard, `wait-${i}`, 'collab:wait', {
+ senderThreadId: 'parent', receiverThreadIds: [],
+ }, 'completed')).toEqual({ kind: 'ok' });
+ const verdict = feed(guard, `read-${i}`, 'read', { path: 'same.ts' }, 'unchanged');
+ if (i < 3) expect(verdict.kind).toBe('ok');
+ else expect(verdict).toMatchObject({ kind: 'hard', reason: 'consecutive', count: 4 });
+ }
+ });
+
+ it.each(['collab:spawnAgent', 'collab:sendInput', 'collab:resumeAgent', 'collab:closeAgent'])(
+ 'still detects repeated non-wait collaboration calls: %s', (name) => {
+ const guard = new ToolLoopGuard();
+ let verdict: ToolLoopGuardVerdict = { kind: 'ok' };
+ for (let i = 0; i < 4; i++) {
+ verdict = feed(guard, String(i), name, { senderThreadId: 'parent', receiverThreadIds: ['child'] }, 'completed');
+ }
+ expect(verdict).toMatchObject({ kind: 'hard', reason: 'consecutive', count: 4 });
+ },
+ );
+
it('resets long read evidence on a new turn', () => {
const guard = new ToolLoopGuard();
for (let turn = 0; turn < 3; turn++) {
diff --git a/packages/maker-core/src/agents/shared/loop-guard.ts b/packages/maker-core/src/agents/shared/loop-guard.ts
index c277f74901..21d61386ca 100644
--- a/packages/maker-core/src/agents/shared/loop-guard.ts
+++ b/packages/maker-core/src/agents/shared/loop-guard.ts
@@ -121,6 +121,8 @@ export function classifyToolContractError(
*/
const LOOP_GUARD_EXEMPT_TOOL_NAMES = new Set([
'TaskOutput', 'write_stdin', 'wait', 'sleep',
+ // Codex translates native subagent waits to this name, often with a stable result.
+ 'collab:wait',
// Codex translator retains the namespace of host dynamic tools.
'dynamic:functions:write_stdin', 'dynamic:functions:wait',
'dynamic:clock:sleep', 'mcp:clock:sleep',
diff --git a/packages/maker-core/src/session.tool-loop.test.ts b/packages/maker-core/src/session.tool-loop.test.ts
index 1b17651da1..f06877266e 100644
--- a/packages/maker-core/src/session.tool-loop.test.ts
+++ b/packages/maker-core/src/session.tool-loop.test.ts
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { Session, MANUAL_ABORT_RECOVERY_GRACE_MS } from './session.js';
import { createAsyncQueue } from './agents/shared/async-queue.js';
import { createPiTranslateContext, translatePiEvent } from './agents/pi/translator.js';
+import { newCodexRuntimeState, translateItemNotification } from './agents/codex/translator.js';
import type { AgentSessionHandle } from './agents/base-agent.js';
import type { AgentEvent, InteractionDecision } from './types/events.js';
import type { Logger } from './interfaces/logger.js';
@@ -188,6 +189,36 @@ describe.each(['pi', 'codex'] as const)('%s Session tool loop coverage', (agentK
});
});
+it.each([false, true])('keeps translated Codex waits alive with agent states=%s', async (hasAgentStates) => {
+ const t = setup('codex');
+ const context = { rt: newCodexRuntimeState(), log: { info() {}, warn() {}, error() {}, debug() {} } };
+ await t.session.send('wait for the child');
+ for (let i = 0; i < 20; i++) {
+ const item = {
+ type: 'collabAgentToolCall', id: `wait-${i}`, tool: 'wait', status: 'completed',
+ senderThreadId: 'parent', receiverThreadIds: hasAgentStates ? ['child'] : [],
+ agentsStates: hasAgentStates ? { child: { status: 'running' } } : {},
+ };
+ translateItemNotification('started', {
+ threadId: 'parent', turnId: 'turn', item: { ...item, status: 'inProgress' },
+ }, t.queue, context);
+ translateItemNotification('completed', { threadId: 'parent', turnId: 'turn', item }, t.queue, context);
+ await vi.advanceTimersByTimeAsync(0);
+ }
+ expect(t.errors()).toHaveLength(0);
+ expect(t.handle.abort).not.toHaveBeenCalled();
+ expect(t.session.getStatus()).toBe('active');
+ expect(t.seen.filter(e => e.type === 'tool_use')).toHaveLength(20);
+ expect(t.seen.filter(e => e.type === 'tool_result')).toHaveLength(20);
+ expect(t.seen.filter(e => e.type === 'tool_result_full').map(e => e.data)).toEqual(
+ Array.from({ length: 20 }, (_, i) => ({
+ toolUseId: `wait-${i}`, fullText: hasAgentStates ? 'child: running' : 'completed', isError: false,
+ })),
+ );
+ await t.end();
+ expect(t.handle.abort).not.toHaveBeenCalled();
+});
+
it('pairs real Pi translator tool events without changing their results', async () => {
const t = setup('pi');
const logger: Logger = { trace() {}, debug() {}, info() {}, warn() {}, error() {}, fatal() {}, child() { return logger; } };