Skip to content

Create fix branch from PR branch, not main#110

Merged
ejc3 merged 6 commits intomainfrom
claude-review-prompting-fix
Jan 6, 2026
Merged

Create fix branch from PR branch, not main#110
ejc3 merged 6 commits intomainfrom
claude-review-prompting-fix

Conversation

@ejc3
Copy link
Copy Markdown
Owner

@ejc3 ejc3 commented Jan 5, 2026

Summary

Fixes the Claude review agent getting lost trying to read files that don't exist locally.

Problem: The agent was wasting many turns doing:

[driver] Tool: Read  (file not found)
The files don't exist on my current branch. Let me check them out...
[driver] Tool: Bash  (git checkout)
Let me view these files from the origin branch directly...
[driver] Tool: Bash  (git show origin/...)

Root cause: Workflow checks out main, then setupFixBranch creates the fix branch from main. But the PR code is on origin/${headBranch}.

Fix: Create fix branch from origin/${headBranch}:

gitOrFail("checkout", "-b", ctx.fixBranch, `origin/${ctx.headBranch}`);

Now the PR code is checked out locally and the Read tool works directly.

Test plan

  • Push to trigger Claude review on a PR
  • Verify agent can Read files directly without workarounds
  • Verify agent doesn't waste turns on git checkout/show commands

Stacked on: ci-log-truncation-check (PR #109)

ejc3 added 2 commits January 5, 2026 19:40
When a Claude assistant job is killed mid-execution (e.g., by
cancel-in-progress), the process exits with code 0 and GitHub
marks the job as "success" even though it didn't complete.

Fix:
- Add completion marker in index.ts after runClaude finishes
- Verify marker exists in workflow steps before declaring success
- Applies to review, manual-review, respond, and ci-fix jobs

Tested: Verified old run 20726814304 has no completion marker
in logs, confirming it was killed mid-execution.
The Claude review agent was getting lost because:
1. Workflow checked out main (default branch)
2. setupFixBranch created fix branch from current HEAD (main)
3. Agent tried to Read files that only exist on PR branch
4. Agent wasted turns trying to checkout/view from origin

Fix: Create fix branch from origin/${headBranch} so PR code is
checked out locally. Agent can now use Read tool directly.

Also updated prompt to clarify that PR code is available locally.
@claude-claude
Copy link
Copy Markdown
Contributor

claude-claude bot commented Jan 5, 2026

🔍 Claude Review

SEVERITY: medium

Findings

[MEDIUM] - Stale branch reuse: When the fix branch already exists (line 128), the code checks it out without updating it to the latest origin/. If the PR has new commits pushed since the last Claude run, the existing fix branch will point to an old commit, causing Claude to review/fix stale code instead of the current PR state.

Fix: After checking out an existing branch, reset it to origin/:

if (branchExists(ctx.fixBranch)) {
  log(`Branch ${ctx.fixBranch} already exists, checking out and updating`);
  gitOrFail("checkout", ctx.fixBranch);
  gitOrFail("reset", "--hard", `origin/${ctx.headBranch}`);
} else {
  // Create fix branch FROM the PR branch, not from main
  // This ensures Claude can read PR files locally with the Read tool
  log(`Creating new branch ${ctx.fixBranch} from origin/${ctx.headBranch}`);
  gitOrFail("checkout", "-b", ctx.fixBranch, `origin/${ctx.headBranch}`);
}

Summary

The core fix (creating branch from PR head instead of main) is correct and solves the immediate issue. However, there's a case where reusing an existing fix branch could leave Claude working on outdated code if the PR has been updated since the last run.


Review by Claude | Run

When a fix branch already exists from a previous Claude run, ensure
it's updated to the latest commit on the PR branch. Without this,
Claude would review/fix stale code if new commits were pushed to the PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@claude-claude
Copy link
Copy Markdown
Contributor

claude-claude bot commented Jan 5, 2026

🔧 Auto-Fix Created

I found issues and created a fix PR: #111

Please review and merge the fix PR first, then this PR.

View Claude Run

fix: reset existing fix branch to latest PR head
@claude-claude
Copy link
Copy Markdown
Contributor

claude-claude bot commented Jan 5, 2026

🔍 Claude Review

SEVERITY: medium

Findings

[MEDIUM] - Silent fetch failure: Line 125 uses git("fetch", ...) which returns a boolean but doesn't check or handle the result. If the fetch fails (network issues, invalid branch name, etc.), the code silently continues and may:

  • Use a stale remote ref when checking out/resetting
  • Fail later with confusing errors about missing refs
  • Succeed with stale data if an old remote ref exists

Impact: Claude could review outdated code or encounter unclear failures during branch setup.

Fix: Use gitOrFail instead of git to ensure the fetch succeeds:

gitOrFail("fetch", "origin", ctx.headBranch);

Summary

The core fix and the stale branch issue (PR #111) are both properly addressed. However, the fetch operation should fail loudly rather than silently to prevent reviewing stale code.


Review by Claude | Run

Changes git("fetch") to gitOrFail("fetch") to prevent silent failures
that could lead to reviewing stale code or unclear errors during branch
checkout/reset operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@claude-claude
Copy link
Copy Markdown
Contributor

claude-claude bot commented Jan 5, 2026

🔧 Auto-Fix Created

I found issues and created a fix PR: #119

Please review and merge the fix PR first, then this PR.

View Claude Run

fix: ensure fetch succeeds before branch setup
@claude-claude
Copy link
Copy Markdown
Contributor

claude-claude bot commented Jan 5, 2026

🔍 Claude Review

SEVERITY: none

Findings

No issues found. All previously identified issues have been addressed:

The code correctly:

  1. Fetches the latest PR branch with error handling
  2. Creates or updates the fix branch to point to the current PR state
  3. Updates prompts to clarify that PR code is locally available

Summary

The PR successfully fixes the Claude review agent's workflow issues. All code changes are correct and complete.


Review by Claude | Run

@ejc3 ejc3 changed the base branch from ci-log-truncation-check to main January 6, 2026 04:12
@ejc3 ejc3 merged commit bcb63bb into main Jan 6, 2026
7 checks passed
@ejc3 ejc3 deleted the claude-review-prompting-fix branch January 6, 2026 04:12
ejc3 added a commit that referenced this pull request Mar 2, 2026
Create fix branch from PR branch, not main
ejc3 added a commit that referenced this pull request Mar 2, 2026
Create fix branch from PR branch, not main
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.

1 participant