Repository navigation
Description
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_memoryupdate_cache_memoryupdate_drive_memorypush_ledger_changespush_evals_statepush_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
-
Model the post-agent maintenance jobs once (
pkg/constants/job_constants.go):- Add a
PostAgentMaintenanceJobNamesset (or a helperIsPostAgentMaintenanceJobName) that contains
the six names above. - Make
IsCompilerOwnedJobNameuse it instead of its inlineswitch. - Do not add these names to
KnownBuiltInJobNames: that map drives customisation and lint
semantics (for examplepkg/workflow/lint/custom_job_detection.go), which should not change.
- Add a
-
Seed the graph (
pkg/workflow/aw/job_dependencies.go,AuthoredJobDependencies):- After the
KnownBuiltInJobNamesloop, also seedgraph[id] = []string{"agent"}for every
post-agent maintenance job name. - This makes
graph.DependsOn("publish", "agent")true, sobuildMainJobDependenciesno longer adds
the job toagent.needs. The referenced-jobs path atcompiler_main_job_helpers.go#L100is fixed
by the same change.
- After the
-
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. -
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 withtools.repo-memoryand a custom
jobneeds: [push_repo_memory]compiles;agent.needsdoes not contain that job; and the custom
job'sneedsin the lock file is[push_repo_memory].- Keep a regression case for
needs: [agent, push_repo_memory], which must still compile unchanged.
-
Docs (
docs/src/content/docs/reference/steps-jobs.md): note that custom jobs may depend on the
generated post-agent jobs (for examplepush_repo_memory) and then run after the agent, without
listingagentexplicitly. -
Run
make agent-finish.
Acceptance criteria
- The reproduction workflow above compiles with
needs: [push_repo_memory]alone. - In its lock file,
agent.needsdoes not containpublish, andpublish.needsis[push_repo_memory]. needs: [agent, push_repo_memory]still compiles to the same job order.KnownBuiltInJobNamesis unchanged.
Suggested labels: bug, workflow
Activity