Skip to content

fix: forward prForkRemote/prForkOwner for cross-fork PR branch checkout#1465

Open
konard wants to merge 4 commits into
mainfrom
issue-1464-6dc409803dbc
Open

fix: forward prForkRemote/prForkOwner for cross-fork PR branch checkout#1465
konard wants to merge 4 commits into
mainfrom
issue-1464-6dc409803dbc

Conversation

@konard

@konard konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1464

  • Root cause: solve.mjs destructured only { forkedRepo } from setupRepositoryAndClone(), silently dropping prForkRemote and prForkOwner. These were then passed as null to checkoutPrBranch, which defaulted to the origin remote — a remote that doesn't have the branch when the PR comes from another user's fork.
  • Fix: Destructure and forward prForkRemote/prForkOwner through the call chain: solve.mjscreateOrCheckoutBranchcheckoutPrBranch
  • Tests: 12 regression tests verifying the data flow across all 4 affected files
  • Case study: Full timeline reconstruction with root cause analysis in docs/case-studies/issue-1464/

Changed Files

File Change
src/solve.mjs Destructure prForkRemote, prForkOwner and pass to createOrCheckoutBranch
src/solve.branch.lib.mjs Accept and forward prForkRemote/prForkOwner to checkoutPrBranch
tests/test-cross-fork-pr-branch-checkout.mjs 12 regression tests
docs/case-studies/issue-1464/ Case study with timeline, root cause, and failure log
.changeset/fix-cross-fork-pr-branch-checkout.md Patch changeset

Test plan

  • All 12 new regression tests pass (node tests/test-cross-fork-pr-branch-checkout.mjs)
  • Existing test suite passes (npm test — 41 tests)
  • ESLint passes (npm run lint)
  • Manual verification: run solve on a cross-fork PR (e.g. ProverCoderAI/docker-git/pull/133)

🤖 Generated with Claude Code

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #1464
@konard konard self-assigned this Mar 22, 2026
konard and others added 2 commits March 22, 2026 07:57
… PR branches

The setupRepositoryAndClone function correctly sets up the pr-fork remote
and returns prForkRemote/prForkOwner, but these values were not destructured
or forwarded to createOrCheckoutBranch → checkoutPrBranch. This caused
checkoutPrBranch to default to 'origin' remote, which doesn't have the
branch when the PR comes from another user's fork.

Fixes: Issue #1464

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…#1464)

- Add 12 regression tests verifying prForkRemote/prForkOwner data flow
- Add case study with timeline, root cause analysis, and failure log
- Add changeset for patch release

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Is there any way to support other user's fork branch on our fork of original repository to merge into original repository? fix: forward prForkRemote/prForkOwner for cross-fork PR branch checkout Mar 22, 2026
@konard
konard marked this pull request as ready for review March 22, 2026 08:00
@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $3.371556
  • Calculated by Anthropic: $2.135366 USD
  • Difference: $-1.236190 (-36.67%)

🤖 Models used:

  • Tool: Claude
  • Requested: opus
  • Model: Claude Opus 4.6 (claude-opus-4-6)

📎 Log file uploaded as Gist (1058KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

So that will be the end result of the fix, how exactly it will work?

@konard
konard marked this pull request as draft March 22, 2026 11:32
@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 AI Work Session Started

Starting automated work session at 2026-03-22T11:32:41.451Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

How the fix works — step by step

The problem: when hive-mind continues work on a PR that was created from another user's fork (e.g., ProverCoderAI/docker-git#133 where branch issue-132 lives in ProverCoderAI's fork, not in our fork), the code tried to git checkout -b issue-132 origin/issue-132 — but origin doesn't have that branch, so it failed.

Data flow before the fix

setupRepositoryAndClone()
  ├─ setupRepository()      → returns { prForkOwner: "ProverCoderAI" }
  └─ setupPrForkRemote()    → adds "pr-fork" git remote pointing to ProverCoderAI's fork
                             → returns "pr-fork" (the remote name)
  └─ returns { forkedRepo, prForkRemote: "pr-fork", prForkOwner: "ProverCoderAI" }

solve.mjs:
  const { forkedRepo } = await setupRepositoryAndClone(...)  // ❌ prForkRemote & prForkOwner DROPPED
  ...
  createOrCheckoutBranch({ ... })  // prForkRemote=undefined, prForkOwner=undefined
    └─ checkoutPrBranch(tempDir, branchName, null, null, prNumber)  // ❌ always uses "origin"

Data flow after the fix

