Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([voice-taskcomplete-announce-once-guard]): announce each terminal task outcome once
[._.]/ Adam Eivy98391a1918b3
diff --git a/server/services/voice/proactiveTriggers.js b/server/services/voice/proactiveTriggers.jsindex ee2f8a902b..d90a49e1fd 100644--- a/server/services/voice/proactiveTriggers.js+++ b/server/services/voice/proactiveTriggers.js@@ -136,6 +136,17 @@ export const wireProactiveTriggers = ({ io, speak = defaultSpeak, limits = RATE_// isolated state and a rewire starts fresh.const lastSpokenAt = new Map();+ // Terminal outcomes already announced, keyed `${taskId}:${status}`. A task's+ // completion line is solicited and fires once at its terminal status, but+ // `updateTask` on an already-terminal voice-dispatched task re-emits+ // `tasks:changed action:'updated'` with the same status — without this guard+ // the spoken line would re-fire on every such re-update. Keying on id+status+ // (not id alone) keeps a DISTINCT outcome announceable: a blocked task later+ // re-dispatched to completed still speaks its success line. Grows only with+ // distinct voice-dispatched task outcomes (human-paced, rare), so no eviction+ // is needed; cleared on unwire.+ const announcedOutcomes = new Set();+// Speak one line, advancing the source's rate-limit bucket. The slot is// reserved BEFORE awaiting `speak`: synthesis is async, so a same-tick burst// of same-source events (an error storm) would otherwise all read the stale@@ -197,6 +208,15 @@ export const wireProactiveTriggers = ({ io, speak = defaultSpeak, limits = RATE_if (status !== 'completed' && status !== 'blocked') return;if (!isMetaTrue(task.metadata?.voiceDispatch)) return;if (status === 'blocked' && task.metadata?.blockedCategory === 'user-terminated') return;+ // Announce each terminal outcome at most once. Checked synchronously (before+ // queueing onto the async tail) so a same-tick duplicate burst of identical+ // events dedups to a single line too. A task without an id (shouldn't happen+ // for real tasks) fails open — better to re-announce than to silently swallow.+ const outcomeKey = task?.id != null ? `${task.id}:${status}` : null;+ if (outcomeKey) {+ if (announcedOutcomes.has(outcomeKey)) return;+ announcedOutcomes.add(outcomeKey);+ }taskCompleteTail = taskCompleteTail.then(async () => {const cfg = await getVoiceConfig();if (cfg?.llm?.codeAgent?.announceOnComplete === false) return;@@ -219,5 +239,6 @@ export const wireProactiveTriggers = ({ io, speak = defaultSpeak, limits = RATE_cosEvents.off('task:ready', onTaskReady);cosEvents.off('tasks:changed', onTaskUpdated);notificationEvents.off('added', onNotification);+ announcedOutcomes.clear();};};diff --git a/server/services/voice/proactiveTriggers.test.js b/server/services/voice/proactiveTriggers.test.jsindex 3c1591ad66..bbe24d8d82 100644--- a/server/services/voice/proactiveTriggers.test.js+++ b/server/services/voice/proactiveTriggers.test.js@@ -335,4 +335,39 @@ describe('wireProactiveTriggers', () => {await flush();expect(speak).not.toHaveBeenCalled();});++ it('announces an already-completed task only once when updated again', async () => {+ unwire = wireProactiveTriggers({ io: {}, speak });+ // A second updateTask() on the same already-completed task re-emits the+ // event with the same terminal status; the once-guard must suppress it.+ cosEvents.emit('tasks:changed', taskUpdate('completed'));+ await flush();+ cosEvents.emit('tasks:changed', taskUpdate('completed', { title: 'now with a PR url' }));+ await flush();+ expect(speak).toHaveBeenCalledTimes(1);+ });++ it('dedups a same-tick duplicate completion burst to one line', async () => {+ unwire = wireProactiveTriggers({ io: {}, speak });+ // Both emit on the same tick (no flush between) — the synchronous guard+ // must dedup before either reaches the async tail.+ cosEvents.emit('tasks:changed', taskUpdate('completed'));+ cosEvents.emit('tasks:changed', taskUpdate('completed'));+ await flush();+ await flush();+ expect(speak).toHaveBeenCalledTimes(1);+ });++ it('still announces a distinct terminal outcome (blocked then completed)', async () => {+ unwire = wireProactiveTriggers({ io: {}, speak });+ // Same task id, different terminal status: a blocked task later re-dispatched+ // to completed is a NEW outcome and must speak its success line.+ cosEvents.emit('tasks:changed', taskUpdate('blocked'));+ await flush();+ cosEvents.emit('tasks:changed', taskUpdate('completed'));+ await flush();+ expect(speak).toHaveBeenCalledTimes(2);+ const priorities = speak.mock.calls.map((c) => c[0].priority);+ expect(priorities).toEqual(['high', 'normal']);+ });});