Skip to content

fix: fix Pi agent models.json and AWF reflect URL configurations#30011

Closed
Copilot wants to merge 4 commits intomainfrom
copilot/fix-pi-agent-models-json-configurations
Closed

fix: fix Pi agent models.json and AWF reflect URL configurations#30011
Copilot wants to merge 4 commits intomainfrom
copilot/fix-pi-agent-models-json-configurations

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 3, 2026

Fixes three issues in the Pi agent configuration that prevented Pi CLI from connecting to the LLM gateway inside the AWF container and from successfully fetching the AWF /reflect endpoint.

Root Causes

  1. models.json base URL hardcoded at compile time: buildPiModelsJSON embedded http://host.docker.internal:PORT via base64 encoding. Inside the AWF container, the correct gateway URL must come from the base URL env var configured at runtime.

  2. AWF reflect URL used unresolvable hostname: AWF_API_PROXY_REFLECT_URL used http://api-proxy:10000/reflect, but the api-proxy Docker service name does not resolve in the Pi container context. The correct URL uses the fixed container IP 172.30.0.30 (AWFAPIProxyContainerIP).

  3. AWF reflect fetched too early: pi_provider.cjs called fetchAWFReflect at agent_start — before the api-proxy management endpoint is ready to serve a complete /reflect response. The copilot and claude harnesses call it after the agent subprocess exits. Calling it at process.once('beforeExit') matches that timing: Pi finishes all turns, the event loop drains, the fetch runs while the AWF container is still alive, then Pi exits.

Changes

  • pkg/workflow/pi_engine.go: Replace buildPiModelsJSON (hardcoded base64 URL) with buildPiModelsJSONSetup that generates models.json at runtime using printf and shell variable expansion from the backend-specific base URL env var. Also sets the env var (GITHUB_COPILOT_BASE_URL / ANTHROPIC_BASE_URL / OPENAI_BASE_URL) in the Pi step environment when firewall is enabled. Uses json.Marshal with a typed struct for injection-safe JSON generation.

  • pkg/workflow/pi_engine_test.go: Add tests for buildPiModelsJSONSetup and the firewall execution path.

  • pkg/workflow/compiler_experiments.go: Fix pre-existing build error (missing WorkflowData arg in generateSetupStep call).

  • actions/setup/js/awf_reflect.cjs: Change AWF_API_PROXY_REFLECT_URL from http://api-proxy:10000/reflect to http://172.30.0.30:10000/reflect. The fixed container IP (AWFAPIProxyContainerIP) is always reachable from all agent container contexts; the management port (10000) is the same host as COPILOT_API_URL=http://172.30.0.30:10002 but on a different port.

  • actions/setup/js/awf_reflect.test.cjs: Update constant expectation to match new URL.

  • actions/setup/js/pi_provider.cjs: Move fetchAWFReflect from the agent_start handler (too early) to process.once('beforeExit'). This fires after Pi finishes all agent turns and the event loop drains — while the AWF container is still running — matching the lifecycle point at which copilot_harness.cjs and claude_harness.cjs call /reflect.

  • Lock files: Recompiled — now shows printf '...' "${GITHUB_COPILOT_BASE_URL}" + GITHUB_COPILOT_BASE_URL: http://host.docker.internal:10002 in step env instead of echo BASE64 | base64 -d.

Before / After (models.json generation)

Before:

echo eyJwcm92aWRlcnMi... | base64 -d > /tmp/gh-aw/pi-agent-dir/models.json

(hardcoded URL embedded in base64)

After:

printf '{"providers":{"aw-gateway":{"api":"openai-completions","apiKey":"COPILOT_GITHUB_TOKEN","baseUrl":"%s","models":[{"id":"claude-sonnet-4-20250514"}]}}}' "${GITHUB_COPILOT_BASE_URL}" > /tmp/gh-aw/pi-agent-dir/models.json

