Skip to content

Cross-org workflow_call: resolve_host_repo, checkout, and hash check all fail #24949

Closed
3 of 3 issues completed

Description

@bbonafed

Summary

When a reusable workflow compiled by gh aw compile is invoked cross-org via workflow_call (caller in org-A, callee/platform repo in org-B, same enterprise), the activation job fails at multiple points. The compiled lock file cannot resolve the correct source repository, cannot check out the callee's files, and cannot verify the frontmatter hash.

This blocks all cross-org central-repo-ops patterns.

Environment

  • gh-aw CLI: v0.67.2
  • gh-aw-actions/setup: v0.67.2 (3922978bff4d7cf117e185580ad108da5a0134d8)
  • Both organizations are in the same GitHub Enterprise Cloud account
  • Callee repository visibility: internal

Bug 1: resolve_host_repo.cjs resolves to the caller repo

Expected

The "Resolve host repo for activation checkout" step should resolve to the callee (platform) repository so the checkout fetches the correct .github/ and .agents/ content.

Actual

It resolves to the caller repository. The script relies on GITHUB_WORKFLOW_REF (line 38), but in a workflow_call invocation, GITHUB_WORKFLOW_REF points to the top-level caller's workflow — not the reusable workflow being executed.

The code comment on line 14 states:

"GITHUB_WORKFLOW_REF always reflects the currently executing workflow file"

This is incorrect for workflow_call. The GitHub Actions docs confirm that github.workflow_ref resolves to the caller's workflow ref in reusable workflow contexts.

Suggested Fix

Apply the same referenced_workflows API lookup that check_workflow_timestamp_api.cjs already uses (lines 118–157). When the env workflow ref doesn't match the current lock file, query GET /repos/{caller}/actions/runs/{run_id} and find the matching entry in referenced_workflows[] to determine the correct callee repo and ref.

The target_repo_name output is already designed for actions/create-github-app-token (per the comment on line 76–77), confirming that cross-org was anticipated — the resolution logic just wasn't updated.

Bug 2: Checkout step cannot access the callee repo cross-org

Expected

The "Checkout .github and .agents folders" step should successfully clone the callee's repository content.

Actual

The checkout step uses the default GITHUB_TOKEN (no explicit token: parameter). The GITHUB_TOKEN is a GitHub App installation token scoped to the caller's organization. It cannot access repositories in a different org, even if both orgs are in the same enterprise and the callee repo is internal. The checkout fails with:

remote: Repository not found.
Error: fatal: repository 'https://github.com/<callee-org>/<callee-repo>/' not found

Suggested Fix — Two Options

Option A: actions/create-github-app-token integration

When resolve_host_repo detects a cross-org invocation (targetRepo !== currentRepo and different org prefix), the compiled workflow should include a step that mints a short-lived installation token via actions/create-github-app-token. This would require:

  1. The user to install a GitHub App in both orgs (one-time admin setup)
  2. App ID and private key stored as secrets, passed via workflow_call secrets
  3. The compiled workflow to call actions/create-github-app-token with owner: and repositories: (using the existing target_repo_name output) to generate a cross-org token
  4. That token is passed to the checkout step and hash check step

This is the standard GitHub-recommended approach for cross-org access.

Option B: Pre-inline all runtime imports during compilation (optional frontmatter flag)

