Files
SuperCharged-Claude-Code-Up…/.agent/scratchpad.md
uroma c5dbb6c244 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>
2026-01-22 14:49:36 +00:00

1.9 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:

  1. createSessionInFolder() creates the session via API
  2. It calls await this.loadProjects() - fetches fresh session data from API
  3. BUG: It then calls await this.initialize()
  4. initialize() calls loadManuallyCreatedProjects() which RESTores projects with STALE session data from localStorage
  5. 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:

  1. loadManuallyCreatedProjects() restores projects with their saved (stale) sessions
  2. The merge logic in loadProjects() tries to add virtual sessions to these projects
  3. 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:

  1. Load the project metadata (name, id, workingDir, manuallyCreated flag)
  2. NOT load the sessions array - it should start empty
  3. 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

Remove the await this.initialize() call from createSessionInFolder() after loadProjects(). The loadProjects() call already refreshes the data from the API, so we don't need to re-initialize.

Testing Steps

  1. Create new project named 'test'
  2. Start new session in 'test' project
  3. Check that session appears in left sidebar
  4. Refresh page
  5. Verify session still appears in 'test' project