-
Notifications
You must be signed in to change notification settings - Fork 316
Description
Analysis
In workflows that use a proxied / integrity-filtered (e.g. DIFC-style) pre-agent setup, environment variables for the GitHub CLI are often rewritten so GH_HOST (and sometimes related GITHUB_*_URL values) target a local proxy host, while the checked-out repository’s origin remote remains the canonical GitHub.com / GHES HTTPS host (as set by typical actions/checkout + tokenized remotes).
The generated PR checkout path then runs gh pr checkout <pr-number> with GH_HOST still pointing at the proxy. The GitHub CLI validates remotes against GH_HOST and exits with:
none of the git remotes configured for this repository correspond to the GH_HOST environment variable
So the job fails before normal agent execution, even when the repository, PR, and token are valid. The failure is environment normalization / step isolation, not token scope. It is also easy to misdiagnose as permissions, fork handling, or invalid PR metadata.
Summary
This issue asks that generated gh-aw workflows (and/or shared setup actions) normalize or scope environment for PR checkout so gh pr checkout sees GH_HOST / API URLs consistent with git remotes, or use a git-native checkout for same-repo heads where appropriate—without downstream consumers hand-editing compiled lockfiles after every compile.
Observed failure shape
Typical gh error:
none of the git remotes configured for this repository correspond to the GH_HOST environment variable
Logs may show GH_HOST set to a localhost / loopback hostname (or another non-canonical host) while git remote -v still shows the real GitHub instance host.
What appears to be happening
- Early steps start a proxy (or similar) and adjust
GH_HOST/ relatedGITHUB_*_URLsoghtraffic goes through the proxy. - PR checkout runs
gh pr checkoutwhileGH_HOSTstill reflects the proxy, butgitremotes still reference the real GitHub server hostname. ghrefuses to proceed because no remote matchesGH_HOST.
Minimal repro (shape)
Conditions
- Workflow uses a proxy / DIFC-style pre-agent
ghsetup that setsGH_HOSTto a local proxy host. - The workspace
gitremote still targets the normal GitHub.com or GHES host. - The generated checkout step uses
gh pr checkout(by PR number).
Result
gh pr checkoutexits non-zero with the message above; dependent steps do not run.
A minimal public repro could be a small workflow that sets GH_HOST to a synthetic localhost value before gh pr checkout, without relying on proprietary proxy details.
Why this matters
- PR-triggered agent workflows can fail very early despite valid PRs and working auth.
- Operators and automation often assume 403 / permissions or fork issues first; the fix is checkout-scoped env or checkout strategy.
- Consumers should not rely on permanent post-compile patches to injected YAML for this class of failure.
Suggested implementation plan (for maintainers / implementing agent)
-
Smallest / targeted (compiler or shared action)
Immediately before the generated PR checkout step, emit step-levelenv(or equivalent) so that step uses real instance values, for example:- Derive
GH_HOSTfromGITHUB_SERVER_URL(strip scheme). - Set
GITHUB_API_URLandGITHUB_GRAPHQL_URLto the non-proxied endpoints that match that instance for the checkout step only.
Then rungh pr checkoutunder that env. Do not rely on job-wideGITHUB_ENValone if later steps still need proxy settings—prefer scoping to the checkout step.
- Derive
-
Better isolation
Ensure proxy-specificGH_HOST/ API overrides do not leak into steps that must align with normalgitremotes (explicit stepenv, or explicit unset/override for checkout only). -
Stronger long-term
For same-repository PR heads, prefer deterministicgit fetch/git checkoutof the head ref when safe, and reservegh pr checkoutfor cross-repo / fork cases where it is required. -
Tests / validation
Add a regression test or workflow fixture that simulatesGH_HOSTmismatch (e.g. localhost) before checkout and asserts the generated workflow or helper normalizes env or chooses a git-native path. -
Observability (optional but helpful)
When webhook PR metadata is partial, concise logging of same-repo vs cross-repo checkout decisions (from API-resolved metadata) helps distinguish fork/cross-repo needs, metadata ambiguity, and proxy /GH_HOSTmismatch.
Additional note (observability)
When webhook PR metadata is thin (e.g. missing head repo), checkout strategy may differ. Logging same-repo vs cross-repo decisions would help separate:
- true fork / cross-repo checkout needs
- metadata ambiguity
- proxy /
GH_HOSTmismatch (this issue)
Expected outcome
Generated gh-aw workflows check out PR branches reliably in proxied / DIFC-style environments without requiring consumers to hand-patch compiled lockfiles after every compile.
Thanks for considering this — happy to help validate a fix against our setup if useful (in generic terms, without sharing private repository details).