Skip to content

Fix cross-repo dynamic target-repo silently dropping PR (forward GH_AW_INPUT_* to agent step env) - #48598

Merged
pelikhan merged 2 commits into
mainfrom
copilot/fix-cross-repo-create-pull-request
Jul 28, 2026
Merged

Fix cross-repo dynamic target-repo silently dropping PR (forward GH_AW_INPUT_* to agent step env)#48598
pelikhan merged 2 commits into
mainfrom
copilot/fix-cross-repo-create-pull-request

Conversation

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

When target-repo uses a dynamic ${{ inputs.owner }}/${{ inputs.repo }} expression, the patch file is named using the unexpanded ${GH_AW_INPUT_OWNER}-${GH_AW_INPUT_REPO} slug while the consumer reconstructs the filename from the Actions-expanded value — the two never match, the PR is silently dropped, and the run concludes green.

Root cause

buildSafeOutputsConfigRuntimeData replaces ${{ inputs.* }} with ${GH_AW_INPUT_*} placeholders in config.json. The safe-outputs MCP server is expected to resolve these at runtime via resolveEnvPlaceholders(process.env). For TOML-based engines (Copilot, Codex), the container receives its environment via the TOML env_vars forwarding chain:

runner step env → AWF sandbox (--env-all) → engine CLI → safe-outputs container

The GH_AW_INPUT_* vars were only injected into the "Start MCP Gateway" step env — not the agent execution step env. Because Copilot and Codex start the safe-outputs container from within their own process (not the long-running gateway), the vars were absent from the container, leaving the placeholders unexpanded in the patch filename.

Fix

pkg/workflow/safe_outputs_env.go

Add maps.Copy(env, data.SafeOutputsInputEnvVars) to applySafeOutputEnvToMap, which is called by all engine GetExecutionSteps implementations:

// Forward GH_AW_INPUT_* vars so TOML-based MCP clients (Codex, Copilot) can
// pass them through to the containerised safe-outputs MCP server via env_vars.
maps.Copy(env, data.SafeOutputsInputEnvVars)

SafeOutputsInputEnvVars is populated by generateMCPSetup (phase 3), before GetExecutionSteps is called (phase 4), so the data is always available. For JSON/gateway-based engines (Claude, Pi), the vars are already present in the gateway step env — adding them to the agent step is redundant but harmless.

Tests

  • TestApplySafeOutputEnvToMap — new table entry verifying GH_AW_INPUT_* propagates through applySafeOutputEnvToMap
  • TestCopilotEngineForwardsSafeOutputsInputEnvVars — verifies Copilot execution step includes the vars when SafeOutputsInputEnvVars is populated
  • TestCodexEngineForwardsSafeOutputsInputEnvVars — same for Codex

… GH_AW_INPUT_* to agent step env

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cross-repo create_pull_request issue with dynamic target-repo Fix cross-repo dynamic target-repo silently dropping PR (forward GH_AW_INPUT_* to agent step env) Jul 28, 2026
Copilot AI requested a review from pelikhan July 28, 2026 12:45
@github-actions github-actions Bot mentioned this pull request Jul 28, 2026
@pelikhan
pelikhan marked this pull request as ready for review July 28, 2026 12:57
Copilot AI review requested due to automatic review settings July 28, 2026 12:57
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (98 additions detected).

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

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

Fixes dynamic cross-repository safe-output targets by forwarding generated GH_AW_INPUT_* variables into agent execution environments.

Changes:

  • Copies safe-output input variables into engine step environments.
  • Adds helper-level and Copilot/Codex regression tests.
Show a summary per file
File Description
pkg/workflow/safe_outputs_env.go Forwards dynamic input variables to agent steps.
pkg/workflow/safe_output_helpers_test.go Tests shared environment propagation.
pkg/workflow/copilot_engine_test.go Verifies Copilot step forwarding.
pkg/workflow/codex_engine_test.go Verifies Codex step forwarding.

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: 0
  • Review effort level: Medium

@github-actions github-actions Bot 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.

The fix is correct and well-tested. maps.Copy(env, data.SafeOutputsInputEnvVars) in applySafeOutputEnvToMap correctly ensures GH_AW_INPUT_* vars reach TOML-based engine steps, fixing the silent PR-drop when target-repo uses dynamic ${{ inputs.* }} expressions.

No issues found — the change is minimal, safe for gateway-based engines (redundant but harmless), and covered by three targeted tests.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 11.8 AIC · ⌖ 5.21 AIC · ⊞ 5K

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — this is a well-targeted bug fix with solid regression tests. Approving.

