Files
SuperCharged-Claude-Code-Up…/.agent/scratchpad.md
uroma 55aafbae9a Fix project isolation: Make loadChatHistory respect active project sessions
- Modified loadChatHistory() to check for active project before fetching all sessions
- When active project exists, use project.sessions instead of fetching from API
- Added detailed console logging to debug session filtering
- This prevents ALL sessions from appearing in every project's sidebar

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 14:43:05 +00:00

2.3 KiB

Project Isolation Bug - Scratchpad

Task Overview

Fix project isolation bug where ALL sessions appear in every project's left sidebar instead of only that project's sessions.

Files to Modify

  • /home/uroma/obsidian-web-interface/public/claude-ide/project-manager.js (main logic)
  • /home/uroma/obsidian-web-interface/public/claude-ide/chat-enhanced.js (left sidebar)

Root Cause Analysis

After analyzing the code:

  1. project-manager.js line 365: switchProject() calls loadChatHistory(project.sessions) - this passes the correct sessions
  2. chat-enhanced.js line 52: loadChatHistory() accepts sessionsToRender parameter
  3. BUT - When loadChatHistory() is called without parameters (initial load), it fetches ALL sessions from API

The issue: The left sidebar loadChatHistory function is being called in multiple places:

  1. Initial page load (no filter) - loads ALL sessions
  2. When switching projects (with filter) - should load only project sessions
  3. When sessions are created/updated

The problem is that loadChatHistory caches and reuses all sessions, and the filtering mechanism isn't working correctly.

Progress

Iteration 1 - Analysis - COMPLETED

  • Read all relevant files
  • Identified the root cause
  • Created fix plan

Next Steps

  1. Fix loadChatHistory to properly filter by project
  2. Ensure sessions are tracked per project correctly
  3. Test the fix

Detailed Root Cause

Looking at chat-enhanced.js lines 64-81:

if (sessionsToRender) {
  // Use provided sessions (for project filtering)
  allSessions = sessionsToRender;
} else {
  // Fetch all sessions from API
  const res = await fetch('/claude/api/claude/sessions');
  // ... loads ALL sessions
}

The problem: When loadChatHistory() is called from switchProject() with project.sessions, it correctly uses those sessions. BUT there are other calls to loadChatHistory() throughout the code that don't pass the filter parameter, causing all sessions to load.

Also, the session tabs (window.sessionTabs.setSessions) are correctly updated but the left sidebar isn't properly isolated.

Solution

The fix needs to:

  1. Make loadChatHistory always respect the current project's sessions
  2. Track which project is active globally
  3. Filter sessions by the active project's workingDir or project ID