(URL read from env var at runtime, env var set to http://host.docker.internal:10002)

Before / After (AWF reflect URL)

Before: http://api-proxy:10000/reflect — hostname does not resolve in Pi container

After: http://172.30.0.30:10000/reflect — fixed container IP, always reachable

Before / After (AWF reflect timing in Pi extension)

Before: Called at agent_start — too early, api-proxy management endpoint not yet ready

After: Called at process.once('beforeExit') — after all agent turns complete, matching copilot_harness.cjs / claude_harness.cjs pattern

Copilot AI and others added 2 commits May 3, 2026 20:55
…ded URL

Replace buildPiModelsJSON (which embedded a hardcoded http://host.docker.internal:PORT
URL via base64) with buildPiModelsJSONSetup that generates models.json at runtime
using printf and the GITHUB_COPILOT_BASE_URL (or equivalent) env var.

Also set the base URL env var in the Pi step environment (alongside PI_CODING_AGENT_DIR)
so the printf command can read the correct gateway URL inside the AWF container.

Also fix pre-existing build error: missing WorkflowData arg in
compiler_experiments.go generateSetupStep call.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/7be7f469-08a4-4da4-a4c3-2bbfe7d18aca

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

Dev completed successfully!

@github-actions github-actions Bot removed the dev label May 3, 2026
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 3, 2026

@copilot the configuration of the api-proxy provider extension is bogus.

See this log entry

[gh-aw/pi-provider] 2026-05-03T21:18:54.675Z awf-reflect: fetching http://api-proxy:10000/reflect (timeout=5000ms)

but http://api-proxy is incorrect.

See this log that states where the copilot base api url:

[health-check] COPILOT_API_URL=http://172.30.0.30:10002

The /reflect must also be in that url (different port)

Review sources at github/gh-aw-firewall to details

Replace http://api-proxy:10000 with http://172.30.0.30:10000 in
AWF_API_PROXY_REFLECT_URL. The api-proxy Docker service name does not
resolve in all agent container contexts (notably Pi). The fixed IP
172.30.0.30 (AWFAPIProxyContainerIP) is always reachable.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/16318405-89a5-4591-bbfe-9bb6ce063dc1

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 3, 2026

@copilot the configuration of the api-proxy provider extension is bogus.

See this log entry...

Fixed in db3f0a3 — changed AWF_API_PROXY_REFLECT_URL in awf_reflect.cjs from http://api-proxy:10000/reflect to http://172.30.0.30:10000/reflect (the fixed container IP, same host as COPILOT_API_URL, port 10000 = management port). The api-proxy DNS name doesn't resolve in the Pi container context.

Copilot AI changed the title fix: generate Pi models.json using BASE_URL env var instead of hardcoded URL fix: fix Pi agent models.json and AWF reflect URL configurations May 3, 2026
@pelikhan pelikhan added the dev label May 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

Dev completed successfully!

@github-actions github-actions Bot removed the dev label May 3, 2026
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 3, 2026

@copilot review how the other harness connect to /reflect and fix pi extension

See [gh-aw/pi-provider] 2026-05-03T21:44:36.171Z awf-reflect: fetching http://172.30.0.30:10000/reflect (timeout=5000ms) it is failings

Also search for api-proxy references in the in extensions and fix

The pi_provider.cjs extension was calling fetchAWFReflect at agent_start
(very early, before any LLM turns). Copilot and Claude harnesses call it
AFTER the agent subprocess exits. Moving to process.once('beforeExit')
matches that pattern: Pi finishes all turns, the event loop drains, the
async fetch runs while the AWF container is still alive, then Pi exits.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/377ac46f-2514-4541-9074-1cfea3ef5054

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 3, 2026

@copilot review how the other harness connect to /reflect and fix pi extension

See [gh-aw/pi-provider] 2026-05-03T21:44:36.171Z awf-reflect: fetching http://172.30.0.30:10000/reflect (timeout=5000ms...

Fixed in d2e174a. Two changes:

  1. awf_reflect.cjs (previous commit db3f0a3): Changed AWF_API_PROXY_REFLECT_URL from http://api-proxy:10000/reflect (hostname that doesn't resolve in Pi's container context) to http://172.30.0.30:10000/reflect (the fixed container IP).

  2. pi_provider.cjs (d2e174a): Moved fetchAWFReflect from agent_start (too early — the api-proxy management endpoint isn't ready before the first LLM turn) to process.once('beforeExit'). This matches the pattern used by copilot_harness.cjs and claude_harness.cjs, which call /reflect after the agent subprocess finishes, while the AWF container is still alive.

@pelikhan pelikhan added the dev label May 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

Dev completed successfully!

@github-actions github-actions Bot removed the dev label May 3, 2026
@pelikhan pelikhan closed this May 3, 2026
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.

2 participants