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: add fallback polling for completion sentinels
[._.]/ Adam Eivy531576dfa905
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.jsindex 56d204c2d2..d69b780fd7 100644--- a/server/lib/fileUtils.js+++ b/server/lib/fileUtils.js@@ -38,14 +38,16 @@ const WIN_RETRY_DELAY_MS = 10;const WIN_RENAME_LOCK_CODES = ['EPERM', 'EACCES', 'EEXIST'];// read failures with the same transient meaning on the reader side.const WIN_READ_LOCK_CODES = ['EPERM', 'EACCES', 'EBUSY'];+const FILE_WATCH_FALLBACK_POLL_MS = 5000;/** Watch for a file to appear without repeatedly stat'ing its parent directory. */-export function watchForFile(filePath, onDetected, { settleMs = 50 } = {}) {+export function watchForFile(filePath, onDetected, { settleMs = 50, pollMs = FILE_WATCH_FALLBACK_POLL_MS } = {}) {const targetName = basename(filePath);const targetDir = dirname(filePath);let closed = false;let detected = false;let settleTimer = null;+ let pollTimer = null;const notify = () => {Promise.resolve(onDetected()).catch((err) => {@@ -56,6 +58,7 @@ export function watchForFile(filePath, onDetected, { settleMs = 50 } = {}) {if (closed) return;closed = true;if (settleTimer) clearTimeout(settleTimer);+ if (pollTimer) clearInterval(pollTimer);if (onClosed) watcher.once('close', onClosed);watcher.close();};@@ -75,6 +78,10 @@ export function watchForFile(filePath, onDetected, { settleMs = 50 } = {}) {const watcher = watchFileSystem(targetDir, (_eventType, changedName) => {if (changedName == null || changedName.toString() === targetName) detect();});+ // fs.watch is low-latency but best-effort: native backends can miss a file+ // creation or atomic rename. Keep a deliberately relaxed fallback so a+ // missed event cannot strand an agent indefinitely.+ pollTimer = setInterval(() => detect(), pollMs);detect(false);return close;}diff --git a/server/lib/fileUtils.test.js b/server/lib/fileUtils.test.jsindex ae95b34944..46c861a03a 100644--- a/server/lib/fileUtils.test.js+++ b/server/lib/fileUtils.test.js@@ -1627,10 +1627,10 @@ describe('watchForFile', () => {// after a watched temp directory is removed, even after FSWatcher emits// `close`. Linux covers the native integration; agentTuiSpawning tests cover// the close-event and process-exit races with a platform-neutral watcher.- it.skipIf(process.platform === 'win32')('detects a newly written file without interval polling', async () => {+ it.skipIf(process.platform === 'win32')('detects a newly written file with the event watcher and fallback poll', async () => {const dir = mkdtempSync(join(tmpdir(), 'watch-file-test-'));const target = join(dir, 'done.sentinel');- const detected = new Promise((resolve) => watchForFile(target, resolve, { settleMs: 0 }));+ const detected = new Promise((resolve) => watchForFile(target, resolve, { settleMs: 0, pollMs: 10 }));await new Promise((resolve) => setImmediate(resolve));await writeFile(target, 'done');await expect(detected).resolves.toBeUndefined();