Skip to content

Avoid unborn HEAD branch probe failures - #7201

Closed
brennanb2025 wants to merge 1 commit into
stablyai:mainfrom
brennanb2025:brennanb2025/win-unborn-head-branch-probe
Closed

brennanb2025 wants to merge 1 commit into
stablyai:mainfrom
brennanb2025:brennanb2025/win-unborn-head-branch-probe

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • read the first-work auto-rename current branch with git symbolic-ref --quiet --short HEAD
  • keep the post-generation branch recheck on the same non-dereferencing branch probe
  • add a regression for an unborn/empty repo where rev-parse --abbrev-ref HEAD fails with ambiguous argument HEAD

Crash evidence

  • Original report 03-renderer-oom-taifunk recorded a renderer OOM on Windows at 2026-06-30T21:53:16.870Z.
  • The crash breadcrumbs were dominated by agent working transitions, which is the signal that triggers first-work branch auto-rename.
  • The NDJSON crash window includes repeated git rev-parse --abbrev-ref HEAD failures against C:\Users\taifu\CLAUDE with fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
  • That error is the normal behavior of rev-parse --abbrev-ref HEAD in an unborn repo. The hook only needs the symbolic branch name, and git symbolic-ref --quiet --short HEAD reads it without requiring a commit.

ELI5

Orca was asking Git “what branch am I on?” in a way that only works after the branch has at least one commit. In brand-new or unusual repos, Git answered with an error every time the auto-rename helper woke up. Now Orca asks the branch-name question directly, so it does not trip over repos whose HEAD has no commit yet.

Validation

  • Confirmed the new regression failed before the fix: the hook called rev-parse --abbrev-ref HEAD, logged the unborn-HEAD error, and did not rename.
  • pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/first-work-branch-rename.test.ts src/main/git/branch-rename.test.ts src/main/git/upstream.test.ts src/main/git/status-upstream-probe-churn.test.ts src/main/git/status-upstream-negative-cache.test.ts passed: 69 tests.
  • pnpm run typecheck passed.
  • Pre-commit hooks ran oxlint, oxlint --config config/oxlint-react-doctor.json, and oxfmt --write on staged files.

Tradeoffs / gaps

  • This removes the repeated unborn-HEAD failure path from the auto-rename hook. It is not proof that the native renderer OOM in report 03 is fully fixed without the original C:\Users\taifu\... repos or a fresh current-build crash bundle.
  • Detached HEAD still returns no symbolic branch and remains a retry/skip path for the convenience auto-rename feature.
  • The fix applies to both local and SSH auto-rename branch probes because the helper uses the shared GitExec abstraction.

Report 03 showed repeated git rev-parse --abbrev-ref HEAD failures with 'ambiguous argument HEAD' around the renderer OOM window. The first-work branch rename hook only needs the symbolic branch ref, so read it with symbolic-ref instead of dereferencing HEAD and cover the unborn-HEAD fixture.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This change modifies how the current git branch is determined in the auto-rename hook, replacing git rev-parse --abbrev-ref HEAD with a new readCurrentBranch helper that uses git symbolic-ref --quiet --short HEAD. This avoids failures when HEAD is unborn. The test harness's mock git responder is updated to handle symbolic-ref and rev-parse --verify requests distinctly, replacing its previous catch-all rev-parse handling. Corresponding tests are added and updated to reflect the new branch-reading behavior, including a new test for the unborn HEAD scenario.

Changes

Area Change
first-work-branch-rename.ts Adds readCurrentBranch(exec) helper using symbolic-ref; replaces two rev-parse based branch lookups
first-work-branch-rename-test-harness.ts Refines mock git responder to handle symbolic-ref and rev-parse --verify distinctly
first-work-branch-rename.test.ts Adds unborn-HEAD test; updates existing tests' git mocks for symbolic-ref

Sequence Diagram(s)

sequenceDiagram
  participant runAutoRename
  participant readCurrentBranch
  participant git

  runAutoRename->>readCurrentBranch: readCurrentBranch(exec)
  readCurrentBranch->>git: symbolic-ref --quiet --short HEAD
  git-->>readCurrentBranch: branch name
  readCurrentBranch-->>runAutoRename: trimmed branch name
Loading

Estimated code review effort: 2 (~15 minutes)

Related PRs: None identified.

Suggested labels: none

Suggested reviewers: none

Poem

A rabbit hops past HEAD unborn,
No rev-parse cries at early dawn,
symbolic-ref shows the way so true,
Branches renamed, tests pass anew,
Hop, hop, hooray — the mocks align! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is informative but misses several required template sections, including Summary, Screenshots, AI Review Report, Security Audit, and Notes. Reformat the description to match the template and add the missing required sections, including screenshots status, testing checklist, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: switching the branch probe to avoid unborn HEAD failures.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/agent-hooks/first-work-branch-rename.test.ts (1)

