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
+13 -5
View File
@@ -1160,8 +1160,12 @@ export class RespawnController extends EventEmitter {
private startDetectionUpdates(): void {
this.stopDetectionUpdates();
this.detectionUpdateTimer = setInterval(() => {
if (this._state !== 'stopped') {
this.emit('detectionUpdate', this.getDetectionStatus());
try {
if (this._state !== 'stopped') {
this.emit('detectionUpdate', this.getDetectionStatus());
}
} catch (err) {
console.error(`[RespawnController] Error in detectionUpdateTimer:`, err);
}
}, 500);
}
@@ -1724,7 +1728,7 @@ export class RespawnController extends EventEmitter {
this.hookConfirmTimer = null;
}
if (this.stuckStateTimer) {
clearTimeout(this.stuckStateTimer);
clearInterval(this.stuckStateTimer);
this.stuckStateTimer = null;
}
// Clear all tracked timers
@@ -1743,7 +1747,7 @@ export class RespawnController extends EventEmitter {
// Clear existing timer
if (this.stuckStateTimer) {
clearTimeout(this.stuckStateTimer);
clearInterval(this.stuckStateTimer);
this.stuckStateTimer = null;
}
@@ -1751,7 +1755,11 @@ export class RespawnController extends EventEmitter {
const checkIntervalMs = Math.min(this.config.stuckStateWarningMs, 60000); // Check every minute max
this.stuckStateTimer = setInterval(() => {
this.checkStuckState();
try {
this.checkStuckState();
} catch (err) {
console.error(`[RespawnController] Error in stuckStateTimer:`, err);
}
}, checkIntervalMs);
}