Skip to content

fix(compiler): normalize gateway policy server IDs - #58023

Merged
lpcox merged 11 commits into
mainfrom
lpcox-fix-multi-agent-gateway-startup
Sep 3, 2026
Merged

fix(compiler): normalize gateway policy server IDs#58023
lpcox merged 11 commits into
mainfrom
lpcox-fix-multi-agent-gateway-startup

Conversation

@lpcox

@lpcox lpcox commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • derive shared-gateway primary agent policy server references from normalized generated MCP server IDs
  • emit safeoutputs instead of the frontmatter descriptor safe-outputs
  • mark the delayed awf-enclave HTTP backend optional while preserving deferred-server readiness handoff
  • union the enclave issues-read-v1 GitHub toolset requirement into the shared GitHub MCP server without broadening primary identity policy
  • hand the gateway API key from the startup step to the AWF host while explicitly excluding it from the primary agent
  • add focused startup-script, unit, and compiled-workflow regression coverage for these handoff defects

Context

This fixes failures exposed by the gh-aw-firewall shared-enclave smoke runs after #57973:

  • run 33675275581: agentPolicies referenced unknown server safe-outputs
  • run 33676040801: eager connection to the deferred enclave backend failed, and the enclave GitHub policy referenced tools absent from the registered context-only server
  • run 33676618843: AWF preflight could not authenticate shared-gateway readiness because MCP_GATEWAY_API_KEY was absent

The generated shared gateway now uses actual MCP server IDs, treats the AWF-hosted enclave backend as deferred/optional during gateway initialization, and registers the issues toolset needed by the enclave. Identity policy remains the isolation boundary: the primary gets only get_me, while the enclave gets only list_issues and issue_read. The startup action exports a gateway-api-key alias, and enclave execution passes it to the AWF wrapper while --exclude-env MCP_GATEWAY_API_KEY keeps it out of the primary agent.

Validation

  • go test ./pkg/workflow -run 'Test(GenerateEnclaveGatewayContract|CompileEnclaveStartupOrdering|ToolsWithEnclaveGitHubIssuesUnionsTypedToolsets|EnclaveGitHubMCPGatewayConfiguration|CompileEnclaveGitHubSharedGateway)$' -count=1
  • go test ./pkg/workflow -run 'Test(CompileEnclaveGitHubSharedGateway|ComputeAWFExcludeEnvVarNames)$' -count=1
  • npx vitest run actions/setup/js/start_mcp_gateway.test.cjs
  • bash actions/setup/sh/start_mcp_gateway_test.sh
  • make agent-report-progress

Run: https://github.com/github/gh-aw/actions/runs/33679827993

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

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


PR Sous Chef branch refresh requested. Run: https://github.com/github/gh-aw/actions/runs/33682167508

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 22.7 AIC · ⌖ 8.79 AIC · ⊞ 9.2K ·
Comment /souschef to run again


Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 37.4 AIC · ⌖ 8.65 AIC · ⊞ 9K ·
Comment /souschef to run again

lpcox and others added 3 commits September 2, 2026 11:06
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1ad74329-b8a6-4ad4-b378-805e3fbfc0ce
Copilot AI balanced review requested due to automatic review settings September 2, 2026 20:00
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1ad74329-b8a6-4ad4-b378-805e3fbfc0ce

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.

Copilot review overview

🟢 Approval recommended

The focused normalization fix is consistent with MCP rendering and has targeted unit and compilation coverage.

Review tier: Balanced
Findings: None

What changed in this PR

Fixes shared-gateway policies to reference normalized MCP server IDs.

Changes:

  • Derives primary policy servers from normalized manifest entries.
  • Adds regression coverage for safeoutputs and policy references.
File Description
pkg/​workflow/​mcp_gateway_config.go Uses normalized generated server names in policies.
pkg/​workflow/​enclave_github_proxy_test.go Verifies policy resolution and compiled safe-output naming.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1ad74329-b8a6-4ad4-b378-805e3fbfc0ce
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please review the current PR state, refresh the branch if needed, and run the pr-finisher skill before handing back to maintainers.

  • Local formatter push was not possible in this sandbox because checking out the PR branch required a blocked promisor fetch.
  • Please summarize any remaining maintainer-facing blocker once done.

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

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

@pelikhan

pelikhan commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

/review

@pelikhan

pelikhan commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

/matt

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-09-02T20:44:48.948+00:00
review_event: REQUEST_CHANGES
top_themes:
  - enclave startup no longer fails fast when backend wiring is broken
files_reviewed:
  - actions/setup/js/start_mcp_gateway.cjs
  - actions/setup/sh/start_mcp_gateway.sh
  - pkg/workflow/awf_env.go
  - pkg/workflow/copilot_engine_execution.go
  - pkg/workflow/enclave_github_proxy_test.go
  - pkg/workflow/enclaves.go
  - pkg/workflow/enclaves_test.go
  - pkg/workflow/mcp_gateway_config.go
  - pkg/workflow/mcp_manifest.go
  - pkg/workflow/mcp_setup_generator.go
comment_count: 1

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 36 AIC · ⌖ 7.34 AIC · ⊞ 23.5K ·
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.

Request changes

This patch fixes the original gateway wiring regressions, but it also makes the enclave backend explicitly optional for every generated config. That trades a deterministic startup contract for a silent fallback: if the AWF-hosted enclave never comes up, the gateway can still initialize and the primary agent will only fail later when it first touches an enclave tool.

Blocking theme

The new "required": false on awf-enclave removes the only hard startup check for the deferred enclave path. The deferred-server handoff already prevents eager connection attempts; marking the backend optional as well means a broken readiness export, wrong capability header, or dead enclave process no longer fails fast during setup. The workflow will instead proceed into agent execution and blow up at tool-use time with a much less diagnosable error.

That is a correctness regression in the startup contract, not just a logging nuance. Keep the deferred connection behavior, but preserve a positive readiness assertion before handing control to the agent.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 36 AIC · ⌖ 7.34 AIC · ⊞ 23.5K
Comment /review to run again

Comment thread pkg/workflow/enclaves.go Outdated
fmt.Fprintf(yaml, " %q: {\n", enclaveMCPServerName)
yaml.WriteString(" \"type\": \"http\",\n")
fmt.Fprintf(yaml, " \"url\": %q,\n", enclaveMCPUpstreamURL)
yaml.WriteString(" \"required\": false,\n")

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.

Making awf-enclave globally optional removes the fail-fast check for the deferred enclave path, so a broken enclave startup now escapes setup and only crashes later when the first enclave tool is invoked.

💡 Why this blocks

The deferred-server export already solves the eager-connect problem; adding "required": false on top changes behavior again by telling the gateway that missing enclave connectivity is acceptable. That hides real startup defects such as a dead enclave process, bad capability header, or missing readiness handoff, and turns them into harder-to-debug runtime failures during agent execution.

A safer fix is to preserve deferred startup while keeping an explicit readiness assertion before the agent step begins. If the gateway truly must tolerate a deferred backend here, the generated workflow needs a separate check that proves the enclave endpoint became reachable before any enclave tool can be used.

@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 /codebase-design and /diagnosing-bugs to this multi-file gateway/enclave handoff fix.

📋 Key Themes & Highlights

Key Themes

  • Engine parity gap: writeEnclaveMCPJSON gained required: false for the deferred awf-enclave backend, but the parallel Codex TOML writer (writeEnclaveMCPTOML) did not, leaving the same eager-connection failure this PR fixes unaddressed for Codex-engine workflows using enclaves. No test exercises this TOML path.
  • Naming clarity: gateway-api-key output is set to the same value as gateway-agent-id (agentId) rather than a distinct credential — worth a comment or rename to avoid confusion about whether a real API key is being minted.

Positive Highlights

  • ✅ Good root-cause fix for the agentPolicies referencing unknown server IDs — now driven from collectMCPServersForManifest instead of a separate tool-name list, closing the drift between manifest and policy.
  • ✅ Solid, targeted regression tests added for the shared-gateway compile path (TestCompileEnclaveGitHubSharedGateway, TestToolsWithEnclaveGitHubIssuesUnionsTypedToolsets) that assert both the fixed behavior and non-regression (NotContains on the old broken values).
  • MCP_GATEWAY_API_KEY correctly added to both the AWF exclude-env list and the copilot execution step's filtered env, keeping the primary agent's visible environment minimal per the stated security goal.

See inline comments for the two actionable items.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 111 AIC · ⌖ 15.1 AIC · ⊞ 10.3K
Comment /matt to run again

Comments that could not be inline-anchored

pkg/workflow/enclaves.go:366

[/codebase-design] writeEnclaveMCPTOML (Codex engine path) doesn't get the required = false field that writeEnclaveMCPJSON gained in this PR — the deferred/optional-backend fix is engine-specific and silently absent for Codex.

<details>
<summary>💡 Details</summary>

The PR's goal is to mark the delayed awf-enclave HTTP backend optional so eager connection failures (seen in run 33676040801) don't abort startup. writeEnclaveMCPJSON was updated with `yaml.WriteString(" …

actions/setup/js/start_mcp_gateway.cjs:1359

[/diagnosing-bugs] gateway-api-key is set to the same value as gateway-agent-id (agentId) — this isn't really an "API key", it's the existing agent ID reused under a new name. If that's intentional (agent ID doubles as bearer credential), a short comment would help; if a distinct secret was meant to be minted here, this silently reuses a non-secret identifier as the credential handed to the AWF enclave container.

<details>
<summary>💡 Context</summary>

The PR's stated goal is: "hand…

Copilot AI commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@copilot Please review the current PR state, refresh the branch if needed, and run the pr-finisher skill before handing back to maintainers.

  • Local formatter push was not possible in this sandbox b...

Ran the PR finisher pass. The branch is current and clean at 706f86a; no formatter or source changes were needed. make fmt, make lint, make test-unit, make test, make recompile, and make agent-report-progress passed, and there are no unresolved review threads. The prior firewall smoke failures were inspected and correspond to the defects fixed by this PR. Maintainer hand-off: CI is stale/in progress for the current PR state and must be re-triggered by a maintainer before merge; the PR remains blocked on those checks.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Hey @lpcox 👋 — thanks for fixing the gateway policy server ID normalization! This PR looks ready for review:

Well-focused — all changes stay within the MCP gateway initialization and policy configuration boundary, touching only the compiler and setup action infrastructure.

Strong test coverage — includes regression tests for startup scripts, enclave GitHub proxy configuration, and compiled workflow ordering.

Clear context — references specific firewall smoke run failures with links and explains the isolation-boundary approach (primary gets get_me, enclave gets list_issues + issue_read).

Comprehensive validation — detailed test commands with run results demonstrate the fixes address the exposed defects.

This looks good for maintainer review. The changes are mechanically sound and the test additions show confidence in the fix.

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

Generated by ✅ Contribution Check · copilot · auto · 54.8 AIC · ⌖ 6.07 AIC · ⊞ 9.3K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the current blocking review feedback, refresh the branch if needed, and run the pr-finisher skill before handing back to maintainers.

  • Blocking review: github-actions — the startup contract regressed because awf-enclave became optional and failures can now surface later at tool-use time instead of failing fast during setup.
  • Review link: fix(compiler): normalize gateway policy server IDs #58023 (review)
  • Please summarize the maintainer-facing blocker once updated.

Generated by PR Sous Chef

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 22.7 AIC · ⌖ 8.79 AIC · ⊞ 9.2K ·
Comment /souschef to run again

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

Copilot AI commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@copilot Please address the current blocking review feedback, refresh the branch if needed, and run the pr-finisher skill before handing back to maintainers.

  • Blocking review: github-actions — th...

Addressed in commit 1e76031. The generated awf-enclave entry no longer sets required: false, so the gateway does not globally tolerate a missing backend. The compiler-owned GH_AW_MCP_DEFERRED_SERVERS handoff remains in place for deferred startup, with regression assertions updated. Targeted and full tests, lint, formatting, recompilation, and final validation pass; CodeQL reported no alerts. CI must be re-triggered by a maintainer before merge.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please verify the current head against the remaining open review state and close out any still-applicable follow-up before handing back to maintainers.

  • The previously blocking startup-contract review appears addressed in commit 1e76031; please confirm every still-open review comment is either fixed on the latest head or explicitly superseded.
  • The remaining visible feedback now looks like follow-up review commentary around the Codex TOML parity path and gateway-api-key naming clarity; reconcile anything that still applies to the current head and summarize what is intentionally deferred versus fixed now.
  • Branch refresh was requested from this pass.

Please run the pr-finisher skill and leave a concise maintainer-facing summary once the latest head is fully reconciled with review feedback.

Generated by PR Sous Chef

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 37.4 AIC · ⌖ 8.65 AIC · ⊞ 9K ·
Comment /souschef to run again

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

Copilot AI commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@copilot Please verify the current head against the remaining open review state and close out any still-applicable follow-up before handing back to maintainers.

  • The previously blocking startup-cont...

Latest head is reconciled. The startup-contract review is superseded by 1e76031: awf-enclave is no longer globally optional, while the deferred-server handoff remains. The Codex TOML parity note no longer applies because the optional flag was removed from JSON and was never added to TOML. The gateway API-key naming concern is addressed in 332f6a1 with a comment documenting that it intentionally aliases the gateway agent ID used for AWF authentication. Startup tests, formatting, pre-push validation, final review, and security checks pass. The remaining maintainer blocker is CI re-trigger/confirmation on the refreshed branch.

@pelikhan

pelikhan commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

@lpcox shouldn't it be optional?

awf-enclave is no longer globally optional,

@lpcox

lpcox commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

@lpcox shouldn't it be optional?

awf-enclave is no longer globally optional,

not required if there are no enclaves, but required network isolation when enclaves are enabled.

@lpcox

lpcox commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@copilot fix this failing ci check https://github.com/github/gh-aw/actions/runs/33692826660/job/100456290392?pr=58023

Fixed in commit 2c4ab8d. The failing check was TestFallbackAWFilesMatchesLocalAWDirectory: .github/aw/compat.md was present but missing from the embedded fallback manifest. Added compat.md to pkg/cli/data/agentic_workflows_fallback_aw_files.json; the targeted test and final local validation now pass. CI must be re-triggered by a maintainer on the updated head.

@lpcox
lpcox merged commit dc5c0d2 into main Sep 3, 2026
42 checks passed
@lpcox
lpcox deleted the lpcox-fix-multi-agent-gateway-startup branch September 3, 2026 01:16
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.88.2

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.

5 participants