fix: graceful degradation when API calls fail in root layout#2184
fix: graceful degradation when API calls fail in root layout#2184tessaherself wants to merge 2 commits intohuggingface:mainfrom
Conversation
The root layout currently crashes the entire app shell if any API call fails (e.g., expired session returns 302/401). This replaces the hard crash with graceful fallbacks for auth-dependent calls (settings, models, user, feature-flags, conversations) while keeping public-config as a hard requirement since it's needed to render anything. Each swallowed error is logged via console.warn for debugging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e12a7cd2f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| withFallback( | ||
| client.user.settings.get().then(handleResponse), | ||
| { | ||
| welcomeModalSeen: false, | ||
| welcomeModalSeenAt: null, |
There was a problem hiding this comment.
Avoid persisting synthetic settings after read failures
If client.user.settings.get() fails transiently (for example a timeout or 5xx while the user is still authenticated), this fallback injects a complete default settings object and the app continues; later, any settings write via setSettings/instantSet posts the entire store (src/lib/stores/settings.ts), which can silently overwrite real server-side preferences (including sharing opt-in, active model, and custom prompts) with these defaults. This introduces a user-data regression that did not exist when the load failed fast.
Useful? React with 👍 / 👎.
When settings API call fails transiently, mark the resulting defaults as fallback and skip all server POST calls so they never overwrite real user preferences. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
withFallback()so the root layout doesn't crash on session expiry or API failurespublic-configas a hard requirement (needed to render anything)console.warnfor debuggingInternal Errorwhen expired session causes 302/401 on/api/v2/modelsProblem
When a user's session expires mid-navigation, API calls in
+layout.tsfail with 302/401. Since all calls are in aPromise.allwith no error handling, a single failure crashes the entire app shell with an unhelpful "Internal Error" page.Changes
src/routes/+layout.ts: AddwithFallback<T>()helper, wrap auth-dependent calls with safe defaultsTest plan
🤖 Generated with Claude Code