Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): clear stale reconnect notice on visible thinking (#6474)
Lizi8bd60e8549cd
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.tsindex 911bbdff38..4afe4f04ae 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.ts@@ -669,6 +669,116 @@ describe('Codex 原生重连进行态与终态接管交棒', () => {).toBe(false);});+ // 测试价值+ // - 生产入口与可观察结果:handleStreamEvent;可见 thinking 出现时不再同时显示过期的重连行。+ // - Bug/规则依据:Codex/Pi 原生重连期间思考流仍可继续,UI 不应让用户看到相互矛盾的状态。+ // - 现有覆盖缺口:原有用例只覆盖正文、工具和 done,未覆盖 thinking 与重连行交错。+ // - 最小失败输入:Reconnecting 1/5 → thinking start/delta → 下一次 Reconnecting 2/5。+ // - tier:unit;只调用 renderer reducer,不依赖网络或真实进程。+ // - 实测耗时:文件级 vitest 约 2s。+ it.each(['codex', 'pi'] as const)(+ '%s 可见 thinking 会撤掉旧重连提示,后续重连仍可正常显示',+ (source) => {+ const reconnecting = handleStreamEvent(+ EMPTY_SESSION_STATE,+ reconnectEvent('Reconnecting... 1/5', false),+ );+ const thinkingStarted = handleStreamEvent(reconnecting, {+ sessionId: SID,+ type: 'thinking',+ source,+ data: { stage: 'start', blockId: 'thinking-1', startedAt: 1 },+ });+ const withThinking = handleStreamEvent(thinkingStarted, {+ sessionId: SID,+ type: 'thinking',+ source,+ data: { stage: 'delta', blockId: 'thinking-1', text: '正在分析下一步' },+ });++ expect(withThinking.messages.some((m) => m.clientId === '__codex_reconnect_pending__')).toBe(+ false,+ );+ expect(+ withThinking.messages.some((m) => m.role === 'thinking' && m.content === '正在分析下一步'),+ ).toBe(true);++ const retrying = handleStreamEvent(+ withThinking,+ reconnectEvent('Reconnecting... 2/5', false),+ );+ expect(+ retrying.messages.find((m) => m.clientId === '__codex_reconnect_pending__')?.systemCardData,+ ).toMatchObject({ attempt: 2, maxAttempts: 5 });++ const repeatedFinal = handleStreamEvent(retrying, {+ sessionId: SID,+ type: 'thinking',+ source,+ data: { stage: 'final', blockId: 'thinking-1', text: '正在分析下一步', durationMs: 10 },+ });+ expect(composerReconnect(repeatedFinal)).toMatchObject({ attempt: 2, maxAttempts: 5 });++ const freshFinal = handleStreamEvent(repeatedFinal, {+ sessionId: SID,+ type: 'thinking',+ source,+ data: {+ stage: 'final',+ blockId: 'thinking-1',+ text: '正在分析下一步,已找到原因',+ durationMs: 20,+ },+ });+ expect(composerReconnect(freshFinal)).toBeNull();++ const finalOnly = handleStreamEvent(retrying, {+ sessionId: SID,+ type: 'thinking',+ source,+ data: { stage: 'final', blockId: 'thinking-2', text: '仅收到最终思考内容', durationMs: 30 },+ });+ expect(composerReconnect(finalOnly)).toBeNull();+ expect(finalOnly.messages.find((m) => m.clientId === 'thinking-2')?.content).toBe(+ '仅收到最终思考内容',+ );+ },+ );++ it('后台或空白 thinking 不会撤掉原生活动行', () => {+ const reconnecting = handleStreamEvent(+ EMPTY_SESSION_STATE,+ reconnectEvent('Reconnecting... 1/5', false),+ );+ const thinkingStarted = handleStreamEvent(reconnecting, {+ sessionId: SID,+ type: 'thinking',+ source: 'codex',+ data: { stage: 'start', blockId: 'thinking-bg', startedAt: 1 },+ });+ expect(composerReconnect(thinkingStarted)).not.toBeNull();+ const backgroundThinking = handleStreamEvent(thinkingStarted, {+ sessionId: SID,+ type: 'thinking',+ source: 'codex',+ turnScope: 'background',+ data: { stage: 'delta', blockId: 'thinking-bg', text: '后台协作' },+ });+ expect(+ backgroundThinking.messages.some((m) => m.clientId === '__codex_reconnect_pending__'),+ ).toBe(true);++ const whitespaceThinking = handleStreamEvent(backgroundThinking, {+ sessionId: SID,+ type: 'thinking',+ source: 'codex',+ data: { stage: 'delta', blockId: 'thinking-bg', text: ' \n ' },+ });+ expect(+ whitespaceThinking.messages.some((m) => m.clientId === '__codex_reconnect_pending__'),+ ).toBe(true);+ });+it('带 turnContinuationId 的 done 不会清除原生活动行', () => {const reconnecting = handleStreamEvent(EMPTY_SESSION_STATE,diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 0841582cbc..982b999555 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -4636,7 +4636,7 @@ function isCodexUserActionableRetryError(data: unknown): boolean {}/**- * Codex 原生重连行只应在真正的 turn 进展或明确收尾时让位。+ * 清除可操作的临时错误仍需真正的 turn 进展或明确收尾。** `maker:event` 里还混着后台任务更新、tool_result、thinking 等旁路事件;它们* 可能属于同一会话但不代表重连已经恢复。Codex 子代理的 descendant 状态通知不会走这条@@ -4657,6 +4657,46 @@ function isCodexReconnectRecoveryOutput(event: CCAgentStreamEvent): boolean {return event.type === 'done' && !isTurnContinuationBoundaryEvent(event);}+/**+ * Fresh, visible root thinking ends the native reconnect presentation, just+ * as it ends Codex's reconnect-stall wait. This is independent of recovery+ * success: Main still requires substantive text/tools to settle its retry+ * episode. A final snapshot repeating already rendered text is not progress.+ */+function isCodexReconnectVisibleThinkingProgress(+ messages: readonly ChatMessage[],+ event: CCAgentStreamEvent,+): boolean {+ if (+ event.type !== 'thinking' ||+ event.turnScope === 'background' ||+ (event.source !== 'codex' && event.source !== 'pi')+ ) {+ return false;+ }+ const data = event.data as+ { stage?: unknown; blockId?: unknown; text?: unknown } | null | undefined;+ if (+ (data?.stage !== 'delta' && data?.stage !== 'final') ||+ typeof data.blockId !== 'string' ||+ typeof data.text !== 'string' ||+ !hasUserVisibleText(data.text) ||+ !messages.some((message) => message.clientId === CODEX_RECONNECT_PENDING_CLIENT_ID)+ )+ return false;++ const block = messages.find((message) => message.clientId === data.blockId);+ if (data.stage === 'delta') {+ return block?.role === 'thinking' && block.isStreaming === true;+ }+ if (!block) return true; // final-only delivery is rendered by the reducer below.+ if (block.role !== 'thinking' || block.thinkingRedacted) return false;+ const newText = data.text.startsWith(block.content)+ ? data.text.slice(block.content.length)+ : data.text;+ return hasUserVisibleText(newText);+}+/** Main 的接管 projection 与随后 maker:event 来自两个 channel。只有活动行里保存的* 原始错误与终态 event 完全一致,才把 event 视为同一次接管的广播回声;不能仅凭存在* 一张 pending 卡就吞掉后来其它 turn 的错误。 */@@ -5666,8 +5706,11 @@ export function handleStreamEvent(reconnectAttempt !== null &&!isCodexUserActionableRetryError(event.data);const hasCodexReconnectRecoveryOutput = isCodexReconnectRecoveryOutput(event);+ const hasCodexReconnectVisibleProgress =+ hasCodexReconnectRecoveryOutput ||+ isCodexReconnectVisibleThinkingProgress(inputState.messages, event);const shouldClearCodexReconnectPendingCard =- event.type === 'error' ? !isCodexReconnectProgress : hasCodexReconnectRecoveryOutput;+ event.type === 'error' ? !isCodexReconnectProgress : hasCodexReconnectVisibleProgress;const stateBeforeReconnectCleanup =!hasCodexReconnectRecoveryOutput || inputState.recoverableError == null? inputState