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(desktop): 自动续跑时静音失败提醒 (#1278)

Dash8f3a4f2de5a0
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 38fa73de56..bf51a36ec4 100644
--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
@@ -2636,6 +2636,77 @@ describe('AgentIslandService native publishing', () => {
});
});
+ it('keeps an auto-resumed failure transition silent and restores it if recovery does not start', async () => {
+ const { AgentIslandService } = await import('../service.js');
+ const publish = vi.fn((state: AgentIslandDisplayState, frameOrFrames: AgentIslandNativeFrame | AgentIslandNativeFrame[]) => {
+ void state;
+ void frameOrFrames;
+ return true;
+ });
+ const playSound = vi.fn<(sound: AgentIslandSoundChoice) => boolean>(() => true);
+ const service = new AgentIslandService({
+ getMainWindow: () => null,
+ nativeHost: { failed: false, publish, playSound },
+ });
+ syncEnabledForTest(service, publish);
+ service.setSoundSettings({
+ enabled: true,
+ sounds: {
+ ...DEFAULT_AGENT_ISLAND_SOUND_SETTINGS.sounds,
+ error: customSound('error.wav'),
+ },
+ });
+ const meta = { sessionId: 'auto-resume', agentKind: 'claude-code' };
+ service.handleUserPrompt(meta, 'run tests');
+ playSound.mockClear();
+
+ service.handleAgentEvent(meta, terminalErrorEvent('connection closed mid-response'), {
+ suppressErrorSound: true,
+ });
+
+ expect(playSound).not.toHaveBeenCalled();
+ expect(publish.mock.calls.at(-1)?.[0].sessions[0]).toMatchObject({
+ sessionId: 'auto-resume',
+ phase: 'error',
+ detail: 'connection closed mid-response',
+ });
+ service.restoreTaskFailureSound(meta.sessionId);
+ expect(playSound).toHaveBeenCalledTimes(1);
+ expect(playSound).toHaveBeenCalledWith(customSound('error.wav'));
+ });
+
+ it('keeps an auto-resumed failure silent through the initial enabled sync', async () => {
+ const { AgentIslandService } = await import('../service.js');
+ const publish = vi.fn((state: AgentIslandDisplayState, frameOrFrames: AgentIslandNativeFrame | AgentIslandNativeFrame[]) => {
+ void state;
+ void frameOrFrames;
+ return true;
+ });
+ const playSound = vi.fn<(sound: AgentIslandSoundChoice) => boolean>(() => true);
+ const service = new AgentIslandService({
+ getMainWindow: () => null,
+ nativeHost: { failed: false, publish, playSound },
+ });
+ service.setSoundSettings({
+ enabled: true,
+ sounds: {
+ ...DEFAULT_AGENT_ISLAND_SOUND_SETTINGS.sounds,
+ error: customSound('error.wav'),
+ },
+ });
+ const meta = { sessionId: 'pre-sync-auto-resume', agentKind: 'claude-code' };
+ service.handleUserPrompt(meta, 'run tests');
+ service.handleAgentEvent(meta, terminalErrorEvent('connection closed before sync'), {
+ suppressErrorSound: true,
+ });
+ service.setEnabled(true);
+
+ expect(playSound).not.toHaveBeenCalled();
+ service.restoreTaskFailureSound(meta.sessionId);
+ expect(playSound).toHaveBeenCalledTimes(1);
+ expect(playSound).toHaveBeenCalledWith(customSound('error.wav'));
+ });
+
it('allows a remote daemon close inside the upgrade window to converge to completed', async () => {
const { AgentIslandService } = await import('../service.js');
const publish = vi.fn((state: AgentIslandDisplayState, frameOrFrames: AgentIslandNativeFrame | AgentIslandNativeFrame[]) => {
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index d7e71b0d6e..c39bbfcee2 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -150,6 +150,11 @@ interface AgentIslandUserPromptDebugMeta {
notifiedAt?: number;
}
+interface AgentIslandEventOptions {
+ /** The host is automatically recovering this failure, so this transition stays silent. */
+ suppressErrorSound?: boolean;
+}
+
export interface AgentIslandServiceDeps {
getMainWindow: () => BrowserWindow | null;
nativeHost?: AgentIslandNativeRenderer;
@@ -242,6 +247,7 @@ export class AgentIslandService {
private readonly silencedRunHadAttention = new Map<string, boolean>();
private readonly silencedRunClearTimers = new Map<string, ReturnType<typeof setTimeout>>();
private readonly mutedCompletionSoundSessionIds = new Set<string>();
+ private readonly mutedErrorSoundSessionIds = new Set<string>();
private readonly stoppedSessionIds = new Set<string>();
private readonly replacementTurnPendingSessionIds = new Set<string>();
private readonly replacementTurnDispatchingSessionIds = new Set<string>();
@@ -509,6 +515,7 @@ export class AgentIslandService {
this.hiddenPublished = false;
if (!wasSynced && !enabled) {
this.mutedCompletionSoundSessionIds.clear();
+ this.mutedErrorSoundSessionIds.clear();
this.clearPublishTimer();
this.hiddenPublished = true;
return;
@@ -559,6 +566,7 @@ export class AgentIslandService {
this.metadataLoading.clear();
this.lastSoundDisplayState = null;
this.soundCooldownUntilByEvent.clear();
+ this.mutedErrorSoundSessionIds.clear();
this.silencedRunSessionIds.clear();
this.silencedSessionRunIds.clear();
this.silencedRunHadAttention.clear();
@@ -605,7 +613,11 @@ export class AgentIslandService {
setAgentIslandAppFocused(this.state, focused, now);
}
- handleAgentEvent(meta: AgentIslandSessionMeta, event: AgentEvent): void {
+ handleAgentEvent(
+ meta: AgentIslandSessionMeta,
+ event: AgentEvent,
+ options: AgentIslandEventOptions = {},
+ ): void {
const hydrated = this.hydrateMeta(meta);
const providerTurnId = providerTurnIdFromAgentEvent(event);
const replacementPending =
@@ -719,9 +731,26 @@ export class AgentIslandService {
return;
}
this.clearStreamingPreviewPublishTimer();
+ if (isTerminalAgentErrorEvent(event) && options.suppressErrorSound === true) {
+ // Keep the mute through the initial enabled-state sync. A sound-capable
+ // publish consumes it immediately; no retry or delivery lifecycle is stored.
+ this.mutedErrorSoundSessionIds.add(hydrated.sessionId);
+ }
this.publish();
}
+ /** Automatic recovery did not start; notify only while the failure still needs attention. */
+ restoreTaskFailureSound(sessionId: string): void {
+ this.mutedErrorSoundSessionIds.delete(sessionId);
+ if (!this.enabledSynced || !this.enabled) return;
+ const now = Date.now();
+ const displayState = buildAgentIslandDisplayState(this.state, now);
+ if (!displayState.visible || displayState.smartSuppressed) return;
+ const session = displayState.sessions.find((candidate) => candidate.sessionId === sessionId);
+ if (!session?.attention || session.phase !== 'error') return;
+ this.playConfiguredSound('error', now);
+ }
+
handleScheduleEvent(event: SchedulerEvent): void {
if (event.type === 'silenced') {
this.markSilencedScheduleRun(event.runId, event.sessionId);
@@ -1255,6 +1284,7 @@ export class AgentIslandService {
next,
this.mutedCompletionSoundSessionIds,
new Set(this.silencedSessionRunIds.keys()),
+ this.mutedErrorSoundSessionIds,
);
if (!event) return;
this.playConfiguredSound(event, now);
@@ -1401,6 +1431,7 @@ export class AgentIslandService {
}
if (!this.enabled) {
this.mutedCompletionSoundSessionIds.clear();
+ this.mutedErrorSoundSessionIds.clear();
this.clearStreamingPreviewPublishTimer();
this.lastSoundDisplayState = withAgentIslandConfig(
buildAgentIslandDisplayState(this.state, now),
@@ -1433,6 +1464,7 @@ export class AgentIslandService {
this.scheduleNextPublish(now);
this.playSoundForDisplayTransition(this.lastSoundDisplayState, displayState, now);
this.mutedCompletionSoundSessionIds.clear();
+ this.mutedErrorSoundSessionIds.clear();
this.lastSoundDisplayState = displayState;
if (this.nativeHost.failed) {
@@ -2173,6 +2205,7 @@ function getAgentIslandSoundEventForTransition(
next: AgentIslandDisplayState,
mutedCompletionSessionIds: ReadonlySet<string> = new Set(),
mutedStartSessionIds: ReadonlySet<string> = new Set(),
+ mutedErrorSessionIds: ReadonlySet<string> = new Set(),
): AgentIslandSoundEvent | null {
const previousById = new Map(previous?.sessions.map((session) => [session.sessionId, session]) ?? []);
for (const session of next.sessions) {
@@ -2182,6 +2215,7 @@ function getAgentIslandSoundEventForTransition(
}
for (const session of next.sessions) {
if (!session.attention || session.phase !== 'error') continue;
+ if (mutedErrorSessionIds.has(session.sessionId)) continue;
const prev = previousById.get(session.sessionId);
if (prev?.phase !== 'error') return 'error';
}
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index feae5347b7..29b7b4008f 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -2222,7 +2222,16 @@ function handleAgentIslandEventAfterBroadcast(
service.deferRemoteAuthRetryError(meta, event);
return;
}
- service.handleAgentEvent(meta, event);
+ const terminalError = event.type === 'error' && isTerminalTurnErrorEvent(event);
+ const suppressErrorSound = terminalError && (
+ agentInputCoordinatorHolder?.isAutoResumePending(session.id) === true ||
+ agentInputCoordinatorHolder?.isAutoResumeDeferred(session.id) === true
+ );
+ service.handleAgentEvent(meta, event, {
+ // The auto-resume decision owns this one failure transition. A later
+ // retry failure is evaluated independently and sounds normally if final.
+ suppressErrorSound,
+ });
} catch (error) {
log.warn('Agent Island event update failed after maker event broadcast', {
sessionId: session.id,
@@ -7745,6 +7754,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
// 被按住的 error 最终没接管 → 只补落 error 行(横幅 coordinator 自己设)。
onResumableTurnErrorDiscarded: (sessionId: string) => {
autoResumeBookkeeping.flushSuppressedError(sessionId);
+ getAgentIslandService()?.restoreTaskFailureSound(sessionId);
},
onResumableTurnError: (sessionId: string, signals: InterruptedTurnErrorSignals) => {
if (!isInterruptedTurnError(signals)) return null;
@@ -7795,6 +7805,9 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
autoResumeBookkeeping.finalizeSuppressedError(sessionId, {
surfaceBanner: outcome === 'no-progress',
});
+ if (outcome === 'no-progress') {
+ getAgentIslandService()?.restoreTaskFailureSound(sessionId);
+ }
log.debug('interrupted-turn auto-resume not dispatched', { sessionId, outcome });
return;
}
@@ -7805,6 +7818,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
interruptedTurnAutoResumeGuard.noteResumeSendFailed(sessionId);
// 补发本身失败 → 回落成常规错误呈现,让用户能手点重试。
autoResumeBookkeeping.finalizeSuppressedError(sessionId, { surfaceBanner: true });
+ getAgentIslandService()?.restoreTaskFailureSound(sessionId);
log.warn('interrupted-turn auto-resume failed', {
sessionId,
error: err instanceof Error ? err.message : String(err),