Skip to content

fix: emit interpolation step when prompt contains runtime-import macros - #49122

Merged
pelikhan merged 7 commits into
mainfrom
copilot/fix-compiler-runtime-import
Jul 30, 2026
Merged

fix: emit interpolation step when prompt contains runtime-import macros#49122
pelikhan merged 7 commits into
mainfrom
copilot/fix-compiler-runtime-import

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

In normal (non-inline) compilation mode the compiler unconditionally emits a {{#runtime-import <workflow>.md}} self-import macro into the prompt, but generateInterpolationAndTemplateStep would skip generating the "Interpolate variables and render templates" step when none of its four existing guards fired — most commonly when tools.github: false with no expressions or {{#if}} blocks. Since interpolate_prompt.cjs is the only consumer of {{#runtime-import}} macros, the macro reached the agent unresolved and the entire workflow body was silently dropped.

Changes

  • pkg/workflow/compiler_yaml_prompt.go — after building userPromptChunks, compute hasRuntimeImports by checking whether any chunk starts with {{#runtime-import (using sliceutil.Any), then pass it as a new parameter to generateInterpolationAndTemplateStep.

  • pkg/workflow/template.go — add hasRuntimeImports bool parameter; fold it into the skip guard so the step is always emitted when runtime-import macros are present:

    // Before
    hasTemplates := hasTemplatePattern || hasGitHubContext || hasInlineSubAgents
    
    // After
    hasTemplates := hasTemplatePattern || hasGitHubContext || hasInlineSubAgents || hasRuntimeImports
  • pkg/workflow/template_test.go — update existing call sites; add TestGenerateInterpolationAndTemplateStep_WithRuntimeImport covering the previously-silent skip.

  • pkg/workflow/compiler_yaml_test.go — add TestInterpolationStepPresentWithGitHubFalse, an end-to-end regression that compiles the exact failing frontmatter (github: false, no expressions, no {{#if}}) and asserts both the {{#runtime-import}} macro and the interpolation step are present in the generated lock file.


Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.65 AIC · ⊞ 8.7K ·
Comment /souschef to run again

The compiler always emits a {{#runtime-import}} self-import macro in
normal (non-inline) mode, but generateInterpolationAndTemplateStep
skipped generating the "Interpolate variables and render templates"
step when there were no expressions, no {{#if}} patterns, no GitHub
tool, and no inline sub-agents — even though that step is the only
consumer of {{#runtime-import}} macros (via interpolate_prompt.cjs).

Fix: compute hasRuntimeImports from the userPromptChunks in generatePrompt
(where chunks are already known) and pass it as an explicit bool parameter
to generateInterpolationAndTemplateStep. The step is now emitted whenever
any chunk starts with '{{#runtime-import '.

Closes #49102

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compiler to emit interpolation step when using runtime import fix: emit interpolation step when prompt contains runtime-import macros Jul 30, 2026
Copilot AI requested a review from pelikhan July 30, 2026 11:57
@pelikhan
pelikhan marked this pull request as ready for review July 30, 2026 12:04
Copilot AI review requested due to automatic review settings July 30, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates prompt compilation to emit interpolation for runtime-import macros.

Changes:

  • Detects runtime imports and passes that state into step generation.
  • Extends interpolation-step guards and logging.
  • Adds unit and end-to-end regression tests.
Show a summary per file
File Description
pkg/workflow/compiler_yaml_prompt.go Detects runtime-import prompt chunks.
pkg/workflow/template.go Includes runtime imports in interpolation-step generation.
pkg/workflow/template_test.go Updates and expands unit tests.
pkg/workflow/compiler_yaml_test.go Adds compilation regression coverage.

Review details

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread pkg/workflow/compiler_yaml_prompt.go Outdated

c.generateInterpolationAndTemplateStep(yaml, expressionMappings, data)
hasRuntimeImports := sliceutil.Any(userPromptChunks, func(chunk string) bool {
return strings.HasPrefix(chunk, "{{#runtime-import ")
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill, address the failing checks below, and rerun the necessary tests once the branch is up to date.

Failed checks:

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.6 AIC · ⊞ 8.7K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 30, 2026 12:29
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…w files JSON

- Change hasRuntimeImports detection from strings.HasPrefix to
  strings.Contains so macros embedded after other text in a chunk are
  detected correctly
- Also detect the optional form {{#runtime-import? ...}}
- Add github-mcp-server-pagination.md, syntax-engine.md, and
  token-optimization-caching-budgets.md to the fallback aw files JSON
  to fix TestFallbackAWFilesMatchesLocalAWDirectory

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Fixed in commit fix: detect runtime-import macros anywhere in chunks; sync fallback aw files JSON.

Two changes:

  1. Changed hasRuntimeImports detection from strings.HasPrefix to strings.Contains so macros appearing after other text in a chunk are correctly detected. Also added detection for the optional form {{#runtime-import? ...}}.
  2. Added the three .github/aw/*.md files (github-mcp-server-pagination.md, syntax-engine.md, token-optimization-caching-budgets.md) that were added by the daily glossary scan to pkg/cli/data/agentic_workflows_fallback_aw_files.json, fixing TestFallbackAWFilesMatchesLocalAWDirectory.

The remaining CI failures (TestAuditCachingBehavior, TestViewWorkflowRun_*) fail with "GitHub CLI authentication required" — they are environment-level failures not caused by changes in this PR.

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: bug
  • Risk: low
  • Score: 68/100 (impact 32, urgency 20, quality 16)
  • Recommended action: fast_track

Rationale: Small, well-scoped compiler fix (111+/13-, 6 files) with new unit tests covering the runtime-import interpolation regression. Mergeable, only 1h old. No CI results reported yet — recommend confirming CI before merge.

Generated by 🔧 PR Triage Agent · auto · 69.5 AIC · ⌖ 8.05 AIC · ⊞ 7.9K ·

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add a integration workflow test that ensure the expansion is hapening

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill address any unresolved review feedback and rerun checks once updates are pushed.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.65 AIC · ⊞ 8.7K ·
Comment /souschef to run again

github-actions Bot and others added 2 commits July 30, 2026 13:07
Add runtime_import_expansion_integration_test.go with three integration
tests covering the scenarios from the bug fix:

- TestRuntimeImportExpansionWithGitHubFalse: primary regression case —
  github:false + no expressions must still emit the interpolation step
  for the compiler's self-import runtime-import macro
- TestRuntimeImportExpansionWithOptionalMacro: optional {{#runtime-import?}}
  form also triggers the interpolation step
- TestRuntimeImportExpansionWithMacroAfterText: macro embedded after other
  body text is still detected (strings.Contains, not HasPrefix)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add a integration workflow test that ensure the expansion is hapening

Added pkg/workflow/runtime_import_expansion_integration_test.go in commit test: add integration tests for runtime-import macro expansion with three integration tests:

  • TestRuntimeImportExpansionWithGitHubFalse — the primary regression: tools.github: false, no expressions, no {{#if}} → verifies the self-import {{#runtime-import}} macro and interpolate_prompt.cjs step are both present
  • TestRuntimeImportExpansionWithOptionalMacro — optional {{#runtime-import? ...}} form also triggers the interpolation step
  • TestRuntimeImportExpansionWithMacroAfterText — macro appearing after other body text is detected (strings.Contains vs HasPrefix)

@pelikhan
pelikhan merged commit 8b1faa3 into main Jul 30, 2026
29 of 30 checks passed
@pelikhan
pelikhan deleted the copilot/fix-compiler-runtime-import branch July 30, 2026 13:20
Copilot stopped work on behalf of gh-aw-bot due to an error July 30, 2026 13:20
@github-actions

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🎯 Excellent Work on This Runtime-Import Fix

Thanks for addressing the silent failure in #49102! This fix correctly identifies a critical compiler bug where workflows with tools.github: false and no template expressions would skip the interpolation step, silently dropping unresolved {{#runtime-import}} macros that the agent needs to execute.

✅ Evaluation Against Guidelines

This PR aligns perfectly with the project's contribution model:

  • On-topic ✓ — Bug fix in the workflow compiler, a core gh-aw concern
  • Focused ✓ — Single issue: detecting runtime imports and ensuring the interpolation step is always emitted when needed
  • Follows process ✓ — Created and submitted by the Copilot coding agent (core team workflow per CONTRIBUTING.md)
  • Tests included ✓ — Three comprehensive integration tests cover the regression scenario, optional macros, and macros embedded after body text
  • Well-described ✓ — Clear explanation of the bug, root cause, and fix strategy
  • No new dependencies

Implementation Quality

The fix is surgical and well-reasoned:

  1. Detection logicsliceutil.Any() scans userPromptChunks for both {{#runtime-import }} and {{#runtime-import? }} patterns, catching both mandatory and optional imports
  2. Guard condition — The new hasRuntimeImports boolean folds cleanly into the existing skip logic alongside template patterns and GitHub context checks
  3. Test coverage — Three scenarios validate the fix: the exact failing case (github: false + no expressions), optional imports, and macros appearing mid-body
  4. Regression preventionTestInterpolationStepPresentWithGitHubFalse() compiles real workflow YAML and asserts both the macro and the step are in the lock file

The PR is ready for review and merge.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • patchdiff.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "patchdiff.githubusercontent.com"

See Network Configuration for more information.

Generated by ✅ Contribution Check · auto · 61 AIC · ⊞ 8.7K ·

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.1

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler emits {{#runtime-import}} but skips the step that resolves it, silently delivering an empty prompt

4 participants