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
refactor([voice-tool-edge-hardening]): reuse createFileWriteQueue, drop unused force flag
Adam Eivy0f4e5c99c5ee
diff --git a/server/services/voice/timers.js b/server/services/voice/timers.jsindex 9f4d25b4ac..368e0b3c68 100644--- a/server/services/voice/timers.js+++ b/server/services/voice/timers.js@@ -12,6 +12,7 @@import { randomUUID } from 'crypto';import { join } from 'path';import { PATHS, atomicWrite, readJSONFile } from '../../lib/fileUtils.js';+import { createFileWriteQueue } from '../../lib/fileWriteQueue.js';import { addNotification, NOTIFICATION_TYPES, PRIORITY_LEVELS } from '../notifications.js';const STORE_PATH = join(PATHS.data, 'voice-timers.json');@@ -31,16 +32,16 @@ const DEDUP_WINDOW_MS = 10_000;const active = new Map();// Serialize snapshot writes onto a single tail so a fire and a schedule can't-// clobber each other's atomicWrite.-let writeTail = Promise.resolve();+// clobber each other's atomicWrite. The snapshot is taken synchronously at call+// time; only the write is deferred onto the queue.+const queueWrite = createFileWriteQueue();function persist() {const timers = [...active.values()].map(({ handle, ...rec }) => rec);- writeTail = writeTail.then(() =>+ return queueWrite(() =>atomicWrite(STORE_PATH, { version: 1, timers }).catch((err) =>console.error(`❌ voice-timer persist failed: ${err.message}`)));- return writeTail;}// Raise the reminder. Runs outside the request lifecycle, so the write is@@ -112,8 +113,8 @@ let initialized = false;* fire immediately (once); the rest re-arm for their remaining delay. The store* is then rewritten with only the still-pending timers.*/-export async function initVoiceTimers({ force = false } = {}) {- if (initialized && !force) return { skipped: true };+export async function initVoiceTimers() {+ if (initialized) return { skipped: true };initialized = true;const stored = await readJSONFile(STORE_PATH, { version: 1, timers: [] });const list = Array.isArray(stored?.timers) ? stored.timers : [];diff --git a/server/services/voice/timers.test.js b/server/services/voice/timers.test.jsindex 71dfe71736..5e32d1a35c 100644--- a/server/services/voice/timers.test.js+++ b/server/services/voice/timers.test.js@@ -54,7 +54,7 @@ describe('scheduleTimer', () => {vi.useFakeTimers();vi.setSystemTime(new Date('2026-05-26T12:00:00Z'));scheduleTimer({ totalMs: 600000, label: 'tea' });- await tick(); // let the schedule's persist() write run+ await tick(); await tick(); // let the schedule's queued persist() write runconst afterSchedule = atomicWriteMock.mock.calls.at(-1)[1];expect(afterSchedule.timers).toHaveLength(1);expect(afterSchedule.timers[0]).toMatchObject({ label: 'tea' });@@ -105,7 +105,7 @@ describe('initVoiceTimers', () => {{ id: 'bad', label: 42, fireAt: now + 1000 }, // malformed label → skipped],};- const res = await initVoiceTimers({ force: true });+ const res = await initVoiceTimers();expect(res).toEqual({ armed: 1, fired: 1 });expect(addNotificationMock).toHaveBeenCalledWith(expect.objectContaining({ title: '⏰ overdue' }));@@ -120,7 +120,7 @@ describe('initVoiceTimers', () => {vi.useRealTimers();});- it('is idempotent unless forced', async () => {+ it('is idempotent — a second init is skipped', async () => {const first = await initVoiceTimers();expect(first).toEqual({ armed: 0, fired: 0 });const second = await initVoiceTimers();