An alternative that requires zero extra token setup: add an optional frontmatter flag (e.g., inline-imports: true or self-contained: true) that causes gh aw compile to inline all {{#runtime-import ...}} content directly into the lock file at compile time, rather than leaving them as runtime directives.

With fully inlined content:

  • The cross-org checkout of .agents/ becomes unnecessary (no runtime imports to resolve)
  • The checkout of .github/workflows/ is only needed for the hash check, which could be made non-fatal or skipped for cross-org scenarios
  • The lock file becomes entirely self-contained — no runtime file dependencies

This would be particularly helpful for teams using central-repo-ops patterns where the platform repo and caller repos are in different organizations. The trade-off is larger lock files, which is why making it opt-in via frontmatter seems ideal.

Option B would be particularly valuable for our use case — we maintain a central platform repo with reusable agentic workflows consumed by repos across multiple orgs in the same enterprise. Eliminating the cross-org checkout dependency would significantly simplify adoption.

Bug 3: check_workflow_timestamp_api.cjs requires actions: read but the compiler doesn't add it

The hash check step calls github.rest.actions.getWorkflowRun() via the referenced_workflows API lookup (line 124). This requires the actions: read permission on the GITHUB_TOKEN. However, the compiled activation job only declares contents: read in its permissions: block.

Since explicit permissions: restricts the token to only the listed scopes, actions: read is absent and the API call fails with:

Error: Resource not accessible by integration

Suggested Fix

The compiler should add actions: read to the activation job's permissions: whenever it emits the check_workflow_timestamp_api.cjs step.

Reproduction

  1. Create a reusable workflow in org-B using gh aw compile
  2. Create a caller workflow in org-A (different org, same enterprise) that uses workflow_call to invoke the reusable workflow
  3. Run the caller workflow
  4. Observe:
    • resolve_host_repo resolves to org-A's repo (wrong)
    • Checkout clones org-A's repo (no .agents/ or .github/workflows/*.md present)
    • Hash check fails (no files on disk, API fallback also fails)

Summary of Fixes Needed

Component Issue Fix
resolve_host_repo.cjs Uses GITHUB_WORKFLOW_REF which points to caller Add referenced_workflows API lookup (same as check_workflow_timestamp_api.cjs)
Checkout step (compiled) No cross-org token Option A: actions/create-github-app-token integration; Option B: inline-imports frontmatter flag to eliminate runtime checkout
Compiler (permissions:) Missing actions: read Add actions: read when emitting hash check step

Option B (pre-inline with frontmatter flag) would be particularly valuable for our use case and likely for other teams adopting central-repo-ops across org boundaries.

Sub-issues

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. pelikhan commented on Apr 6, 2026

    @pelikhan
    Collaborator

    There is a inlined-imports front matter flag. The agent should have sugggested it...

  2. pelikhan commented on Apr 6, 2026

    @pelikhan
    Collaborator

    /plan

  3. github-actions commented on Apr 6, 2026

    @github-actions
    Contributor

    ✅ Plan Command completed successfully!

  4. bbonafed commented on Apr 6, 2026

    @bbonafed
    Author

    There is a inlined-imports front matter flag. The agent should have sugggested it...

    Oops, I should have noticed that. Thanks for info

  5. locked and limited conversation to collaborators on Apr 6, 2026
  6. unlocked this conversation on Apr 6, 2026
  7. added a commit that references this issue on Apr 6, 2026
    aa50846
  8. theletterf commented on Apr 8, 2026

    @theletterf

    We're hitting a related issue with cross-repo workflow_call in v0.67.2 — specifically, the frontmatter hash computed at compile time doesn't match the hash computed at runtime, even though both are v0.67.2.

    Evidence

    After compiling with gh aw compile (v0.67.2), the lock file metadata contains:

    frontmatter_hash: cef41fa48a0af36bffbe2e4b41a022829db14706a30947e619c83eaa3b9b3eb5
    compiler_version: v0.67.2
    

    But gh aw hash-frontmatter (also v0.67.2) on the same .md source produces a different hash:

    3bf3394da2b667fffb279e50f4e25e9077b20e04d879b68d1f53aee2f7612906
    

    The runtime verification (check_workflow_timestamp_api.cjs from gh-aw-actions/[email protected]) recomputes the hash and gets the same value as hash-frontmatter, so it fails:

    Frontmatter hash comparison:
      Lock file hash:    cef41fa48a0af36bffbe2e4b41a022829db14706a30947e619c83eaa3b9b3eb5
      Recomputed hash:   3bf3394da2b667fffb279e50f4e25e9077b20e04d879b68d1f53aee2f7612906
    
    ERR_CONFIG: Lock file '...' is outdated! The workflow file '...' frontmatter has changed.
    

    Context

    • The cross-repo resolution fix in v0.67.2 works — the activation job now correctly resolves the callee repo (elastic/docs-actions) instead of the caller (elastic/docs-content). The .md source and lock file are both found.
    • The failure is purely the hash mismatch between what compile embeds and what the runtime recomputes from the same file.
    • Tried adding inlined-imports: true — same result (different hashes, but still mismatched).

    Setup

    • Callee (platform repo): elastic/docs-actions — public, contains the .md source + .lock.yml
    • Caller: elastic/docs-content — public, thin trigger with uses: elastic/docs-actions/...@v1
    • Both gh aw CLI and gh-aw-actions/setup at v0.67.2
  9. locked and limited conversation to collaborators on Apr 8, 2026
  10. unlocked this conversation on Apr 8, 2026
  11. pelikhan commented on Apr 10, 2026

    @pelikhan
    Collaborator
  12. bbonafed commented on Apr 10, 2026

    @bbonafed
    Author

    Update: inlined-imports: true does not fully resolve cross-org workflow_call

    We've been using inlined-imports: true as recommended (PR #24977), and it successfully eliminates the need for a cross-org checkout of .agents/ and .github/ content. However, the hash check step (check_workflow_timestamp_api.cjs) still fails in cross-org scenarios.

    What works

    What still fails

    The hash check step calls the GitHub API to fetch the lock file from the callee repo for hash comparison:

    GET /repos/{callee-org}/{callee-repo}/contents/.github/workflows/{lock-file}.lock.yml?ref={sha}
    

    The default GITHUB_TOKEN is scoped to the caller's organization and cannot access repositories in a different org, even within the same enterprise. The API call returns 404, the local filesystem fallback (PR #24057) also fails (since inlined-imports: true means the callee's files aren't checked out locally), and the step fails with:

    Could not fetch content for .github/workflows/{lock-file}.lock.yml: Not Found
    Unable to fetch lock file content for hash comparison via API, trying local filesystem fallback
    Local lock file not found: /home/runner/work/{repo}/{repo}/.github/workflows/{lock-file}.lock.yml
    Warning: Could not compare frontmatter hashes - assuming lock file is outdated
    Error: ERR_CONFIG: Lock file is outdated or unverifiable!
    

    Current workaround

    We're patching the compiled lock file to pass a cross-org PAT to the hash check step:

    - name: Check workflow lock file
      uses: actions/github-script@...
      with:
        github-token: ${{ secrets.CROSS_ORG_TOKEN || github.token }}

    This must be re-applied after every gh aw compile.

    Suggestion

    The compiler could accept an optional github-token override for the hash check step (e.g., via frontmatter or workflow_call input), so cross-org users don't need to manually patch lock files. Alternatively, when inlined-imports: true is set, the hash check could use only the inlined content for verification rather than requiring API access to the callee repo.

  13. locked and limited conversation to collaborators on Apr 10, 2026
  14. unlocked this conversation on Apr 10, 2026
  15. pelikhan commented on Apr 11, 2026

    @pelikhan
    Collaborator
  16. pelikhan commented on Apr 12, 2026

    @pelikhan
    Collaborator

    Fixed with new job.workflow_* variables

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions