Fix session persistence after page refresh

Root cause: loadManuallyCreatedProjects() was restoring projects with
stale session arrays from localStorage. When loadProjects() tried to
merge with fresh API data, the stale sessions would override.

Fix 1: In loadManuallyCreatedProjects(), reset the sessions array to
empty for each loaded project. This ensures sessions always come from
the API (authoritative source) rather than localStorage.

Fix 2: In createSessionInFolder(), remove the redundant initialize()
call after loadProjects(). initialize() would reload stale localStorage
data, undoing the fresh data fetched by loadProjects().

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
uroma
2026-01-22 14:49:36 +00:00
Unverified
parent 9107b3db85
commit c5dbb6c244
5 changed files with 105 additions and 61 deletions

View File

@@ -22,13 +22,25 @@ User creates new project (e.g., 'roman') and clicks 'Start new session' → ALL
## Progress
### Iteration 1 - Fixed loadChatHistory to respect active project ✅
Modified `loadChatHistory()` in chat-enhanced.js to check for active project before fetching all sessions from API. When active project exists, it uses `activeProject.sessions` instead. Added detailed console logging for debugging.
Modified `loadChatHistory()` in chat-enhanced.js to check for active project before fetching all sessions from API. When active project exists, it uses `activeProject.sessions` instead.
**Commit:** 55aafba
### Next Steps
- Test in browser to verify isolation works
- May need additional fixes for initialization timing issues
### Iteration 2 - Fixed virtual workingDir handling ✅
Modified `addSessionToProject()` in project-manager.js to correctly extract projectKey from virtual workingDirs (`/virtual/projects/{key}`) instead of converting slashes to dashes.
**Commit:** ec790a2
### Iteration 3 - Added debugging logging ✅
Added extensive console logging to track session assignment and project isolation.
**Commit:** 9107b3d
## Status
**ALL FIXES IMPLEMENTED** - Ready for browser testing. The fixes address:
1. loadChatHistory now respects active project filter
2. Virtual workingDirs are correctly handled when assigning sessions to projects
3. Detailed logging helps identify any remaining issues
<!-- Ralph will continue iterating until task is complete -->