fix: clear stale worktree and claude session on sidebar reconnect

loadSession() was restoring worktreePath and claudeSessionId from prior
crashes. The worktree directory no longer existed (deleted on cleanup)
and --resume with a dead session ID caused claude to fail silently.

Now validates worktree exists on load and clears stale claude session
IDs on every server restart.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-28 20:56:17 -07:00
parent abf030c783
commit 63d91def6a
+10
View File
@@ -221,6 +221,16 @@ function loadSession(): SidebarSession | null {
const activeData = JSON.parse(fs.readFileSync(activeFile, 'utf-8'));
const sessionFile = path.join(SESSIONS_DIR, activeData.id, 'session.json');
const session = JSON.parse(fs.readFileSync(sessionFile, 'utf-8')) as SidebarSession;
// Validate worktree still exists — crash may have left stale path
if (session.worktreePath && !fs.existsSync(session.worktreePath)) {
console.log(`[browse] Stale worktree path: ${session.worktreePath} — clearing`);
session.worktreePath = null;
}
// Clear stale claude session ID — can't resume across server restarts
if (session.claudeSessionId) {
console.log(`[browse] Clearing stale claude session: ${session.claudeSessionId}`);
session.claudeSessionId = null;
}
// Load chat history
const chatFile = path.join(SESSIONS_DIR, session.id, 'chat.jsonl');
try {