Avoid unborn HEAD branch probe failures
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 HEADfails withambiguous argument HEAD
Crash evidence
- Original report
03-renderer-oom-taifunkrecorded a renderer OOM on Windows at2026-06-30T21:53:16.870Z. - The crash breadcrumbs were dominated by agent
workingtransitions, which is the signal that triggers first-work branch auto-rename. - The NDJSON crash window includes repeated
git rev-parse --abbrev-ref HEADfailures againstC:\Users\taifu\CLAUDEwithfatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree. - That error is the normal behavior of
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 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.tspassed: 69 tests.pnpm run typecheckpassed.- Pre-commit hooks ran
oxlint,oxlint --config config/oxlint-react-doctor.json, andoxfmt --writeon 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
GitExecabstraction.
π 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
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.
Comment @coderabbitai help to get the list of available commands.
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.