Skip to content

Commit 0b0a1d9

Browse files
markturanskyuserclaudemergify[bot]
authored
fix(frontend): prevent session polling from stopping permanently after backend errors (#1692)
## Summary - When the backend restarts during session creation, `useSession`'s `refetchInterval` callback receives `undefined` data (query in error state after retries exhausted). The phase-based polling logic falls through to `return false`, permanently stopping polling — the UI gets stuck on "Starting Session" forever. - Adds `if (\!session) return 2000;` early return to keep polling every 2s when data is unavailable, allowing automatic recovery once the backend is reachable. ## Root Cause `refetchInterval` reads `query.state.data` which is `undefined` when the query is in error state. The existing logic only checked phase values (`Running`, `Pending`, etc.), so when phase was `undefined`, the function fell through to `return false` — permanently disabling polling. ## Evidence Backend logs showed ZERO session detail requests after the initial failures — only pod-events requests were reaching the backend. The `SessionStartingEvents` component polls pod-events unconditionally (not gated by React Query's `refetchInterval`), which is why those continued while `useSession` polling stopped. ## Test plan - [x] TypeScript check passes (`npx tsc --noEmit`) - [x] Next.js build passes (`npm run build`) - [ ] Verify on UAT: create a new session while backend is restarting, confirm UI recovers to chat view after backend comes back 🤖 Generated with [Claude Code](https://claude.ai/code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Bug Fixes * Improved session data loading performance by preventing unnecessary computations while session information is still being retrieved. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: user <u@example.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent cbb6023 commit 0b0a1d9

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

components/frontend/src/services/queries/use-sessions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export function useSession(projectName: string, sessionName: string, port: Sessi
8080
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000),
8181
refetchInterval: (query) => {
8282
const session = query.state.data as AgenticSession | undefined;
83+
if (!session) return 2000;
84+
8385
const phase = session?.status?.phase;
8486
const annotations = session?.metadata?.annotations || {};
8587

0 commit comments

Comments
 (0)