fix: E2E exit reason precedence + worktree prune race condition

Two fixes for E2E test reliability:

1. session-runner.ts: error_max_turns was misclassified as error_api
   because is_error flag was checked before subtype. Now known subtypes
   like error_max_turns are preserved even when is_error is set. The
   is_error override only applies when subtype=success (API failure).

2. worktree.ts: pruneStale() now skips worktrees < 1 hour old to avoid
   deleting worktrees from concurrent test runs still in progress.
   Previously any second test execution would kill the first's worktrees.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-05 15:45:20 -07:00
parent 8801a62339
commit 7b60c0bbe6
3 changed files with 10 additions and 1 deletions
+5
View File
@@ -259,6 +259,11 @@ export class WorktreeManager {
const entryPath = path.join(worktreeBase, entry);
try {
// Skip recent worktrees (< 1 hour old) to avoid killing
// worktrees from concurrent test runs still in progress
const stat = fs.statSync(entryPath);
const ageMs = Date.now() - stat.mtimeMs;
if (ageMs < 3600_000) continue;
fs.rmSync(entryPath, { recursive: true, force: true });
} catch { /* non-fatal */ }
}
+2 -1
View File
@@ -303,12 +303,13 @@ export async function runSkillTest(options: {
// Use resultLine for structured result data
if (resultLine) {
if (resultLine.is_error) {
if (resultLine.subtype === 'success' && resultLine.is_error) {
// claude -p can return subtype=success with is_error=true (e.g. API connection failure)
exitReason = 'error_api';
} else if (resultLine.subtype === 'success') {
exitReason = 'success';
} else if (resultLine.subtype) {
// Preserve known subtypes like error_max_turns even if is_error is set
exitReason = resultLine.subtype;
}
}
+3
View File
@@ -231,6 +231,9 @@ describe('WorktreeManager', () => {
spawnSync('git', ['worktree', 'remove', '--force', oldPath], { cwd: repo, stdio: 'pipe' });
// Recreate the directory to simulate orphaned state
fs.mkdirSync(oldPath, { recursive: true });
// Backdate mtime to simulate a stale worktree (> 1 hour old)
const staleTime = new Date(Date.now() - 7200_000);
fs.utimesSync(oldRunDir, staleTime, staleTime);
// New manager should prune the old run's directory
const newMgr = new WorktreeManager(repo);