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
address review (self): harden voice-timer read path against corrupt store
Adam Eivyb2126f117ece
diff --git a/server/services/voice/timers.js b/server/services/voice/timers.jsindex 368e0b3c68..71e05284bc 100644--- a/server/services/voice/timers.js+++ b/server/services/voice/timers.js@@ -68,9 +68,12 @@ async function fire(timer) {await notify(timer);}-// Arm a Node timer for a still-pending record. Durations are capped at 24h, well-// within setTimeout's max delay. `unref` so a lone pending timer never keeps the-// process (or a test runner) alive on its own.+// Arm a Node timer for a still-pending record. Both callers bound `fireAt` to at+// most MAX_DURATION_MS out (scheduleTimer validates the duration; initVoiceTimers+// drops implausible records), so the delay is always within setTimeout's int32+// max — never the silent clamp-to-1ms-and-fire-now that an overflowing delay+// triggers. `unref` so a lone pending timer never keeps the process (or a test+// runner) alive on its own.function arm(timer) {const delay = Math.max(0, timer.fireAt - Date.now());timer.handle = setTimeout(() => {@@ -122,7 +125,14 @@ export async function initVoiceTimers() {let armed = 0;let fired = 0;for (const rec of list) {- if (!rec || typeof rec.fireAt !== 'number' || typeof rec.label !== 'string') continue;+ // The store is an untrusted read boundary (hand-edited / partial write).+ // `Number.isFinite` rejects NaN/Infinity that `typeof === 'number'` lets+ // through; the upper bound rejects a corrupt far-future `fireAt` — the write+ // path caps every timer at MAX_DURATION_MS out, so anything farther can't be+ // a real timer and must not reach arm() (an overflowing setTimeout delay+ // silently clamps to ~0 and fires a phantom reminder).+ if (!rec || !Number.isFinite(rec.fireAt) || typeof rec.label !== 'string') continue;+ if (rec.fireAt - now > MAX_DURATION_MS) continue;const timer = {id: typeof rec.id === 'string' && rec.id ? rec.id : randomUUID(),label: rec.label,diff --git a/server/services/voice/timers.test.js b/server/services/voice/timers.test.jsindex 5e32d1a35c..d7b36f5a03 100644--- a/server/services/voice/timers.test.js+++ b/server/services/voice/timers.test.js@@ -73,7 +73,7 @@ describe('scheduleTimer', () => {vi.useRealTimers();});- it('dedups a re-issued identical timer but keeps a distinct label / out-of-window one', () => {+ it('dedups a re-issued identical timer but keeps a distinct label / out-of-window one', async () => {vi.useFakeTimers();vi.setSystemTime(new Date('2026-05-26T12:00:00Z'));const a = scheduleTimer({ totalMs: 600000, label: 'tea' });@@ -81,6 +81,12 @@ describe('scheduleTimer', () => {expect(b.deduped).toBe(true);expect(b.id).toBe(a.id);+ // Behavioral effect, not just the return value: the dup must NOT arm or+ // persist a second timer — exactly one 'tea' is on disk.+ await tick(); await tick();+ const snap = atomicWriteMock.mock.calls.at(-1)[1];+ expect(snap.timers.filter((t) => t.label === 'tea')).toHaveLength(1);+// Different label → not a duplicate.expect(scheduleTimer({ totalMs: 600000, label: 'eggs' }).deduped).toBe(false);@@ -102,7 +108,10 @@ describe('initVoiceTimers', () => {timers: [{ id: 'past', label: 'overdue', fireAt: now - 1000, createdAt: now - 600000 },{ id: 'future', label: 'soon', fireAt: now + 300000, createdAt: now },- { id: 'bad', label: 42, fireAt: now + 1000 }, // malformed label → skipped+ { id: 'bad', label: 42, fireAt: now + 1000 }, // malformed label → skipped+ { id: 'nan', label: 'nan', fireAt: Number.NaN }, // NaN fireAt → skipped (not armed-now)+ { id: 'inf', label: 'inf', fireAt: Infinity }, // Infinity fireAt → skipped+ { id: 'huge', label: 'huge', fireAt: now + 40 * 24 * 60 * 60 * 1000 }, // > 24h cap → skipped],};const res = await initVoiceTimers();