Repository navigation
Fix cold start loading hang on Desktop/iOS - #484
Conversation
Close auth timing race condition where CenterPanel mounts and SWR fires before loadSession() can block the UI, causing hung requests on Desktop (IPC) and iOS (Keychain) platforms. Changes: - Set initial isLoading to true in auth store (not persisted, so only affects cold starts) to prevent premature CenterPanel mount - Add else branch in useAuth to explicitly clear isLoading when no session check is needed, unblocking the UI - Add 3s timeout to bearer token retrieval in fetchWithAuth as safety net against hung IPC/Keychain calls - Set session cookie for iOS in mobile login and device refresh routes (matching existing desktop behavior) - Add appendSessionCookie to mobile refresh response - Add SWR error retry config to useBreadcrumbs (errorRetryCount: 3) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughThis PR extends iOS device support in authentication flows to match desktop behavior, adds a timeout mechanism for token retrieval to prevent hangs on cold starts, improves error handling with SWR retry configuration, and adjusts UI loading state initialization to ensure proper UI unblocking. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/web/src/lib/auth/auth-fetch.ts`:
- Around line 924-943: The getSessionTokenWithTimeout function currently starts
a setTimeout that logs a warning but never clears it, causing false timeout
warnings when tokenPromise resolves first; update getSessionTokenWithTimeout to
store the timer id (from setTimeout), and when tokenPromise resolves or rejects
first clearTimeout(timerId) before returning the token (or null), ensuring the
timeout callback is canceled; keep use of TOKEN_RETRIEVAL_TIMEOUT_MS and ensure
both branches (this.getSessionFromElectron() and storage.getSessionToken()) are
wrapped so clearing the timer happens on success or failure to avoid spurious
logs.
The session cookie should only be set for desktop and iOS platforms (which need it for Next.js middleware), not unconditionally for all platforms including Android. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevents orphaned setTimeout when the token promise wins the race in getSessionTokenWithTimeout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Add missing appendSessionCookie mock to @/lib/auth in mobile-refresh tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Root Cause
On cold start, there's a 1-render window where CenterPanel mounts and SWR fires BEFORE
loadSession()can setisLoading=trueand unmount it. On web this is harmless (cookies are synchronous), but on Desktop/iOS thefetchWithAuthawaits IPC/Keychain with no timeout — hanging forever.Changes
stores/useAuthStore.tsisLoading: true(not persisted — only affects cold starts)hooks/useAuth.tssetLoading(false)when no session check neededlib/auth/auth-fetch.tsgetSessionTokenWithTimeout()with 3s timeout for bearer token retrievalapi/auth/mobile/login/route.tsapi/auth/mobile/refresh/route.tsappendSessionCookieto responseapi/auth/device/refresh/route.tshooks/useBreadcrumbs.tserrorRetryCount: 3,errorRetryInterval: 2000to SWR configTest plan
Set-Cookie: session=...🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Improvements