Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
a25dfc5
1
Parent(s): f0c7e64
fix: reconnect WS on session switch instead of deleting dead sessions
Browse files
frontend/src/components/SessionChat.tsx
CHANGED
|
@@ -38,6 +38,11 @@ export default function SessionChat({ sessionId, isActive, onSessionDead }: Sess
|
|
| 38 |
const prevActiveRef = useRef(isActive);
|
| 39 |
useEffect(() => {
|
| 40 |
if (isActive && !prevActiveRef.current) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
const store = useAgentStore.getState();
|
| 42 |
|
| 43 |
// Sync WebSocket connection state
|
|
|
|
| 38 |
const prevActiveRef = useRef(isActive);
|
| 39 |
useEffect(() => {
|
| 40 |
if (isActive && !prevActiveRef.current) {
|
| 41 |
+
// Force reconnect if WS is dead (e.g. retries exhausted while on another session)
|
| 42 |
+
if (transport && !transport.isWebSocketConnected()) {
|
| 43 |
+
transport.connectToSession(sessionId);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
const store = useAgentStore.getState();
|
| 47 |
|
| 48 |
// Sync WebSocket connection state
|
frontend/src/lib/ws-chat-transport.ts
CHANGED
|
@@ -313,8 +313,7 @@ export class WebSocketChatTransport implements ChatTransport<UIMessage> {
|
|
| 313 |
if (!noRetry.includes(evt.code) && this.currentSessionId === sessionId) {
|
| 314 |
this.retries += 1;
|
| 315 |
if (this.retries > WS_MAX_RETRIES) {
|
| 316 |
-
logger.warn('WS max retries reached');
|
| 317 |
-
this.sideChannel.onSessionDead(sessionId);
|
| 318 |
return;
|
| 319 |
}
|
| 320 |
this.reconnectTimeout = setTimeout(() => {
|
|
|
|
| 313 |
if (!noRetry.includes(evt.code) && this.currentSessionId === sessionId) {
|
| 314 |
this.retries += 1;
|
| 315 |
if (this.retries > WS_MAX_RETRIES) {
|
| 316 |
+
logger.warn('WS max retries reached, will reconnect on session switch');
|
|
|
|
| 317 |
return;
|
| 318 |
}
|
| 319 |
this.reconnectTimeout = setTimeout(() => {
|