Skip to content

Custom job with needs: [push_repo_memory] fails to compile with a false dependency cycle #74103

Done

Description

@johnwilliams-12

Summary

A custom job that runs after the repo-memory push (needs: [push_repo_memory]) fails to compile:

cycle detected in job dependencies: job 'publish' has circular dependency through 'push_repo_memory'

There is no cycle in what the author wrote. The compiler adds the custom job to the agent job's
needs because it does not see that push_repo_memory already runs after agent. The workaround is to
also list agent explicitly: needs: [agent, push_repo_memory].

Reproduced with gh-aw v1.0.1, the latest release, and with a build of main at f37d3b9 (2026-11-02).
The job named in the error varies between runs ('agent' … through 'publish',
'push_repo_memory' … through 'agent'), so the cycle check apparently starts from map order.

Reproduction

.github/workflows/demo.md:

---
on:
  workflow_dispatch:
engine: copilot
permissions:
  contents: read
tools:
  repo-memory:
    branch-name: memory/demo
jobs:
  publish:
    needs: [push_repo_memory]
    runs-on: ubuntu-latest
    steps:
      - run: echo "publish what the agent saved"
---
Write a note to repo memory.
$ gh aw compile demo
✗ demo.md (1 error(s)):
  • 1. .github/workflows/demo.md:1:1: error: failed to generate YAML: workflow compilation requires valid
    jobs and dependencies; check job definitions and needs references: job dependency validation expected
    each needs entry to reference an existing job id (for example, needs: build): cycle detected in job
    dependencies: job 'publish' has circular dependency through 'push_repo_memory'

With needs: [agent, push_repo_memory] the workflow compiles.

Analysis

buildMainJobDependencies (pkg/workflow/compiler_main_job_helpers.go#L59-L70)
adds every custom job to agent.needs unless graph.DependsOn(job, "agent") is true. The graph comes
from aw.AuthoredJobDependencies.

AuthoredJobDependencies
is documented as "includes the compiler-owned post-agent dependencies", but it only seeds a
<job> → agent edge for names in constants.KnownBuiltInJobNames
(pkg/constants/job_constants.go#L122-L139).

The generated maintenance jobs that also run after agent are not in that map. They are recognised
separately by IsCompilerOwnedJobName
(#L144-L154):

  • push_repo_memory
  • update_cache_memory
  • update_drive_memory
  • push_ledger_changes
  • push_evals_state
  • push_experiments_state

So for publish → push_repo_memory the graph has no path to agent. publish is added to
agent.needs, and since the generated push_repo_memory needs agent, the result is
agent → publish → push_repo_memory → agent.

isReservedOnNeedsTarget in pkg/workflow/on_needs_validation.go#L325
keeps yet another hand-written list that includes push_repo_memory and update_cache_memory, so the
"which jobs are post-agent" knowledge lives in three places.

The dependency graph was introduced in #70997, so v0.93.5 and later are affected. Related but distinct:
#27747 (built-in job names used as jobs: keys) and #23483 (ordering custom safe-output jobs).

Implementation plan

  1. Model the post-agent maintenance jobs once (pkg/constants/job_constants.go):

    • Add a PostAgentMaintenanceJobNames set (or a helper IsPostAgentMaintenanceJobName) that contains
      the six names above.
    • Make IsCompilerOwnedJobName use it instead of its inline switch.
    • Do not add these names to KnownBuiltInJobNames: that map drives customisation and lint
      semantics (for example pkg/workflow/lint/custom_job_detection.go), which should not change.
  2. Seed the graph (pkg/workflow/aw/job_dependencies.go, AuthoredJobDependencies):

    • After the KnownBuiltInJobNames loop, also seed graph[id] = []string{"agent"} for every
      post-agent maintenance job name.
    • This makes graph.DependsOn("publish", "agent") true, so buildMainJobDependencies no longer adds
      the job to agent.needs. The referenced-jobs path at compiler_main_job_helpers.go#L100 is fixed
      by the same change.
  3. Reuse the set in isReservedOnNeedsTarget (pkg/workflow/on_needs_validation.go) instead of its
    own list, if that function is meant to cover the same jobs.

  4. Tests:

    • pkg/workflow/aw/job_dependencies_test.go: DependsOn("x", "agent") is true for a job with
      needs: [push_repo_memory], and for each of the other maintenance names.
    • pkg/workflow/compiler_main_job_helpers_test.go: a workflow with tools.repo-memory and a custom
      job needs: [push_repo_memory] compiles; agent.needs does not contain that job; and the custom
      job's needs in the lock file is [push_repo_memory].
    • Keep a regression case for needs: [agent, push_repo_memory], which must still compile unchanged.
  5. Docs (docs/src/content/docs/reference/steps-jobs.md): note that custom jobs may depend on the
    generated post-agent jobs (for example push_repo_memory) and then run after the agent, without
    listing agent explicitly.

  6. Run make agent-finish.

Acceptance criteria

  • The reproduction workflow above compiles with needs: [push_repo_memory] alone.
  • In its lock file, agent.needs does not contain publish, and publish.needs is [push_repo_memory].
  • needs: [agent, push_repo_memory] still compiles to the same job order.
  • KnownBuiltInJobNames is unchanged.

Suggested labels: bug, workflow

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions