Skip to content

fix: trial command missing remote dependency fetching for imports#23165

Merged
pelikhan merged 9 commits intomainfrom
fix/trial-fetch-remote-imports
Mar 28, 2026
Merged

fix: trial command missing remote dependency fetching for imports#23165
pelikhan merged 9 commits intomainfrom
fix/trial-fetch-remote-imports

Conversation

@dsyme
Copy link
Copy Markdown
Collaborator

@dsyme dsyme commented Mar 26, 2026

githubnext/agentics#266

Problem

gh aw trial fails with import file not found errors when the workflow uses frontmatter imports: (e.g. shared/formatting.md), while the equivalent gh aw add works fine.

✗ .github/workflows/code-simplifier.md:22:5: error: import file not found
21 | imports:
22 |   - shared/formatting.md
         ^^^^^^^^^^^^^^^^^^^^

Root Cause

installWorkflowInTrialMode in trial_repository.go only called fetchAndSaveRemoteIncludes (for @include directives in the markdown body) but was missing three other dependency fetchers that AddWorkflows in add_command.go called:

  • fetchAndSaveRemoteFrontmatterImports — frontmatter imports: field
  • fetchAndSaveRemoteDispatchWorkflowssafe-outputs.dispatch-workflow references
  • fetchAndSaveRemoteResourcesresources: frontmatter field

Fix

Extract a shared fetchAllRemoteDependencies() function in includes.go that both add_command.go and trial_repository.go now call. This ensures parity between the two code paths and prevents future drift when new dependency types are added.

Changes

  • pkg/cli/includes.go: New fetchAllRemoteDependencies() function
  • pkg/cli/add_command.go: Replaced inline dependency fetching with shared function
  • pkg/cli/trial_repository.go: Replaced incomplete dependency fetching with shared function


✨ PR Review Safe Output Test - Run 23617381060

💥 [THE END] — Illustrated by Smoke Claude ·

dsyme and others added 5 commits March 26, 2026 19:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…spatch workflows, and resources

The trial command only called fetchAndSaveRemoteIncludes but not
fetchAndSaveRemoteFrontmatterImports, fetchAndSaveRemoteDispatchWorkflows,
or fetchAndSaveRemoteResources. This caused 'import file not found'
errors when running 'gh aw trial' with workflows that use frontmatter
imports (e.g. shared/formatting.md), while 'gh aw add' worked fine.

Extract a shared fetchAllRemoteDependencies function in includes.go
that both add_command.go and trial_repository.go now call, ensuring
parity and preventing future drift.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes gh aw trial failing with import file not found for workflows that use frontmatter imports: by aligning trial-mode dependency fetching with the add command’s behavior.

Changes:

  • Added a shared fetchAllRemoteDependencies() helper to fetch includes, frontmatter imports, dispatch-workflow references, and resources.
  • Updated add to call the shared helper instead of duplicating dependency-fetch logic inline.
  • Updated trial install flow to call the shared helper so remote workflows fetch the same dependency types as add.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/cli/includes.go Introduces fetchAllRemoteDependencies() to centralize remote dependency fetching.
pkg/cli/add_command.go Replaces inline dependency-fetch calls with fetchAllRemoteDependencies().
pkg/cli/trial_repository.go Uses fetchAllRemoteDependencies() in trial installs to prevent dependency-fetch drift.
actions/setup/js/extra_empty_commit.cjs Improves logging for git fetch/reset failures by including the underlying error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 153 to 155
const syncErrorMessage = error instanceof Error ? error.message : String(error);
core.warning(`Could not sync local branch with remote ${branchName} - will attempt push with local HEAD. Underlying error: ${syncErrorMessage}`);
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning logs the underlying git fetch/reset error message while the temporary remote URL contains the auth token (https://x-access-token:@...). Some git/exec errors can include the remote URL or other sensitive output, which would risk leaking the token into Actions logs. Please redact the token/remote URL from the error before logging, or avoid logging the raw error message here (e.g., log a generic warning and only include sanitized details).

Copilot uses AI. Check for mistakes.
Comment on lines +446 to +455
// fetchAllRemoteDependencies fetches all remote dependencies for a workflow:
// includes (@include directives), frontmatter imports, dispatch workflows, and resources.
// This is the single entry point shared by both the add and trial commands.
func fetchAllRemoteDependencies(ctx context.Context, content string, spec *WorkflowSpec, targetDir string, verbose bool, force bool, tracker *FileTracker) error {
// Fetch and save @include directive dependencies
if err := fetchAndSaveRemoteIncludes(content, spec, targetDir, verbose, force, tracker); err != nil {
if verbose {
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch include dependencies: %v", err)))
}
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says this function “fetches all remote dependencies”, but the implementation intentionally swallows errors from includes and frontmatter imports (only emitting a warning when verbose). This mismatch can confuse callers (e.g., trial wraps the returned error as if all dependency fetch failures would surface). Either update the comment/name to make the best-effort semantics explicit, or change the function to propagate/aggregate include/import errors when they occur.

Copilot uses AI. Check for mistakes.
dsyme and others added 2 commits March 26, 2026 20:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The test was timing out at 10s default. Increase to 30s to handle
slow API responses.
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 Automated smoke test review - all systems nominal!

💥 [THE END] — Illustrated by Smoke Claude

fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch resource dependencies: %v", err)))
}
return fmt.Errorf("failed to fetch resource dependencies: %w", err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function provides a clean, unified entry point for all remote dependency fetching. Smoke test review comment — Run 23617381060.

if err := fetchAllRemoteDependencies(ctx, string(content), parsedSpec, result.WorkflowsDir, opts.Verbose, true, nil); err != nil {
return fmt.Errorf("failed to fetch remote dependencies: %w", err)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good refactor — using fetchAllRemoteDependencies here ensures trial mode stays in sync with add command parity. Smoke test review comment — Run 23617381060.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions bot mentioned this pull request Mar 28, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

…e-imports

# Conflicts:
#	actions/setup/js/extra_empty_commit.cjs

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

@copilot merge main and recompile

Done — merged main (resolved conflict in extra_empty_commit.cjs using getErrorMessage helper) and recompiled all 178 workflows successfully. Commit: 0cc8f15

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw -pack /home/REDACTED/work/gh-aw/gh-aw/pkg/cli/access_log.go /home/REDACTED/work/gh-aw/gh-aw/pkg/cli/actionlint.go (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0 --jq .object.sha (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan March 28, 2026 01:41
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

Hey @dsyme 👋 — great find on the gh aw trial / gh aw add parity gap! The root cause analysis is spot-on and the refactor to fetchAllRemoteDependencies() is exactly the right shape — a single shared entry point that prevents future drift is a solid design decision. A couple of things to tighten up before merge:

  • Split the unrelated test change — the timeout addition in actions/setup/js/frontmatter_hash_github_api.test.cjs is a separate concern from the pkg/cli/ bug fix. It mixes two unrelated areas in one PR; consider landing it as a standalone fix or noting in the body why it's bundled here.

  • Add unit tests for fetchAllRemoteDependenciespkg/cli/includes.go has no test file at all right now. The new function is the single authoritative entry point for dependency fetching and should have at least a basic table-driven test verifying that all four fetchers are invoked (or gracefully skipped) for a mock remote workflow. The existing test patterns in pkg/cli/add_command_test.go and pkg/cli/trial_command_test.go use testutil helpers and table-driven testing.T — that's the right model.

If you'd like a hand, you can assign this prompt to your coding agent:

In the repository github/gh-aw, add unit tests for the new `fetchAllRemoteDependencies` function in `pkg/cli/includes.go`.

Context:
- PR #23165 introduced `fetchAllRemoteDependencies` as a shared entry point that calls:
  1. `fetchAndSaveRemoteIncludes` (errors swallowed, logged if verbose)
  2. `fetchAndSaveRemoteFrontmatterImports` (errors swallowed, logged if verbose)
  3. `fetchAndSaveRemoteDispatchWorkflows` (errors returned)
  4. `fetchAndSaveRemoteResources` (errors returned)
- There is currently no test file for `includes.go`.
- Follow the table-driven test patterns found in `pkg/cli/add_command_test.go` and `pkg/cli/trial_command_test.go`, using `testutil` helpers.

Create `pkg/cli/includes_test.go` with tests covering:
1. All four fetchers are invoked for a remote workflow (happy path — use mocks or stubs for the fetcher functions if needed).
2. Errors from `fetchAndSaveRemoteDispatchWorkflows` are propagated and cause `fetchAllRemoteDependencies` to return an error.
3. Errors from `fetchAndSaveRemoteResources` are propagated and cause `fetchAllRemoteDependencies` to return an error.
4. Errors from `fetchAndSaveRemoteIncludes` and `fetchAndSaveRemoteFrontmatterImports` are swallowed (function returns nil).

Run `make test` to confirm all tests pass, then run `make agent-finish` before completing.

Generated by Contribution Check ·

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review comments, add tests

…tring and add tests

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/78861777-a15b-4057-82d1-a28adf6deaba

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

@copilot review comments, add tests

Addressed the review comments and added tests in c877da6:

  • Updated the fetchAllRemoteDependencies docstring to explicitly document the asymmetric error handling: includes and frontmatter imports are best-effort (errors are swallowed with an optional warning), while dispatch-workflow and resource errors are fatal and propagated.
  • Added 5 tests for fetchAllRemoteDependencies: no dependencies, local spec no-op, include error swallowed, dispatch conflict propagated, and resource macro error propagated.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/github/gh-aw/contents/.github/workflows/shared/reporting.md
    • Triggering command: /tmp/go-build437764890/b001/cli.test /tmp/go-build437764890/b001/cli.test -test.testlogfile=/tmp/go-build437764890/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -test.run=TestFetchAll|TestFetchAndSave GOPROXY 64/bin/go GOSUMDB GOWORK 64/bin/go /opt/hostedtoolcache/go/1.25.0/xGO111MODULE -o /tmp/go-build984086534/b429/_pkgGOINSECURE -trimpath 64/bin/go -p github.com/githu-unsafeptr=false -lang=go1.25 go (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@pelikhan pelikhan merged commit 5301987 into main Mar 28, 2026
55 checks passed
@pelikhan pelikhan deleted the fix/trial-fetch-remote-imports branch March 28, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants