diff --git a/packages/core/src/session-manager.ts b/packages/core/src/session-manager.ts index 1d60a91f4..640052f4d 100644 --- a/packages/core/src/session-manager.ts +++ b/packages/core/src/session-manager.ts @@ -200,12 +200,16 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager { project: ProjectConfig | undefined, workspacePath: string, ): boolean { - if (!project) return true; + if (!project) return false; const isProjectPath = normalizePath(workspacePath) === normalizePath(project.path); if (isProjectPath) return false; return isPathInside(workspacePath, getProjectWorktreesDir(project)); } + function shouldDestroySpawnWorkspacePath(project: ProjectConfig, workspacePath: string): boolean { + return normalizePath(workspacePath) !== normalizePath(project.path); + } + /** * List all session files across all projects (or filtered by projectId). * Scans project-specific directories under ~/.agent-orchestrator/{hash}-{projectId}/sessions/ @@ -462,7 +466,7 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager { try { await plugins.workspace.postCreate(wsInfo, project); } catch (err) { - if (shouldDestroyWorkspacePath(project, workspacePath)) { + if (shouldDestroySpawnWorkspacePath(project, workspacePath)) { try { await plugins.workspace.destroy(workspacePath); } catch { @@ -531,7 +535,7 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager { }); } catch (err) { // Clean up workspace and reserved ID if agent config or runtime creation failed - if (plugins.workspace && shouldDestroyWorkspacePath(project, workspacePath)) { + if (plugins.workspace && shouldDestroySpawnWorkspacePath(project, workspacePath)) { try { await plugins.workspace.destroy(workspacePath); } catch { @@ -586,7 +590,7 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager { } catch { /* best effort */ } - if (plugins.workspace && shouldDestroyWorkspacePath(project, workspacePath)) { + if (plugins.workspace && shouldDestroySpawnWorkspacePath(project, workspacePath)) { try { await plugins.workspace.destroy(workspacePath); } catch {