100-139: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Good regression coverage for the unborn-HEAD scenario described in the PR.

Consider also adding a case where symbolic-ref --quiet --short HEAD itself fails (simulating detached HEAD) to lock in the intended fallback behavior once addressed in first-work-branch-rename.ts.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 64bc95ba-eee3-400d-88bc-9209ae46c5ef

📥 Commits

Reviewing files that changed from the base of the PR and between bf6a399 and dfa76e7.

📒 Files selected for processing (3)
  • src/main/agent-hooks/first-work-branch-rename-test-harness.ts
  • src/main/agent-hooks/first-work-branch-rename.test.ts
  • src/main/agent-hooks/first-work-branch-rename.ts

Comment on lines +86 to +92
async function readCurrentBranch(exec: GitExec): Promise<string> {
// Why: `rev-parse --abbrev-ref HEAD` dereferences HEAD and fails in unborn
// repos; symbolic-ref reads the branch ref without requiring a first commit.
const { stdout } = await exec(['symbolic-ref', '--quiet', '--short', 'HEAD'])
return stdout.trim()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify how gitExecFileAsync handles non-zero exit codes
rg -n -A 15 'function gitExecFileAsync|export.*gitExecFileAsync' --type=ts

Repository: stablyai/orca

Length of output: 151


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate relevant files =="
git ls-files | rg 'src/main/agent-hooks/first-work-branch-rename\.ts|git|exec'

echo
echo "== outline candidate file =="
ast-grep outline src/main/agent-hooks/first-work-branch-rename.ts --view expanded || true

echo
echo "== read the relevant section =="
sed -n '1,260p' src/main/agent-hooks/first-work-branch-rename.ts

echo
echo "== search for git exec wrapper and branch checks =="
rg -n -A 8 -B 8 'symbolic-ref|abbrev-ref|currentBranch === '"'"'HEAD'"'"'|retry\(|exec\(' src/main --type ts

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== first-work-branch-rename.ts relevant slice =="
sed -n '1,260p' src/main/agent-hooks/first-work-branch-rename.ts

echo
echo "== git exec wrapper / provider exec signatures =="
rg -n -A 6 -B 6 'type GitExec|gitExecFileAsync|provider\.exec|class .*Git.*Exec|function .*exec' src/main/git src/main --type ts | sed -n '1,260p'

echo
echo "== detached-HEAD / symbolic-ref handling around similar code =="
rg -n -A 4 -B 4 "symbolic-ref|currentBranch === 'HEAD'|detached|unborn|rev-parse --abbrev-ref HEAD" src/main --type ts | sed -n '1,260p'

Repository: stablyai/orca

Length of output: 44634


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== git runner implementation =="
ast-grep outline src/main/git/runner.ts --view expanded || true
sed -n '1,260p' src/main/git/runner.ts

echo
echo "== branch-rename helper and related tests =="
ast-grep outline src/main/git/branch-rename.ts --view expanded || true
sed -n '1,260p' src/main/git/branch-rename.ts

echo
echo "== ssh provider symbolic-ref handling =="
sed -n '820,880p' src/main/providers/ssh-git-provider.ts

echo
echo "== first-work-branch-rename around the branch check =="
sed -n '86,230p' src/main/agent-hooks/first-work-branch-rename.ts

Repository: stablyai/orca

Length of output: 23872


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '720,815p' src/main/git/runner.ts

echo
sed -n '1,140p' src/main/git/branch-rename.ts

echo
sed -n '830,870p' src/main/providers/ssh-git-provider.ts

Repository: stablyai/orca

Length of output: 7187


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '324,470p' src/main/git/runner.ts

echo
node - <<'JS'
const fs = require('fs');
const text = fs.readFileSync('src/main/git/runner.ts', 'utf8');
const m = text.match(/function execFileCapture[\s\S]*?function spawnCommandCapture/);
console.log(m ? m[0].slice(0, 6000) : 'not found');
JS

Repository: stablyai/orca

Length of output: 6884


Handle detached HEAD in readCurrentBranch
symbolic-ref --quiet --short HEAD rejects on detached HEAD, so this path skips the existing currentBranch === 'HEAD' retry branch and falls through to the generic outer catch. Catch here and return '' (or 'HEAD') so unborn and detached HEAD cases stay on the same control path.

@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-03T06:40:17Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

@brennanb2025 brennanb2025 closed this by deleting the head repository Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants