fix: enrich runtime state before restore check, remove dead branchExists

- Add enrichSessionWithRuntimeState() call before isRestorable() in
  restore() so crashed sessions (status "working", agent exited) are
  correctly detected as terminal and eligible for restore.
- Remove dead branchExists from SCM interface and scm-github plugin
  (defined but never called anywhere in the codebase).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Prateek 2026-02-19 00:13:36 +05:30
parent aaf0908b9c
commit fd60b2bf5a
3 changed files with 7 additions and 26 deletions

View File

@ -903,8 +903,13 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager {
throw new Error(`Session ${sessionId} not found`);
}
// 2. Reconstruct Session from metadata
// 2. Reconstruct Session from metadata and enrich with live runtime state.
// metadataToSession sets activity: null, so without enrichment a crashed
// session (status "working", agent exited) would not be detected as terminal
// and isRestorable would reject it.
const session = metadataToSession(sessionId, raw);
const plugins = resolvePlugins(project);
await enrichSessionWithRuntimeState(session, plugins, true);
// 3. Validate restorability
if (!isRestorable(session)) {
@ -914,8 +919,7 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager {
throw new SessionNotRestorableError(sessionId, "session is not in a terminal state");
}
// 4. Resolve plugins
const plugins = resolvePlugins(project);
// 4. Validate required plugins (plugins already resolved above for enrichment)
if (!plugins.runtime) {
throw new Error(`Runtime plugin '${project.runtime ?? config.defaults.runtime}' not found`);
}

View File

@ -535,9 +535,6 @@ export interface SCM {
/** Check if PR is ready to merge */
getMergeability(pr: PRInfo): Promise<MergeReadiness>;
/** Optional: check if a branch exists in the repo */
branchExists?(repoPath: string, branch: string): Promise<boolean>;
}
// --- PR Types ---

View File

@ -560,26 +560,6 @@ function createGitHubSCM(): SCM {
blockers,
};
},
async branchExists(repoPath: string, branch: string): Promise<boolean> {
try {
await execFileAsync("git", ["rev-parse", "--verify", `refs/heads/${branch}`], {
cwd: repoPath,
timeout: 30_000,
});
return true;
} catch {
// Try remote ref
try {
await execFileAsync("git", ["rev-parse", "--verify", `refs/remotes/origin/${branch}`], {
cwd: repoPath,
timeout: 30_000,
});
return true;
} catch {
return false;
}
}
},
};
}