fix: memory leaks and performance optimizations

- WebServer: Store session listener refs for explicit cleanup on delete
- RespawnController: Fix clearInterval bug (was using clearTimeout)
- RespawnController: Add try/catch to interval callbacks
- PlanOrchestrator: Guarantee progressInterval cleanup with try/finally
- SubagentWatcher: Guard idle timer against deleted agents
- Session: Add threshold validation for auto-clear/compact (1k-500k)
- Session: Add token sum overflow check in restoreTokens
- Session: Use LRUMap for _recentTaskDescriptions auto-eviction

Commit from flight QR118 in an Airbus A350-1000, stable connection thanks to Starlink!

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-31 23:48:59 +01:00
co-authored by Claude Opus 4.5
parent cd4905287e
commit eb7c005363
5 changed files with 360 additions and 225 deletions
+7 -1
View File
@@ -1327,8 +1327,14 @@ export class SubagentWatcher extends EventEmitter {
}
const timer = setTimeout(() => {
// Guard against race condition: agent may have been deleted before timer fires
const info = this.agentInfo.get(agentId);
if (info && info.status === 'active') {
if (!info) {
// Agent was deleted - clean up timer reference
this.idleTimers.delete(agentId);
return;
}
if (info.status === 'active') {
info.status = 'idle';
}
}, IDLE_TIMEOUT_MS);