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 claims on non-transport terminal errors

Dash9c01db21ef36
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index ec1682b1ce..bf4c0638a5 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -79,8 +79,9 @@ timeout 不得触发自动换窗或 replay。Codex 当前没有与 Claude `AutoC
后续 `wait` 输出 `Script completed` / `Script terminated` 后视为该 cell 已结算,不得
再铸 claim,也不得报 lost-handle。禁止把 `last_agent_message == null` 或开场白当结算
判据;cell 跨 turn 存活性未证实前,续段失败必须诚实报 lost-handle,不得 replay 原请求
- 或重跑已执行命令。Claude wake continuation 与 Codex yield continuation 先分账,不抽
- 公共模块。
+ 或重跑已执行命令。续段 claim 一旦挡住产品结束,所有非重试终态错误路径(不限
+ transport)都必须同步结算它,不能只推 Done 而让 `isTurnRunning()` 仍为 true。
+ Claude wake continuation 与 Codex yield continuation 先分账,不抽公共模块。
## 3. 守住四项核心数据指标
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index e4c0c98896..ea08df7e1c 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -18314,6 +18314,63 @@ describe('CodexAgent yield continuation', () => {
});
await handle.close();
});
+
+ it('releases a yield claim on a non-transport terminal error so the session is not permanently busy', 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-terminal-error',
+ model: 'gpt-5.4',
+ workingDir: '/repo',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.itemCompleted || !handlers.turnCompleted || !handlers.error) {
+ throw new Error('expected item, turn, and error handlers');
+ }
+ const events = await collectYieldEvents(handle);
+ await handle.send({ type: 'user', content: 'run typecheck' });
+ handlers.itemCompleted({
+ threadId: 'start-thread-id',
+ turnId: 'turn-1',
+ item: {
+ id: 'item-exec-terminal',
+ 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 waitForExpectation(() => {
+ expect(events.some((event) => event.type === 'done' && event.turnContinuationId != null)).toBe(true);
+ });
+ await vi.waitFor(() => {
+ expect(yieldTurnStartCalls(host)).toHaveLength(1);
+ });
+ expect(handle.isTurnRunning?.()).toBe(true);
+ // 原 turn 已落墓碑: 非 transport 的 turn-1 error 会被 stale guard 丢掉。
+ // 必须打到续段 turn, 才能覆盖「只在 transport 路径结算 claim」的旧修法。
+ handlers.error({
+ threadId: 'start-thread-id',
+ turnId: 'turn-2',
+ willRetry: false,
+ error: { message: 'model request failed' },
+ });
+ await waitForExpectation(() => {
+ 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 144339a2f9..ad5a2c9202 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -10736,6 +10736,10 @@ export class CodexAgent extends BaseAgent {
// 没接管(预算耗尽 / 已有产出 / 非容量错误)且这一轮确实在跑 → 下面推 Done 收口。
// 同上: 收口即撤销重投资格, 否则延后标记会在别的 start settle 时补排。
revokeOverloadRetryOnTerminalSettle('terminal error notification');
+ // yield claim 让 isTurnRunning() 在 SDK turn 结束后仍为 true。transport
+ // 路径在订阅作废时已经结算;非 transport 的终态 error 同样会推 Done,
+ // 若不在这里同步取消, UI 已失败而后续 send 仍被 SESSION_RUNNING 拒绝。
+ cancelActiveYieldContinuation('terminal error');
eventQueue.push({
type: 'status',
data: { status: 'Done', ...usageTracker.snapshot(), isRunning: false },