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>
This commit is contained in:
uroma
2026-01-22 14:43:05 +00:00
Unverified
parent b82837aa5f
commit 55aafbae9a
6463 changed files with 1115462 additions and 4486 deletions

View File

@@ -0,0 +1,128 @@
# Session Attachment Bug - COMPLETE FIX
**Date:** 2025-01-22
**Status:** ✅ Root cause found and fixed
**Server PID:** 1723610
## The Bug
User flow: https://rommark.dev/claude/ > select folder > navigates to session URL > shows "No sessions yet"
## Root Cause Found
**Race Condition:** Two components both initializing on `DOMContentLoaded`:
1. **ide.js** - Extracts sessionId from URL, sets `window.pendingSessionAttach`, switches to chat view, calls `attachToSession()`
2. **session-picker.js** - Initializes and shows modal with "No sessions yet"
The problem: **session-picker was showing its modal BEFORE ide.js could switch to the chat view**.
The session-picker only checked for `?session=XXX` query parameter, NOT the route-based URL path `/claude/ide/session/session-XXX`.
## The Fix
### File: `/home/uroma/obsidian-web-interface/public/claude-ide/components/session-picker.js`
**Before:**
```javascript
async initialize() {
// Only checked query params
const urlParams = new URLSearchParams(window.location.search);
const sessionId = urlParams.get('session');
// ...
}
```
**After:**
```javascript
async initialize() {
// FIRST: Check URL path for session ID (route-based: /claude/ide/session/XXX)
const pathname = window.location.pathname;
const pathMatch = pathname.match(/\/claude\/ide\/session\/([^\/]+)$/);
if (pathMatch && pathMatch[1]) {
const sessionId = pathMatch[1];
console.log('[SessionPicker] Session ID in URL path, NOT showing picker:', sessionId);
console.log('[SessionPicker] ide.js will handle attachment');
this.initialized = true;
return; // Don't show picker, let ide.js handle it
}
// SECOND: Check URL params (legacy format: ?session=XXX)
// ...
}
```
## All Files Modified
1. **`/home/uroma/obsidian-web-interface/public/claude-ide/components/session-picker.js`**
- Added URL path check BEFORE showing modal
- If session ID in URL path, don't show picker, let ide.js handle it
2. **`/home/uroma/obsidian-web-interface/public/claude-ide/chat-functions.js`**
- Moved URL-based session attachment check to execute FIRST
- Before rendering session list
3. **`/home/uroma/obsidian-web-interface/public/claude-ide/index.html`**
- Re-added `ide.js` script tag
- Updated all script versions to `v1769079800000`
- Updated cache buster version to `1769079800000`
## How It Works Now
**User flow:**
1. User clicks "Select Folder" on landing page
2. Folder selected, session created via POST `/claude/api/claude/sessions`
3. Response: `{ id: "session-1769079417244-0ynpja8dc" }`
4. Browser navigates to: `/claude/ide/session/session-1769079417244-0ynpja8dc`
5. **Page loads:**
- PRELOAD script extracts session ID → `window.PRELOAD_SESSION_ID`
- Cache-bust script runs (version matches, no reload)
- ide.js initializes → sees sessionId → switches to chat view → calls attachToSession
- session-picker.js initializes → sees sessionId in URL path → DOESN'T show modal
- chat-functions.js loads → loadChatView() → attaches to session
6. **Result:** Chat interface shows with session attached ✅
## Testing
**To verify the fix:**
1. Hard refresh browser (Ctrl+Shift+R or Cmd+Shift+R)
2. Go to https://rommark.dev/claude/
3. Click "Start New Session" → "Choose Folder"
4. Select any folder
5. Click "Select Folder"
6. Should navigate to session URL and show chat interface (not "No sessions yet")
## Browser Console Logs
When it works, you should see:
```
[PRELOAD] Session ID extracted from URL: session-XXX
[Cache-Bust] Fresh load confirmed
[Init] Using PRELOAD_SESSION_ID: session-XXX
[Init] Set pendingSessionAttach: session-XXX
[SessionPicker] Session ID in URL path, NOT showing picker: session-XXX
[SessionPicker] ide.js will handle attachment
[loadChatView] Pending session attachment detected: session-XXX
[loadChatView] Attaching IMMEDIATELY (no delay)
[attachToSession] Attaching to session: session-XXX
```
## Server Status
- **PID:** 1723610
- **Status:** Running
- **Port:** 3010
- **Working Directory:** `/home/uroma/obsidian-web-interface`
## Version Information
- **Cache Buster:** 1769079800000
- **Script Versions:** v1769079800000
- **Fix Date:** 2025-01-22 11:07 UTC
## Related Files
- Ralph wrapper: `/home/uroma/obsidian-web-interface/bin/ralphloop`
- /ralph alias: `/home/uroma/.claude/skills/ralph/SKILL.md`
- Ralph integration: `/home/uroma/.claude/skills/brainstorming/ralph-integration.py`