From 44db68bb5f841de347ff50c532e20261d15fac95 Mon Sep 17 00:00:00 2001 From: Prateek Date: Thu, 19 Feb 2026 01:08:03 +0530 Subject: [PATCH] fix: distinguish missing branch from missing restore support Split the compound condition so workspace restore gives an accurate error message when branch metadata is null ("branch metadata is missing") vs when the workspace plugin lacks a restore method. Co-Authored-By: Claude Opus 4.6 --- packages/core/src/session-manager.ts | 48 +++++++++++++++------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/core/src/session-manager.ts b/packages/core/src/session-manager.ts index 1868c12d9..47c9b80ab 100644 --- a/packages/core/src/session-manager.ts +++ b/packages/core/src/session-manager.ts @@ -935,31 +935,33 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager { if (!workspaceExists) { // Try to restore workspace if plugin supports it - if (plugins.workspace?.restore && session.branch) { - try { - const wsInfo = await plugins.workspace.restore( - { - projectId, - project, - sessionId, - branch: session.branch, - }, - workspacePath, - ); - - // Run post-create hooks on restored workspace - if (plugins.workspace.postCreate) { - await plugins.workspace.postCreate(wsInfo, project); - } - } catch (err) { - throw new WorkspaceMissingError( - workspacePath, - `restore failed: ${err instanceof Error ? err.message : String(err)}`, - ); - } - } else { + if (!plugins.workspace?.restore) { throw new WorkspaceMissingError(workspacePath, "workspace plugin does not support restore"); } + if (!session.branch) { + throw new WorkspaceMissingError(workspacePath, "branch metadata is missing"); + } + try { + const wsInfo = await plugins.workspace.restore( + { + projectId, + project, + sessionId, + branch: session.branch, + }, + workspacePath, + ); + + // Run post-create hooks on restored workspace + if (plugins.workspace.postCreate) { + await plugins.workspace.postCreate(wsInfo, project); + } + } catch (err) { + throw new WorkspaceMissingError( + workspacePath, + `restore failed: ${err instanceof Error ? err.message : String(err)}`, + ); + } } // 6. Get launch command — try restore command first, fall back to fresh launch