Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 自动续跑后收掉过期的侧边栏错误红点 (#3579)
Dasha43b75abe9b3
diff --git a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.tsindex dfe105dfbb..640c56bb5a 100644--- a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts+++ b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts@@ -13,6 +13,7 @@ import {} from '@/lib/silencedSessionDoneStore';import { markSessionStarting, resetSessionStartingStoreForTests } from '@/lib/sessionStartingStore';import { useSessionRunningStatus } from '@/hooks/useSessionRunningStatus';+import { noteSessionTurnStartedForAlerts } from '@/hooks/usePendingAlertAttention';import {addSessionAttention,clearSessionAttention,@@ -48,6 +49,10 @@ vi.mock('@/lib/sessionAttentionStore', () => ({useSessionAttentionSnapshot: () => new Set<string>(),}));+vi.mock('@/hooks/usePendingAlertAttention', () => ({+ noteSessionTurnStartedForAlerts: vi.fn(),+}));+function status(isRunning: boolean, hasError = false, sideTask?: boolean): SessionStatusInfo {return {isRunning,@@ -483,6 +488,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {expect(vi.mocked(clearSessionAttention)).toHaveBeenCalledWith('s-orphan', {intent: 'explicit',});+ expect(vi.mocked(noteSessionTurnStartedForAlerts)).toHaveBeenCalledWith('s-orphan');vi.mocked(getSessionAttentionKind).mockReturnValue(undefined);});@@ -496,6 +502,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {expect(vi.mocked(clearSessionAttention)).not.toHaveBeenCalledWith('s-real', {intent: 'explicit',});+ expect(vi.mocked(noteSessionTurnStartedForAlerts)).toHaveBeenCalledWith('s-real');vi.mocked(getSessionAttentionKind).mockReturnValue(undefined);storeMock.terminalErrorSessions.delete('s-real');});diff --git a/apps/desktop/src/renderer/hooks/__tests__/usePendingAlertAttention.test.ts b/apps/desktop/src/renderer/hooks/__tests__/usePendingAlertAttention.test.tsindex c13a1fe8e3..55e979bef3 100644--- a/apps/desktop/src/renderer/hooks/__tests__/usePendingAlertAttention.test.ts+++ b/apps/desktop/src/renderer/hooks/__tests__/usePendingAlertAttention.test.ts@@ -8,6 +8,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import {_resetPendingAlertAttentionForTests,+ noteSessionTurnStartedForAlerts,refreshPendingAlerts,usePendingAlertAttention,} from '@/hooks/usePendingAlertAttention';@@ -28,6 +29,9 @@ const clearMock = vi.mocked(clearSessionAttention);const kindMock = vi.mocked(getSessionAttentionKind);const errorTailPendingMock = vi.fn<() => Promise<string[]>>();const interruptedPendingMock = vi.fn<() => Promise<string[]>>();+const createdListeners: Array<+ (payload: { sessionId: string; message: { role?: string } }, ownerStamp?: unknown) => void+> = [];/** 驱动一次错误尾行重算并等它收敛完成。 */async function reconcile(ids: string[]): Promise<void> {@@ -38,12 +42,25 @@ async function reconcile(ids: string[]): Promise<void> {describe('usePendingAlertAttention (派生收敛)', () => {beforeEach(() => {_resetPendingAlertAttentionForTests();+ createdListeners.length = 0;(window as unknown as { electronAPI: unknown }).electronAPI = {localDb: {sessions: {errorTailPending: errorTailPendingMock,interruptedPending: interruptedPendingMock,},+ sessionsPush: {+ onPatched: () => () => {},+ },+ messages: {+ onErrorPersisted: () => () => {},+ onCreated: (+ cb: (payload: { sessionId: string; message: { role?: string } }, ownerStamp?: unknown) => void,+ ) => {+ createdListeners.push(cb);+ return () => {};+ },+ },},};kindMock.mockReturnValue('error');@@ -201,4 +218,65 @@ describe('usePendingAlertAttention (派生收敛)', () => {expect(addMock).toHaveBeenCalledWith('s-boot-tail', 'error');});++ it('认领了错误尾行时,该会话的 user 行触发重算;告警已消失则 explicit 清点', async () => {+ await reconcile(['s1']);+ interruptedPendingMock.mockResolvedValue([]);+ renderHook(() => usePendingAlertAttention());+ expect(createdListeners.length).toBeGreaterThan(0);++ addMock.mockClear();+ clearMock.mockClear();+ errorTailPendingMock.mockClear();+ errorTailPendingMock.mockResolvedValue([]);++ createdListeners[0]!({ sessionId: 's1', message: { role: 'user' } });+ await refreshPendingAlerts();+ expect(clearMock).toHaveBeenCalledWith('s1', { intent: 'explicit' });+ });++ it('未认领错误尾行时,user 行不打 IPC', async () => {+ interruptedPendingMock.mockResolvedValue([]);+ errorTailPendingMock.mockResolvedValue([]);+ renderHook(() => usePendingAlertAttention());+ expect(createdListeners.length).toBeGreaterThan(0);++ await refreshPendingAlerts();+ errorTailPendingMock.mockClear();+ createdListeners[0]!({ sessionId: 's1', message: { role: 'user' } });+ await Promise.resolve();+ await Promise.resolve();+ expect(errorTailPendingMock).not.toHaveBeenCalled();+ });++ it('assistant 行不触发错误尾行重算', async () => {+ await reconcile(['s1']);+ interruptedPendingMock.mockResolvedValue([]);+ renderHook(() => usePendingAlertAttention());+ errorTailPendingMock.mockClear();++ createdListeners[0]!({ sessionId: 's1', message: { role: 'assistant' } });+ await Promise.resolve();+ await Promise.resolve();+ expect(errorTailPendingMock).not.toHaveBeenCalled();+ });++ it('新一轮启动时重算仍认领的错误尾行,告警消失则 explicit 清点', async () => {+ await reconcile(['s1']);+ clearMock.mockClear();+ errorTailPendingMock.mockClear();+ errorTailPendingMock.mockResolvedValue([]);++ noteSessionTurnStartedForAlerts('s1');+ await refreshPendingAlerts();+ expect(clearMock).toHaveBeenCalledWith('s1', { intent: 'explicit' });+ });++ it('新一轮启动时未认领该会话则不打 IPC', async () => {+ await reconcile(['s1']);+ errorTailPendingMock.mockClear();+ noteSessionTurnStartedForAlerts('other');+ await Promise.resolve();+ expect(errorTailPendingMock).not.toHaveBeenCalled();+ });});diff --git a/apps/desktop/src/renderer/hooks/usePendingAlertAttention.ts b/apps/desktop/src/renderer/hooks/usePendingAlertAttention.tsindex 995bb94b11..a547b52714 100644--- a/apps/desktop/src/renderer/hooks/usePendingAlertAttention.ts+++ b/apps/desktop/src/renderer/hooks/usePendingAlertAttention.ts@@ -27,7 +27,12 @@* 重算触发点(全量重查 + 差分,不做增量推断):* - 错误行落库脏信号(local-db:session:error-persisted)—— 正是 makerChatStore 清掉* live error 的同一个信号,交接窗口红点不掉;- * - refreshPendingAlerts() 显式调用 —— 横幅处置(dismiss / 继续 / 批量已读)后触发。+ * - 已认领错误尾行的会话插入新 user 行(messages:created)—— 文件头不变量:+ * turn 一起就插 user 行,error 不再是尾行。自动续跑的 UI_ACTION_TRIGGER 也是+ * user 行;此前只订 error 行,续跑成功、横幅已灭时红点不掉。+ * - refreshPendingAlerts() 显式调用 —— 横幅处置(dismiss / 继续 / 批量已读)后触发;+ * - noteSessionTurnStartedForAlerts() —— 新一轮启动时补一次,覆盖 running 投影+ * 早于 user 行落库的窗口。** 打点范围限定:只清**本 hook 自己打过**且当前仍是 'error' 的点,不误伤 live error、* done、awaiting 等其它来源。@@ -172,6 +177,18 @@ function noteInterruptedAck(sessionId: string): void {clearAlertIfStillError(sessionId);}+/**+ * 新一轮启动时收敛错误尾行红点。中断腿仍只认 lastTurnEndedAt(side-task 上升沿+ * 也会把 isRunning 翻成 true,不能当成「继续 / 忽略」)。+ *+ * 只在本 hook 仍认领该会话的错误尾行时才打 IPC;查询结果若已不是尾行,差分会+ * explicit 清点。生产调用点 fire-and-forget。+ */+export function noteSessionTurnStartedForAlerts(sessionId: string): void {+ if (!_errorTailOwned.has(sessionId)) return;+ void refreshPendingAlerts();+}+/** 启动首拉:中断腿 + 错误尾行腿各拉一次,分别记账。 */async function initialFetch(): Promise<void> {const gen = ++_queryGen;@@ -246,14 +263,23 @@ export function usePendingAlertAttention(): void {// error 行的**更新**广播(peer 收敛):另一个窗口 / device-link 端点点「忽略」时,// dismissErrorMessage 会把 merge 后的行经 messages:created 广播出去,peer 的横幅// 据此即时熄灭 —— 但 error-persisted 只在错误**首次落库**时发,peer 的红点因此会- // 一直残留到某个无关的重算(PR #879 review P1)。这里按 role 过滤后重算,把- // dismiss / 新错误行两种情况都收敛掉;非 error 行不触发,避免每条消息都查一次库。+ // 一直残留到某个无关的重算(PR #879 review P1)。+ //+ // user 行:只在本 hook 仍认领该会话的错误尾行时重算。文件头不变量是「新 turn+ // 的 user 行会让 error 不再是尾行」;自动续跑的 UI_ACTION_TRIGGER 也是 user 行,+ // 若不订这条,横幅已灭、任务已在跑,红点却一直亮。其它会话 / 非 user 行不打 IPC。useEffect(() => {const onCreated = window.electronAPI?.localDb?.messages?.onCreated;if (!onCreated) return;- return onCreated(({ message }, ownerStamp) => {+ return onCreated(({ sessionId, message }, ownerStamp) => {if (!isDataOwnerPushCurrent(ownerStamp)) return;- if (message?.role === 'error') void refreshPendingAlerts();+ if (message?.role === 'error') {+ void refreshPendingAlerts();+ return;+ }+ if (message?.role === 'user' && _errorTailOwned.has(sessionId)) {+ void refreshPendingAlerts();+ }});}, []);}diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.tsindex d8ad5a5e27..0a92eb91a6 100644--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts@@ -53,6 +53,7 @@ import {isSessionTerminalNotificationOwnedByScheduler,isSessionDoneSilenced,} from '@/lib/silencedSessionDoneStore';+import { noteSessionTurnStartedForAlerts } from '@/hooks/usePendingAlertAttention';// Codex maker 化后, codex session 也走 makerChatStore;// 不再需要双 store 合并 —— 直接订阅 makerChatStore 即可。@@ -157,12 +158,16 @@ export function useSessionRunningStatus(// 重新挂角标,提醒不丢失。// 与派生红点(usePendingAlertAttention)一致:turn 启动会插入新的 user 行,// 原 error 行不再是尾行,pending-alerts 也不再命中 —— 两条路径同向收敛。+ // hasSessionTerminalError 仍为 true 时不清(mivo 等 skipTurnReset 上升沿+ // 不拆横幅);派生账本另走 noteSessionTurnStartedForAlerts,只在仍认领+ // 错误尾行时重算,横幅已灭则差分熄灭红点。if (getSessionAttentionKind(sessionId) === 'error' &&!makerChatStore.hasSessionTerminalError(sessionId)) {clearSessionAttention(sessionId, { intent: 'explicit' });}+ noteSessionTurnStartedForAlerts(sessionId);// Queue auto-drain cancellation:如果此 session 有 pending done 定时器// (刚 turn done 还在 debounce 窗口内),说明 main 正在自动衔接下一条队列// 消息 —— 取消这次通知/角标 fire。用户视角这是一条完整任务的中间态。