Skip to content

refactor(copilot): extract buildCopilotModelsRequest to deduplicate /models auth headers#5518

Merged
lpcox merged 4 commits into
mainfrom
copilot/fix-duplicate-oauth-header-construction
Jun 25, 2026
Merged

refactor(copilot): extract buildCopilotModelsRequest to deduplicate /models auth headers#5518
lpcox merged 4 commits into
mainfrom
copilot/fix-duplicate-oauth-header-construction

Conversation

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

getValidationProbe and getModelsFetchConfig in copilot.js each independently constructed the same /models GET request object — identical URL, Authorization, and Copilot-Integration-Id headers — with no shared source of truth. Any drift (token prefix change, new header, auth mode change) would require matching edits in both places.

Changes

  • Extracted buildCopilotModelsRequest(extra = {}) — a closure-scoped helper inside createCopilotAdapter that builds the standard /models GET request using githubToken and integrationId.
  • Both call-sites replaced: getValidationProbe calls it with no args; getModelsFetchConfig passes { cacheKey: 'copilot' } as the extra spread.
  • The BYOK branch in getModelsFetchConfig (uses apiKey, custom modelsPath) is left intentionally separate — it is a distinct auth mode, not a duplicate.
function buildCopilotModelsRequest(extra = {}) {
  return {
    url: `https://${rawTarget}/models`,
    opts: {
      method: 'GET',
      headers: {
        'Authorization': ['Bearer', githubToken].join(' '),
        'Copilot-Integration-Id': integrationId,
      },
    },
    ...extra,
  };
}

// getValidationProbe
return buildCopilotModelsRequest();

// getModelsFetchConfig (standard target)
return buildCopilotModelsRequest({ cacheKey: 'copilot' });

Copilot AI changed the title [WIP] Fix duplicate OAuth header construction in model-fetch requests refactor(copilot): extract buildCopilotModelsRequest to deduplicate /models auth headers Jun 25, 2026
Copilot finished work on behalf of lpcox June 25, 2026 14:44
Copilot AI requested a review from lpcox June 25, 2026 14:44
@lpcox lpcox marked this pull request as ready for review June 25, 2026 14:45
Copilot AI review requested due to automatic review settings June 25, 2026 14:45

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

This PR refactors the Copilot API proxy provider to avoid duplicated construction of the Copilot /models request, reducing the risk of header/auth drift between validation and startup model-fetch behavior.

Changes:

  • Extracted buildCopilotModelsRequest(extra = {}) inside createCopilotAdapter to build the standard /models GET request object.
  • Updated getValidationProbe and the standard-target branch of getModelsFetchConfig to use the shared helper.
  • Left the BYOK/custom provider branch intentionally separate.
Show a summary per file
File Description
containers/api-proxy/providers/copilot.js Deduplicates /models request construction by extracting a helper used by both validation probing and startup model-fetch config.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread containers/api-proxy/providers/copilot.js Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini reports failed. Facets need polishing...

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — Service connectivity failed ⚠️

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) reports failed. AOAI BYOK (Entra) mode investigation needed...

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

📰 DEVELOPING STORY: Smoke Copilot reports failed. Our correspondents are investigating the incident...

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot PAT reports failed. PAT auth path may have issues...

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Contribution Check failed. Please review the logs for details.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Chroot tests failed Smoke Chroot failed - See logs for details.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Build Test Failed Build Test Suite - See logs for details

Comment thread containers/api-proxy/providers/copilot.js Fixed
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing reports failed. OTel tracing regression detected. ⚠️

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

🌑 The shadows whisper... Smoke Codex failed. The oracle requires further meditation...

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK reports failed. BYOK mode investigation needed...

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude failed

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) reports failed. AOAI BYOK (api-key) mode investigation needed...

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Security Guard failed. Please review the logs for details.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Security Guard failed. Please review the logs for details.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

Copy link
Copy Markdown
Contributor

🔥 Smoke Test Results

Test Status
GitHub MCP connectivity ✅ PASS
GitHub.com HTTP connectivity ⚠️ N/A (template vars not expanded)
File write/read ⚠️ N/A (template vars not expanded)

