Skip to content

Fix environment variable placeholder format in prompt rendering#10455

Closed
pelikhan with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-environment-variable-formatting
Closed

Fix environment variable placeholder format in prompt rendering#10455
pelikhan with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-environment-variable-formatting

Conversation

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

Fix Environment Variable Placeholder Format in Prompt Rendering

Issue: Environment variable placeholders in prompt text were not being replaced at runtime, resulting in literal placeholders appearing in the final prompt instead of actual values.

Root Cause:

  • expression_extraction.go: Created placeholders as __VAR__ format
  • interpolate_prompt.cjs: Expected different format for variable interpolation AND was filtering variables incorrectly
  • Format mismatch and incorrect variable filtering prevented variable interpolation from working

Changes Made:

  • Changed placeholder format to @@VAR@@ to avoid interfering with bash heredoc variable expansion syntax
  • Updated expression_extraction.go to use @@VAR@@ format
  • Updated interpolate_prompt.cjs to recognize and replace @@VAR@@ placeholders
  • Fixed interpolate_prompt.cjs to include all GH_AW_ prefixed variables (not just GH_AW_EXPR_) - the compiler generates both GH_AW_GITHUB_ACTOR for simple expressions and GH_AW_EXPR_12345678 for complex expressions
  • Added unresolved placeholder detection in print_prompt_summary.sh - warns about any @@VAR@@ placeholders that weren't replaced, helping catch interpolation issues early
  • Updated template.go to recognize @@ prefix and skip wrapping
  • Updated test files to expect new @@VAR@@ format:
    • expression_extraction_test.go
    • template_rendering_test.go
    • template_expression_integration_test.go
    • interpolate_prompt.test.cjs
  • All expression extraction and interpolation tests pass
  • Code formatted with make fmt
  • Merged main branch (resolved conflicts in campaign-generator.lock.yml)
  • Recompiled all workflows with make recompile (126 workflows compiled successfully)

Key Fix:
The interpolate_prompt.cjs script was only looking for environment variables starting with GH_AW_EXPR_, but the compiler generates two types of variable names:

  1. Simple expressions (e.g., github.actor) → GH_AW_GITHUB_ACTOR (no EXPR_ prefix)
  2. Complex expressions (e.g., expressions with operators) → GH_AW_EXPR_12345678 (with EXPR_ prefix and hash)

The fix now includes all GH_AW_ prefixed variables (excluding GH_AW_PROMPT), ensuring both simple and complex expressions are properly interpolated.

Example Output:

# Environment variable definition
GH_AW_GITHUB_EVENT_ISSUE_NUMBER: ${{ github.event.issue.number }}

# Placeholder in heredoc (safe from bash expansion)
cat << 'PROMPT_EOF' >> "$GH_AW_PROMPT"
{{#if @@GH_AW_GITHUB_EVENT_ISSUE_NUMBER@@ }}
- **issue-number**: #@@GH_AW_GITHUB_EVENT_ISSUE_NUMBER@@
{{/if}}
PROMPT_EOF

Warning Detection:
The print prompt step now checks for unresolved placeholders and reports them as warnings:

::warning::Unresolved placeholders found in prompt:
::warning::  - @@GH_AW_SOME_VARIABLE@@

The @@VAR@@ format:

  • Does not interfere with bash heredoc variable expansion (${VAR})
  • Is visually distinct and commonly used for placeholders
  • Works correctly with single-quoted heredoc delimiters
  • Enables proper runtime interpolation by interpolate_prompt.cjs
Original prompt

Reference: https://github.com/githubnext/gh-aw/actions/runs/21093306445/job/60667503208#step:22:1

The step that renders the prompt is not properly formatting the environment variable entries and as a result they are not replaced. See this generated prompt:

  • issue-number: #GH_AW_GITHUB_EVENT_ISSUE_NUMBER

It should have been the issue number value. Fix compiler, add tests.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Changeset

  • Type: patch
  • Description: Auto-generated changeset added to record this PR as a patch-level change.

Ahoy! This treasure was crafted by 🏴‍☠️ Changeset Generator

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot use variable format that does not interfere with heredoc

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix environment variable formatting in prompt rendering Fix environment variable placeholder format in prompt rendering Jan 17, 2026
Copilot AI requested a review from pelikhan January 17, 2026 12:03
…erference

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

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot use variable format that does not interfere with heredoc

Changed placeholder format from ${VAR} to @@VAR@@ to avoid any potential interference with bash heredoc variable expansion syntax. The @@ format is visually distinct, commonly used for placeholders, and works correctly within single-quoted heredoc delimiters. Commit: 9939e6d

@pelikhan pelikhan added the smoke label Jan 17, 2026
@pelikhan pelikhan marked this pull request as ready for review January 17, 2026 14:09
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot merge main and recompile

Merged main branch and recompiled all workflows. Resolved merge conflict in campaign-generator.lock.yml. Successfully compiled 127 workflows with the @@var@@ placeholder format. Commit: 26c4280

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

🎉 Yo ho ho! Changeset Generator found the treasure and completed successfully! ⚓💰

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results (Claude Engine)

Last 2 merged PRs: ❌ (GitHub API placeholder issue)
Serena Go: ❌ (Go not available)
Playwright: ✅ (Navigated to GitHub, verified title)
Tavily Web Search: ✅ (5 results for "GitHub Agentic Workflows")
File Writing: ✅ (Created test file)
Bash Tool: ✅ (Verified file contents)

Overall Status: FAIL (2/6 tests passed)

AI generated by Smoke Claude

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results for Copilot Engine

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP - Retrieved last 2 merged PRs
  • ❌ Serena Go - go command not available
  • ✅ Playwright - Navigated to github.com, title contains "GitHub"
  • ✅ File Writing - Created test file successfully
  • ✅ Bash Tool - Verified file creation

Overall Status: FAIL (1/5 tests failed)

AI generated by Smoke Copilot

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot the substitution did not work see the final prompt from this run:

Reference: https://github.com/githubnext/gh-aw/actions/runs/21095670266/job/60672836421#step:24:1

Add check in print prompt to search for unresolved expression and report them as warnings.

- Fix interpolate_prompt.cjs to include all GH_AW_ prefixed variables, not just GH_AW_EXPR_
- Add warning detection in print_prompt_summary.sh for unresolved @@var@@ placeholders
- Recompile all workflows with the fix

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

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the substitution did not work see the final prompt from this run:

Reference: https://github.com/githubnext/gh-aw/actions/runs/21095670266/job/60672836421#step:24:1...

Fixed the interpolation issue - interpolate_prompt.cjs was only looking for GH_AW_EXPR_* variables but the compiler generates GH_AW_* variables for simple expressions (e.g., GH_AW_GITHUB_ACTOR). Now includes all GH_AW_ prefixed variables.

Also added warning detection in print_prompt_summary.sh that checks for unresolved @@VAR@@ placeholders and reports them as warnings. This will help catch any future interpolation issues.

Commit: 4fde3a7

@pelikhan pelikhan closed this Jan 17, 2026
@github-actions github-actions Bot deleted the copilot/fix-environment-variable-formatting branch April 2, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants