From 3842adf5620e4777290db7511a1be9f211be8f33 Mon Sep 17 00:00:00 2001 From: sol Date: Mon, 9 Mar 2026 15:53:53 +0000 Subject: [PATCH] fix: ghost-watch reactivation for consistent session restart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: after a session completes, removeSession() deleted the file→session mapping. When the next user message caused the JSONL to be written, fs.watch fired but fileToSession returned undefined — silently dropped. Reactivation only happened on the next session-monitor poll (up to 2s later), and by then the watcher had missed the first lines of the new turn. Fix: - removeSession() keeps the file in fileToSession as a ghost marker - fs.watch fires → ghost detected → emit 'session-reactivate' - watcher-manager clears completedSessions cooldown + calls pollNow() - session-monitor re-detects immediately with no poll lag - Ghost removed after first fire (one-shot) Also adds SessionMonitor.pollNow() for forced immediate polling. --- src/session-monitor.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/session-monitor.js b/src/session-monitor.js index 41ff3fd..6272e0e 100644 --- a/src/session-monitor.js +++ b/src/session-monitor.js @@ -108,6 +108,14 @@ class SessionMonitor extends EventEmitter { this._completedSessions.delete(sessionKey); } + /** + * Trigger an immediate poll without waiting for the next interval tick. + * Used by ghost-watch reactivation to avoid up to pollMs latency. + */ + pollNow() { + this._poll(); + } + /** * Get all agent directories under transcriptDir. * @private