SideRepoOps: create_pull_request base-branch resolved via GitHub GET /repos 404, then stringified into the ref name → ERR_SYSTEM merge-base failure (live agent)
🤖 This issue was investigated and filed by Claude Code.
Summary
In a SideRepoOps workflow (an agentic workflow running in repo <workflow-repo> that targets a private side repository <side-repo> via target-repo:), the create_pull_request safe-output never produces a PR. The MCP create_pull_request handler fails during patch generation with:
Pinned SHA <sha> failed to generate patch: ERR_SYSTEM: No remote refs available for merge-base calculation
The agent had correctly implemented and committed its change locally on a feature branch; the failure is entirely in the handler's patch generation, not the agent's git state.
This is the same ERR_SYSTEM symptom as #37836, but observed in a live agent run (not samples mode), and the logs reveal a more specific root cause than the hypothesis in #37836: the base branch is resolved by a GitHub GET /repos/{owner}/{repo} call that returns 404 Not Found, and the 404 error object is then stringified and used as the base-branch name.
Environment
github/gh-aw-actions/[email protected]- firewall containers
ghcr.io/github/gh-aw-firewall/{agent,api-proxy,squid}:0.25.68 ghcr.io/github/gh-aw-mcpg:v0.3.25- engine:
claude(Claude Code) - Pattern: SideRepoOps — workflow repo
<workflow-repo>, side repo<side-repo>(both private)
Root cause (from the safeoutputs MCP server log)
The handler logs the base branch it will diff against as the JSON body of a 404 response:
[safeoutputs] Using configured patch_workspace_path for create_pull_request: <side-repo-path> -> /home/runner/work/<workflow-repo>/<workflow-repo>/<side-repo-path>
[safeoutputs] Pinned branch '<feature-branch>' to SHA <sha>
[safeoutputs] Generating patch for create_pull_request with branch: <feature-branch> in .../<side-repo-path> baseBranch: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/repos/repos#get-a-repository","status":"404"}
[generate_git_patch] Starting patch generation: mode=full, branch=<feature-branch>, defaultBranch={"message":"Not Found","documentation_url":"https://docs.github.com/rest/repos/repos#get-a-repository","status":"404"}
[generate_git_patch] Environment: cwd=.../<side-repo-path>, GITHUB_SHA=<workflow-repo-sha>
[generate_git_patch] Strategy 1: Using pinned SHA <sha> (branch: <feature-branch>)
[generate_git_patch] Strategy 1 (full): Computing merge-base with {"message":"Not Found",...,"status":"404"} (ignoring any stale origin/<feature-branch>)
[generate_git_patch] Strategy 1 (full): origin/{"message":"Not Found",...,"status":"404"} not present locally and remote fetch failed (likely private repo without credentials in MCP server). Add "{...404 json...}" to checkout.fetch to enable this strategy.
[generate_git_patch] Strategy 1 (full): No remote refs available, falling through to Strategy 2
[generate_git_patch] Strategy 1: Branch '<feature-branch>' does not exist locally - ERR_SYSTEM: No remote refs available for merge-base calculation
[safeoutputs] Patch generation failed: Pinned SHA <sha> failed to generate patch: ERR_SYSTEM: No remote refs available for merge-base calculation
So the failing chain is:
- The handler resolves the side repo's base/default branch via a GitHub
GET /repos/{owner}/{repo}API call. - That call returns
404 Not Found— the token available to the safeoutputs MCP server cannot see the private side repo (404 = no visibility). - The 404 is not detected as an error. The error JSON object is stringified and used as both
baseBranchanddefaultBranch:{"message":"Not Found",...,"status":"404"}. generate_git_patchthen computes a merge-base against the literal reforigin/{"message":"Not Found",...}, which of course doesn't exist locally and can't be fetched, and aborts withERR_SYSTEM: No remote refs available for merge-base calculation.
Why #37836's hypothesis does not fully explain this
#37836 hypothesizes that origin/<baseBranch> simply isn't fetched into the side-repo checkout. In this run that is not the case — the side repo is checked out with full history and all branch refs are fetched:
- name: Checkout <side-repo> into <side-repo-path>
uses: actions/checkout@v6
with:
repository: <side-repo>
ref: master
path: <side-repo-path>
persist-credentials: false
fetch-depth: 0
- name: Fetch additional refs for <side-repo>
run: git -C .../<side-repo-path> fetch origin '+refs/heads/*:refs/remotes/origin/*'
The agent's own diagnostics inside that checkout confirmed origin/master resolves and 22 refs/remotes/origin/* refs are present locally, and git merge-base HEAD origin/master succeeds. A merge-base against master would have worked — the handler just never asks for master because the base-branch lookup 404'd and poisoned the ref name.
The base branch is also explicitly configured, so the API lookup shouldn't be needed at all:
safe-outputs:
create-pull-request:
target-repo: <side-repo>
allowed-repos: [<side-repo>]
allowed-base-branches: [master]
Likely trigger: missing cross-repo token on create-pull-request
In our config, tools.github is given a cross-repo token, but the create-pull-request safe-output has no github-token: override. The repro in #37836 passes github-token: ${{ secrets.TEMP_USER_PAT }} to create-pull-request. It looks like the handler's base-branch GET /repos call uses a token without read access to the private side repo, producing the 404. (persist-credentials: false also means the MCP server has no creds to re-fetch — though that's moot here since the refs are already present locally.)
Misleading error surface (matches #37836 secondary observation)
The handler returns the failure as {"result":"error", ...} inside a JSON-RPC response with isError: false, and the details field is actively misleading:
{"result":"error","error":"Pinned SHA <sha> failed to generate patch: ERR_SYSTEM: No remote refs available for merge-base calculation","details":"No commits were found to create a pull request. Make sure you have committed your changes using git add and git commit before calling create_pull_request."}
The details told the agent commits were missing (they weren't). In a live agent run this caused the agent to give up on create_pull_request and fall back to other outputs — every job still reported success, so the run looks green but silently produces no PR. This has recurred on every cross-repo PR attempt in this workflow since ~2026-06-08.
Suggested fixes
- Detect non-2xx responses from the base-branch / default-branch
GET /reposlookup. Never stringify an error object into a branch name. - Prefer configured base branch. When
allowed-base-branches(or the checkoutref:) is set, use it for the merge-base instead of an API round-trip — the local checkout already hasorigin/<base>. - Use the cross-repo token (the same one resolving
target-repo:/allowed-repos:) for the base-branch lookup so private side repos return 200, or document thatcreate-pull-request.github-tokenis required for SideRepoOps. - Fix the error surface: map
result: "error"toisError: true(also raised in #37836), and correct thedetailstext so it doesn't claim "no commits" when the real failure is base-branch resolution.
Redaction note
Private repository names, branch names, commit SHAs, and run URLs have been replaced with placeholders (<workflow-repo>, <side-repo>, <feature-branch>, <sha>). The literal {"message":"Not Found",...,"status":"404"} strings are reproduced verbatim from the logs because they are the core of the bug. Happy to share additional redacted log context on request.
Related: #37836.
Fork PR: https://github.com/Tarekchehahde/gh-aw/pull/9
Upstream compare: https://github.com/github/gh-aw/compare/main...Tarekchehahde:gh-aw:fix/39404-base-branch-404-validation
Approach: Validate branch names (reject 404 JSON bodies), honor sole allowed-base-branches entry without API, fail closed with actionable errors, fix misleading "no commits" details on merge-base failures.
Local tests: vitest run git_patch_utils.test.cjs create_pull_request_helpers.test.cjs get_base_branch.test.cjs — 111/111 pass
Hitting the same class of bug on GitHub Enterprise Server (not github.com), with a 401 instead of 404, so leaving this here rather than filing a duplicate.
Setup: gh aw CLI v0.88.7, dnb.ghe.com, create_pull_request safe-output targeting a different repo (target-repo: cross-repo, public within the enterprise — not private), Copilot engine.
Symptom: intermittent — 2 failures out of 5 consecutive live-mode runs of the same workflow against the same target repo, same checkout config (fetch-depth: 0, plus a custom step re-fetching refs/heads/* after checkout). create_pull_request fails with:
{"result":"error","error":"Pinned SHA <sha> failed to generate patch: ERR_SYSTEM: No remote refs available for merge-base calculation", ...}
...even though git merge-base, git log, and calling generateGitPatch() directly all succeed against the exact same checkout moments later in the same job.
Root cause found in job logs: the build_checkout_manifest step (which runs right after the actions/checkout steps, before our custom "fetch additional refs" step populates refs/remotes/origin/*) tries to resolve the target repo's default branch two ways, and both fail:
[debug] build_checkout_manifest: git default branch lookup failed for <target-repo>: Failed to run git symbolic-ref --short refs/remotes/origin/HEAD
fatal: ref refs/remotes/origin/HEAD is not a symbolic ref
[debug] build_checkout_manifest: gh api default branch lookup failed for <target-repo>: Failed to run gh api repos/<target-repo> --jq .default_branch
gh: Bad credentials (HTTP 401)
[info] checkout-manifest: <target-repo> -> path= default_branch=<unresolved>
[info] checkout-manifest: <target-repo> -> path=target default_branch=<unresolved>
So instead of a stringified 404 body becoming the ref name (as in the original report), here it resolves to the literal string <unresolved>, which presumably also fails to resolve to a real ref later.
Two distinct issues stacked here, same as the original report's diagnosis:
git symbolic-ref refs/remotes/origin/HEADis dead-end —actions/checkout's sparse/manual checkout mode never sets that ref, so this lookup always fails first.- The
gh api repos/<target-repo>fallback doesn't appear to use the same token that successfully performed the checkout of that repo a few steps earlier — it gets401 Bad credentialseven though the checkout itself (usingGH_AW_GITHUB_TOKEN) worked fine for the same repo.
This intermittently poisons later merge-base computation depending on timing between this early manifest-building step and the later "fetch additional refs" step. When it fails 3 retries in the same run, our workflow gracefully falls back to filing an issue with a ready-to-apply patch instead of crashing, so the impact is "no unattended PR" rather than data loss — but it does defeat unattended create_pull_request for cross-repo/live-mode workflows on GHES.
Happy to share full anonymized job logs if useful — this reproduced reliably enough (2/5 runs) that I could probably get a fresh repro on request.
Status (2026-10-07; Contributor proposal): A July 11 fork proposal would reject API error bodies used as branch names; a September 11 GHES report describes an intermittent 401 variant of the merge-base failure. The next step is to assess that proposal against both 404 and 401 cases and verify that failures produce actionable errors rather than invalid refs.
Community issue refresher — 2026-10-16: Partially addressed; private-repository/GHES failure handling still needs verification.
One reported credential gap has improved: the compiler now emits per-checkout GH_AW_CHECKOUT_TOKEN_*, and manifest resolution passes that token as GH_TOKEN to gh api. Its tests explicitly check this token override. Failed gh calls throw instead of treating nonzero-exit stdout as a successful branch lookup.
However, unresolved metadata still falls through to API/default resolution, which warns and returns DEFAULT_BRANCH/main on API failure rather than failing closed for an inaccessible side repo. The fork validation proposal Tarekchehahde/gh-aw#9 remains open. Also, <unresolved> in manifest logging is a display placeholder, not the literal stored ref.
The remaining check is a credential-free MCP plus private/GHES integration covering 401/404, unavailable origin/HEAD, correct target base, and actionable MCP errors. I did not reproduce the original stringified-404 failure, so this is not a claim that its exact error path still occurs.
Rechecked 2026-10-22 against current main (ffdd9c9): partially addressed; keep open for remaining resolution/error handling and private/GHES verification.
There is a newer concrete improvement since the October 16 refresher: merged #69452 preserves inherited GH_HOST and other subprocess environment while overriding GH_TOKEN with the per-checkout credential. Current regression coverage checks host/token combinations. Failed gh commands now throw rather than supply their error stdout as branch names; <unresolved> is only the manifest log's display placeholder. I cannot substantiate the original stringified-404 path on current code.
Two actionable gaps remain visible: failed target-repository API resolution still warns and falls back to DEFAULT_BRANCH/main, and patch failure details still incorrectly assert that no commits exist. That response does now set isError: true, so the original false-error-flag complaint is no longer accurate. Tarekchehahde/gh-aw#9 remains open/unmerged.
Next step: add a private-target/GHES integration matrix with unavailable origin/HEAD, valid per-checkout credentials, and explicit 401/404 failures. Verify the correct target base or a fail-closed actionable resolution error, never a guessed base/API-error ref, and replace generic "no commits" advice for resolution failures. No private-repository or GHES live reproduction was performed.