Skip to content

checkout: false aborts with 'not a git repository' on PR triggers; pull_request_target also racey with microsoft/apm-action #30791

Done

Description

@danielmeppiel

Summary

Two gh-aw v0.71.5 issues hit during real-world wiring of a pull_request_target review-panel workflow at hackathon-white-pig-8/zava-storefront. Both blocked the run before the agent started; both have local workarounds. Filing for upstream visibility.

Repro context

Issue 1 — checkout: false is incompatible with PR-context triggers

When checkout: false is set under any PR trigger (pull_request or pull_request_target), the compiler still emits a Checkout PR branch step in the agent job. That step runs checkout_pr_branch.cjs via actions/github-script, which executes git fetch / git rev-parse against the runner's working directory — but with checkout: false, no actions/checkout ran, so there is no .git and the helper aborts:

fatal: not a git repository (or any of the parent directories): .git
##[error]Event type: pull_request
##[error]PR number: 3
##[error]Error message: The process '/usr/bin/git' failed with exit code 128
##[error]Attempted to check out: test/panel-smoke
##[error]ERR_API: Failed to checkout PR branch: The process '/usr/bin/git' failed with exit code 128

Failing run (pull_request): https://github.com/hackathon-white-pig-8/zava-storefront/actions/runs/25479961077

Workaround: remove checkout: false. After removal the next run was fully green: https://github.com/hackathon-white-pig-8/zava-storefront/actions/runs/25480109686.

Suggested fix: when checkout: false is in frontmatter and the trigger is PR-context, either (a) skip the Checkout PR branch helper step entirely in the compiled lock yml, or (b) emit a fast-fail at compile time so users learn this isn't a supported combination before they ship.

Issue 2 — pull_request_target × microsoft/apm-action wipes .git before the helper runs

Independent of Issue 1: with pull_request_target and checkout: true (default), the lock yml correctly emits an actions/checkout (sparse) step early in the agent job, which DOES create .git. But by the time the Checkout PR branch helper runs (after the microsoft/[email protected] step that installs bundles), .git is gone and the same fatal: not a git repository error fires.

Failing run (pull_request_target): https://github.com/hackathon-white-pig-8/zava-storefront/actions/runs/25479764768

I have not yet root-caused which step wipes .git — it's somewhere between the sparse-checkout step (lock line ~152) and the Checkout PR branch helper (lock line ~434). Strong suspicion is microsoft/apm-action (line ~430) altering the workspace, but it could be one of the intervening agent-config save/restore steps.

Workaround: switch the workflow trigger from pull_request_target to pull_request. This loses fork-safety but is acceptable in a workshop / same-org context where label application requires repo write.

Suggested investigation: repro inside gh aw test fixtures with microsoft/apm-action enabled, isolate the step that wipes .git, and either preserve the workspace or have the helper re-actions/checkout lazily before its git operations.

Why both matter together

Anyone vendoring a pull_request_target review-panel workflow alongside microsoft/apm-action (the canonical pattern for fork-safe agentic CI) currently can't ship: Issue 2 forces them off _target, and if they try checkout: false as a defensive measure on the way to pull_request, Issue 1 catches them. The combination meant ~3 hours of debugging across 4 failed runs before we got to green.

Reference

  • Local fix PRs: #4 (trigger swap), #5 (remove checkout: false)
  • Smoke green: run 25480109686, advisory comment posted on PR #3

Happy to bring more repro detail or test against a fix candidate.

