Skip to content

Fix agent job needs not populated from engine.env needs expressions#30239

Merged
pelikhan merged 5 commits into
mainfrom
copilot/fix-engine-env-needs-issue
May 5, 2026
Merged

Fix agent job needs not populated from engine.env needs expressions#30239
pelikhan merged 5 commits into
mainfrom
copilot/fix-engine-env-needs-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

engine.env values containing needs.<job>.outputs.* expressions were silently ignored during compilation — referenced custom jobs were never added to the agent job's needs list, causing those expressions to evaluate to empty strings at runtime.

Changes

  • compiler_main_job.go: Extend the custom-job reference scan in buildMainJob to include all engine.env values in addition to markdown content and custom steps. Engine env content is computed once and reused for:
    • Adding referenced custom jobs as direct needs dependencies of the agent job
    • Emitting a compiler warning when engine.env values reference built-in jobs (detection, safe_outputs, etc.) that cannot be wired as direct agent dependencies — built-in jobs already present as direct dependencies (e.g., activation) are correctly excluded from this warning

Example

Given this frontmatter:

engine:
  id: copilot
  env:
    RECEIVED_VALUE: ${{ needs.provide_value_to_agent.outputs.provided_value }}
jobs:
  provide_value_to_agent:
    runs-on: ubuntu-latest
    # ...

Before: agent.needs = [activation]needs.provide_value_to_agent is undefined at runtime.
After: agent.needs = [activation, provide_value_to_agent] → expression evaluates correctly.

Tests

  • Unit test: engine.env reference adds custom job as direct dependency
  • Unit test: no duplication when job is referenced in both engine.env and normal content
  • Unit test: no false warning emitted when engine.env references activation (already a direct dependency)
  • Integration unit test (pkg/workflow): end-to-end compilation of the exact bug-report scenario
  • CLI integration test (pkg/cli): compiles test-engine-env-needs.md fixture and asserts provide_value_to_agent appears in the agent job's needs

[!WARNING]

Copilot AI and others added 2 commits May 5, 2026 00:51
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/0d59bfbd-af1d-4dbb-929a-9387b68a271e

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
When engine.env values contain needs.<job>.outputs.* expressions, the
referenced custom jobs are now scanned and added as direct dependencies
of the agent job — matching the existing behavior for markdown content
and custom steps.

Additionally, emit a warning when engine.env values reference built-in
jobs (e.g., detection, safe_outputs) via needs expressions, since
those jobs cannot be added as direct agent dependencies and the
expression would silently evaluate to empty at runtime.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/0d59bfbd-af1d-4dbb-929a-9387b68a271e

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix agent needs not incorporating jobs in engine.env expressions Fix agent job needs not populated from engine.env needs expressions May 5, 2026
Copilot AI requested a review from pelikhan May 5, 2026 01:11
@pelikhan pelikhan marked this pull request as ready for review May 5, 2026 01:27
Copilot AI review requested due to automatic review settings May 5, 2026 01:27
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 a compilation gap where engine.env values containing needs.<job>.outputs.* were not considered when computing the agent job’s direct needs, leading to those expressions evaluating to empty strings at runtime.

Changes:

  • Extend agent job dependency scanning in buildMainJob to include all engine.env values.
  • Emit a compiler warning when engine.env references built-in jobs via needs.* expressions.
  • Add unit + end-to-end compilation tests covering the engine.env dependency behavior.
Show a summary per file
File Description
pkg/workflow/compiler_main_job.go Includes engine.env values in the referenced-job scan so the agent job needs list is correctly populated; adds warnings for built-in job references in engine.env.
pkg/workflow/compiler_jobs_test.go Adds tests ensuring engine.env needs-expressions add custom jobs to agent needs and don’t duplicate entries; includes an end-to-end compilation assertion.
.github/workflows/metrics-collector.lock.yml Regenerates the lock workflow output (adds GH_AW_INFO_VERSION in a setup step env block).

Copilot's findings

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment on lines +169 to +176
builtinNames := make([]string, 0, len(constants.KnownBuiltInJobNames))
for name := range constants.KnownBuiltInJobNames {
builtinNames = append(builtinNames, name)
}
sort.Strings(builtinNames)
builtinsWarned := make(map[string]bool)
for _, builtinJobName := range builtinNames {
if !builtinsWarned[builtinJobName] && strings.Contains(engineEnvContent, fmt.Sprintf("needs.%s.", builtinJobName)) {
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 5, 2026

@copilot review all comments

When engine.env references a built-in job that is already a direct
dependency of the agent job (e.g., activation), skip the warning.
The warning now only fires for built-in jobs that are not in the
agent's depends list — i.e., those that would silently produce empty
strings at runtime.

Add a regression test to verify that activation references in engine.env
do not trigger a spurious warning.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/abe615eb-6bb4-4ba0-a6c3-b3c8b4f10821

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

Copilot AI commented May 5, 2026

@copilot review all comments

Addressed in 7e3bc98. The warning now skips any built-in job already present in depends (e.g., activation), so ${{ needs.activation.outputs.* }} in engine.env no longer triggers a false warning. A regression test TestBuildMainJobEngineEnvActivationNoFalseWarning was added to cover this case.

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/actions/github-script/git/ref/tags/v9
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9 --jq [.object.sha, .object.type] | @tsv (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9 --jq [.object.sha, .object.type] | @tsv ignore-path ../../../.prettierignore (http block)

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

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 5, 2026

@copilot add integration workflow tests in pkg/cli/workflows

…cli/workflows

- Add test fixture: test-engine-env-needs.md — a workflow where engine.env
  references provide_value_to_agent via a needs expression
- Add integration test: TestCompileEngineEnvNeedsExpression — compiles the
  fixture and asserts that the agent job's needs list includes both
  activation and provide_value_to_agent

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d869ed3d-87d8-4270-8065-3d4371b6aaae

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

Copilot AI commented May 5, 2026

@copilot add integration workflow tests in pkg/cli/workflows

Added in d4f67c8:

  • pkg/cli/workflows/test-engine-env-needs.md — workflow fixture with a custom job referenced via engine.env
  • pkg/cli/compile_engine_env_needs_integration_test.goTestCompileEngineEnvNeedsExpression compiles the fixture and asserts the agent job's needs contains both activation and provide_value_to_agent

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/actions/github-script/git/ref/tags/v9
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9 --jq [.object.sha, .object.type] | @tsv (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9 --jq [.object.sha, .object.type] | @tsv GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE sh -c npx prettier --cGOINSECURE GOPROXY 64/bin/go GOSUMDB GOWORK 64/bin/go node (http block)
  • https://api.github.com/repos/actions/github-script/git/ref/tags/v9.0.0
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9.0.0 --jq [.object.sha, .object.type] | @tsv (http block)

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

@pelikhan pelikhan merged commit 4f2f37e into main May 5, 2026
@pelikhan pelikhan deleted the copilot/fix-engine-env-needs-issue branch May 5, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent 'needs' does not incorporate jobs in engine.env expressions

3 participants