PR: refactor(copilot): extract buildCopilotModelsRequest to deduplicate /models auth headers
Author: @Copilot | Assignees: @lpcox @Copilot

Overall: PARTIAL PASS — MCP verified ✅; pre-step outputs unavailable (pipeline variable expansion issue).

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test: Copilot PAT Auth — PR #5518

Test Result
GitHub MCP connectivity
GitHub.com HTTP status ✅ 200
File write/read ⚠️ template vars unexpanded

Overall: PASS (2/2 verifiable tests passed; file test skipped due to unexpanded workflow variables)

PR: refactor(copilot): extract buildCopilotModelsRequest to deduplicate /models auth headers
Author: @Copilot · Assignees: @lpcox @Copilot
Auth mode: PAT (COPILOT_GITHUB_TOKEN)

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

Check Result
API Status ✅ PASS
GH Check ✅ PASS
File Status ✅ PASS

Overall Result: PASS

Generated by Smoke Claude for issue #5518 · 61.8 AIC · ⊞ 3.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK
✅ GitHub MCP connectivity
✅ GitHub.com HTTP 200
✅ File write/read verified
✅ BYOK inference (api-proxy → api.githubcopilot.com)

Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY) via api-proxy sidecar.

Status: PASS

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox @Copilot
refactor(api-proxy): extract guard enforcement into proxy-guards.js ✅
refactor(copilot): extract buildCopilotModelsRequest to deduplicate /models auth headers ✅
GitHub.com connectivity ✅
File write/read ✅
BYOK inference ✅
Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)
Overall: PASS

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #5518 · 42.8 AIC · ⊞ 7.8K ·

@github-actions

Copy link
Copy Markdown
Contributor

Merged PRs:

  • refactor(api-proxy): extract sliding-window data structure into rate-limiter-window.js
  • refactor: split agent-volumes-mounts.test.ts by feature area

✅ GitHub PR list
✅ GitHub title check
✅ temp file write/read
✅ discussion comment
✅ npm ci && npm run build

Overall status: PASS

Warning

Firewall blocked 1 domain

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

  • registry.npmjs.org

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

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results — FAIL

Check Result
Redis PING ❌ Timeout (port 6379 unreachable)
PostgreSQL pg_isready ❌ No response (port 5432 unreachable)
PostgreSQL SELECT 1 ❌ Not attempted (pg_isready failed)

host.docker.internal resolves to 172.17.0.1 but both service ports timed out. Service containers do not appear to be reachable from this runner environment.

Overall: FAIL

🔌 Service connectivity validated by Smoke Services

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading ✅ Pass otel.js loads; exports startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled + test helpers
2. Test Suite ✅ Pass 59/59 tests passed across 2 suites (otel.test.js, otel-fanout.test.js)
3. Env Var Forwarding ✅ Pass api-proxy-env-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID, OTEL_SERVICE_NAME
4. Token Tracker Integration ✅ Pass onUsage callback present in token-tracker-http.js (line 324) as the OTEL hook point
5. OTEL Diagnostics ✅ Pass No OTLP endpoint configured → graceful degradation to FileSpanExporter writing /var/log/api-proxy/otel.jsonl; isEnabled() returns true

All 5 scenarios pass. ✅

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Smoke test PASS for:

  • refactor(api-proxy): extract guard enforcement into proxy-guards.js
  • refactor(copilot): extract buildCopilotModelsRequest to deduplicate /models auth headers
    ✅ MCP connectivity
    ✅ github.com connectivity
    ✅ File I/O
    ✅ BYOK inference
    Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)
    cc @lpcox @Copilot

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ NO
Node.js v24.17.0 v22.23.0 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results: Gemini\n- PR #5523: refactor(api-proxy): extract sliding-window data structure into rate-limiter-window.js ✅\n- PR #5522: refactor: split agent-volumes-mounts.test.ts by feature area ✅\n- GitHub.com Connectivity: 200 ✅\n- File Writing & Bash Tooling: Verified ✅\n\nOverall status: PASS

Warning

Firewall blocked 1 domain

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

  • localhost

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

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@lpcox lpcox merged commit 9235c70 into main Jun 25, 2026
85 of 88 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-oauth-header-construction branch June 25, 2026 17:22
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.

4 participants