fix(sessions): handle 401 redirect gracefully in loadSession flow#1460
fix(sessions): handle 401 redirect gracefully in loadSession flow#14602 commits merged intonesquena:masterfrom
Conversation
|
Thanks for catching this — the diagnosis is correct. The One follow-up I'd ask before merge: there's a fourth callsite with the same shape that this PR doesn't touch — async function _ensureAllMessagesLoaded() {
if (!_messagesTruncated || !S.session) return;
const sid = S.session.session_id;
const data = await api(`/api/session?session_id=...&messages=1&resolve_model=0`);
const msgs = (data.session.messages || []).filter(m => m && m.role); // ← same crash
...
}This one is called from undo / export / context-restore paths. Less common than (The Other than that the patch is good. The early-return on |
When the webui auth session expires (e.g., after a server restart), api() returns undefined after redirecting to /login. Previously, loadSession() and _ensureMessagesLoaded() would dereference the undefined response and throw, surfacing a confusing 'Failed to load session' toast while the browser was already navigating away. Add guards after api() calls that may trigger 401 redirects: - loadSession(): bail early if data is undefined - _ensureMessagesLoaded(): return silently if data is missing - _loadOlderMessages(): return silently if data is missing This prevents the stuck loading state and unnecessary error toasts when the user is already being redirected to re-authenticate. Fixes nesquena#1391 (reported as 'Failed to load session' after restart)
91a861c to
22fce2f
Compare
|
Thanks for the follow-up commit —
LGTM on my end. Leaving final merge call to the maintainer. |
…le action when desktop chip hidden
|
Thanks for the follow-up commit // Before
if(!dd||!chip||!footer) return;
const anchor=(panel&&panel.classList.contains('open')&&mobileAction)?mobileAction:chip;
// After
if(!dd||!footer) return;
const anchor=(panel&&panel.classList.contains('open')&&mobileAction)?mobileAction:(chip&&chip.offsetParent?chip:mobileAction);
if(!anchor) return;The reasoning is sound: on mobile breakpoints Two small concerns:
The only thing I'd ask is a comment explaining why the chip might be invisible — the // On mobile, #composerModelChip is display:none and #composerMobileModelAction
// is the visible target. offsetParent===null detects the hidden state cheaply
// (display:none returns null, visible returns ancestor).Scope concernThis commit is unrelated to the 401-redirect fix in
Otherwise the original Verdict on the original fixThe If you (a) split the dropdown fix into its own PR or (b) update the title/body to cover both, I'd merge. |
5650d11
…w-up - CHANGELOG.md: v0.50.267 entry detailing nesquena#1454/nesquena#1474/nesquena#1461/nesquena#1465/nesquena#1467/nesquena#1460/nesquena#1473 + Opus advisor SHOULD-FIX trailing-empty guard for _norm_model_id - ROADMAP.md: bump to v0.50.267, 3776 tests collected - TESTING.md: bump header + total to 3776 - api/config.py: trailing-empty fallback in _norm_model_id (parts[-1] or s) - static/ui.js: mirror trailing-empty fallback in _normalizeConfiguredModelKey - tests/test_norm_model_id_trailing_empty_guard.py: 5 regression tests
Problem
When the webui auth session expires (e.g., after a server restart), all API calls return 401. The
api()helper correctly redirects to/loginviawindow.location.href, but the calling code inloadSession(),_ensureMessagesLoaded(), and_loadOlderMessages()continues executing with anundefinedresponse. This causes:undefined(data.session)Changes
Add early-return guards after
api()calls that may trigger 401 redirects:loadSession(): bail early ifdatais undefined_ensureMessagesLoaded(): return silently if data is missing_loadOlderMessages(): return silently if data is missingThis prevents the stuck loading state and unnecessary error toasts when the user is already being redirected to re-authenticate.
Tested
Fixes the "Failed to load session" error reported after service restart.