Commit 0b0a1d9
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
| |||
0 commit comments