fix: preserve spawn cleanup while hardening kill path checks

This commit is contained in:
Harsh 2026-03-06 14:37:38 +05:30
parent 86b34c8923
commit 1c9adba947
1 changed files with 8 additions and 4 deletions

View File

@ -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 {