fix(chat): isolate concurrent session events by refactoring WebSocket event handling (#365)

Refactored the WebSocket event handling mechanism to use global listeners with session-specific event routing instead of per-session listeners. This prevents event cross-talk when multiple chat sessions run concurrently.

Key changes:
- Client: Added sessionEventHandlers Map to route events to appropriate sessions
- Client: Registered global listeners once per socket connection
- Server: Extracted message processing logic into handleMessage method
- Server: Improved Hermes session ID tracking with dedicated Map
- Server: Added replaceByHermesSessionId for targeted message replacement

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-05-01 08:13:55 +08:00
committed by GitHub
parent 7f01fdf56e
commit f15deef3fc
4 changed files with 560 additions and 390 deletions
@@ -421,6 +421,7 @@ export function updateSessionStats(id: string): void {
last_active = COALESCE((SELECT MAX(timestamp) FROM ${MESSAGES_TABLE} WHERE session_id = ?), started_at)
WHERE id = ?`,
).run(id, id, id)
console.log(`Updated session ${id} stats`)
}
export function getSessionDetailPaginated(