Repository navigation
Avoid unborn HEAD branch probe failures - #7201
brennanb2025 wants to merge 1 commit into
Conversation
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.
📝 WalkthroughWalkthroughThis change modifies how the current git branch is determined in the auto-rename hook, replacing Changes
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
Estimated code review effort: 2 (~15 minutes) Related PRs: None identified. Suggested labels: none Suggested reviewers: none Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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 valueGood regression coverage for the unborn-HEAD scenario described in the PR.
Consider also adding a case where
symbolic-ref --quiet --short HEADitself fails (simulating detached HEAD) to lock in the intended fallback behavior once addressed infirst-work-branch-rename.ts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 64bc95ba-eee3-400d-88bc-9209ae46c5ef
📒 Files selected for processing (3)
src/main/agent-hooks/first-work-branch-rename-test-harness.tssrc/main/agent-hooks/first-work-branch-rename.test.tssrc/main/agent-hooks/first-work-branch-rename.ts
| 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() | ||
| } | ||
|
|
There was a problem hiding this comment.
🩺 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=tsRepository: 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 tsRepository: 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.tsRepository: 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.tsRepository: 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');
JSRepository: 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.
|
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. |
Description
git symbolic-ref --quiet --short HEADrev-parse --abbrev-ref HEADfails withambiguous argument HEADCrash evidence
03-renderer-oom-taifunkrecorded a renderer OOM on Windows at2026-06-30T21:53:16.870Z.workingtransitions, which is the signal that triggers first-work branch auto-rename.git rev-parse --abbrev-ref HEADfailures againstC:\Users\taifu\CLAUDEwithfatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.rev-parse --abbrev-ref HEADin an unborn repo. The hook only needs the symbolic branch name, andgit symbolic-ref --quiet --short HEADreads 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
HEADhas no commit yet.Validation
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.tspassed: 69 tests.pnpm run typecheckpassed.oxlint,oxlint --config config/oxlint-react-doctor.json, andoxfmt --writeon staged files.Tradeoffs / gaps
C:\Users\taifu\...repos or a fresh current-build crash bundle.GitExecabstraction.