diff --git a/frontend/src/hooks/useSSE.ts b/frontend/src/hooks/useSSE.ts index cbfa5c1c..d8999b80 100644 --- a/frontend/src/hooks/useSSE.ts +++ b/frontend/src/hooks/useSSE.ts @@ -39,7 +39,7 @@ const handleRestartServer = async () => { } -export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) => { +export const useSSE = (opcodeUrl: string | null | undefined, directory?: string, currentSessionId?: string) => { const client = useOpenCodeClient(opcodeUrl, directory) const queryClient = useQueryClient() const mountedRef = useRef(true) @@ -292,6 +292,7 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) case 'session.error': { if (!('error' in event.properties)) break + if ('sessionID' in event.properties && event.properties.sessionID === currentSessionId) break const parsed = parseOpenCodeError(event.properties.error) if (parsed) { @@ -306,7 +307,7 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) default: break } - }, [queryClient, opcodeUrl, directory, setSessionStatus, setSessionTodos]) + }, [queryClient, opcodeUrl, directory, setSessionStatus, setSessionTodos, currentSessionId]) const fetchInitialData = useCallback(async () => { if (!client || !mountedRef.current) return diff --git a/frontend/src/pages/SessionDetail.tsx b/frontend/src/pages/SessionDetail.tsx index 0a64d3c5..1b97741e 100644 --- a/frontend/src/pages/SessionDetail.tsx +++ b/frontend/src/pages/SessionDetail.tsx @@ -112,7 +112,7 @@ export function SessionDetail() { onScrollStateChange: setShowScrollButton }); - const { isConnected, isReconnecting } = useSSE(opcodeUrl, repoDirectory); + const { isConnected, isReconnecting } = useSSE(opcodeUrl, repoDirectory, sessionId); const abortSession = useAbortSession(opcodeUrl, repoDirectory, sessionId); const updateSession = useUpdateSession(opcodeUrl, repoDirectory); const createSession = useCreateSession(opcodeUrl, repoDirectory);