Activity

  1. locked and limited conversation to collaborators on May 7, 2026
  2. unlocked this conversation on May 7, 2026
  3. danielmeppiel commented on May 7, 2026

    @danielmeppiel
    Author

    Update — RCA done locally against gh-aw@6c1b6bd69 and microsoft/[email protected]. The two failing runs are the same bug, not two. Issue 2 retracted; microsoft/apm-action is innocent. Sharper Issue 1 + a patch + a branch ready to cherry-pick below.

    (Apologies for the original "two bugs" framing — I jumped to a pull_request_target × supply-chain hypothesis before finishing the RCA.)


    Single root cause

    pkg/workflow/compiler_yaml_main_job.go has two places that emit git-dependent steps:

    1. Line ~228 — generateGitConfigurationSteps is correctly gated on needsGitConfig := needsCheckout || customStepsContainCheckout. The original author noted the precondition explicitly: without .git, git remote set-url origin would crash.
    2. Line ~241 (this bug) — c.generatePRReadyForReviewCheckout(yaml, data) is called unconditionally. The "Checkout PR branch" helper it emits (actions/setup/js/checkout_pr_branch.cjs) shells out to git fetch origin (line 153) and gh pr checkout (line 180) — both require a .git directory. With checkout: false and no custom checkout step, the workspace is bare and the helper fails the entire agent job with fatal: not a git repository before the agent ever runs.

    Setting checkout: false correctly suppresses gate (1) via shouldAddCheckoutStep in compiler_jobs.go:759 (which honors CheckoutDisabled), but gate (2) was missed.

    Proof that Issue 2 is the same bug, not a separate pull_request_target × apm-action interaction

    Both failing runs in our smoke test had checkout: false in their workflow source at the head SHA:

    • Run 25479764768 (pull_request_target variant) — workflow source line 80: checkout: false
    • Run 25479961077 (pull_request variant) — workflow source line 70: checkout: false

    Step-by-step inspection of run 25479764768's agent job logs:

    • Step 11 ([email protected] restoring APM) ran with working-directory: . and successfully unpacked 31 files into /home/runner/work/zava-storefront/zava-storefront. No .git to wipe — .git was never created by any prior step. No actions/checkout appears anywhere in the job's step list.
    • Step 12 (Checkout PR branch) immediately failed with fatal: not a git repository (or any of the parent directories): .git.

    The sister apm-prep job's apm-action invocation runs in /tmp/gh-aw/apm-workspace — entirely outside the repo workspace — so it cannot affect the agent job's working directory either way.

    I also re-read microsoft/[email protected] end-to-end: src/runner.ts and the install/restore paths never touch .git. (For what it's worth, v1.4.2 was released specifically to keep apm-action from dirtying the workspace.)

    Patch (cherry-pick ready)

    I have a branch with the fix + two regression tests at:
    👉 https://github.com/danielmeppiel/gh-aw/tree/fix/pr-checkout-honor-checkout-disabled

    (Couldn't open a PR — github/gh-aw blocks fork-based PRs from non-org members. Happy to do whatever wires this into your contribution flow — file under your name, get added as a contributor, etc.)

    The change is two files, +51/-2:

    pkg/workflow/compiler_yaml_main_job.go — gate the helper on the same precondition the git-config step already uses:

    // Add step to checkout PR branch if the event is pull_request.
    // The PR-checkout helper runs `git fetch` / `gh pr checkout` against the workspace
    // and therefore requires a .git directory, which is only present when the repo was
    // checked out. Skip it when checkout is disabled and no custom steps perform a
    // checkout — otherwise the helper aborts with "fatal: not a git repository" and
    // the entire agent job fails before the agent ever runs.
    if needsGitConfig {
        c.generatePRReadyForReviewCheckout(yaml, data)
    } else {
        compilerYamlLog.Print("Skipping PR-checkout helper: checkout disabled and custom steps do not check out (helper requires .git in workspace)")
    }

    This preserves the existing escape hatch: if the user opted out of actions/checkout but supplied a custom step that does its own checkout, customStepsContainCheckout is true and the helper still emits.

    pkg/workflow/pr_ready_for_review_checkout_test.go — added two regression cases to TestPRCheckout:

    • pull_request + checkout: false ⇒ helper MUST NOT emit
    • pull_request_target + checkout: false ⇒ helper MUST NOT emit

    Both fail before the patch and pass after. Full integration suite green locally:

    $ go test -tags=integration ./pkg/workflow/ -count=1
    ok  github.com/github/gh-aw/pkg/workflow  57.770s
    

    Workaround (until fix lands)

    Either:

    • remove checkout: false from PR-context workflows, or
    • add a custom step in steps: that performs a checkout (will set customStepsContainCheckout=true once the fix lands; today, even without the fix, this also works because the helper at least has a .git to operate on).

    Optional polish (orthogonal to the fix)

    actions/setup/js/checkout_pr_branch.cjs could detect fatal: not a git repository in its catch path and emit a hint pointing at checkout: false — would have saved me ~3 hours.

  4. locked and limited conversation to collaborators on May 7, 2026
  5. unlocked this conversation on May 7, 2026
  6. pelikhan commented on Aug 25, 2026

    @pelikhan
    Collaborator

    /scout investigate status of this issue

  7. github-actions commented on Aug 25, 2026

    @github-actions
    Contributor

    ⚠️ Security scanning failed for Scout. Review the logs for details.

    🔭 Intelligence gathered by Scout

  8. github-actions commented on Aug 25, 2026

    @github-actions
    Contributor

    🔍 Scout Research Report

    Triggered by @pelikhan

    Executive Summary

    Issue 1 (the checkout: false + PR-trigger crash) is already fixed on main, merged over a month ago in PR #46771 (2026-07-20) — before this issue's own RCA patch was even proposed. A second PR, #49815 ("Fixes #30791"), added further runtime hardening but was closed without merging by @pelikhan on 2026-08-02. The issue itself is still open.

    Click to expand detailed findings

    Research Findings

    Issue 1 — already fixed on main

    pkg/workflow/pr.go's ShouldGeneratePRCheckoutStep currently reads:

    func ShouldGeneratePRCheckoutStep(data *WorkflowData) bool {
    	if data.CheckoutDisabled || data.IsPullRequestTarget {
    		return false
    	}
    	...
    }

    This exact guard — landed via PR #46771, "Disable checkout by default for pull_request_target workflows" (merged 2026-07-20) — makes generatePRReadyForReviewCheckout a no-op whenever checkout: false is set, for any PR-context trigger (not just pull_request_target). The PR's own description independently reproduces this issue's root cause:

    checkout: false in frontmatter was not suppressing this step — only the default actions/checkout was skipped... This fixes the pre-existing bug where checkout: false still generated the "Checkout PR branch" step (confirmed by ai-moderator.lock.yml which had checkout: false but the step was present).

    Regression coverage exists in current pkg/workflow/pr_test.go:79 (TestShouldGeneratePRCheckoutStep_CheckoutDisabled) and pkg/workflow/pr_ready_for_review_checkout_test.go:232 (TestPullRequestTargetCheckoutDisabledByDefault), both asserting no "Checkout PR branch" step is emitted.

    PR #46771 also auto-sets CheckoutDisabled = true for pull_request_target triggers with no explicit checkout: key — which independently neutralizes the retracted "Issue 2" scenario (pull_request_target × apm-action), since checkout is now off by default in that case too.

    The reporter's own patch (PR #49815) was closed, not merged

    danielmeppiel's branch was later opened upstream as PR #49815, "Harden PR branch checkout against missing .git and lock in checkout: false behavior", explicitly tagged Fixes #30791. It bundled two things:

    1. A compiler regression test locking in the checkout: false behavior (redundant by then — Disable checkout by default for pull_request_target workflows #46771 had already shipped the fix and its own tests).
    2. New runtime hardening in actions/setup/js/checkout_pr_branch.cjs: detect a missing .git, git init, and re-add origin before the fetch/checkout logic runs — a defense-in-depth layer for cases where some other step wipes workspace git metadata after checkout.

    A github-actions bot review commented positively on the PR, but @pelikhan closed it without merging or commenting on 2026-08-02. Confirmed by grepping the current actions/setup/js/checkout_pr_branch.cjs: there is no git init / missing-.git recovery logic in main today — that part of #49815 did not land.

    Recommendations

    • The compiler-level bug this issue reports is resolved on main; the issue can likely be closed (or narrowed to track only the runtime-hardening idea, if still wanted).
    • Decide explicitly on the runtime-hardening half of Harden PR branch checkout against missing .git and lock in checkout: false behavior #49815 (missing-.git auto-recovery in checkout_pr_branch.cjs). It's a reasonable defense-in-depth addition for cases where a custom step between checkout and the PR-checkout helper strips .git, but it was silently dropped — worth a one-line decision (accept/reject and why) so it isn't proposed again.
    • No action needed regarding microsoft/apm-action — the reporter's own RCA retracted that hypothesis, and it's independently moot now since pull_request_target defaults to checkout: false.

    Key Sources

    • PR #46771 — the fix that actually landed (merged 2026-07-20)
    • PR #49815 — closed, unmerged, explicitly targeted this issue
    • pkg/workflow/pr.go, pkg/workflow/pr_test.go, pkg/workflow/pr_ready_for_review_checkout_test.go on current main

    Suggested Next Steps

    1. Confirm the fix behaves as expected against the original repro workflow (hackathon-white-pig-8/zava-storefront's pr-review-panel.md), then close this issue.
    2. If the missing-.git runtime recovery is still wanted, reopen it as its own scoped PR/issue rather than reviving Harden PR branch checkout against missing .git and lock in checkout: false behavior #49815 as-is.

    🔭 Intelligence gathered by Scout · claude · agent · 100.1 AIC · ⌖ 6.36 AIC · ⊞ 7.4K · ◷
    Comment /scout to run again

  9. pelikhan commented on Oct 7, 2026

    @pelikhan
    Collaborator

    Status (2026-10-07; Verify resolution): The checkout: false portion is reported fixed by merged #46771, while the original report's pull_request_target behavior has not been fully verified. Confirm the remaining behavior with a current workflow before closing the issue.

  10. added
    bug
    cluster:checkout-event-timing
    on Oct 14, 2026
  11. pelikhan commented on Oct 16, 2026

    @pelikhan
    Collaborator

    Current-state refresher — 2026-10-16

    Verdict: Apparently resolved for the reported bug. Current main (0d15bd1649f6) supports the August Scout finding, with an important correction to the October 7 refresher.

    Merged #46771 fixed helper generation. ShouldGeneratePRCheckoutStep returns false for disabled checkout and pull_request_target; regression tests explicitly cover both conditions.

    The reporter's May 7 RCA retracted the separate apm-action/workspace-wipe hypothesis: both failing runs had checkout: false, so neither had a .git directory to wipe. That should not remain listed as an independently unresolved second bug.

    #49815 closed without merging; recovery if a later custom step deletes .git is separate defense-in-depth, not evidence that the original compiler bug persists.

    Remaining confirmation is a fresh reproduction using a newly compiled workflow/current version before a maintainer resolves the issue. I inspected source, tests, and merge history; I did not rerun the hosted workflow or change issue state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-inspectedbugcluster:checkout-event-timingcommunityscout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions