Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(notifications): 自动恢复期间不发送完成通知 (#4478)
Dashafc8f968fad2
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.tsindex 1a8bd22287..e927b8a6d9 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts@@ -11981,6 +11981,32 @@ describe('AgentInputCoordinator 中断自动续跑', () => {expect(projection.error).toBeNull();});+ it.each(['allow', 'reject', 'close'] as const)(+ 'keeps recovery projected through drained preparation and settles on %s', async (outcome) => {+ const h = createHarness();+ const sid = `takeover-preparing-${outcome}`;+ h.setResumableTurnErrorTakeover(TAKEOVER_INFO);+ h.setHasAssistantProgressAfter(async () => true);+ await failAfterDispatch(h, sid);+ const screen = deferred<{ action: 'allow' }>();+ h.setScreenUserMessage(() => screen.promise);+ await h.coordinator.autoRetryLastError(sid, TAKEOVER_INFO.sessionTotal);+ await flush();+ expect(h.coordinator.getProjection(sid).pendingQueue).toEqual([]);+ expect(h.coordinator.getProjection(sid).autoResumePending).toEqual(TAKEOVER_INFO);+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);+ if (outcome === 'close') {+ h.coordinator.onSessionClosed(sid);+ expect(h.coordinator.getProjection(sid).autoResumePending).toBeUndefined();+ }+ if (outcome === 'reject') screen.reject(new Error('preparation failed'));+ else screen.resolve({ action: 'allow' });+ await flush();+ expect(h.coordinator.getProjection(sid).autoResumePending).toBeUndefined();+ expect(h.sendToAgent).toHaveBeenCalledTimes(outcome === 'allow' ? 2 : 1);+ },+ );+it('abandonAutoResume 带 message → 错误回落成横幅', async () => {const h = createHarness();const sid = 'abandon-surfaces-banner';diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex 1006e18bb6..705d3d771c 100644--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@ -3829,6 +3829,15 @@ export class AgentInputCoordinator {private toProjection(sessionId: string, state: SessionInputState): AgentInputProjection {const pendingQueue = state.pendingQueue.map((item) => this.toProjectedItem(item));+ // Draining removes the queue row before asynchronous preparation starts.+ // Keep the existing recovery projection until dispatch settles; derive it+ // from the active owner so cancellation/failure cannot leave a stale flag.+ const autoResumePending = state.autoResumePending ?? (+ state.activeTurn?.item?.autoResume &&+ state.activeTurn.dispatchLifecycle !== 'dispatched'+ ? state.activeTurn.item.autoResumeInfo+ : undefined+ );const recovery: AgentInputRecovery =state.recovery?.kind === 'active-turn'? { ...state.recovery, item: this.toProjectedItem(state.recovery.item) }@@ -3856,7 +3865,7 @@ export class AgentInputCoordinator {...(state.error && state.errorReason ? { errorReason: state.errorReason } : {}),...(state.error && state.toolLoop ? { toolLoop: state.toolLoop } : {}),recovery,- ...(state.autoResumePending ? { autoResumePending: state.autoResumePending } : {}),+ ...(autoResumePending ? { autoResumePending } : {}),errorRetryText: projectionRetryText(state.pendingQueue, state.recovery),credentialSwitchWait: state.credentialSwitchWait? {diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.tsindex ca0357ccc2..23298348e0 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreAutoResumeCard.test.ts@@ -278,6 +278,52 @@ describe('applyInputProjection 自愈进行中提示', () => {expect(snapshot.error).toBeNull();});+ it('keeps recovery running until a pre-dispatch failure settles as error', () => {+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(false);+ inputProjectionCb!(projection({ autoResumePending: PENDING_INFO }));+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(true);+ expect(makerChatStore.getRunningSnapshot().get(SID)?.isRunning).toBe(true);+ inputProjectionCb!(projection({ pendingQueue: [{ clientId: 'retry', autoResume: true }] }));+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(true);+ expect(makerChatStore.getSnapshot(SID).agentStatus.isRunning).toBe(false);+ expect(makerChatStore.getRunningSnapshot().get(SID)?.isRunning).toBe(true);+ inputProjectionCb!(projection({ error: 'Selected model is at capacity.' }));+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(false);+ expect(makerChatStore.hasSessionTerminalError(SID)).toBe(true);+ expect(makerChatStore.getRunningSnapshot().get(SID)).toMatchObject({+ isRunning: false, hasError: true,+ });+ });++ it('does not classify a normal Continue as recovery when it finishes before projection cleanup', () => {+ makerEventCb!({ sessionId: SID, event: { type: 'status', data: { isRunning: true } } });+ inputProjectionCb!(projection({ continuationInFlightClientId: 'manual-continue' }));+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(false);+ expect(makerChatStore.getRunningSnapshot().get(SID)?.isRunning).toBe(true);+ makerEventCb!({ sessionId: SID, event: { type: 'done', data: {} } });+ expect(makerChatStore.getSnapshot(SID).continuationInFlightClientId).toBe('manual-continue');+ expect(makerChatStore.getRunningSnapshot().get(SID)).toMatchObject({+ isRunning: false, hasError: false,+ });+ inputProjectionCb!(projection());+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(false);+ });++ it('does not mark a paused or restored auto-resume queue as running', () => {+ const pendingQueue = [{ clientId: 'retry', autoResume: true }];+ inputProjectionCb!(projection({ pendingQueue, queuePaused: true }));+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(false);+ expect(makerChatStore.getRunningSnapshot().get(SID)?.isRunning ?? false).toBe(false);+ inputProjectionCb!(projection({ pendingQueue }));+ expect(makerChatStore.getRunningSnapshot().get(SID)?.isRunning).toBe(true);+ inputProjectionCb!(projection({ pendingQueue, queuePaused: true }));+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(false);+ expect(makerChatStore.getRunningSnapshot().get(SID)?.isRunning ?? false).toBe(false);+ // Pausing the remaining queue does not cancel an already-drained retry.+ inputProjectionCb!(projection({ queuePaused: true, autoResumePending: PENDING_INFO }));+ expect(makerChatStore.getRunningSnapshot().get(SID)?.isRunning).toBe(true);+ });+it('进度更新时同一张卡的 systemCardData 必须跟着变(1/5 → 2/5)', () => {inputProjectionCb!(projection({ autoResumePending: { ...PENDING_INFO, attempt: 1 } }));const first = makerChatStore@@ -349,6 +395,7 @@ describe('applyInputProjection 自愈进行中提示', () => {.getSnapshot(SID).messages.some((m) => m.clientId === '__codex_reconnect_pending__'),).toBe(true);+ expect(makerChatStore.hasSessionRecoveryPending(SID)).toBe(true);});it('无关 projection 不误删原生重连行,接管 projection 到达时才交棒', () => {diff --git a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.tsindex a658e36aa9..8860a548a4 100644--- a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts+++ b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts@@ -26,6 +26,7 @@ const storeMock = vi.hoisted(() => ({terminalErrorSessions: new Set<string>(),sideTaskStopSessions: new Set<string>(),privateReplySessions: new Set<string>(),+ recoverySessions: new Set<string>(),}));vi.mock('@/lib/makerChatStore', () => ({@@ -38,6 +39,7 @@ vi.mock('@/lib/makerChatStore', () => ({},getRunningSnapshot: () => storeMock.snapshot,hasSessionTerminalError: (sessionId: string) => storeMock.terminalErrorSessions.has(sessionId),+ hasSessionRecoveryPending: (sessionId: string) => storeMock.recoverySessions.has(sessionId),wasLastStopPrivateReply: (sessionId: string) => storeMock.privateReplySessions.has(sessionId),wasLastStopSideTask: (sessionId: string) => storeMock.sideTaskStopSessions.has(sessionId),},@@ -81,6 +83,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {storeMock.terminalErrorSessions.clear();storeMock.sideTaskStopSessions.clear();storeMock.privateReplySessions.clear();+ storeMock.recoverySessions.clear();resetSilencedSessionDoneStoreForTests();resetSessionStartingStoreForTests();vi.clearAllMocks();@@ -88,6 +91,62 @@ describe('useSessionRunningStatus silenced completion handling', () => {vi.useRealTimers();});+ it.each([false, true])('keeps recovery quiet until final success (missing stop snapshot: %s)', async (missing) => {+ vi.useFakeTimers();+ const onSessionDone = vi.fn();+ const onSessionError = vi.fn();+ renderHook(() => useSessionRunningStatus(undefined, { onSessionDone, onSessionError }));+ for (let attempt = 0; attempt < 3; attempt++) {+ storeMock.recoverySessions.delete('retry');+ await emitSnapshot(new Map([['retry', status(true)]]));+ storeMock.recoverySessions.add('retry');+ await emitSnapshot(missing ? new Map() : new Map([['retry', status(false)]]));+ await act(async () => { await vi.advanceTimersByTimeAsync(20_000); });+ expect(onSessionDone).not.toHaveBeenCalled();+ expect(onSessionError).not.toHaveBeenCalled();+ expect(addSessionAttention).not.toHaveBeenCalled();+ }+ storeMock.recoverySessions.delete('retry');+ await emitSnapshot(new Map([['retry', status(true)]]));+ await emitSnapshot(new Map([['retry', status(false)]]));+ await act(async () => { await vi.advanceTimersByTimeAsync(500); });+ expect(onSessionDone).toHaveBeenCalledExactlyOnceWith('retry');+ expect(addSessionAttention).toHaveBeenCalledWith('retry', 'done');+ });++ it('drops a scheduled completion when recovery arrives during debounce', async () => {+ vi.useFakeTimers();+ const onSessionDone = vi.fn();+ renderHook(() => useSessionRunningStatus(undefined, { onSessionDone }));+ await emitSnapshot(new Map([['retry', status(true)]]));+ await emitSnapshot(new Map([['retry', status(false)]]));+ storeMock.recoverySessions.add('retry');+ await act(async () => { await vi.advanceTimersByTimeAsync(500); });+ storeMock.recoverySessions.clear();+ await emitSnapshot(new Map());+ await act(async () => { await vi.advanceTimersByTimeAsync(20_000); });+ expect(onSessionDone).not.toHaveBeenCalled();+ expect(addSessionAttention).not.toHaveBeenCalled();+ });++ it('reports recovery failure before another vendor turn starts', async () => {+ vi.useFakeTimers();+ const onSessionDone = vi.fn();+ const onSessionError = vi.fn();+ renderHook(() => useSessionRunningStatus(undefined, { onSessionDone, onSessionError }));+ await emitSnapshot(new Map([['retry', status(true)]]));+ storeMock.recoverySessions.add('retry');+ // The store keeps recovery logically running even though the vendor stopped.+ await emitSnapshot(new Map([['retry', status(true)]]));+ await act(async () => { await vi.advanceTimersByTimeAsync(20_000); });+ storeMock.recoverySessions.clear();+ storeMock.terminalErrorSessions.add('retry');+ await emitSnapshot(new Map([['retry', status(false, true)]]));+ await act(async () => { await vi.advanceTimersByTimeAsync(500); });+ expect(onSessionDone).not.toHaveBeenCalled();+ expect(onSessionError).toHaveBeenCalledExactlyOnceWith('retry');+ });+it('keeps private replies quiet even when the final attribution arrives during debounce', async () => {vi.useFakeTimers();const onSessionDone = vi.fn();@@ -396,7 +455,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {expect(onSessionDone).toHaveBeenCalledWith('session-active-at-completion');});- it('does not restore done attention if a new run is visible when debounce expires', async () => {+ it('suppresses done attention and notification if a new run is visible when debounce expires', async () => {vi.useFakeTimers();const onSessionDone = vi.fn();renderHook(() => useSessionRunningStatus(undefined, { onSessionDone }));@@ -410,7 +469,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {});expect(vi.mocked(addSessionAttention)).not.toHaveBeenCalledWith('session-running', 'done');- expect(onSessionDone).toHaveBeenCalledWith('session-running');+ expect(onSessionDone).not.toHaveBeenCalled();});it('does not overwrite a terminal error that appears during the done debounce', async () => {diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.tsindex b50a7f9caf..24d9c69644 100644--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts@@ -225,6 +225,10 @@ export function useSessionRunningStatus(// 不进 debounce 调度。中间 done 与最终 done 都会走到这里。if (isSilencedDone) continue;+ // A recoverable interruption clears the terminal error while waiting to+ // retry. That idle gap is not completion, even if it lasts beyond debounce.+ if (makerChatStore.hasSessionRecoveryPending(sessionId)) continue;+// 正常 done:走 debounce。QUEUE_DEBOUNCE_MS 内若同 session 又变 running// (main 自动衔接下一条队列),上面的 "--- 1. Detect new turn starts ---"// 分支会 clearTimeout 取消这次。窗口过完仍是 not-running,才认为队列真的@@ -236,6 +240,8 @@ export function useSessionRunningStatus(const wasActiveAtCompletion = sessionId === activeSessionId;const timer = setTimeout(() => {pendingDoneTimersRef.current.delete(sessionId);+ // Recovery may have been projected after this timer was scheduled.+ if (makerChatStore.hasSessionRecoveryPending(sessionId)) return;// 落地前重查一次当前状态:若此刻会话正等待用户输入(ask-user / permission /// plan-review),不要用 done 橙角标覆盖 section 3 已亮的 awaiting 黄角标 ——// 否则「需要处理的交互」被降级成「已完成」,用户看不到。非 debounce 版本里@@ -269,7 +275,7 @@ export function useSessionRunningStatus() {addSessionAttention(sessionId, 'done');}- if (!ownedNow && !hasTerminalError) {+ if (!ownedNow && !hasTerminalError && !isRunning) {onSessionDoneRef.current?.(sessionId);}}, QUEUE_DEBOUNCE_MS);diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 426f85831d..42314cd670 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -9502,7 +9502,10 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {// (远程会话豁免,见 hasBackgroundAgentWork 注释。)const bgTaskRunning = hasBackgroundAgentWork(id, state);- if (state.agentStatus.isRunning || bgTaskRunning) {+ // Recovery is still unfinished work. Keep the existing running edge alive+ // so a dispatch failure can settle as error without another vendor turn.+ const recoveryPending = !state.error && hasSessionRecoveryPending(id);+ if (state.agentStatus.isRunning || bgTaskRunning || recoveryPending) {// Currently running — always include.next.set(id, {isRunning: true,@@ -9622,6 +9625,18 @@ function hasSessionTerminalError(sessionId: string): boolean {return !!s?.error && !s.lastStopWasSideTask;}+/** Non-creating read: recovery can outlive the one-generation stop snapshot. */+function hasSessionRecoveryPending(sessionId: string): boolean {+ const state = sessions.get(sessionId);+ return !!state && (+ state.messages.some((message) =>+ message.clientId === AUTO_RESUME_PENDING_CLIENT_ID ||+ message.clientId === CODEX_RECONNECT_PENDING_CLIENT_ID,+ ) ||+ (!state.queuePaused && state.pendingQueue.some((item) => item.autoResume === true))+ );+}+// 远程回执 error 免疫的兜底探针:活动镜像缺条目(推送丢失 / 未达)时,// sessionAttentionStore 回落到消息层的终止错误判定(注入避免循环依赖)。setRemoteTerminalErrorProbe(hasSessionTerminalError);@@ -16308,6 +16323,7 @@ export const makerChatStore = {getRunningSnapshot,/** F-SB-7: Authoritative terminal-error read, immune to snapshot-generation races. */hasSessionTerminalError,+ hasSessionRecoveryPending,wasLastStopSideTask,wasLastStopPrivateReply: (sessionId: string): boolean =>sessions.get(sessionId)?.lastStopWasPrivateReply === true,diff --git a/apps/desktop/src/shared/agentInputQueue.ts b/apps/desktop/src/shared/agentInputQueue.tsindex dd1108baf5..f0e0de27fc 100644--- a/apps/desktop/src/shared/agentInputQueue.ts+++ b/apps/desktop/src/shared/agentInputQueue.ts@@ -407,7 +407,7 @@ export interface AgentInputProjection {credentialSwitchWait: { clientId?: string; blockedBySessionIds: string[] } | null;/*** 中断自动续跑接管中:上游把「已经干到一半」的 turn 打断了,main 守卫已决定自动- * 续跑,正在退避窗口里(见 main/maker-ipc/interruptedTurnAutoResume.ts)。+ * 续跑,正在退避或出队后的派发准备阶段(见 main/maker-ipc/interruptedTurnAutoResume.ts)。** 此时 `error` 刻意保持 null —— 自愈过程不该弹红色横幅,只在聊天流里显示一条低调* 的「正在自动继续」分隔条(renderer 据本字段插 ephemeral system card)。真正救不