📋 Key Themes & Highlights

Positive Highlights

  • ✅ Root cause is correctly identified and precisely fixed with a single maps.Copy call in the right place (applySafeOutputEnvToMap), affecting all engine types uniformly
  • ✅ Three regression tests added — one for the helper function, one each for Copilot and Codex engines — covering exactly the failing scenario
  • ✅ Test doc comments clearly document the TOML forwarding chain dependency, making the intent readable for future maintainers
  • ✅ The fix is additive (no deletions) and harmless for non-TOML engines (Claude, Pi) where the vars are already present in the gateway step
  • ✅ PR description traces the root cause through the full env-var forwarding chain with precision

Minor Observations

  • The test values for SafeOutputsInputEnvVars use raw ${{ inputs.owner }} expressions rather than resolved placeholders, which accurately reflects the compile-time state stored in WorkflowData. This is correct.
  • No integration or end-to-end test for the full dynamic target-repo path exists, but that is a pre-existing gap, not introduced here.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 21.2 AIC · ⌖ 4.63 AIC · ⊞ 6.8K
Comment /matt to run again

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 60/100 — Acceptable

Analyzed 3 test(s): 3 design, 0 implementation, 0 violation(s).

📊 Metrics (3 tests)
Metric Value
Analyzed 3 (Go: 3, JS: 0)
✅ Design 3 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 0 (0%)
Duplicate clusters 0
Inflation Yes (8.9:1)
🚨 Violations 0
📋 Test Details (3 tests)
Test File Classification Coverage
TestCodexEngineForwardsSafeOutputsInputEnvVars pkg/workflow/codex_engine_test.go Design Verifies GH_AW_INPUT_* forwarded to Codex execution step env; happy path ✅
TestCopilotEngineForwardsSafeOutputsInputEnvVars pkg/workflow/copilot_engine_test.go Design Verifies GH_AW_INPUT_* forwarded to Copilot execution step env; happy path ✅
safe outputs input env vars... (table case) pkg/workflow/safe_output_helpers_test.go Design Verifies maps.Copy() populates env with input vars; core mechanism ✅

Design Invariant Coverage

All 3 tests verify the core design invariant: GH_AW_INPUT_* environment variables extracted from safe-outputs config flow through the execution step environment. This ensures the TOML env_vars forwarding chain (runner → AWF sandbox → agent CLI → container) can resolve ${GH_AW_INPUT_...} placeholders in config.json.

Environment chain verified:

  • runner stepAWF sandboxCodex/Copilot CLIsafe-outputs container

Strengths

  • Layered coverage: Core mechanism tested in TestApplySafeOutputEnvToMap, integration tested in both engines
  • Clear diagnostics: Assertions show actual step content on failure for debugging
  • Well-documented: Test functions explain the forwarding chain and why this fix prevents silent PR drops
  • No guideline violations: No mock libraries, proper test structure, build-tag compliant

Observations

  • ⚠️ Happy path only: Tests cover the success case but lack edge-case coverage (nil SafeOutputsInputEnvVars, empty map, malformed data)
  • ⚠️ Test inflation flagged: 98 test lines : 11 prod lines = 8.9:1 ratio (threshold: 2:1). Justified for integration testing but worth noting.
  • i️ Duplicate test structure: Codex and Copilot tests are nearly identical, which is reasonable for testing the same mechanism across engines

Verdict

Passed. 0% implementation tests (threshold: 30%), 100% design coverage. Tests verify critical GH_AW_INPUT_* forwarding invariant with clear intent. Edge-case coverage is limited but the core mechanism is well-protected.

🧪 Test quality analysis by Test Quality Sentinel · haiku45 · 18.3 AIC · ⌖ 10.8 AIC · ⊞ 8.1K ·
Comment /review to run again

@github-actions github-actions Bot 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.

✅ Test Quality Sentinel: 60/100. 0% implementation tests (threshold: 30%). All 3 tests verify critical GH_AW_INPUT_* forwarding design invariant with clear intent.

@pelikhan
pelikhan merged commit 4c14213 into main Jul 28, 2026
77 of 89 checks passed
@pelikhan
pelikhan deleted the copilot/fix-cross-repo-create-pull-request branch July 28, 2026 13:09
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.5

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-repo create_pull_request silently drops the PR (green run) when target-repo is a dynamic expression

3 participants