Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(review): 静音只退出展示面,并收口校验与回滚竞态
WZBbiao91adaaf3e889
diff --git a/apps/desktop/src/main/agent-island/__tests__/service.test.ts b/apps/desktop/src/main/agent-island/__tests__/service.test.tsindex 0196227e22..a81f0c8194 100644--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts@@ -62,6 +62,8 @@ const mocks = vi.hoisted(() => ({workingDir: string | null;workspaceKind: string | null;} | null>>(() => Promise.resolve(null)),+ /** 「消息免打扰」同步索引:默认不静音,用例按需覆写。 */+ isSessionNotificationsMutedSync: vi.fn((_sessionId: string) => false),primaryDisplay: {id: 1,label: 'Built-in Retina Display',@@ -137,6 +139,10 @@ vi.mock('../../localDb/ipc/sessions.js', () => ({getSessionRowSnapshot: mocks.getSessionRowSnapshot,}));+vi.mock('../../localDb/sessionFlagRegistry', () => ({+ isSessionNotificationsMutedSync: mocks.isSessionNotificationsMutedSync,+}));+vi.mock('../layoutPreferenceStore.js', () => ({readAgentIslandDetachedLayoutPreferences: mocks.readDetachedLayoutPreferences,readAgentIslandLayoutPreferences: mocks.readLayoutPreferences,@@ -638,6 +644,39 @@ describe('AgentIslandService native publishing', () => {// 显式放宽本用例的超时(用例本身是纯同步断言,不是真长跑)。}, 20_000);+ it('「消息免打扰」只把任务从岛面拿掉,侧栏活动快照照旧保留', async () => {+ const { AgentIslandService } = await import('../service.js');+ const published: AgentIslandDisplayState[] = [];+ const service = new AgentIslandService({+ getMainWindow: () => null,+ nativeHost: {+ failed: false,+ headless: false,+ publish: (display) => {+ published.push(display);+ return true;+ },+ suspend: () => undefined,+ },+ });++ service.setEnabled(true);+ mocks.isSessionNotificationsMutedSync.mockImplementation((id: string) => id === 'muted-task');+ service.handleUserPrompt({ sessionId: 'muted-task', agentKind: 'codex' }, 'run tests');++ // 岛面(含菜单栏与提示音)里没有它。+ expect(published.at(-1)?.sessions).toEqual([]);+ // 但侧栏卡片与远端活动镜像仍有实时活动:静音不是把任务藏起来。+ expect(service.getSessionActivitySnapshots()).toEqual([+ expect.objectContaining({ sessionId: 'muted-task', phase: 'running' }),+ ]);++ // 取消静音 → 重发展示面,任务回到岛上,状态一直都在。+ mocks.isSessionNotificationsMutedSync.mockReturnValue(false);+ service.handleNotificationMuteChanged();+ expect(published.at(-1)?.sessions.map((session) => session.sessionId)).toEqual(['muted-task']);+ }, 20_000);+it('exposes the canonical snapshot and emits per-session transition edges', async () => {const { AgentIslandService } = await import('../service.js');const service = new AgentIslandService({diff --git a/apps/desktop/src/main/agent-island/__tests__/state.test.ts b/apps/desktop/src/main/agent-island/__tests__/state.test.tsindex 7855e3fff6..136386cde4 100644--- a/apps/desktop/src/main/agent-island/__tests__/state.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/state.test.ts@@ -32,6 +32,7 @@ import {setAgentIslandHovered,setAgentIslandLayoutDragActive,setAgentIslandPointerZones,+ setAgentIslandSessionDisplaySuppressed,setAgentIslandVisibleSession,} from '../state.js';@@ -116,6 +117,47 @@ function askUserQuestionRequest(requestId: string): InteractionRequest {}describe('Agent Island display state', () => {+ it('「消息免打扰」只把任务从岛面拿掉,侧栏活动快照照旧保留', () => {+ const state = createAgentIslandState();+ const meta = { sessionId: 'muted-task', title: 'Muted', agentKind: 'codex' };+ applyAgentIslandEvent(state, meta, statusEvent(true, 'Working'), 1_000);+ applyAgentIslandEvent(state, meta, toolUseEvent('tool-1'), 1_100);+ expect(buildAgentIslandDisplayState(state, 1_200).sessions.map((s) => s.sessionId)).toEqual([+ 'muted-task',+ ]);++ expect(setAgentIslandSessionDisplaySuppressed(state, 'muted-task', true)).toBe(true);+ // 岛面(含菜单栏/提示音)不再有它。+ expect(buildAgentIslandDisplayState(state, 1_300).sessions).toEqual([]);+ // 但状态机照常记账:侧栏卡片的实时活动与等待交互态从这份快照来。+ expect(state.sessions.has('muted-task')).toBe(true);+ expect(buildAllSessionActivitySnapshots(state)).toEqual([+ expect.objectContaining({ sessionId: 'muted-task', phase: 'running' }),+ ]);++ // 取消静音后回到岛面,状态没有丢。+ expect(setAgentIslandSessionDisplaySuppressed(state, 'muted-task', false)).toBe(true);+ expect(buildAgentIslandDisplayState(state, 1_400).sessions.map((s) => s.sessionId)).toEqual([+ 'muted-task',+ ]);+ });++ it('a muted task stays off the island even after its entry is recreated', () => {+ const state = createAgentIslandState();+ const meta = { sessionId: 'muted-task', title: 'Muted', agentKind: 'codex' };+ applyAgentIslandEvent(state, meta, statusEvent(true, 'Working'), 1_000);+ setAgentIslandSessionDisplaySuppressed(state, 'muted-task', true);+ // 岛面 TTL / 进程收尾把条目删掉后,新事件重建条目也不得把静音任务放回来。+ state.sessions.delete('muted-task');++ applyAgentIslandEvent(state, meta, statusEvent(true, 'Working again'), 2_000);++ expect(buildAgentIslandDisplayState(state, 2_100).sessions).toEqual([]);+ expect(buildAllSessionActivitySnapshots(state)).toEqual([+ expect.objectContaining({ sessionId: 'muted-task', phase: 'running' }),+ ]);+ });+it('does not complete the island on claimed SDK boundary events', () => {const state = createAgentIslandState();const meta = { sessionId: 'continuing', title: 'Continuing', agentKind: 'codex' };diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.tsindex 686f6581e2..f44763abbe 100644--- a/apps/desktop/src/main/agent-island/service.ts+++ b/apps/desktop/src/main/agent-island/service.ts@@ -75,6 +75,7 @@ import {type AgentIslandScreenLayoutMetrics,} from '../../shared/agentIsland.js';import { getSessionRowSnapshot } from '../localDb/ipc/sessions.js';+import { isSessionNotificationsMutedSync } from '../localDb/sessionFlagRegistry';import { createLogger } from '../logger.js';import { t } from '../i18n.js';import { isAppContentWindow, isFocusedAppContentWindow } from '../windowFocusClassifier.js';@@ -109,6 +110,7 @@ import {setAgentIslandLayoutDragActive,setAgentIslandMeasuredContentHeight,setAgentIslandPointerZones,+ setAgentIslandSessionDisplaySuppressed,setAgentIslandStrings,setAgentIslandToolWording,setAgentIslandVisibleSession,@@ -1196,6 +1198,15 @@ export class AgentIslandService {}}+ /**+ * 「消息免打扰」发生变化:只影响展示面(岛面 / 菜单栏 / 提示音)。重发一次即可 ——+ * 抑制集合在 publish() 里从同步索引重新对齐。静音任务的 Agent 事件仍照常进状态机,+ * 侧栏卡片的实时活动、等待交互态与远端活动镜像不受影响。+ */+ handleNotificationMuteChanged(): void {+ this.publish();+ }+/*** @param options.reason* `'discarded'`(默认)= 这条记录不该再存在(会话归档 / 删除、Orca worker 被策略@@ -1697,7 +1708,22 @@ export class AgentIslandService {}}+ /**+ * 把「消息免打扰」从同步索引对齐到展示面抑制集合。放在每次 publish 的开头:账号+ * 切换、索引重载、直接改库都能自愈,不靠某一条写库路径记得来登记。+ */+ private syncDisplaySuppression(): void {+ for (const sessionId of this.state.sessions.keys()) {+ setAgentIslandSessionDisplaySuppressed(+ this.state,+ sessionId,+ isSessionNotificationsMutedSync(sessionId),+ );+ }+ }+private publish(): void {+ this.syncDisplaySuppression();const now = Date.now();if (!this.enabledSynced) {this.mutedCompletionSoundSessionIds.clear();diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.tsindex 4dff349b1e..df3f166632 100644--- a/apps/desktop/src/main/agent-island/state.ts+++ b/apps/desktop/src/main/agent-island/state.ts@@ -233,6 +233,13 @@ export interface AgentIslandState {* (进程重启后靠 localDb 兜底补发收尾包)。*/remoteUnreadTerminals: Map<string, AgentIslandRemoteUnreadTerminal>;+ /**+ * 「消息免打扰」任务:只从**展示面**(岛面 / 菜单栏 / 提示音)排除,不删+ * `state.sessions`、也不影响事件摄取 —— 侧栏卡片的逐步活动、等待交互态与远端+ * 活动镜像都长在这份状态上,静音不该把任务藏起来。按 sessionId 保存而不是塞进+ * session 条目:条目会随岛面 TTL 被裁剪后重建,塞进去会丢。+ */+ displaySuppressedSessionIds: Set<string>;}export interface AgentIslandRemoteUnreadTerminal {@@ -293,6 +300,7 @@ export function createAgentIslandState(): AgentIslandState {strings: { ...DEFAULT_AGENT_ISLAND_STRINGS },toolWording: DEFAULT_TOOL_ROW_WORDING,remoteUnreadTerminals: new Map(),+ displaySuppressedSessionIds: new Set(),};}@@ -327,6 +335,8 @@ export function resetAgentIslandState(state: AgentIslandState): void {state.compactCurrentUntil = fresh.compactCurrentUntil;state.strings = fresh.strings;state.remoteUnreadTerminals = fresh.remoteUnreadTerminals;+ // 展示面抑制(静音)跟着账号/数据源一起重置:publish() 会从同步索引重新对齐。+ state.displaySuppressedSessionIds = fresh.displaySuppressedSessionIds;// toolWording 是注入的配置(非会话状态),reset 时保留,避免退回默认中文表。}@@ -2685,10 +2695,29 @@ function shouldDisplaySession(now: number,preserveExpiredTransient = false,): boolean {+ // 「消息免打扰」只从展示面排除:任务仍在岛面以外的所有面(侧栏实时活动、等待+ // 交互态、远端活动镜像)照常可见,所以这里是过滤而不是把条目从 state 里删掉。+ if (state.displaySuppressedSessionIds.has(session.sessionId)) return false;return isSessionVisible(session, now, preserveExpiredTransient)&& !isVisibleInteractionSuppressed(state, session, now);}+/**+ * 标记某个任务的岛面展示是否被抑制(当前只用于「消息免打扰」)。返回是否有变化。+ * 抑制只影响 displayState 与提示音,不动 state.sessions。+ */+export function setAgentIslandSessionDisplaySuppressed(+ state: AgentIslandState,+ sessionId: string,+ suppressed: boolean,+): boolean {+ const had = state.displaySuppressedSessionIds.has(sessionId);+ if (had === suppressed) return false;+ if (suppressed) state.displaySuppressedSessionIds.add(sessionId);+ else state.displaySuppressedSessionIds.delete(sessionId);+ return true;+}+function isUnreadTerminalLedger(session: AgentIslandSessionState,): session is AgentIslandSessionState & { phase: 'completed' | 'error' } {diff --git a/apps/desktop/src/main/im/__tests__/desktopConfirmNotice.test.ts b/apps/desktop/src/main/im/__tests__/desktopConfirmNotice.test.tsindex b771992e74..b0c66c0b91 100644--- a/apps/desktop/src/main/im/__tests__/desktopConfirmNotice.test.ts+++ b/apps/desktop/src/main/im/__tests__/desktopConfirmNotice.test.ts@@ -64,6 +64,23 @@ describe('createDesktopConfirmNotifier', () => {expect(send).toHaveBeenCalledOnce();});+ it('解析 openId 期间开启免打扰 → 真正发送前重新判定并放弃', async () => {+ const send = vi.fn(async () => ({}));+ let muted = false;+ const notify = createDesktopConfirmNotifier({+ getFeishuOpenId: async () => {+ // 查库期间用户点了「消息免打扰」。+ muted = true;+ return 'ou_123';+ },+ sendFeishuText: send,+ isSuppressed: () => muted,+ });+ notify('s1', '「提交 GitHub issue」的确认卡');+ await flush();+ expect(send).not.toHaveBeenCalled();+ });+it('查询/发送失败 → 只落 warn,不抛出(不影响确认流程)', async () => {const warn = vi.fn();const notify = createDesktopConfirmNotifier({diff --git a/apps/desktop/src/main/im/desktopConfirmNotice.ts b/apps/desktop/src/main/im/desktopConfirmNotice.tsindex 92d3ed85c9..5edc44b5ae 100644--- a/apps/desktop/src/main/im/desktopConfirmNotice.ts+++ b/apps/desktop/src/main/im/desktopConfirmNotice.ts@@ -75,6 +75,9 @@ export function createDesktopConfirmNotifier(try {const openId = await deps.getFeishuOpenId(sessionId);if (!openId) return;+ // 解析 openId 要查库,期间用户可能刚开了免打扰:真正发之前再确认一次+ // (与 notificationService 在异步富化后、发送前的那道判定同口径)。+ if (deps.isSuppressed?.(sessionId)) return;await deps.sendFeishuText(openId, buildText(what));} catch (err) {deps.logWarn?.(diff --git a/apps/desktop/src/main/localDb/__tests__/agentIslandSessionPatch.test.ts b/apps/desktop/src/main/localDb/__tests__/agentIslandSessionPatch.test.tsindex 5e931946b8..9522384cc9 100644--- a/apps/desktop/src/main/localDb/__tests__/agentIslandSessionPatch.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/agentIslandSessionPatch.test.ts@@ -1,14 +1,16 @@/*** agentIslandSessionPatch —— sessions patch 里灵动岛关心字段的转发口径。*- * 「消息免打扰」不只是「后面的事件别进岛」:任务可能已经上岛了,只挡后续事件会让- * 卡片永远停在「运行中」。所以开静音和转入后台一样,要把这个任务从岛上收走。+ * 「消息免打扰」只挡展示面:任务可能已经上岛了,静音后岛面要收起它;但事件摄取+ * 不能跟着断——侧栏卡片的实时活动、等待交互态与远端活动镜像都长在岛的状态机上。+ * 所以静音走的是「重发一次展示面」,而不是 archive/hidden 那样的 handleSessionClosed。*/import { beforeEach, describe, expect, it, vi } from 'vitest';const h = vi.hoisted(() => ({handleSessionClosed: vi.fn(),handleSessionMetadataPatch: vi.fn(),+ handleNotificationMuteChanged: vi.fn(),getAgentIslandService: vi.fn(),}));@@ -29,23 +31,36 @@ beforeEach(() => {h.getAgentIslandService.mockReturnValue({handleSessionClosed: h.handleSessionClosed,handleSessionMetadataPatch: h.handleSessionMetadataPatch,+ handleNotificationMuteChanged: h.handleNotificationMuteChanged,});});describe('notifyAgentIslandSessionPatch', () => {- it('pulls a task off the island when a mute is turned on', async () => {+ it('republishes the island so a muted task drops off it, without closing the session', async () => {await notify({ notificationsMuted: true });- expect(h.handleSessionClosed).toHaveBeenCalledWith('session-1');+ expect(h.handleNotificationMuteChanged).toHaveBeenCalledWith();+ // 关键:静音不是「关掉这个任务」,删条目会把侧栏实时活动一起带走。+ expect(h.handleSessionClosed).not.toHaveBeenCalled();});- it('leaves the island alone when a mute is turned off', async () => {+ it('republishes again on unmute so the task can come back', async () => {await notify({ notificationsMuted: false });+ expect(h.handleNotificationMuteChanged).toHaveBeenCalledWith();expect(h.handleSessionClosed).not.toHaveBeenCalled();expect(h.handleSessionMetadataPatch).not.toHaveBeenCalled();});+ it('still closes archived, deleted and hidden tasks', async () => {+ await notify({ status: 'deleted' });+ await notify({ status: 'archived' });+ await notify({ hiddenAt: new Date(1).toISOString() });++ expect(h.handleSessionClosed).toHaveBeenCalledTimes(3);+ expect(h.handleSessionClosed).toHaveBeenCalledWith('session-1');+ });+it('still forwards metadata patches', async () => {await notify({ title: 'Renamed' });diff --git a/apps/desktop/src/main/localDb/agentIslandSessionPatch.ts b/apps/desktop/src/main/localDb/agentIslandSessionPatch.tsindex 84d6873171..4ac39a44b5 100644--- a/apps/desktop/src/main/localDb/agentIslandSessionPatch.ts+++ b/apps/desktop/src/main/localDb/agentIslandSessionPatch.ts@@ -6,7 +6,7 @@ export interface AgentIslandSessionPatch {workspaceKind?: unknown;/** 插件后台隐藏时刻;非空 = 任务转入后台,灵动岛与菜单栏收起该任务。 */hiddenAt?: unknown;- /** 开了「消息免打扰」;灵动岛收起该任务。 */+ /** 开了「消息免打扰」;只影响灵动岛展示面与提示音,不影响事件摄取。 */notificationsMuted?: unknown;}@@ -19,11 +19,16 @@ export function notifyAgentIslandSessionPatch(.then(({ getAgentIslandService }) => {const service = getAgentIslandService();if (!service) return;+ // 「消息免打扰」只挡岛面展示与提示音,不挡事件摄取:任务可能已经在岛上,+ // 静音后要让岛面收起它,但状态机必须继续记账——侧栏卡片的实时活动、等待+ // 交互态与远端活动镜像都长在这份状态上。+ if (patch.notificationsMuted !== undefined) {+ service.handleNotificationMuteChanged();+ }if (patch.status === 'archived' ||patch.status === 'deleted' ||- (patch.hiddenAt !== undefined && patch.hiddenAt !== null) ||- patch.notificationsMuted === true+ (patch.hiddenAt !== undefined && patch.hiddenAt !== null)) {service.handleSessionClosed(sessionId);return;diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsPerTaskFlags.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsPerTaskFlags.test.tsindex 493aba5e99..752dc13f30 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsPerTaskFlags.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsPerTaskFlags.test.ts@@ -245,8 +245,8 @@ describe('per-task notification mute (sessions.notifications_muted)', () => {patch: { notificationsMuted: true },});expect(isSessionNotificationsMutedSync('visible')).toBe(true);- // 已经上岛的任务被静音时要顺手把它从岛上收走,否则后面的事件(含终态)都被挡住,- // 卡片会永远停在「运行中」。+ // 岛面要收起它(静音只挡展示面,事件摄取照旧);具体口径由+ // agentIslandSessionPatch.test.ts 钉。expect(h.notifyAgentIslandSessionPatch).toHaveBeenCalledWith('visible', {notificationsMuted: true,});@@ -265,8 +265,10 @@ describe('per-task notification mute (sessions.notifications_muted)', () => {patch: { notificationsMuted: false },});expect(isSessionNotificationsMutedSync('visible')).toBe(false);- // 关闭静音不动岛态(同一函数在每次 update 上还会转发标题/目录等元数据,- // 所以这里不断言整体未调用,只由 agentIslandSessionPatch.test.ts 钉「关静音不收岛」)。+ // 取消静音也要重发一次展示面,否则被抑制的任务回不来。+ expect(h.notifyAgentIslandSessionPatch).toHaveBeenCalledWith('visible', {+ notificationsMuted: false,+ });});it('loads mutes set before this process from the database', async () => {@@ -289,4 +291,14 @@ describe('per-task notification mute (sessions.notifications_muted)', () => {// 这一行被 hidden 改过,不得连带丢掉它原有的静音标记。await vi.waitFor(() => expect(isSessionNotificationsMutedSync('plugin-visible')).toBe(true));});++ it('rejects a non-boolean mute instead of storing it as true', async () => {+ // renderer payload 不可信:字符串 "false" 进了 mapper 的 `!!` 会变成「已静音」。+ const before = readMute('visible');+ await expect(update('visible', { notificationsMuted: 'false' })).rejects.toThrow(/notificationsMuted/);++ // 非法写入不得落库,也不得推进 updated_at。+ expect(readMute('visible')).toEqual(before);+ expect(isSessionNotificationsMutedSync('visible')).toBe(false);+ });});diff --git a/apps/desktop/src/main/localDb/ipc/sessions.ts b/apps/desktop/src/main/localDb/ipc/sessions.tsindex ca9dcd9922..cd97982f4e 100644--- a/apps/desktop/src/main/localDb/ipc/sessions.ts+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts@@ -1760,6 +1760,11 @@ export function registerSessionIpc(ipcMain.handle('local-db:sessions:update', async (_e, id: unknown, patch: unknown) => {const sid = requireString(id, 'id');const p = requireObject(patch, 'patch');+ // renderer payload 不可信:静音是 boolean 语义,字符串 "false" 进 mapper 会被 `!!`+ // 存成 true(开关反转)。出现就必须是真 boolean,与 set-pinned-card-summaries 同口径。+ if (p.notificationsMuted !== undefined && typeof p.notificationsMuted !== 'boolean') {+ throwIpcError('INVALID_PARAMS', 'notificationsMuted must be a boolean');+ }return updateSessionInDb(sid, p, opts);});@@ -2050,11 +2055,9 @@ export async function updateSessionInDb(// 「消息免打扰」是通知面专用标记:同步给进程内索引,免得通知/灵动岛路径逐事件查库。if (p.notificationsMuted !== undefined) {noteSessionNotificationsMuted(sid, updated.notificationsMuted === true, dbClient);- // 已经上岛的任务现在才被静音:后面的事件(含终态)都被门挡住,得先把它从岛上收走,- // 否则卡片会永远停在「运行中」。- if (updated.notificationsMuted === true) {- notifyAgentIslandSessionPatch(sid, { notificationsMuted: true });- }+ // 岛面收敛:静音后要把已经上岛的任务从展示面收走,取消静音要放回来。只影响+ // 展示面 —— 事件仍照常进状态机(侧栏实时活动就长在那份状态上)。+ notifyAgentIslandSessionPatch(sid, { notificationsMuted: updated.notificationsMuted });}if (updated.status === 'deleted' && isOwnerScopeCurrent(ownerScope)) {clearSessionAttention(sid, 'explicit');diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 1e44bdb527..559e12683b 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -3070,6 +3070,9 @@ function notifyInputHandoffOwner(sessionId: string, snapshot: InputHandoffSnapshreadSessionTitle(sessionId),readSessionNotificationPreview(sessionId, false).catch(() => undefined),]);+ // 读标题/预览是异步的:等它回来时用户可能刚开了免打扰,真正发之前再确认一次+ // (手机推送另有 sendMobileSessionNotify 内的同一道判定)。+ if (isSessionNotificationsMutedSync(sessionId)) return;// An IM-driven task gets one text pointer per request, not one per screen.if (!inputHandoffImNotified.has(snapshot.requestId)) {inputHandoffImNotified.add(snapshot.requestId);@@ -4872,9 +4875,9 @@ function handleAgentIslandSessionStopped(function shouldNotifyAgentIslandForSession(sessionId: string): boolean {// 插件后台隐藏任务不在灵动岛/菜单栏展示运行中,也不提醒(显示到任务列表后恢复)。if (isSessionHiddenSync(sessionId)) return false;- // 「消息免打扰」任务不上岛、不播提示音(岛态不进入即无声),其它提醒面见- // notificationService / device-link / scheduler-host 的同名判定。- if (isSessionNotificationsMutedSync(sessionId)) return false;+ // 「消息免打扰」**不在这里挡**:它只退出展示面(岛面/菜单栏/提示音,见+ // agent-island state 的 displaySuppressedSessionIds)。事件必须继续进状态机,+ // 否则侧栏卡片的实时活动与等待交互态会跟着一起消失,而这不该是静音的效果。return shouldNotifyAgentIslandForSessionByPolicy(AGENT_ISLAND_DISPLAY_CONFIG,isKnownOrcaWorkerSession(sessionId),diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionNotificationMute.test.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionNotificationMute.test.tsindex 9e1b29e515..68249ef76d 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionNotificationMute.test.ts+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionNotificationMute.test.ts@@ -66,4 +66,25 @@ describe('setSessionNotificationsMuted', () => {expect(m.patchLocal).toHaveBeenCalledTimes(1);expect(m.patchLocal).toHaveBeenCalledWith('task', { notificationsMuted: true });});++ it('does not roll back over a newer same-direction write that is still in flight', async () => {+ // 两个窗口(或连点两下)都在「关静音」:后发起的那次成功,先发起的那次稍后失败。+ // 只比布尔值分不出这种情况——失败的那次看到的仍是自己写进去的 false。+ let failFirst: (error: Error) => void = () => {};+ m.patchMeta+ .mockImplementationOnce(+ () => new Promise((_resolve, reject) => { failFirst = reject; }),+ )+ .mockImplementationOnce(async () => ({}));++ const first = setSessionNotificationsMuted({ ...session, notificationsMuted: true }, false);+ const second = setSessionNotificationsMuted({ ...session, notificationsMuted: true }, false);+ await second;+ failFirst(new Error('write failed'));+ await expect(first).rejects.toThrow('write failed');++ // 只有两次发起的乐观写,没有回滚写回 true。+ expect(m.patchLocal).toHaveBeenCalledTimes(2);+ expect(m.patchLocal).not.toHaveBeenLastCalledWith('task', { notificationsMuted: true });+ });});diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/sessionNotificationMute.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/sessionNotificationMute.tsindex b5699cde6e..d7f2d41a31 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/sessionNotificationMute.ts+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/sessionNotificationMute.ts@@ -5,6 +5,13 @@ import { sessionsStore } from '@/lib/sessionsStore';const log = createLogger('session-notification-mute');+/**+ * 同一个任务可能有多条静音写入同时在飞(连点、主窗与副窗、两个窗口)。回滚只属于+ * 「最后一次发起、且期间没人再改过」的那一次;只比布尔值分不出同向并发。+ */+const latestWriteSeq = new Map<string, number>();+let writeSeq = 0;+/*** 任务级「消息免打扰」开关(会话右键菜单)。*@@ -17,13 +24,20 @@ const log = createLogger('session-notification-mute');*/export async function setSessionNotificationsMuted(session: Session, muted: boolean): Promise<void> {const previous = session.notificationsMuted === true;+ const seq = ++writeSeq;+ latestWriteSeq.set(session.id, seq);sessionsStore.patchLocal(session.id, { notificationsMuted: muted });try {await sessionService.patchMeta(session.id, { notificationsMuted: muted });} catch (error) {- // 只回滚「还是我们写进去的那个值」的情况:等这一趟的过程中别的窗口可能已经改过它,- // 无条件写回 previous 会把新值盖掉(库里已静音、侧栏显示未静音)。- if (sessionsStore.findById(session.id)?.notificationsMuted === muted) {+ // 两个条件都要:+ // - 自己仍是这个任务最后一次发起的写入(挡同向并发:两个窗口都在关静音,先失败的+ // 那次不能把后一次的成功翻回去);+ // - 值还是自己写进去的那个(挡期间别处广播来的新值)。+ if (+ latestWriteSeq.get(session.id) === seq &&+ sessionsStore.findById(session.id)?.notificationsMuted === muted+ ) {sessionsStore.patchLocal(session.id, { notificationsMuted: previous });}log.error('[session notification mute]', error);