fix(worker): gracefully process orphaned pending messages after session termination

This commit is contained in:
jayvenn21
2026-02-04 15:40:10 -05:00
committed by Alex Newman
parent 1a1297c12a
commit f24bba21e9
3 changed files with 125 additions and 3 deletions
+22
View File
@@ -318,6 +318,28 @@ export class SessionManager {
}
}
/**
* Remove session from in-memory maps and notify without awaiting generator.
* Used when SDK resume fails and we give up (no fallback): avoids deadlock
* from deleteSession() awaiting the same generator promise we're inside.
*/
removeSessionImmediate(sessionDbId: number): void {
const session = this.sessions.get(sessionDbId);
if (!session) return;
this.sessions.delete(sessionDbId);
this.sessionQueues.delete(sessionDbId);
logger.info('SESSION', 'Session removed (orphaned after SDK termination)', {
sessionId: sessionDbId,
project: session.project
});
if (this.onSessionDeletedCallback) {
this.onSessionDeletedCallback();
}
}
/**
* Shutdown all active sessions
*/