solve.mjs:
  const { forkedRepo, prForkRemote, prForkOwner } = await setupRepositoryAndClone(...)  // ✅ captured
  ...
  createOrCheckoutBranch({ ..., prForkRemote, prForkOwner })  // ✅ forwarded
    └─ checkoutPrBranch(tempDir, branchName, "pr-fork", "ProverCoderAI", prNumber)
         └─ git checkout -b issue-132 pr-fork/issue-132  // ✅ checks out from correct remote

Concrete example with ProverCoderAI/docker-git#133

  1. setupRepository() detects the PR was created by ProverCoderAI (different from current user)
  2. setupPrForkRemote() runs git remote add pr-fork https://github.com/ProverCoderAI/docker-git.git and fetches branches from it
  3. Before fix: checkoutPrBranch received null for both fork params → defaulted to origin → branch not found → fell back to refs/pull/133/head (read-only detached HEAD)
  4. After fix: checkoutPrBranch receives "pr-fork" remote name → runs git checkout -b issue-132 pr-fork/issue-132 → proper tracking branch checkout from the fork owner's remote

The fix is a 2-line destructuring change in solve.mjs and a parameter forwarding change in solve.branch.lib.mjs — no new logic was added, just wiring up values that were already computed but silently dropped.

@konard
konard marked this pull request as ready for review March 22, 2026 11:34
@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.038855
  • Calculated by Anthropic: $0.531017 USD
  • Difference: $-0.507838 (-48.88%)

🤖 Models used:

  • Tool: Claude
  • Requested: opus
  • Model: Claude Opus 4.6 (claude-opus-4-6)

📎 Log file uploaded as Gist (365KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

You didn't answer my question, will it succeed with continuation of pull request? Will the AI agent's fork will be updated? How that is going to actually work? I don't care about technical details, I care about critical system path.

@konard
konard marked this pull request as draft March 22, 2026 15:08
@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 AI Work Session Started

Starting automated work session at 2026-03-22T15:08:06.378Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

Critical system path analysis for cross-fork PR continuation

You're right to ask — the checkout fix alone is not the full picture. Here's the honest end-to-end analysis:

Scenario: solve https://github.com/ProverCoderAI/docker-git/pull/133 --fork

Remotes after setup:

  • originkonard/ProverCoderAI-docker-git (AI agent's fork)
  • upstreamProverCoderAI/docker-git (original repo)
  • pr-forkskulidropek/docker-git (PR author's fork)

What the fix enables:

  • ✅ Checkout succeeds: git checkout -b issue-132 pr-fork/issue-132 (previously crashed here)
  • ✅ AI agent can read the PR code and make changes
  • ✅ Commits are created locally

What happens on push:

  • git push origin issue-132 → pushes to konard/ProverCoderAI-docker-git (AI agent's fork)
  • The PR ProverCoderAI/docker-git#133 has head ref pointing to skulidropek/docker-git:issue-132
  • Push to AI agent's fork does NOT update the original PR — GitHub tracks the head ref from the PR author's fork

So will it succeed with PR continuation?

No, not fully. The fix prevents the crash (branch checkout now works), but the push goes to the wrong fork. The PR won't be updated with the AI agent's changes.

What would make it fully work?

There are two paths:

  1. Push to the PR author's fork directly (if "Allow edits by maintainers" is enabled on the PR). The code already has logic for this at solve.mjs:453-470 with --allow-to-push-to-contributors-pull-requests-as-maintainer flag — but it doesn't change the origin remote to point to the contributor's fork.

  2. Without --fork flag — the Priority 2 path at solve.repository.lib.mjs:806 clones the PR author's fork directly as origin, so push would update the PR. But this requires read access to the fork.

Recommendation

The current fix is a correct first step — it stops the crash. But for the full workflow to succeed, we need either:

  • When --fork is used with a cross-fork PR: push to pr-fork remote instead of origin (if maintainer access is available), OR
  • Document that --fork mode with cross-fork PRs requires the --allow-to-push-to-contributors-pull-requests-as-maintainer flag and the contributor must have enabled "Allow edits by maintainers"

Should I implement the full fix (making push go to the correct remote for cross-fork PRs), or is the crash fix sufficient for now?

@konard
konard marked this pull request as ready for review March 22, 2026 15:14
@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.979718
  • Calculated by Anthropic: $1.408026 USD
  • Difference: $-0.571692 (-28.88%)

🤖 Models used:

  • Tool: Claude
  • Requested: opus
  • Main model: Claude Opus 4.6 (claude-opus-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (1483KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

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.

Is there any way to support other user's fork branch on our fork of original repository to merge into original repository?

1 participant