fix: high severity memory leaks and bugs

- Add warningTimer to AgentContext and clean it up in cleanupAgent
- Clear all state in subagent-watcher stop() for clean restart
- Add cleanupStaleAgents() to remove completed agents older than 24h
- Delete pendingToolCalls entries after lookup to prevent memory leak
- Add FSWatcher error handlers to prevent unhandled exceptions
- Bump version to 0.1382

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-26 12:50:39 +01:00
co-authored by Claude Opus 4.5
parent fe334c2ea6
commit e81dc4665a
5 changed files with 65 additions and 6 deletions
+7 -2
View File
@@ -545,6 +545,7 @@ export class SpawnOrchestrator extends EventEmitter {
parentSessionId: task.parentSessionId,
depth: task.depth,
timeoutTimer: null,
warningTimer: null,
progressTimer: null,
status: 'initializing',
startedAt: null,
@@ -688,9 +689,9 @@ export class SpawnOrchestrator extends EventEmitter {
private setupTimeout(agent: AgentContext): void {
const timeoutMs = agent.task.spec.timeoutMinutes * 60 * 1000;
// Warning at 90%
// Warning at 90% - store timer for cleanup
const warningMs = timeoutMs * 0.9;
setTimeout(() => {
agent.warningTimer = setTimeout(() => {
if (agent.status === 'running' && this._sessionCreator && agent.sessionId) {
this._sessionCreator.writeToSession(
agent.sessionId,
@@ -818,6 +819,10 @@ export class SpawnOrchestrator extends EventEmitter {
clearTimeout(agent.timeoutTimer);
agent.timeoutTimer = null;
}
if (agent.warningTimer) {
clearTimeout(agent.warningTimer);
agent.warningTimer = null;
}
if (agent.progressTimer) {
clearInterval(agent.progressTimer);
agent.progressTimer = null;