Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(notifications): 修复跨电脑自动任务静默失效 (#6130)

Dashc256f54c1837
diff --git a/apps/desktop/src/main/agent-island/__tests__/service.test.ts b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
index 0911fbf3e7..7c3184c110 100644
--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
@@ -4011,6 +4011,61 @@ describe('AgentIslandService native publishing', () => {
}
});
+ it.each([false, true])('keeps scheduled completions silent on source and remote devices (oldUnread=%s)', async oldUnread => {
+ vi.useFakeTimers();
+ const { AgentIslandService } = await import('../service.js');
+ const sourcePublish = vi.fn((state: AgentIslandDisplayState) => state.visible);
+ const sourceSound = vi.fn(() => true);
+ const remotePublish = vi.fn((state: AgentIslandDisplayState) => state.visible);
+ const remoteSound = vi.fn(() => true);
+ const desktopEvent = vi.fn();
+ const source = new AgentIslandService({ getMainWindow: () => null, nativeHost: { failed: false, publish: sourcePublish, playSound: sourceSound }, isCompletionHandledByTeammate: async () => false });
+ const remote = new AgentIslandService({ getMainWindow: () => null, nativeHost: { failed: false, publish: remotePublish, playSound: remoteSound } });
+ const desktop = new AgentIslandService({ getMainWindow: () => null, nativeHost: { failed: false, publish: () => false }, onDeviceSessionEvent: desktopEvent });
+ try {
+ syncEnabledForTest(source, sourcePublish);
+ syncEnabledForTest(remote, remotePublish);
+ for (const service of [source, remote]) service.setSoundSettings({ enabled: true, sounds: { ...DEFAULT_AGENT_ISLAND_SOUND_SETTINGS.sounds, complete: customSound('complete.wav') } });
+ mocks.tapWindowBroadcast.mockImplementation((channel, raw) => {
+ if (channel !== SESSION_ACTIVITY_CHANNEL) return;
+ const p = raw as { sessionId: string; phase: 'running' | 'needs-interaction' | 'completed' | 'error'; compactDetail: string; attention: boolean; completionNotification?: 'pending' | 'teammate' | 'silent' };
+ const keep = p.phase === 'running' || p.phase === 'needs-interaction' || p.attention;
+ const inputs = keep ? [{ sessionId: p.sessionId, deviceId: 'source', deviceName: 'Source', title: 'Task', workingDir: null, workspaceKind: 'conversation' as const, agentKind: 'cc' as const, phase: p.phase, detail: p.compactDetail, completionNotification: p.completionNotification }] : [];
+ remote.setDeviceSessions(inputs);
+ desktop.setDeviceSessions(inputs);
+ });
+ const meta = { sessionId: 'scheduled-silent', agentKind: 'codex' };
+ if (oldUnread) {
+ source.handleUserPrompt(meta, 'Earlier manual task');
+ source.handleAgentEvent(meta, doneEvent());
+ await vi.advanceTimersByTimeAsync(2000);
+ }
+ source.handleScheduleEvent({ type: 'silenced', scheduleId: 'schedule', runId: 'run', sessionId: meta.sessionId });
+ source.handleUserPrompt(meta, 'Scheduled check');
+ await vi.advanceTimersByTimeAsync(2000);
+ sourceSound.mockClear(); remoteSound.mockClear(); desktopEvent.mockClear();
+ source.handleAgentEvent(meta, doneEvent());
+ source.handleScheduleEvent({ type: 'completed', scheduleId: 'schedule', runId: 'run', sessionId: meta.sessionId, silenced: true });
+ await vi.advanceTimersByTimeAsync(0);
+ expect(sourceSound).not.toHaveBeenCalled();
+ expect(desktopEvent).not.toHaveBeenCalled();
+ expect(remoteSound).not.toHaveBeenCalled();
+ expect(remotePublish.mock.calls.at(-1)?.[0].pillSnapshot.unreadCompletedCount).toBe(oldUnread ? 1 : 0);
+
+ source.handleUserPrompt(meta, 'Manual follow-up');
+ await vi.advanceTimersByTimeAsync(2000);
+ source.handleAgentEvent(meta, doneEvent());
+ await vi.advanceTimersByTimeAsync(0);
+ expect(sourceSound).toHaveBeenCalledWith(customSound('complete.wav'));
+ expect(remoteSound).toHaveBeenCalledWith(customSound('complete.wav'));
+ expect(desktopEvent).toHaveBeenCalledWith(expect.objectContaining({ kind: 'done' }));
+ } finally {
+ source.resetRuntimeState(); remote.resetRuntimeState(); desktop.resetRuntimeState();
+ mocks.tapWindowBroadcast.mockReset();
+ vi.useRealTimers();
+ }
+ });
+
it('preserves older session attention without playing completion sound for a silenced run', async () => {
vi.useFakeTimers();
try {
diff --git a/apps/desktop/src/main/agent-island/__tests__/sessionActivityRelay.test.ts b/apps/desktop/src/main/agent-island/__tests__/sessionActivityRelay.test.ts
index d0e7115671..2dab4ec05c 100644
--- a/apps/desktop/src/main/agent-island/__tests__/sessionActivityRelay.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/sessionActivityRelay.test.ts
@@ -34,6 +34,30 @@ describe('SessionActivityRelay', () => {
vi.useRealTimers();
});
+ it('keeps a silent completion through replay and ignores a superseded ownership check', async () => {
+ let resolve!: (handled: boolean) => void;
+ const check = vi.fn(() => new Promise<boolean>(r => { resolve = r; }));
+ const emit = vi.fn();
+ const relay = new SessionActivityRelay(emit, { isCompletionHandledByTeammate: check });
+ const done = activity('s1', 'Final result', { phase: 'completed', attention: true });
+ const silent = { ...done, completionNotification: 'silent' as const };
+ relay.publish([done]);
+ await Promise.resolve();
+ const decision = relay.waitForCompletionNotification('s1');
+ const replay = vi.fn();
+ relay.replay([silent], replay);
+ expect(replay).toHaveBeenLastCalledWith(expect.objectContaining({ completionNotification: 'silent' }));
+ relay.publish([silent]);
+ expect(await decision).toBe(true);
+ resolve(false);
+ await vi.advanceTimersByTimeAsync(2000);
+ expect(check).toHaveBeenCalledOnce();
+ expect(emit).toHaveBeenLastCalledWith(expect.objectContaining({ attention: true, completionNotification: 'silent' }));
+ relay.replay([silent], replay);
+ expect(replay).toHaveBeenLastCalledWith(emit.mock.calls.at(-1)?.[0]);
+ relay.dispose();
+ });
+
it.each([true, false])('publishes completion and unread immediately, then only resolves notification ownership (%s)', async handled => {
let resolve!: (handled: boolean) => void;
const check = vi.fn(() => new Promise<boolean>(r => { resolve = r; }));
diff --git a/apps/desktop/src/main/agent-island/__tests__/state.test.ts b/apps/desktop/src/main/agent-island/__tests__/state.test.ts
index 7ee94996e5..7d193c2ece 100644
--- a/apps/desktop/src/main/agent-island/__tests__/state.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/state.test.ts
@@ -2442,6 +2442,25 @@ describe('Agent Island error read semantics (已读以 App 内真实展示为准
});
describe('Agent Island 未读驻留 TTL(避免几小时前完成的任务无限期霸占展开列表)', () => {
+ it('preserves silent completion policy in the unread ledger after expiry and clears it on the next turn', () => {
+ const state = createAgentIslandState();
+ const meta = { sessionId: 'silent', title: 'Schedule' };
+ applyAgentIslandEvent(state, meta, doneEvent(), 2_000);
+ applyAgentIslandUserPrompt(state, meta, 'Scheduled check', 3_000);
+ applyAgentIslandEvent(state, meta, doneEvent(), 4_000, { suppressCompletionAttention: true, preserveCompletionAttention: true });
+ const afterExpiryAt = 4_000 + AGENT_ISLAND_UNREAD_TRANSIENT_TTL_MS + 1_000;
+ buildAgentIslandDisplayState(state, afterExpiryAt);
+ expect(state.sessions.has('silent')).toBe(false);
+ expect(buildAllSessionActivitySnapshots(state)).toEqual([
+ expect.objectContaining({ sessionId: 'silent', phase: 'completed', attention: true, completionNotification: 'silent' }),
+ ]);
+ applyAgentIslandUserPrompt(state, meta, 'Manual follow-up', afterExpiryAt + 1);
+ expect(buildAllSessionActivitySnapshots(state)[0].completionNotification).toBeUndefined();
+ applyAgentIslandEvent(state, meta, doneEvent(), afterExpiryAt + 2);
+ expect(buildAllSessionActivitySnapshots(state)[0]).toMatchObject({ phase: 'completed', attention: true });
+ expect(buildAllSessionActivitySnapshots(state)[0].completionNotification).toBeUndefined();
+ });
+
it('unread completed 条目在 TTL 内仍然可见', () => {
const state = createAgentIslandState();
applyAgentIslandEvent(state, { sessionId: 'done', title: 'Schedule' }, doneEvent(), 2_000);
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index f7bee60500..e45838b3f1 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -669,6 +669,11 @@ export class AgentIslandService {
setDeviceSessions(inputs: readonly AgentIslandRemoteSessionInput[]): void {
setAgentIslandStrings(this.state, buildAgentIslandStrings());
const result = syncAgentIslandDeviceSessions(this.state, inputs, Date.now());
+ for (const input of inputs) {
+ if (input.phase === 'completed' && input.completionNotification === 'silent') {
+ this.mutedCompletionSoundSessionIds.add(input.sessionId);
+ }
+ }
for (const sessionId of result.baselineSessionIds) this.baselineSoundSessionIds.add(sessionId);
if (result.changed) this.publish();
if (this.isEnabled()) return;
@@ -1556,6 +1561,7 @@ export class AgentIslandService {
*/
private buildSessionActivityPayload(): AgentIslandSessionActivity[] {
return buildAllSessionActivitySnapshots(this.state).map((s) => ({
+ ...(s.completionNotification ? { completionNotification: s.completionNotification } : {}),
...projectSessionActivity({
sessionId: s.sessionId,
recordStatus: 'active',
diff --git a/apps/desktop/src/main/agent-island/sessionActivityRelay.ts b/apps/desktop/src/main/agent-island/sessionActivityRelay.ts
index 9a11b56bac..90ed5a0d5a 100644
--- a/apps/desktop/src/main/agent-island/sessionActivityRelay.ts
+++ b/apps/desktop/src/main/agent-island/sessionActivityRelay.ts
@@ -62,7 +62,7 @@ export class SessionActivityRelay {
if (!activity.sessionId) continue;
activeSessionIds.add(activity.sessionId);
const payload = toSessionActivityPayload(activity);
- if (this.checkCompletion && payload.phase === 'completed' && payload.attention) {
+ if (this.checkCompletion && payload.phase === 'completed' && payload.attention && payload.completionNotification !== 'silent') {
this.publishCompletion(activity, payload);
} else {
this.awaitingTerminal.delete(activity.sessionId);
@@ -159,7 +159,7 @@ export class SessionActivityRelay {
if (!activity.sessionId) continue;
seenSessionIds.add(activity.sessionId);
const check = this.completionChecks.get(activity.sessionId);
- const payload = activity.phase === 'completed' && activity.attention && check?.startedAtMs === activity.startedAtMs
+ const payload = activity.phase === 'completed' && activity.attention && activity.completionNotification !== 'silent' && check?.startedAtMs === activity.startedAtMs
? check.payload : toSessionActivityPayload(activity);
emit(isPublishableActivity(payload) ? payload : toTerminalActivityPayload(activity.sessionId));
}
@@ -301,6 +301,7 @@ export class SessionActivityRelay {
function toSessionActivityPayload(activity: AgentIslandSessionActivity): SessionActivityPayload {
return {
+ ...(activity.completionNotification ? { completionNotification: activity.completionNotification } : {}),
sessionId: activity.sessionId,
phase: activity.phase,
workingPhase: activity.workingPhase,
diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.ts
index b10547a2aa..348e94434a 100644
--- a/apps/desktop/src/main/agent-island/state.ts
+++ b/apps/desktop/src/main/agent-island/state.ts
@@ -119,6 +119,7 @@ interface ApplyAgentIslandEventOptions {
}
interface AgentIslandSessionState {
+ completionNotification?: 'silent';
pendingDeviceCompletionNotification?: boolean;
sessionId: string;
title: string | null;
@@ -229,6 +230,7 @@ export interface AgentIslandState {
}
export interface AgentIslandRemoteUnreadTerminal {
+ completionNotification?: 'silent';
sessionId: string;
phase: 'completed' | 'error';
lastActivityAt: number;
@@ -1213,7 +1215,8 @@ function applyDeviceSessionPhase(
return { changed, event: entering && previous !== null ? 'needs-reply' : null };
}
case 'completed': {
- if (previous === 'completed') {
+ const silent = input.completionNotification === 'silent';
+ if (previous === 'completed' && (!silent || session.completionNotification === 'silent')) {
return { changed: mirrorDeviceSessionSummary(session, input.detail), event: null };
}
clearDeviceSessionInteraction(session);
@@ -1224,10 +1227,10 @@ function applyDeviceSessionPhase(
mirrorDeviceSessionSummary(session, input.detail);
// 对方设备已经仲裁过终态,这里不再套本机「报错后的配对 done」保护。
session.completionAllowedAfterTerminalError = true;
- completeAgentIslandSession(state, session, now, observed
+ completeAgentIslandSession(state, session, now, observed && !silent
? { suppressAttention: false, preserveAttention: false }
: { suppressAttention: true, preserveAttention: true });
- return { changed: true, event: observed ? 'done' : null };
+ return { changed: true, event: observed && !silent ? 'done' : null };
}
case 'error': {
if (previous === 'error') return { changed: false, event: null };
@@ -1688,6 +1691,7 @@ function markSessionRunning(
now: number,
): void {
if (!session.running) session.startedAt = now;
+ session.completionNotification = undefined;
session.running = true;
session.completedUntil = null;
session.errorUntil = null;
@@ -1718,6 +1722,7 @@ function completeAgentIslandSession(
if (session.phase === 'error' && !session.completionAllowedAfterTerminalError) return;
session.phase = 'completed';
+ session.completionNotification = options.suppressAttention ? 'silent' : undefined;
session.interactionKind = undefined;
session.interactionRevealDismissed = false;
session.detail = '';
@@ -2583,6 +2588,7 @@ function applyMeta(session: AgentIslandSessionState, meta: AgentIslandSessionMet
function toSnapshot(session: AgentIslandSessionState): AgentIslandSessionSnapshot {
const reconnectStatus = session.phase === 'running' ? session.reconnectStatus : null;
return {
+ ...(session.phase === 'completed' && session.completionNotification ? { completionNotification: session.completionNotification } : {}),
sessionId: session.sessionId,
title: session.title || session.projectName || session.sessionId.slice(0, 8),
projectName: session.projectName,
@@ -2643,6 +2649,7 @@ function syncRemoteUnreadTerminal(state: AgentIslandState, session: AgentIslandS
if (session.sourceDeviceId !== null) return;
if (isUnreadTerminalLedger(session)) {
state.remoteUnreadTerminals.set(session.sessionId, {
+ ...(session.phase === 'completed' && session.completionNotification ? { completionNotification: session.completionNotification } : {}),
sessionId: session.sessionId,
phase: session.phase,
lastActivityAt: session.lastActivityAt,
@@ -2669,6 +2676,7 @@ function unreadIslandTtlAt(session: AgentIslandSessionState): number | null {
function toRemoteUnreadSnapshot(unread: AgentIslandRemoteUnreadTerminal): AgentIslandSessionSnapshot {
return {
+ ...(unread.completionNotification ? { completionNotification: unread.completionNotification } : {}),
sessionId: unread.sessionId,
title: unread.sessionId.slice(0, 8),
projectName: null,
diff --git a/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts b/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts
index 6290462f2e..96068e0b60 100644
--- a/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts
+++ b/apps/desktop/src/renderer/__tests__/sessionEventNotification.test.ts
@@ -32,6 +32,35 @@ const markAttention = vi.fn(() => Promise.resolve());
const showSessionEvent = vi.fn(() => Promise.resolve());
describe('shared session event notifications', () => {
+ it.each(['before-clear', 'after-clear'])('does not notify for a cleared remote completion (%s)', order => {
+ gates.feishu = true;
+ const relay = new SessionActivityRelay(payload => applyRemoteSessionActivity('host', payload));
+ const running = { sessionId: 'remote-silent', phase: 'running', recordStatus: 'active', compactDetail: 'Working', startedAtMs: 1, lastActivityAtMs: 1, currentActionSummary: 'Working', attention: false, workflow: null, turnGeneration: null, gracefulStopState: 'none', source: 'live' } as const;
+ const notify = () => sendSessionEventNotification('remote-silent', 'Silent task', 'done', { remoteDevice: true, remoteDeviceId: 'host' });
+ relay.publish([running]);
+ if (order === 'before-clear') notify();
+ relay.publish([{ ...running, phase: 'completed', attention: false }]);
+ expect(getRemoteSessionActivity('remote-silent', 'host')).toBeUndefined();
+ if (order === 'after-clear') notify();
+ relay.dispose();
+ expect(showSessionEvent).not.toHaveBeenCalled();
+ });
+
+ it.each(['before-done', 'after-done'])('preserves remote unread without notifying for a silent completion (%s)', order => {
+ gates.feishu = true;
+ const notify = () => sendSessionEventNotification('remote-silent', 'Task', 'done', { remoteDevice: true, remoteDeviceId: 'host' });
+ applyRemoteSessionActivity('host', { sessionId: 'remote-silent', phase: 'running', attention: true });
+ if (order === 'after-done') notify();
+ applyRemoteSessionActivity('host', { sessionId: 'remote-silent', phase: 'completed', attention: true, completionNotification: 'silent' });
+ if (order === 'before-done') notify();
+ expect(showSessionEvent).not.toHaveBeenCalled();
+ expect(getRemoteSessionActivity('remote-silent', 'host')).toMatchObject({ attention: true, completionNotification: 'silent' });
+ applyRemoteSessionActivity('host', { sessionId: 'remote-silent', phase: 'running', attention: true });
+ notify();
+ applyRemoteSessionActivity('host', { sessionId: 'remote-silent', phase: 'completed', attention: true });
+ expect(showSessionEvent).toHaveBeenCalledTimes(1);
+ });
+
beforeEach(() => {
clearRemoteSessionActivity();
gates.desktop = true;
diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts b/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts
index 3ef25d3cad..6f8904f87f 100644
--- a/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts
+++ b/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts
@@ -83,6 +83,35 @@ describe('buildAgentIslandRemoteSessionInputs', () => {
relay.dispose(); clearRemoteSessionActivity();
});
+ it('carries silence through relay, store and IPC without losing unread or suppressing later errors', () => {
+ clearRemoteSessionActivity();
+ const state = createAgentIslandState();
+ const events: string[] = [];
+ const relay = new SessionActivityRelay(payload => {
+ applyRemoteSessionActivity('device-a', payload);
+ const inputs = buildAgentIslandRemoteSessionInputs([remoteSession('a-1', 'device-a')], MACHINE_ALL, getRemoteSessionActivity);
+ const parsed = parseAgentIslandRemoteSessions(inputs);
+ expect(parsed).not.toBeNull();
+ events.push(...syncAgentIslandDeviceSessions(state, parsed!, 2_000).events.map(event => event.kind));
+ }, { minIntervalMs: 0 });
+ const activity = { sessionId: 'a-1', phase: 'running', recordStatus: 'active', compactDetail: 'Working', startedAtMs: 1, lastActivityAtMs: 1, currentActionSummary: 'Working', attention: true, workflow: null, turnGeneration: null, gracefulStopState: 'none', source: 'live' } as const;
+ try {
+ relay.publish([activity]);
+ const silent = { ...activity, phase: 'completed' as const, completionNotification: 'silent' as const };
+ relay.publish([silent]);
+ relay.replay([silent]);
+ expect(events).toEqual([]);
+ expect(state.sessions.get('a-1')).toMatchObject({ phase: 'completed', unread: true, completionNotification: 'silent' });
+ expect(state.activeTransientSessionId).toBeNull();
+ relay.publish([activity]);
+ relay.publish([{ ...activity, phase: 'error' }]);
+ expect(events).toEqual(['error']);
+ } finally {
+ relay.dispose();
+ clearRemoteSessionActivity();
+ }
+ });
+
it('includes every remote task with live activity under the "all" scope', () => {
expect(buildAgentIslandRemoteSessionInputs(sessions, MACHINE_ALL, readActivity)).toEqual([
{
diff --git a/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts b/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts
index 09e07fff15..8cb014abaf 100644
--- a/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts
+++ b/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts
@@ -31,7 +31,7 @@ export interface RemoteSessionActivity {
workingPhase?: string;
interactionKind?: string;
attention: boolean;
- completionNotification?: 'pending' | 'teammate';
+ completionNotification?: 'pending' | 'teammate' | 'silent';
}
/** Active remote turns must win over the persisted "started without ended" heuristic. */
@@ -159,7 +159,7 @@ export function applyRemoteSessionActivity(deviceId: string, payload: unknown):
workingPhase: typeof p.workingPhase === 'string' ? p.workingPhase : undefined,
interactionKind: typeof p.interactionKind === 'string' ? p.interactionKind : undefined,
attention,
- completionNotification: p.completionNotification === 'pending' || p.completionNotification === 'teammate' ? p.completionNotification : undefined,
+ completionNotification: p.completionNotification === 'pending' || p.completionNotification === 'teammate' || p.completionNotification === 'silent' ? p.completionNotification : undefined,
};
let activityMap = activityByDevice.get(deviceId);
if (!activityMap) {
diff --git a/apps/desktop/src/renderer/lib/sessionEventNotification.ts b/apps/desktop/src/renderer/lib/sessionEventNotification.ts
index 8ff0c45cc8..68609053b0 100644
--- a/apps/desktop/src/renderer/lib/sessionEventNotification.ts
+++ b/apps/desktop/src/renderer/lib/sessionEventNotification.ts
@@ -126,10 +126,13 @@ function sendRemoteCompletionNotification(sessionId: string, deviceId: string, d
const key = JSON.stringify([deviceId, sessionId]);
if (pendingRemoteCompletions.has(key)) return;
const activity = getRemoteSessionActivity(sessionId, deviceId);
- if (activity?.phase === 'completed' && activity.completionNotification === 'teammate') return;
+ // A clear can arrive before the renderer's delayed done callback. Missing
+ // activity is not proof of a new completion (including on older hosts).
+ if (!activity) return;
+ if (activity.phase === 'completed' && (activity.completionNotification === 'teammate' || activity.completionNotification === 'silent')) return;
if (activity?.phase === 'error' || activity?.phase === 'needs-interaction') return;
- if (!activity || (activity.phase === 'completed' && activity.completionNotification !== 'pending')) {
- deliver(); // Older hosts retain their original notification behavior.
+ if (activity.phase === 'completed' && activity.completionNotification !== 'pending') {
+ deliver(); // Older hosts still publish ordinary unread completion activity.
return;
}
let sawPendingCompletion = activity.phase === 'completed';
@@ -146,7 +149,7 @@ function sendRemoteCompletionNotification(sessionId: string, deviceId: string, d
pendingRemoteCompletions.delete(key);
// Read, disconnect, error, interaction or a replacement turn supersedes this
// completion request. Only the source's resolved ordinary completion sends.
- if (latest?.phase === 'completed' && latest.completionNotification !== 'teammate') deliver();
+ if (latest?.phase === 'completed' && latest.completionNotification !== 'teammate' && latest.completionNotification !== 'silent') deliver();
});
pendingRemoteCompletions.set(key, cancel);
}
diff --git a/apps/desktop/src/shared/agentIsland.ts b/apps/desktop/src/shared/agentIsland.ts
index 16e33400d6..0ea95aa81a 100644
--- a/apps/desktop/src/shared/agentIsland.ts
+++ b/apps/desktop/src/shared/agentIsland.ts
@@ -24,6 +24,8 @@ export interface AgentIslandActivityLine {
* Renderer-facing session snapshot for the macOS Agent Island overlay.
*/
export interface AgentIslandSessionSnapshot {
+ /** This completion preserves older unread state without requesting a new alert. */
+ completionNotification?: 'silent';
sessionId: string;
title: string;
projectName: string | null;
@@ -53,6 +55,7 @@ export interface AgentIslandPermissionActionSnapshot {
*/
export interface AgentIslandSessionActivity
extends Omit<SessionActivitySnapshot, 'phase' | 'interactionKind'> {
+ completionNotification?: 'silent';
phase: AgentIslandSessionPhase;
interactionKind?: AgentIslandInteractionKind;
/** Compatibility/display alias; canonical probe field is currentActionSummary. */
@@ -754,7 +757,7 @@ export const AGENT_ISLAND_SET_REMOTE_SESSIONS_CHANNEL = 'agent-island:set-remote
* 只含 running / needs-interaction / 未读终态;范围由 renderer 按侧栏「任务范围」裁剪。
*/
export interface AgentIslandRemoteSessionInput {
- completionNotification?: 'pending' | 'teammate';
+ completionNotification?: 'pending' | 'teammate' | 'silent';
sessionId: string;
deviceId: string;
deviceName: string | null;
@@ -813,7 +816,7 @@ export function parseAgentIslandRemoteSessions(raw: unknown): AgentIslandRemoteS
workspaceKind: readBoundedString(record.workspaceKind, 64),
agentKind: readBoundedString(record.agentKind, 64),
phase: phase as AgentIslandSessionPhase,
- ...(record.completionNotification === 'pending' || record.completionNotification === 'teammate'
+ ...(record.completionNotification === 'pending' || record.completionNotification === 'teammate' || record.completionNotification === 'silent'
? { completionNotification: record.completionNotification } : {}),
detail: readBoundedString(record.detail, AGENT_ISLAND_REMOTE_TEXT_MAX_LENGTH) ?? '',
...(workingPhase ? { workingPhase } : {}),
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index abb2ec8039..f2a43ab49a 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -1732,20 +1732,24 @@ Chat Server `/me` 追加 `capabilities.groupDiscussionParity: 1`。Desktop 只
- 后续:若服务端放开主时间线 `replyToId`(能力协商后),客户端可同时写 `replyToId` 获得外键约束与
删除感知,卡片继续承担快照与旧端兼容;两者并存时以 `replyToId` 为准。
-## 委派任务的完成通知归属
+## 委派任务与自动任务的完成通知策略
既有 `SessionActivityPayload` 可选字段 `completionNotification` 影响远端桌面、手机与飞书完成通知:
-`pending` 表示该轮终态回传正在判定,`teammate` 表示同一委派执行结果已成功交回伙伴;
+`pending` 表示该轮终态回传正在判定,`teammate` 表示同一委派执行结果已成功交回伙伴,
+`silent` 表示本轮完成静默(即使保留历史未读,也不重新弹出、响铃或发外部通知);
缺省或未知值按普通任务完成通知处理。完成 phase、摘要和 attention 在 pending 阶段照常发送,
回传决定通过同一活动通道更新;执行宿主等到真实 `done` 的回传边界再决定,前置
`status: Done` 不能提前消费归属。本机外部通知共用这一决定;控制端的手机/飞书调用
-在活动仍运行或 `pending` 时等待同一活动通道更新,已回传伙伴则取消调用。已读、断开、
+在活动仍运行或 `pending` 时等待同一活动通道更新,已回传伙伴或本轮静默则取消调用。
+没有活动记录(例如静默完成的清除帧早于 renderer 的 done 回调)不能当作新完成的证据。
+`silent` 随未读账本和重连快照保留,新一轮运行清除;聊天过程与历史未读不受影响。已读、断开、
新一轮运行、报错或待交互使旧完成调用失效,不延迟错误与待答通知,也不更改任何未读。
控制端桌面仅对已观察运行的任务补发必要 fallback 一次,重连的
基线终态不补发历史提醒。错误与待交互不受此字段影响。
-新控制端连接旧执行端沿用原通知;旧控制端忽略该字段,仍可能发独立完成外部通知,完整远端
-去重需要两端更新。手机外部推送在执行端及远控 Desktop 的通知出口完成去重,手机无需新增协议处理;
+新控制端连接旧执行端时,明确的普通未读完成仍按原规则通知;旧控制端忽略该字段或未知枚举,
+仍可能发独立完成通知,完整远端去重和保留旧未读时的静默需要两端更新。
+手机外部推送在执行端及远控 Desktop 的通知出口完成去重,手机无需新增协议处理;
移动列表继续原 phase/attention 语义。无需服务端、数据库 migration 或 Mobile fingerprint 改动。
## 伙伴创建时选择模型
diff --git a/packages/device-link/src/topics.ts b/packages/device-link/src/topics.ts
index 41b1e870a8..e51d219c56 100644
--- a/packages/device-link/src/topics.ts
+++ b/packages/device-link/src/topics.ts
@@ -54,9 +54,9 @@ export function parseFsWatchTopic(topic: string): string | null {
export type SessionActivityPhase = 'running' | 'needs-interaction' | 'completed' | 'error';
export interface SessionActivityPayload {
- /** Completion push ownership only; activity/attention remains unchanged.
+ /** Completion notification policy only; activity/attention remains unchanged.
* Absent on older hosts. Unknown values use ordinary completion semantics. */
- completionNotification?: 'pending' | 'teammate';
+ completionNotification?: 'pending' | 'teammate' | 'silent';
/** Optional public generation category; unknown values must use a generic caption. */
workingPhase?: string;
sessionId: string;