fix: graceful ctrl+c shutdown and await session-end memory writes

This commit is contained in:
William Valentin
2026-02-18 11:30:47 -08:00
parent 55cde541ea
commit 21232748b9
6 changed files with 103 additions and 30 deletions
+11 -9
View File
@@ -53,7 +53,7 @@ export class SessionBridge {
}
/** Remove a WS connection. Does NOT destroy the session (persists in SQLite). */
disconnect(connectionId: string): void {
async disconnect(connectionId: string): Promise<void> {
const client = this.clients.get(connectionId);
if (client) {
// Only remove the agent if no other clients share the session
@@ -73,15 +73,17 @@ export class SessionBridge {
writeToMemory: summaryConfig.write_to_memory,
memoryNamespace: summaryConfig.memory_namespace,
};
void summarizeSessionOnEnd({
agent,
sessionId: client.sessionId,
history,
config: mappedConfig,
memoryStore: this.config.memoryStore,
}).catch((error) => {
try {
await summarizeSessionOnEnd({
agent,
sessionId: client.sessionId,
history,
config: mappedConfig,
memoryStore: this.config.memoryStore,
});
} catch (error) {
console.warn('Session end summary failed:', error);
});
}
}
this.agents.delete(client.sessionId);
}