Yeachan-Heo/oh-my-codex · error · Error
(result.stderr || '').trim() || `git ${args.join(' ')} faile
Error message
(result.stderr || '').trim() || `git ${args.join(' ')} failed` What it means
requireGitSuccess runs a synchronous git subprocess and throws the trimmed stderr (or 'git <args> failed') when the exit status is non-zero. It is used for mutating operations such as resetToLastKeptCommit.
Source
Thrown at src/autoresearch/runtime.ts:231
await symlink(sourceNodeModules, targetNodeModules, process.platform === 'win32' ? 'junction' : 'dir');
}
function readGitShortHead(worktreePath: string): string {
return readGit(worktreePath, ['rev-parse', '--short=7', 'HEAD']);
}
function readGitFullHead(worktreePath: string): string {
return readGit(worktreePath, ['rev-parse', 'HEAD']);
}
function requireGitSuccess(worktreePath: string, args: string[]): void {
const result = spawnSync('git', args, {
cwd: worktreePath,
encoding: 'utf-8',
windowsHide: true,
});
if (result.status === 0) return;
throw new Error((result.stderr || '').trim() || `git ${args.join(' ')} failed`);
}
function gitStatusLines(worktreePath: string): string[] {
const result = spawnSync('git', ['status', '--porcelain', '--untracked-files=all'], {
cwd: worktreePath,
encoding: 'utf-8',
windowsHide: true,
});
if (result.status !== 0) {
throw new Error((result.stderr || '').trim() || `git status failed for ${worktreePath}`);
}
return (result.stdout || '')
.split(/\r?\n/)
.map((line) => line.trimEnd())
.filter(Boolean);
}
function isAllowedRuntimeDirtyLine(line: string): boolean {View on GitHub (pinned to 3ad79a8a6f)
Solutions
- Run the exact printed git command inside the worktree path to reproduce and read the error
- Verify the target commit still exists (git cat-file -t <sha>) and was not garbage-collected
- Confirm the worktree's .git link still points to an existing main repository
- Ensure no other process is concurrently running git in the same worktree
Defensive patterns
Strategy: try-catch
Validate before calling
import { spawnSync } from 'node:child_process';
function commitExists(worktreePath: string, sha: string): boolean {
return spawnSync('git', ['cat-file', '-t', sha], { cwd: worktreePath }).status === 0;
} Try / catch
try { await resetToLastKeptCommit(worktreePath, sha); }
catch (e) { if (e instanceof Error && /git .* failed/.test(e.message)) { /* run the printed git command manually to diagnose */ } throw e; } Prevention
- Verify target commits exist before reset operations
- Keep the main repository alive as long as linked worktrees reference it
- Serialize git mutations per worktree
When it happens
Trigger: Calling resetToLastKeptCommit (or other flows using requireGitSuccess) where the underlying git reset/checkout fails: unknown commit, dirty index conflicts, missing worktree metadata (.git file pointing to a deleted main repo), or git refusing to operate.
Common situations: The autoresearch worktree's backing repository was deleted or moved, the kept commit was garbage-collected, concurrent processes mutating the same worktree, or filesystem permission errors in the worktree.
Related errors
- worktree_add_failed
- stderr || `git ${args.join(' ')} failed`
- (result.stderr || '').trim() || `git status failed for ${wor
- autoresearch_reset_requires_clean_worktree
- worktree_not_planned:${workerName}
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/8db4195033087dd9.
Report an issue: GitHub.