Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): 重连恢复后重置 retry episode (#3620)
Zane6ca4b7d696e2
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex 05eb1e04dd..f8d2a23563 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -21234,6 +21234,154 @@ describe('CodexAgent turn lifecycle', () => {},);+ it('starts a fresh retry episode after same-turn progress (issue #3578)', async () => {+ const agent = new CodexAgent(createDeps());+ const host = installFakeHost(agent);+ const handle = await agent.startSession({+ sessionId: 'session-retry-episode-recovery',+ model: 'gpt-5.4',+ workingDir: '/repo',+ });+ const handlers = host.getThreadHandlers();+ if (!handlers?.error || !handlers.reasoningTextDelta) {+ throw new Error('expected retry and reasoning handlers');+ }+ const events: AgentEvent[] = [];+ void (async () => {+ for await (const event of handle.events()) events.push(event);+ })();++ handlers.turnStarted?.({+ threadId: 'start-thread-id',+ turn: { id: 'turn-retry-episode-recovery' },+ } as never);+ handlers.error({+ threadId: 'start-thread-id',+ turnId: 'turn-retry-episode-recovery',+ willRetry: true,+ error: { message: 'Reconnecting... 1/5' },+ } as never);+ handlers.reasoningTextDelta({+ threadId: 'start-thread-id',+ turnId: 'turn-retry-episode-recovery',+ itemId: 'reasoning-recovered',+ contentIndex: 0,+ delta: 'recovered',+ } as never);+ await waitForExpectation(() => {+ expect(events).toContainEqual(expect.objectContaining({+ type: 'thinking',+ data: expect.objectContaining({ text: 'recovered' }),+ }));+ });++ const retryError = {+ threadId: 'start-thread-id',+ turnId: 'turn-retry-episode-recovery',+ willRetry: true,+ error: {+ message: 'unexpected status 403 Forbidden, url: https://chatgpt.com/backend-api/codex/responses',+ },+ } as const;+ for (let index = 0; index < 29; index += 1) {+ handlers.error(retryError);+ }++ expect(handle.isTurnRunning?.()).toBe(true);+ expect(events).not.toContainEqual(expect.objectContaining({+ type: 'error',+ data: expect.objectContaining({+ isTerminal: true,+ message: expect.stringContaining('Codex backend unreachable'),+ }),+ }));+ expect(host.request).not.toHaveBeenCalledWith(Method.TurnInterrupt, expect.anything());+ await handle.close();+ });++ it('does not reset the active retry episode for a late foreign turn completion', async () => {+ const agent = new CodexAgent(createDeps());+ let turnSequence = 0;+ const host = installFakeHost(agent, (method) => {+ if (method === Method.TurnStart) {+ return { turn: { id: `turn-${++turnSequence}` } };+ }+ if (method === Method.TurnInterrupt) return {};+ return undefined;+ });+ const handle = await agent.startSession({+ sessionId: 'session-retry-episode-late-foreign-completion',+ model: 'gpt-5.4',+ workingDir: '/repo',+ });+ const handlers = host.getThreadHandlers();+ if (!handlers?.error || !handlers.turnCompleted) {+ throw new Error('expected retry and completion handlers');+ }+ const events: AgentEvent[] = [];+ void (async () => {+ for await (const event of handle.events()) events.push(event);+ })();++ await handle.send({ type: 'user', content: 'old turn' });+ handlers.turnStarted?.({+ threadId: 'start-thread-id',+ turn: { id: 'turn-1' },+ } as never);+ await handle.send({ type: 'user', content: 'current turn' });+ handlers.turnStarted?.({+ threadId: 'start-thread-id',+ turn: { id: 'turn-2' },+ } as never);+ handlers.error({+ threadId: 'start-thread-id',+ turnId: 'turn-2',+ willRetry: true,+ error: { message: 'Reconnecting... 1/5' },+ } as never);++ handlers.turnCompleted({+ threadId: 'start-thread-id',+ turn: { id: 'turn-1', status: 'completed' },+ } as never);+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(events).not.toContainEqual(expect.objectContaining({+ type: 'status',+ data: expect.objectContaining({ isRunning: false }),+ }));+ expect(events).not.toContainEqual(expect.objectContaining({+ type: 'done',+ data: expect.objectContaining({ raw: expect.objectContaining({ id: 'turn-1' }) }),+ }));++ const retryError = {+ threadId: 'start-thread-id',+ turnId: 'turn-2',+ willRetry: true,+ error: {+ message: 'unexpected status 403 Forbidden, url: https://chatgpt.com/backend-api/codex/responses',+ },+ } as const;+ for (let index = 0; index < 29; index += 1) {+ handlers.error(retryError);+ }++ await waitForExpectation(() => {+ expect(events).toContainEqual(expect.objectContaining({+ type: 'error',+ data: expect.objectContaining({+ isTerminal: true,+ message: expect.stringContaining('Codex backend unreachable'),+ }),+ }));+ });+ expect(host.request).toHaveBeenCalledWith(Method.TurnInterrupt, {+ threadId: 'start-thread-id',+ turnId: 'turn-2',+ });+ await handle.close();+ });+it('escalates a persistent willRetry retry-loop to a terminal error (issue #677)', async () => {// 远端摸不到 Codex 后端时 daemon 无限发 willRetry=true — 升级逻辑应在阈值处// 合成终态错误并复位 turn (isTurnRunning=false + Done status), 消息里带原始diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex 9015c04cc7..efae7c6f2a 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -6980,6 +6980,9 @@ export class CodexAgent extends BaseAgent {}if (isReconnectRecoveryEvent(event)) {clearReconnectStall();+ // Descendant/background events are filtered by the queue probe. Real+ // root-turn progress starts a new retry episode within the same turn.+ turnRetryTracker.reset();}}/**@@ -9051,8 +9054,15 @@ export class CodexAgent extends BaseAgent {}}clearActiveToolContextsForTurn(turn.id);- const overlapsActiveTurn = suppressTerminalUi && currentTurnId !== null && currentTurnId !== turn.id;- if (overlapsActiveTurn) return;+ const overlapsActiveTurn = currentTurnId !== null && currentTurnId !== turn.id;+ if (overlapsActiveTurn) {+ // A late terminal from an older root turn may overlap a newer active+ // turn. Keep its tombstone/bookkeeping above, but never settle the+ // newer turn's usage, generation, retry episode, or product boundary.+ latestPlanByTurn.delete(turn.id);+ flushDeferredTerminalTurnCompletionsIfIdle();+ return;+ }const activeYieldClaim = activeYieldContinuationClaim();if (activeYieldClaim && !claimOwnsTurn(activeYieldClaim, turn.id)) {// Foreign terminals must not settle the live continuation's usage,