fix: stream opencode reasoning updates (#661)

Emit throttled ACP reasoning snapshots with stable stream ids so OpenCode reasoning updates render live without one row per token.

Collapse matching reasoning snapshots in the web timeline and avoid stale session 404 redirects during refetch.

Tests: targeted Vitest suite and bun typecheck.

Co-authored-by: twshe <twshe@outlook.com>
This commit is contained in:
Taine Zhao
2026-05-22 08:57:50 +08:00
committed by GitHub
co-authored by twshe
parent 5b90a48b33
commit b06251bd53
15 changed files with 369 additions and 32 deletions
+13
View File
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest'
import { isSessionNotFoundError } from './useSession'
describe('isSessionNotFoundError', () => {
it('matches hub 404 session responses', () => {
expect(isSessionNotFoundError(new Error('HTTP 404 Not Found: {"error":"Session not found"}'))).toBe(true)
})
it('does not match unrelated errors', () => {
expect(isSessionNotFoundError(new Error('HTTP 500 Internal Server Error'))).toBe(false)
expect(isSessionNotFoundError(null)).toBe(false)
})
})
+13
View File
@@ -3,10 +3,16 @@ import type { ApiClient } from '@/api/client'
import type { Session } from '@/types/api'
import { queryKeys } from '@/lib/query-keys'
export function isSessionNotFoundError(error: unknown): boolean {
return error instanceof Error
&& (error.message.includes('HTTP 404') || error.message.includes('Session not found'))
}
export function useSession(api: ApiClient | null, sessionId: string | null): {
session: Session | null
isLoading: boolean
error: string | null
notFound: boolean
refetch: () => Promise<unknown>
} {
const resolvedSessionId = sessionId ?? 'unknown'
@@ -19,12 +25,19 @@ export function useSession(api: ApiClient | null, sessionId: string | null): {
return await api.getSession(sessionId)
},
enabled: Boolean(api && sessionId),
retry: (failureCount, error) => {
if (isSessionNotFoundError(error)) {
return false
}
return failureCount < 2
},
})
return {
session: query.data?.session ?? null,
isLoading: query.isLoading,
error: query.error instanceof Error ? query.error.message : query.error ? 'Failed to load session' : null,
notFound: isSessionNotFoundError(query.error) && !query.isFetching,
refetch: query.refetch,
}
}