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

address review (codex): dedup duplicate ids in boot re-arm via seen-set

Adam Eivy4e6d0b1accdf
diff --git a/server/services/voice/timers.js b/server/services/voice/timers.js
index e9444b32b5..3a86ec4113 100644
--- a/server/services/voice/timers.js
+++ b/server/services/voice/timers.js
@@ -124,6 +124,7 @@ export async function initVoiceTimers() {
const now = Date.now();
let armed = 0;
let fired = 0;
+ const seen = new Set(); // ids already handled this init (dedup a corrupt store)
for (const rec of list) {
// The store is an untrusted read boundary (hand-edited / partial write).
// `Number.isFinite` rejects NaN/Infinity that `typeof === 'number'` lets
@@ -139,12 +140,15 @@ export async function initVoiceTimers() {
fireAt: rec.fireAt,
createdAt: typeof rec.createdAt === 'number' ? rec.createdAt : now,
};
- // A timer already live in memory is authoritative — it was scheduled
- // post-boot (during init's async read; routes are up before this
- // fire-and-forget init settles) OR is a duplicate id in a corrupt store.
- // Skip the persisted copy entirely so we neither re-fire it as overdue nor
- // arm a second handle for it (both would double-notify).
- if (active.has(timer.id)) continue;
+ // Skip a record already handled, so it can't double-notify:
+ // - `active.has` — a timer_set scheduled post-boot (during init's async
+ // read; routes are up before this fire-and-forget init settles) is live
+ // in memory and authoritative.
+ // - `seen.has` — a duplicate id earlier in a corrupt/hand-edited store.
+ // `active` alone misses this when the records are OVERDUE, since overdue
+ // timers fire-and-drop without being added to `active`.
+ if (active.has(timer.id) || seen.has(timer.id)) continue;
+ seen.add(timer.id);
if (timer.fireAt <= now) {
// Overdue — notify once. Not added to `active`, so the post-loop persist
// drops it from the store.
diff --git a/server/services/voice/timers.test.js b/server/services/voice/timers.test.js
index 2ebeeadd8f..596157a262 100644
--- a/server/services/voice/timers.test.js
+++ b/server/services/voice/timers.test.js
@@ -129,6 +129,23 @@ describe('initVoiceTimers', () => {
vi.useRealTimers();
});
+ it('does not double-notify on duplicate ids in a corrupt store (both overdue)', async () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date('2026-05-26T12:00:00Z'));
+ const now = Date.now();
+ storeRef.value = {
+ version: 1,
+ timers: [
+ { id: 'dup', label: 'dup', fireAt: now - 1000, createdAt: now },
+ { id: 'dup', label: 'dup', fireAt: now - 2000, createdAt: now }, // duplicate overdue id
+ ],
+ };
+ const res = await initVoiceTimers();
+ expect(res).toEqual({ armed: 0, fired: 1 }); // fired once, not twice
+ expect(addNotificationMock).toHaveBeenCalledTimes(1);
+ vi.useRealTimers();
+ });
+
it('is idempotent — a second init is skipped', async () => {
const first = await initVoiceTimers();
expect(first).toEqual({ armed: 0, fired: 0 });