Skip to content

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

@jeffhandley

Description

@jeffhandley

engine.env values containing needs.<job>.outputs.* expressions are silently ignored during compilation — referenced custom jobs are never added to the agent's needs list, causing runtime failures--potentially silently--where the needs.<job> value is undefined. Additionally, no warning is emitted when built-in jobs (e.g. pre_activation, detection) are referenced in needs expressions across any scanning location.

Frontmatter Content

on:
  steps:
  - id: provide_value
    run: echo "provided_value=hello" >> "$GITHUB_OUTPUT"

jobs:
  pre-activation:
    outputs:
      provided_value: ${{ steps.provide_value.outputs.provided_value }}
  provide_value_to_agent:
    needs: pre-activation
    runs-on: ubuntu-latest
    steps:
      - run: echo "${{ needs.provide_value.outputs.provided_value }}" >> "$GITHUB_OUTPUT"

engine:
  id: copilot
  env:
    RECEIVED_VALUE: ${{ needs.provide_value_to_agent.outputs.provided_value }}

Expected Result

jobs:
  activation:
    needs:
      - pre_activation
      - provide_value_to_agent
    # ...
    steps:
      # ...
      - name: Validate COPILOT_GITHUB_TOKEN secret
        id: validate-secret
        run: # ...
        env:
          COPILOT_GITHUB_TOKEN: ${{ needs.provide_value_to_agent.outputs.provided_value }}
  # ...
  agent:
    needs:
      - activation
      - provide_value_to_agent
    # ...
    steps:
      # ...
      - name: Execute GitHub Copilot CLI
        id: agentic_execution
        # ...
        env:
          # ...
          COPILOT_GITHUB_TOKEN: ${{ needs.provide_value_to_agent.outputs.provided_value }}

Actual Result

jobs:
  activation:
    needs:
      - pre_activation
      - provide_value_to_agent
    # ...
    steps:
      # ...
      - name: Validate COPILOT_GITHUB_TOKEN secret
        id: validate-secret
        run: # ...
        env:
          COPILOT_GITHUB_TOKEN: ${{ needs.provide_value_to_agent.outputs.provided_value }}
          # **REPRO NOTE: `needs.provide_value_to_agent` IS AVAILABLE HERE**
  # ...
  agent:
    needs: activation
    # ...
    steps:
      # ...
      - name: Execute GitHub Copilot CLI
        id: agentic_execution
        # ...
        env:
          # ...
          COPILOT_GITHUB_TOKEN: ${{ needs.provide_value_to_agent.outputs.provided_value }}
          # **REPRO NOTE: `needs.provide_value_to_agent` IS `undefined` HERE**

Workaround

By including needs.provide_value_to_agent. anywhere in the markdown part of the workflow, the provide_value_to_agent job is detected for inclusion in the needs of the agent job. Without that string match in the markdown, only the activation job gains the job need.

Note that the current matching on needs.<job>. is susceptible to the Scunthorpe problem where there's no required word boundary before needs and nothing requires it to be inside a template expression. I only suggest fixing that because false-positive matches result in additional data being available to the agent.

Prototype Fix

I have a branch and a PR within my fork that represents a Copilot-authored fix that I reviewed but have not done end-to-end testing of.

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions