Refactor api-proxy upstream response factory into focused modules#5445
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the api-proxy’s upstream response handling by splitting the previously multi-responsibility createUpstreamResponseHandlers() factory into smaller focused modules (logging, retry-on-400 logic, and token-tracking wiring) while preserving the factory’s public contract used by proxy-request.js.
Changes:
- Extracted request completion + upstream auth error logging into
upstream-log.js. - Extracted 400-response retry/forwarding flow into
upstream-retry.js. - Extracted token tracking / OTEL wiring into
upstream-token.js, and updatedupstream-response.jsto primarily wire these modules together. - Updated the api-proxy image Dockerfile COPY list to include the new runtime modules, and added focused Jest unit tests for each module.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/upstream-response.js | Refactors the factory to wire together extracted logging/retry/token helpers while keeping the external interface stable. |
| containers/api-proxy/upstream-log.js | New module encapsulating request completion metrics/logging and upstream auth error logging logic (incl. Copilot auth diagnostics). |
| containers/api-proxy/upstream-log.test.js | Unit tests for the extracted logging helpers. |
| containers/api-proxy/upstream-retry.js | New module encapsulating buffered-400 retry/forward logic (deprecated header retry + Copilot model-not-supported retry/diagnostic). |
| containers/api-proxy/upstream-retry.test.js | Unit tests for the extracted retry/forwarding logic. |
| containers/api-proxy/upstream-token.js | New module encapsulating request-model fallback extraction and token tracking/OTEL callback wiring. |
| containers/api-proxy/upstream-token.test.js | Unit tests for request-model extraction and OTEL/token callback wiring. |
| containers/api-proxy/Dockerfile | Adds the new upstream modules to the explicit COPY list to keep the runtime image aligned with the refactor. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 8/8 changed files
- Comments generated: 0
|
✅ Copilot review passed with no inline comments. @copilot Add the |
|
✅ Smoke Claude passed |
|
✅ Build Test Suite completed successfully! |
|
📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅ |
|
✅ Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓 |
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤 |
|
✅ Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓 |
|
✅ Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓 |
|
✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟 |
|
❌ Security Guard failed. Please review the logs for details. |
|
🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅ |
|
✅ Smoke Gemini completed. All facets verified. 💎 |
|
🔌 Smoke Services — All services reachable! ✅ |
|
✅ Contribution Check completed successfully! Contribution guidelines review complete for PR #5445: no important missing items found based only on the provided PR metadata, diff, and CONTRIBUTING.md context. |
|
Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded. |
Smoke Test: Claude Engine
Overall result: PASS
|
🔬 Smoke Test ResultsPR: Refactor api-proxy upstream response factory into focused modules
Overall: FAIL — pre-computed step outputs were not substituted (template variables unresolved).
|
🔥 Smoke Test: Copilot PAT Auth — PASS
Overall: PASS · Auth mode: PAT (COPILOT_GITHUB_TOKEN) cc
|
Smoke Test Results: Direct BYOK Mode ✅ PASSTests:
Mode: Direct BYOK via CC:
|
🔭 Smoke Test: API Proxy OpenTelemetry Tracing
All scenarios pass. ✅
|
Gemini Engine Smoke Test Results
Overall Status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
|
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) authenticated via Microsoft Entra Overall: PASS
|
|
Merged PRs: chore: upgrade gh-aw to v0.81.0 and recompile workflows; refactor: extract buildAgentSecurityConfig from buildAgentService Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
Chroot Smoke Test Results
Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environment.
|
Smoke Test: Services Connectivity
Overall: FAIL —
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
|
Smoke Test: Copilot BYOK (Azure Foundry)
Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) PASS
|
createUpstreamResponseHandlers()incontainers/api-proxy/upstream-response.jshad grown into a large multi-responsibility factory (logging, auth diagnostics, retry routing, token tracking, and response dispatch). This change decomposes those concerns into focused modules while preserving the existing factory contract used byproxy-request.js.Decomposition of
upstream-response.jscontainers/api-proxy/upstream-log.jscreateLogRequestCompletioncreateLogUpstreamAuthErrorbuildCopilotAuthErrorMessagecontainers/api-proxy/upstream-retry.jshandle400WithRetrycontainers/api-proxy/upstream-token.jssetupTokenTrackingFactory remains the integration point
createUpstreamResponseHandlers()now wires extracted helpers with shared context.createUpstreamResponseHandlers,parseModelNotSupportedFromBody,MAX_MODEL_NOT_SUPPORTED_RETRIES), so caller behavior remains unchanged.Runtime packaging alignment
containers/api-proxy/DockerfileCOPY list to include:upstream-log.jsupstream-retry.jsupstream-token.jsFocused module-level coverage
upstream-log.test.jsupstream-retry.test.jsupstream-token.test.js