Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 完成通知改读 Main 的团队收口判定
Dash194e70af3aaf
diff --git a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.tsindex 4d34d9ae16..255400a82c 100644--- a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts+++ b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts@@ -28,13 +28,14 @@ const storeMock = vi.hoisted(() => ({privateReplySessions: new Set<string>(),groupLaneSessions: new Set<string>(),recoverySessions: new Set<string>(),- orcaWorkers: new Map<string, Array<{ sessionId: string; status: string }>>(),+ heldByAgentIsland: new Set<string>(),+ pausedQueueSessions: new Set<string>(),}));-vi.mock('@/features/cc-agent/hooks/workerProjectionStore', () => ({- getWorkerProjectionSnapshot: (leadSessionId: string) => ({- workers: storeMock.orcaWorkers.get(leadSessionId) ?? [],- }),+vi.mock('@/state/agentIslandActivity', () => ({+ ensureAgentIslandActivitySubscribed: vi.fn(),+ isSessionCompletionHeldByAgentIsland: (sessionId: string, hasPausedQueue: boolean) =>+ !hasPausedQueue && storeMock.heldByAgentIsland.has(sessionId),}));vi.mock('@/lib/makerChatStore', () => ({@@ -51,6 +52,7 @@ vi.mock('@/lib/makerChatStore', () => ({wasLastStopPrivateReply: (sessionId: string) => storeMock.privateReplySessions.has(sessionId),wasLastStopGroupLane: (sessionId: string) => storeMock.groupLaneSessions.has(sessionId),wasLastStopSideTask: (sessionId: string) => storeMock.sideTaskStopSessions.has(sessionId),+ hasPausedQueue: (sessionId: string) => storeMock.pausedQueueSessions.has(sessionId),},}));@@ -93,7 +95,8 @@ describe('useSessionRunningStatus silenced completion handling', () => {storeMock.sideTaskStopSessions.clear();storeMock.privateReplySessions.clear();storeMock.recoverySessions.clear();- storeMock.orcaWorkers.clear();+ storeMock.heldByAgentIsland.clear();+ storeMock.pausedQueueSessions.clear();resetSilencedSessionDoneStoreForTests();resetSessionStartingStoreForTests();vi.clearAllMocks();@@ -727,13 +730,13 @@ describe('useSessionRunningStatus silenced completion handling', () => {vi.useRealTimers();});- it('holds an Orca Lead completion while its Workers are still running', async () => {+ it('holds an Orca Lead completion while Main keeps its team running', async () => {vi.useFakeTimers();const onSessionDone = vi.fn();renderHook(() => useSessionRunningStatus(undefined, { onSessionDone }));- storeMock.orcaWorkers.set('lead', [{ sessionId: 'worker', status: 'running' }]);- // The Lead only dispatched work; its turn ends while the Worker runs.+ // The Lead only dispatched work; Agent Island defers its completion.+ storeMock.heldByAgentIsland.add('lead');await emitSnapshot(new Map([['lead', status(true)]]));await emitSnapshot(new Map([['lead', status(false)]]));await act(async () => { await vi.advanceTimersByTimeAsync(600); });@@ -741,11 +744,25 @@ describe('useSessionRunningStatus silenced completion handling', () => {expect(addSessionAttention).not.toHaveBeenCalledWith('lead', 'done');// The Worker report wakes the Lead; that turn's done is the team's completion.- storeMock.orcaWorkers.set('lead', [{ sessionId: 'worker', status: 'done' }]);+ storeMock.heldByAgentIsland.delete('lead');await emitSnapshot(new Map([['lead', status(true)]]));await emitSnapshot(new Map([['lead', status(false)]]));await act(async () => { await vi.advanceTimersByTimeAsync(600); });expect(onSessionDone).toHaveBeenCalledExactlyOnceWith('lead');expect(addSessionAttention).toHaveBeenCalledWith('lead', 'done');});++ it('keeps the completion of a session whose paused queue holds Agent Island', async () => {+ vi.useFakeTimers();+ const onSessionDone = vi.fn();+ renderHook(() => useSessionRunningStatus(undefined, { onSessionDone }));+ storeMock.heldByAgentIsland.add('paused');+ storeMock.pausedQueueSessions.add('paused');++ await emitSnapshot(new Map([['paused', status(true)]]));+ await emitSnapshot(new Map([['paused', status(false)]]));+ await act(async () => { await vi.advanceTimersByTimeAsync(600); });++ expect(onSessionDone).toHaveBeenCalledExactlyOnceWith('paused');+ });});diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/orcaTeamActivity.ts b/apps/desktop/src/renderer/features/cc-agent/lib/orcaTeamActivity.tsdeleted file mode 100644index a1a73ab89c..0000000000--- a/apps/desktop/src/renderer/features/cc-agent/lib/orcaTeamActivity.ts+++ /dev/null@@ -1,18 +0,0 @@-import type { SessionStatusInfo } from '@/lib/makerChatStore';-import { getWorkerProjectionSnapshot } from '../hooks/workerProjectionStore';--/**- * Whether an Orca Lead still has Workers on its task.- *- * A Lead turn that only dispatched work is not the team's completion: the Lead- * runs again when the Worker reports arrive, and that turn's done is the one to- * announce. Mirrors Main's Agent Island deferral and the sidebar's running roll-up.- */-export function hasActiveOrcaWorker(- leadSessionId: string,- statusMap: ReadonlyMap<string, SessionStatusInfo>,-): boolean {- return getWorkerProjectionSnapshot(leadSessionId).workers.some(- (worker) => worker.status === 'running' || statusMap.get(worker.sessionId)?.isRunning === true,- );-}diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.tsindex e79448a736..7c0450b6c4 100644--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts@@ -54,7 +54,10 @@ import {isSessionDoneSilenced,} from '@/lib/silencedSessionDoneStore';import { noteSessionTurnStartedForAlerts } from '@/hooks/usePendingAlertAttention';-import { hasActiveOrcaWorker } from '@/features/cc-agent/lib/orcaTeamActivity';+import {+ ensureAgentIslandActivitySubscribed,+ isSessionCompletionHeldByAgentIsland,+} from '@/state/agentIslandActivity';// Codex maker 化后, codex session 也走 makerChatStore;// 不再需要双 store 合并 —— 直接订阅 makerChatStore 即可。@@ -119,6 +122,10 @@ export function useSessionRunningStatus(onSessionErrorRef.current = options?.onSessionError;onSessionNeedsReplyRef.current = options?.onSessionNeedsReply;}, [options?.onSessionDone, options?.onSessionError, options?.onSessionNeedsReply]);+ // The done debounce reads Main's completion hold; mirror it from mount.+ useEffect(() => {+ ensureAgentIslandActivitySubscribed();+ }, []);// Track previous running set to detect running -> done transitionsconst prevRunningRef = useRef(new Set<string>());@@ -246,10 +253,18 @@ export function useSessionRunningStatus(pendingDoneTimersRef.current.delete(sessionId);// Recovery may have been projected after this timer was scheduled.if (makerChatStore.hasSessionRecoveryPending(sessionId)) return;+ // Orca Lead 只是派完活结束本轮:Worker 还欠回报,Main 让灵动岛保持运行中,+ // 这一轮不算完成。判据只认 Main 的同一份结论;Worker 回报唤起的那一轮+ // done 才发完成通知、亮完成角标。+ if (+ isSessionCompletionHeldByAgentIsland(+ sessionId,+ makerChatStore.hasPausedQueue(sessionId),+ )+ ) {+ return;+ }const runningSnapshot = makerChatStore.getRunningSnapshot();- // Orca Lead 只是派完活结束本轮:团队仍在干活,不算完成。Worker 回报会- // 再唤起 Lead,那一轮的 done 才发完成通知、亮完成角标。- if (hasActiveOrcaWorker(sessionId, runningSnapshot)) return;// 落地前重查一次当前状态:若此刻会话正等待用户输入(ask-user / permission /// plan-review),不要用 done 橙角标覆盖 section 3 已亮的 awaiting 黄角标 ——// 否则「需要处理的交互」被降级成「已完成」,用户看不到。非 debounce 版本里diff --git a/apps/desktop/src/renderer/state/__tests__/agentIslandActivity.test.ts b/apps/desktop/src/renderer/state/__tests__/agentIslandActivity.test.tsnew file mode 100644index 0000000000..57a49dc6fd--- /dev/null+++ b/apps/desktop/src/renderer/state/__tests__/agentIslandActivity.test.ts@@ -0,0 +1,56 @@+// @vitest-environment jsdom+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import type { AgentIslandSessionActivity } from '../../../shared/agentIsland';++type ActivityListener = (list: AgentIslandSessionActivity[]) => void;++let pushActivity: ActivityListener | null = null;++function activity(+ sessionId: string,+ phase: AgentIslandSessionActivity['phase'],+): AgentIslandSessionActivity {+ return { sessionId, phase, attention: false } as AgentIslandSessionActivity;+}++describe('isSessionCompletionHeldByAgentIsland', () => {+ beforeEach(() => {+ vi.resetModules();+ pushActivity = null;+ Object.assign(window, {+ electronAPI: {+ agentIsland: {+ onSessionActivity: (cb: ActivityListener) => {+ pushActivity = cb;+ return () => undefined;+ },+ },+ },+ });+ });++ afterEach(() => {+ Reflect.deleteProperty(window, 'electronAPI');+ });++ it('follows the phase Main keeps for a session after its turn ended', async () => {+ const store = await import('../agentIslandActivity');+ store.ensureAgentIslandActivitySubscribed();++ pushActivity?.([activity('lead', 'running'), activity('done', 'completed')]);++ expect(store.isSessionCompletionHeldByAgentIsland('lead', false)).toBe(true);+ expect(store.isSessionCompletionHeldByAgentIsland('done', false)).toBe(false);+ expect(store.isSessionCompletionHeldByAgentIsland('unknown', false)).toBe(false);+ });++ it('does not hold a session whose own paused queue keeps the island running', async () => {+ const store = await import('../agentIslandActivity');+ store.ensureAgentIslandActivitySubscribed();++ pushActivity?.([activity('paused', 'running')]);++ expect(store.isSessionCompletionHeldByAgentIsland('paused', true)).toBe(false);+ });+});diff --git a/apps/desktop/src/renderer/state/agentIslandActivity.ts b/apps/desktop/src/renderer/state/agentIslandActivity.tsindex f85700f2f3..bb7c20eda4 100644--- a/apps/desktop/src/renderer/state/agentIslandActivity.ts+++ b/apps/desktop/src/renderer/state/agentIslandActivity.ts@@ -79,6 +79,26 @@ function ensureSubscribed(): void {}}+/** Start mirroring before a non-React reader needs the latest snapshot. */+export function ensureAgentIslandActivitySubscribed(): void {+ ensureSubscribed();+}++/**+ * Whether Main still keeps this session running after its turn ended.+ *+ * Agent Island defers an Orca Lead's completion while Workers still owe it+ * reports, so the Lead stays `running` here. A paused input queue also holds the+ * island completion; it keeps its existing renderer completion and is excluded.+ */+export function isSessionCompletionHeldByAgentIsland(+ sessionId: string,+ hasPausedQueue: boolean,+): boolean {+ if (hasPausedQueue) return false;+ return activityMap.get(sessionId)?.phase === 'running';+}+function subscribe(cb: () => void): () => void {ensureSubscribed();listeners.add(cb);diff --git a/docs/dev-rules/orca-team-architecture.md b/docs/dev-rules/orca-team-architecture.mdindex 9b3bece7f2..87edd70346 100644--- a/docs/dev-rules/orca-team-architecture.md+++ b/docs/dev-rules/orca-team-architecture.md@@ -335,7 +335,7 @@ Worker turn 被 vendor 报终止型 error,但 interrupted-turn auto-resume 仍worker 的回报 settle(`send_to_lead` 被接受/入队)会先把持久化状态置 `done`,而 worker 自己的 turn 可能还在收尾;renderer「看到 done 即 ack」此时会被 active-turn / send 锁守卫以 `WORKER_STATE_CHANGED` 拒绝。被这两类守卫拒绝的确认必须登记下来,在该 turn 的 `handleWorkerTerminalTurn` done 分支重试一次(fire-once,重试失败不重登记);新 turn 开始(`handleWorkerTurnStarted`)必须作废登记。没有登记过的 done 不得在 terminal 边界自动收口——`done` 的产品语义是「保持到用户看到为止」。实现指针:`orcaTeamService.ts` 的 `deferredDoneAcknowledgements`、`idleWorker`、`handleWorkerTurnStarted`、`handleWorkerTerminalTurn`。9. **Lead 的完成以团队收口为准(状态:不变量)**- Lead 派完活结束本轮时,团队仍在干活,这一轮不是完成:灵动岛保持 Lead 为运行中(不出完成卡片、不响完成音、不记未读),Work Louder 键盘、侧栏卡片与远程会话列表读同一份活动快照,因此一起保持运行中;renderer 不发完成通知(桌面/手机/飞书)、不亮完成角标。Worker 回报送达后 Lead 被唤起,那一轮的 done 才是团队完成。判据分两处:Main 以「仍有 accepted 派活欠 Lead 回报」(auto-bridge pending)为准,最后一份回报送达或被丢弃(手动停止、归档等)时,若 Lead 空闲则补发被推迟的完成;renderer 以「Lead 名下仍有 Worker 在跑」为准,与侧栏的运行中汇总同一口径。Worker 自身仍不进灵动岛、不单独发通知。实现指针:`orcaTeamService.ts` 的 `hasPendingWorkerReports` / `deletePendingReport` / `onLeadWorkerReportsSettled`,`register.ts` 的 `setCompletionDeferResolver` 与 `onLeadWorkerReportsSettled` wiring,`agent-island/service.ts` 的 `notifyQueueEmptied`,`orcaTeamActivity.ts` 的 `hasActiveOrcaWorker` 与 `useSessionRunningStatus.ts` 的 done debounce。+ Lead 派完活结束本轮时,团队仍在干活,这一轮不是完成:灵动岛保持 Lead 为运行中(不出完成卡片、不响完成音、不记未读),Work Louder 键盘、侧栏卡片与远程会话列表读同一份活动快照,因此一起保持运行中;renderer 不发完成通知(桌面/手机/飞书)、不亮完成角标。Worker 回报送达后 Lead 被唤起,那一轮的 done 才是团队完成。判据只有一份,在 Main:以「仍有 accepted 派活欠 Lead 回报」(auto-bridge pending)为准,最后一份回报送达或被丢弃(手动停止、归档等)时,若 Lead 空闲则补发被推迟的完成;renderer 不自行推算 Worker 状态,完成去抖落地时读灵动岛活动快照,Main 仍把该会话保持为 `running` 就不算完成(暂停的输入队列同样会让灵动岛保持运行中,但保留原有完成提醒,故排除)。Worker 自身仍不进灵动岛、不单独发通知。已知边界(刻意不处理,保持简单):派给正忙 Worker、尚在其队列里未被接收的任务还没有待回报记录(Worker 正忙通常意味着已有同一 Lead 的待回报记录);静默完成(如静默的自动运行)不走推迟,Lead 活动会直接变为完成。实现指针:`orcaTeamService.ts` 的 `hasPendingWorkerReports` / `deletePendingReport` / `onLeadWorkerReportsSettled`,`register.ts` 的 `setCompletionDeferResolver` 与 `onLeadWorkerReportsSettled` wiring,`agent-island/service.ts` 的 `notifyQueueEmptied`,renderer `state/agentIslandActivity.ts` 的 `isSessionCompletionHeldByAgentIsland` 与 `useSessionRunningStatus.ts` 的 done debounce。### 测试与回归清单