Update PROMPT.md and scratchpad with complete documentation of the bug fix for session persistence after page refresh. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2.7 KiB
Session Persistence Bug - Scratchpad
Task Overview
Fix bug where sessions disappear from manually created projects after page refresh.
Root Cause Analysis
When a session is created in a manually created project:
createSessionInFolder()creates the session via API- It calls
await this.loadProjects()- fetches fresh session data from API - BUG: It then calls
await this.initialize() initialize()callsloadManuallyCreatedProjects()which RESTores projects with STALE session data from localStorage- Then
loadProjects()is called again, but the damage is done
The problem is that saveManuallyCreatedProjects() saves the entire project object including its sessions array. When the page refreshes:
loadManuallyCreatedProjects()restores projects with their saved (stale) sessions- The merge logic in
loadProjects()tries to add virtual sessions to these projects - BUT the session array from localStorage already exists and may be empty/stale
The Fix
The session arrays stored in localStorage for manually created projects are stale and should be ignored. The loadManuallyCreatedProjects() function should:
- Load the project metadata (name, id, workingDir, manuallyCreated flag)
- NOT load the sessions array - it should start empty
- Let
loadProjects()populate the sessions from the API
This ensures sessions always come from the authoritative source (the backend API) rather than stale localStorage data.
Implementation
Fix 1: Reset sessions in loadManuallyCreatedProjects()
File: project-manager.js lines 52-87
Modified loadManuallyCreatedProjects() to create a sanitized project object with:
sessions: []- Reset to empty arrayactiveSessionId: null- Reset active session
This prevents stale localStorage session data from overriding fresh API data.
Fix 2: Remove redundant initialize() call
File: project-manager.js lines 542-563
Modified createSessionInFolder() to:
- Remove
await this.initialize()call - Add
this.renderProjectTabs()to update UI - Make
switchProject()call await properly
This prevents reloading stale localStorage data after fetching fresh API data.
Commit
Commit: c5dbb6c
"Fix session persistence after page refresh"
Testing Steps
To verify the fix works:
- Create new project named 'test'
- Start new session in 'test' project
- Check that session appears in left sidebar
- Refresh page
- Verify session still appears in 'test' project's session list
- Verify session is correctly displayed in left sidebar
Status
FIX IMPLEMENTED AND COMMITTED
The fix ensures:
- Session data always comes from the API (authoritative source)
- localStorage only stores project metadata (name, id, workingDir)
- No stale session data can override fresh API data