Skip to content

Runtime import deduplication: inline runtime-imports in workflow body are expanded twice due to recursive self-import #31650

@tore-unumed

Description

@tore-unumed

Description

When a workflow .md file contains inline {{#runtime-import}} macros in the prompt body, those macros are expanded twice in the final prompt sent to the agent.

Root cause

The compiled .lock.yml always includes the workflow body itself as the last runtime-import entry:

{{#runtime-import .github/workflows/shared/agent/some-shared-content.md}}   ← Import 5
{{#runtime-import .github/workflows/shared/agent/another-content.md}}       ← Import 6
{{#runtime-import .github/workflows/my-workflow.md}}                        ← Import 8 (self)

At runtime, the import resolver:

  1. Expands Import 5 (some-shared-content.md) → content appears once
  2. Expands Import 6 (another-content.md) → content appears once
  3. Expands Import 8 (my-workflow.md) → recursively processes the workflow body, which contains the {{#runtime-import}} macros for Imports 5 and 6 → content appears a second time

The recursive expansion of the self-import does not skip macros that were already resolved in the top-level pass.

Observed impact

  • Content from shared .md imports appears 2x in the generated prompt
  • In a real workflow with 3 inline runtime-imports, the prompt contained each shared block duplicated, wasting tokens and potentially confusing the model with redundant instructions
  • Verified by inspecting the "Print prompt" step in the activation job logs — <wiki-context> block appeared twice, <subagent-delegation> appeared 4 times

Expected behavior

Each {{#runtime-import}} macro should be resolved exactly once in the final prompt, regardless of whether it appears in a top-level import or is discovered during recursive expansion of the workflow body.

Suggested fix

During recursive import processing, track which import paths have already been resolved. Skip any macro whose target path matches an already-expanded import. This would be a simple set-based deduplication in the runtime import resolver.

Reproduction

  1. Create a workflow .md with an inline {{#runtime-import shared/agent/foo.md}} in the prompt body
  2. Compile with gh aw compile
  3. Dispatch the workflow
  4. Check the "Print prompt" activation step — the content of foo.md will appear twice

Version

gh aw v0.71.5

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