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

  1. Run the exact printed git command inside the worktree path to reproduce and read the error
  2. Verify the target commit still exists (git cat-file -t <sha>) and was not garbage-collected
  3. Confirm the worktree's .git link still points to an existing main repository
  4. 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

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


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/8db4195033087dd9. Report an issue: GitHub.