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): settle yield failures once and drop queued follow-ups

Dash042e6ab2c7f8
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index 0c44bf0da1..5c03365da0 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -89,6 +89,11 @@ timeout 不得触发自动换窗或 replay。Codex 当前没有与 Claude `AutoC
产品 `done`。同一产品 turn 上的
ask_user/plan 内部续段必须等 yield 空闲后再 `turn/start`,不得并发;Stop/
close 取消 yield 时,排队中的内部续段必须退出而不是被当成正常空闲继续发送。
+ 只有 cell 真正结算的成功空闲才能唤醒排队续段;lost-handle、重试耗尽、
+ 续段 `turn/start` 失败等产品失败必须以 cancelled 释放 waiter,不得在用户
+ 已看到失败后再开 ask_user/plan turn。续段启动失败的产品终态只由续段层
+ 发送一次(`yield-continuation-start-failed`),`handle.send` 不得再发一组
+ 通用终态。
续段必须继承铸造 claim 时的 `turnPermissionPolicy`,不得把无人值守只读边界
重置成普通 Auto。
Claude wake continuation 与 Codex yield continuation 先分账,不抽公共模块。
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index bde70d4396..b2c7e051eb 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -17974,11 +17974,17 @@ describe('CodexAgent yield continuation', () => {
turn: { id: 'turn-1', status: 'completed' },
});
await waitForExpectation(() => {
- expect(events.some((event) => (
+ expect(events.filter((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '').includes('yield-continuation-start-failed')
- ))).toBe(true);
+ && (event.data as { isTerminal?: boolean }).isTerminal === true
+ ))).toHaveLength(1);
});
+ const terminalErrors = events.filter((event) => (
+ event.type === 'error'
+ && (event.data as { isTerminal?: boolean }).isTerminal === true
+ ));
+ expect(String((terminalErrors[0]?.data as { reason?: string }).reason ?? ''))
+ .toBe('yield-continuation-start-failed');
expect(handle.isTurnRunning?.()).toBe(false);
await handle.close();
});
@@ -18238,11 +18244,21 @@ describe('CodexAgent yield continuation', () => {
turn: { id: 'turn-1', status: 'completed' },
});
await waitForExpectation(() => {
- expect(events.some((event) => (
+ expect(events.filter((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '').includes('yield-continuation-start-failed')
- ))).toBe(true);
+ && (event.data as { isTerminal?: boolean }).isTerminal === true
+ ))).toHaveLength(1);
});
+ const terminalErrors = events.filter((event) => (
+ event.type === 'error'
+ && (event.data as { isTerminal?: boolean }).isTerminal === true
+ ));
+ expect(String((terminalErrors[0]?.data as { reason?: string }).reason ?? ''))
+ .toBe('yield-continuation-start-failed');
+ expect(events.some((event) => (
+ event.type === 'error'
+ && /^turn\/start failed:/.test(String((event.data as { message?: string }).message ?? ''))
+ ))).toBe(false);
expect(handle.isTurnRunning?.()).toBe(false);
await handle.close();
});
@@ -18760,6 +18776,90 @@ describe('CodexAgent yield continuation', () => {
))).toBe(false);
await handle.close();
});
+
+ it('does not start a queued ask_user continuation after lost-handle', async () => {
+ const agent = new CodexAgent(createDeps());
+ let turnSeq = 0;
+ const host = installFakeHost(agent, (method) => {
+ if (method === Method.TurnStart) {
+ turnSeq += 1;
+ return { turn: { id: `turn-${turnSeq}` } };
+ }
+ return undefined;
+ });
+ const handle = await agent.startSession({
+ sessionId: 'session-yield-lost-handle-drops-ask-user',
+ model: 'gpt-5.4',
+ workingDir: '/repo',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.itemCompleted || !handlers.turnCompleted || !handlers.requestUserInput) {
+ throw new Error('expected item, turn, and user-input handlers');
+ }
+ const ownerDecision = deferred<InteractionDecision>();
+ handle.setInteractionResolver(async () => ownerDecision.promise);
+ const events = await collectYieldEvents(handle);
+ await handle.send({ type: 'user', content: 'run typecheck' });
+ void handlers.requestUserInput({
+ threadId: 'start-thread-id',
+ turnId: 'turn-1',
+ itemId: 'item-ask-lost',
+ questions: [{
+ id: 'native-q1',
+ header: 'Question',
+ question: 'Pick one',
+ isOther: false,
+ isSecret: false,
+ options: [{ label: 'A', description: null }],
+ }],
+ }, { requestId: 'req-ask-lost' });
+ handlers.itemCompleted({
+ threadId: 'start-thread-id',
+ turnId: 'turn-1',
+ item: {
+ id: 'item-exec-ask-lost',
+ type: 'commandExecution',
+ command: 'pnpm --filter desktop run typecheck',
+ status: 'completed',
+ aggregatedOutput: 'Script running with cell ID 226',
+ },
+ });
+ handlers.turnCompleted({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-1', status: 'completed' },
+ });
+ await vi.waitFor(() => {
+ expect(yieldTurnStartCalls(host)).toHaveLength(1);
+ });
+ ownerDecision.resolve({
+ kind: 'ask_user_question',
+ answers: { 'Pick one': 'A' },
+ });
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ expect(host.request.mock.calls.filter(([method]) => method === Method.TurnStart)).toHaveLength(2);
+ handlers.turnStarted?.({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-2', status: 'inProgress' },
+ });
+ handlers.turnCompleted({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-2', status: 'completed' },
+ });
+ await waitForExpectation(() => {
+ expect(events.some((event) => (
+ event.type === 'error'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ ))).toBe(true);
+ });
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ expect(host.request.mock.calls.filter(([method]) => method === Method.TurnStart)).toHaveLength(2);
+ expect(events.some((event) => (
+ event.type === 'error'
+ && String((event.data as { message?: string }).message ?? '').includes('ask_user continuation turn failed to start')
+ ))).toBe(false);
+ expect(handle.isTurnRunning?.()).toBe(false);
+ await handle.close();
+ });
});
describe('CodexAgent steer', () => {
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 6a99880a81..d1e767b427 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -3349,6 +3349,9 @@ export class CodexAgent extends BaseAgent {
data: { status: 'Done', ...usageTracker.snapshot(), isRunning: false },
source: 'codex',
});
+ // Failure is a product terminal. Queued ask_user / plan waiters must exit
+ // rather than treat this as idle success and start another turn.
+ flushYieldContinuationIdleWaiters(true);
};
const emitYieldContinuationStartFailure = (error: unknown, cells: YieldedExecCell[]): void => {
emitYieldContinuationFailure({
@@ -9035,7 +9038,6 @@ export class CodexAgent extends BaseAgent {
yieldedCells.length === 0 ? 'empty_completion' : 'retry_exhausted',
);
suppressSuccessfulYieldBoundary = true;
- flushYieldContinuationIdleWaiters();
} else {
yieldClaim = mintYieldContinuationClaim(outstandingCells, turn.id, retryCount);
}
@@ -11021,16 +11023,20 @@ export class CodexAgent extends BaseAgent {
rejectIfCancelled(sendOpts, 'send');
const message = `Failed to restore Codex read-only reference permissions: ${String(e)}`;
log.error('read-only reference profile refresh failed', { error: String(e), threadId });
- eventQueue.push({
- type: 'error',
- data: { message, isTerminal: true },
- source: 'codex',
- });
- eventQueue.push({
- type: 'status',
- data: { status: 'Done', ...usageTracker.snapshot(), isRunning: false },
- source: 'codex',
- });
+ // Yield continuation owns its product terminal. Emitting here would
+ // duplicate the later yield-continuation-start-failed events.
+ if (yieldAttempt == null) {
+ eventQueue.push({
+ type: 'error',
+ data: { message, isTerminal: true },
+ source: 'codex',
+ });
+ eventQueue.push({
+ type: 'status',
+ data: { status: 'Done', ...usageTracker.snapshot(), isRunning: false },
+ source: 'codex',
+ });
+ }
if (sendOpts?.throwOnStartFailure) throw new Error(message);
return;
}
@@ -11635,7 +11641,7 @@ export class CodexAgent extends BaseAgent {
log.info('turn/start failure suppressed — this send was already settled by cancel', {
threadId,
});
- } else {
+ } else if (yieldAttempt == null) {
eventQueue.push({
type: 'error',
data: { message: `turn/start failed: ${String(finalErr)}`, isTerminal: true },