diff --git a/src/session-monitor.js b/src/session-monitor.js index ddaad1c..e0f337a 100644 --- a/src/session-monitor.js +++ b/src/session-monitor.js @@ -67,6 +67,15 @@ class SessionMonitor extends EventEmitter { if (this.logger) this.logger.info('SessionMonitor stopped'); } + /** + * Remove a session from known sessions so it can be re-detected on next poll. + * Called when the watcher marks a session as idle/done. + * @param {string} sessionKey + */ + forgetSession(sessionKey) { + this._knownSessions.delete(sessionKey); + } + /** * Get all agent directories under transcriptDir. * @private diff --git a/src/watcher-manager.js b/src/watcher-manager.js index b5a86e0..b334bf7 100644 --- a/src/watcher-manager.js +++ b/src/watcher-manager.js @@ -339,9 +339,10 @@ async function startDaemon() { logger.warn({ sessionKey, err: unpinErr }, 'Failed to unpin status post'); } - // Clean up + // Clean up — remove from all tracking so session can be re-detected if it becomes active again activeBoxes.delete(sessionKey); watcher.removeSession(sessionKey); + monitor.forgetSession(sessionKey); globalMetrics.activeSessions = activeBoxes.size; // Persist final offsets