Skip to content

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

fix([voice-taskcomplete-announce-once-guard]): roll back the announce-once guard when no line goes out

[._.]/ Adam Eivybc216309e4c1
diff --git a/server/services/voice/proactiveTriggers.js b/server/services/voice/proactiveTriggers.js
index d90a49e1fd..ecc6908a2c 100644
--- a/server/services/voice/proactiveTriggers.js
+++ b/server/services/voice/proactiveTriggers.js
@@ -142,9 +142,13 @@ export const wireProactiveTriggers = ({ io, speak = defaultSpeak, limits = RATE_
// `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.
+ // re-dispatched to completed still speaks its success line. The key is
+ // RESERVED synchronously (so a same-tick / in-flight duplicate dedups) but
+ // rolled BACK if no line actually went out — config-disabled, quiet-hours,
+ // voice-disabled, or a TTS failure — mirroring `dispatch`'s rate-limit slot,
+ // so a later legitimate re-update can still announce. 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
@@ -155,11 +159,12 @@ export const wireProactiveTriggers = ({ io, speak = defaultSpeak, limits = RATE_
// that goes out; on suppression/failure/throw we roll it back (unless a later
// event already claimed the slot) so the budget isn't spent on a non-line.
// try/finally only — a synthesis rejection still propagates to the caller's
- // catch.
+ // catch. Returns whether a line actually went out, so callers with their own
+ // once-guards (task-complete) can roll those back on suppression too.
const dispatch = async (source, text, priority, { solicited = false } = {}) => {
- if (!text) return;
+ if (!text) return false;
const now = Date.now();
- if (!allowBySource(source, lastSpokenAt.get(source), now, limits)) return;
+ if (!allowBySource(source, lastSpokenAt.get(source), now, limits)) return false;
const previous = lastSpokenAt.get(source) ?? null;
lastSpokenAt.set(source, now);
let ok = false;
@@ -169,6 +174,7 @@ export const wireProactiveTriggers = ({ io, speak = defaultSpeak, limits = RATE_
} finally {
if (!ok && lastSpokenAt.get(source) === now) lastSpokenAt.set(source, previous);
}
+ return ok;
};
// EventEmitter doesn't await async listeners, so a rejected dispatch would
@@ -208,20 +214,27 @@ 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.
+ // Reserve this terminal outcome synchronously (before queueing onto the
+ // async tail) so a same-tick / in-flight duplicate dedups to one line. The
+ // reservation is rolled back inside the tail if no line went out (config
+ // off, quiet hours, voice off, TTS failure) so a later legitimate re-update
+ // can still announce. 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;
- const priority = status === 'completed' ? 'normal' : 'high';
- await dispatch('task-complete', formatTaskCompletionLine(task), priority, { solicited: true });
+ let spoke = false;
+ try {
+ const cfg = await getVoiceConfig();
+ if (cfg?.llm?.codeAgent?.announceOnComplete === false) return;
+ const priority = status === 'completed' ? 'normal' : 'high';
+ spoke = await dispatch('task-complete', formatTaskCompletionLine(task), priority, { solicited: true });
+ } finally {
+ if (!spoke && outcomeKey) announcedOutcomes.delete(outcomeKey);
+ }
}).catch((err) =>
console.error(`🔕 voice: proactive task-complete trigger failed: ${err?.message || err}`),
);
diff --git a/server/services/voice/proactiveTriggers.test.js b/server/services/voice/proactiveTriggers.test.js
index bbe24d8d82..ce0e3d808d 100644
--- a/server/services/voice/proactiveTriggers.test.js
+++ b/server/services/voice/proactiveTriggers.test.js
@@ -370,4 +370,34 @@ describe('wireProactiveTriggers', () => {
const priorities = speak.mock.calls.map((c) => c[0].priority);
expect(priorities).toEqual(['high', 'normal']);
});
+
+ it('rolls back the once-guard when the line was suppressed (ok:false), so a re-update re-announces', async () => {
+ // First completion is suppressed downstream (quiet hours / voice off): the
+ // outcome must NOT be marked announced, so a later identical re-update can
+ // still speak it once the suppression clears.
+ speak = vi.fn(async () => ({ ok: false, reason: 'quiet-hours' }));
+ unwire = wireProactiveTriggers({ io: {}, speak });
+ cosEvents.emit('tasks:changed', taskUpdate('completed'));
+ await flush();
+ expect(speak).toHaveBeenCalledTimes(1);
+
+ speak.mockResolvedValue({ ok: true });
+ cosEvents.emit('tasks:changed', taskUpdate('completed'));
+ await flush();
+ expect(speak).toHaveBeenCalledTimes(2);
+ });
+
+ it('rolls back the once-guard when announceOnComplete is off, so re-enabling re-announces', async () => {
+ getVoiceConfig.mockResolvedValue({ enabled: true, llm: { codeAgent: { announceOnComplete: false } } });
+ unwire = wireProactiveTriggers({ io: {}, speak });
+ cosEvents.emit('tasks:changed', taskUpdate('completed'));
+ await flush();
+ expect(speak).not.toHaveBeenCalled();
+
+ // User re-enables completion announcements; a later re-update now speaks.
+ getVoiceConfig.mockResolvedValue({ enabled: true, llm: { codeAgent: { announceOnComplete: true } } });
+ cosEvents.emit('tasks:changed', taskUpdate('completed'));
+ await flush();
+ expect(speak).toHaveBeenCalledTimes(1);
+ });
});