From 7f7e845cd527dad12e81e3942e01d0ed19e7ad48 Mon Sep 17 00:00:00 2001 From: AndyMik90 Date: Wed, 18 Feb 2026 09:49:35 +0100 Subject: [PATCH] fix: resolve 3 remaining PR #1819 review issues - Preserve 'exited' status in setClaudeMode(false) instead of overwriting to 'running' - Add isResumingPhase guard to SWAP_RESUME_COMPLETE for consistency with other swap events - Clean up stale migratedSessionFlags when resumeClaudeAsync finds no terminal Co-Authored-By: Claude Opus 4.6 --- apps/frontend/src/main/terminal/terminal-manager.ts | 4 ++++ apps/frontend/src/renderer/stores/terminal-store.ts | 2 +- apps/frontend/src/shared/state-machines/terminal-machine.ts | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/frontend/src/main/terminal/terminal-manager.ts b/apps/frontend/src/main/terminal/terminal-manager.ts index 7f12a7f2..78cd6f3d 100644 --- a/apps/frontend/src/main/terminal/terminal-manager.ts +++ b/apps/frontend/src/main/terminal/terminal-manager.ts @@ -229,6 +229,10 @@ export class TerminalManager { async resumeClaudeAsync(id: string, sessionId?: string, options?: { migratedSession?: boolean }): Promise { const terminal = this.terminals.get(id); if (!terminal) { + // Clean up stale migratedSessionFlags if terminal no longer exists + if (options?.migratedSession && sessionId) { + this.migratedSessionFlags.delete(sessionId); + } return; } diff --git a/apps/frontend/src/renderer/stores/terminal-store.ts b/apps/frontend/src/renderer/stores/terminal-store.ts index 9ef51adb..1764f475 100644 --- a/apps/frontend/src/renderer/stores/terminal-store.ts +++ b/apps/frontend/src/renderer/stores/terminal-store.ts @@ -417,7 +417,7 @@ export const useTerminalStore = create((set, get) => ({ ? { ...t, isClaudeMode, - status: isClaudeMode ? 'claude-active' : 'running', + status: isClaudeMode ? 'claude-active' : (t.status === 'exited' ? 'exited' : 'running'), // Reset busy state and naming flag when leaving Claude mode isClaudeBusy: isClaudeMode ? t.isClaudeBusy : undefined, claudeNamedOnce: isClaudeMode ? t.claudeNamedOnce : undefined diff --git a/apps/frontend/src/shared/state-machines/terminal-machine.ts b/apps/frontend/src/shared/state-machines/terminal-machine.ts index f002ec61..4a990fae 100644 --- a/apps/frontend/src/shared/state-machines/terminal-machine.ts +++ b/apps/frontend/src/shared/state-machines/terminal-machine.ts @@ -108,6 +108,7 @@ export const terminalMachine = createMachine( }, SWAP_RESUME_COMPLETE: { target: 'claude_active', + guard: 'isResumingPhase', actions: 'applySwapComplete', }, SWAP_FAILED: { @@ -142,6 +143,7 @@ export const terminalMachine = createMachine( isCapturingPhase: ({ context }) => context.swapPhase === 'capturing', isMigratingPhase: ({ context }) => context.swapPhase === 'migrating', isRecreatingPhase: ({ context }) => context.swapPhase === 'recreating', + isResumingPhase: ({ context }) => context.swapPhase === 'resuming', }, actions: { setProfileId: assign({