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