Bugfix: Clicking a backend-sourced session in the Vitto chat sidebar...
Documentation for Sessions
🐛 Bugfix: Clicking a backend-sourced session in the Vitto chat sidebar...
Date: 2026-02-21
Time: 22:03:02 UTC
Session: gspace1-133.20
Agent: angular
Confidence: 97%
Status: ✅ Documented
📋 Decision Context
Question:
Clicking a backend-sourced session in the Vitto chat sidebar does nothing — the active session does not switch. The user sees the session list (loaded from /ai-api/sessions) but clicking any item has no visible effect.
Task: Fix session switching in Vitto chat sidebar — backend sessions were unclickable
🎯 Decision Made
Chosen:
Change the constructor effect() to check mergedSessions() instead of state().sessions when validating the active session
Options Considered:
- Copy backend sessions into local autoFlashState on load so they exist in state().sessions
- Change the constructor effect() to check mergedSessions() instead of state().sessions when validating the active session
- Add a guard flag to skip the effect when switchSession is called externally
- Remove the constructor effect entirely and rely on explicit session management
💭 Reasoning
ROOT CAUSE: The constructor effect() in VittoChatPersistenceService validated the active session by checking s.sessions[s.activeSessionId] — which only contains LOCAL sessions stored in autoFlashState. Backend sessions (fetched from /ai-api/sessions/my/history) are stored in a separate _backendSessions signal and merged via mergedSessions() computed. The race condition: (1) User clicks backend session → switchSession(backendId) sets state().activeSessionId = backendId. (2) state() change triggers the effect to re-run. (3) Effect checks s.sessions[backendId] → undefined (backend session not in local state). (4) Effect treats this as 'no valid active session' and overwrites activeSessionId back to the most recent LOCAL session. FIX: Replace s.sessions[s.activeSessionId] with all[s.activeSessionId] where all = this.mergedSessions(), so the effect recognizes both local and backend sessions. This is the minimal, correct fix because: (a) mergedSessions() already exists and is the authoritative source used by sessionList, activeSession, and switchSession; (b) copying backend sessions to local state would create duplication and persistence overhead; (c) guard flags are fragile and create hidden coupling; (d) removing the effect breaks scope-change handling.
📁 Files Involved
libs/libs-ai/vitto-chat/src/lib/services/vitto-chat-persistence.service.tslibs/libs-ai/vitto-chat/src/lib/services/vitto-chat-engine.service.tslibs/libs-ai/vitto-chat/src/lib/components/chat-shell/chat-shell.component.ts
🔗 Related
- Decision ID:
dev_1771711382203_858u64h - Session: 133
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation