Skip to content

Activate task-level model routing in the API proxy server - #8966

Merged
lpcox merged 5 commits into
mainfrom
copilot/activate-routing-api-proxy-server
Sep 24, 2026
Merged

lpcox merged 5 commits into
mainfrom
copilot/activate-routing-api-proxy-server

Conversation

Copilot AI commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

The routing controller and enforcement from #8942 exist but nothing constructs them, nothing reads the private files the host watches, and the running proxy never calls them. This wires both ends: a routing session the server owns for the run, started after startup validation and drained on shutdown.

routing-runtime.js (new — the twelfth routing module)

  • Builds the controller from AWF_ROUTING_CONFIG, the allow/deny policy env vars, the live Copilot adapter, the discovered model cache, and proxyRequest/checkRateLimit. Returns null when routing is unconfigured, so an unset deployment constructs nothing.
  • Conversations load under an explicit 1 MiB bound via an O_NOFOLLOW descriptor that is size- and link-checked before parsing. The low-level reader preserves filesystem errors; only the public loader translates them into routing codes.
  • The session refuses to plan when any result file already exists, so a stale selection is never reused. Results are published atomically and exactly once — selection.json, failure.json, runtime-failure.json, complete.json.
  • A failure raised after selection (i.e. from the live agent response path) publishes runtime-failure.json and never throws back into that stream. If that publication fails, the proxy exits 78 rather than leaving the host waiting on a claim nobody verified.

Server wiring

  • server-factory.js — screens inference after health and reflect but before the enabled check, so a rejection never reveals provider configuration; admitted routed requests use the enforcement transform, not the adapter's (which would reintroduce aliases and fallback); upgrades are rejected while routing is active.
  • server.js — constructs the session and passes it to the server factory and bootPrimary.
  • startup.js — routing starts only after key validation and model discovery resolve; shutdown() drains before servers close, and completeShutdown() runs after log and telemetry shutdown, exiting 78 if it throws.
  • Dockerfile — copies the twelve routing runtime modules (enforced by the existing dockerfile-copy-coverage guard).
// server-factory.js — the selection is pinned from the first agent request
const bodyTransform = req.awfRouting ? req.awfRouting.bodyTransform : adapter.getBodyTransform();

Behavior

Without AWF_ROUTING_CONFIG the proxy is unchanged. With the block configured, it fails closed — routing cannot load the conversation and every inference request is rejected — until issue 06 supplies the private mounts and the container conversation path. That failure is intentional; no missing value is defaulted.

Two review suggestions were deliberately not taken: the 90s deadline is anchored at session construction, and upgrades are rejected for every adapter whenever a session exists. Both are the specified fail-closed contract ("do not enable routed WebSocket requests"); relaxing them is a separate decision.

Tests cover the new runtime module plus the factory and startup wiring, including drain ordering and both exit-78 paths.

Copilot AI and others added 2 commits September 24, 2026 13:51
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Activate routing in the API proxy server Activate task-level model routing in the API proxy server Sep 24, 2026
Copilot AI requested a review from lpcox September 24, 2026 13:54
@lpcox

lpcox commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

@copilot make sure that all decisions by the model router are logged in a structured log that will be easy for an agent to parse and easy to export to a dashboard

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

Copilot AI commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot make sure that all decisions by the model router are logged in a structured log that will be easy for an agent to parse and easy to export to a dashboard

Added structured decision logging for the enforcement layer in 8e3f8c2 (routing-enforcement.js). Every screenRequest call now records {stage: 'decision', decision: 'admit'|'reject', reason, method, pathname} through the same model_routing JSON log line used for classification/selection/failure, with a specific reason per outcome (draining, no_selection, terminal_failure, foreign_adapter, method_not_allowed, unsupported_endpoint, effort_endpoint_mismatch, header_override, invalid_url, model_discovery_exempt, selected_model_pinned, upgrade_rejected). Rejections log at warn, admits at info, so the full admit/reject trail is now parseable and exportable alongside the existing planning-stage events.

@lpcox
lpcox marked this pull request as ready for review September 24, 2026 18:34
Copilot AI balanced review requested due to automatic review settings September 24, 2026 18:34

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

🟡 Changes recommended

Unpublishable bootstrap failures can leave the proxy running without a result, and rejected bodies are incorrectly logged as admitted.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Activates task-level model routing in the API proxy lifecycle and enforces selected models on live requests.

Changes:

  • Adds secure routing-session setup, result publication, and shutdown handling.
  • Integrates routing enforcement into HTTP and WebSocket handling.
  • Adds lifecycle, enforcement, and packaging tests.
File Description
containers/​api-proxy/​startup.test.js Tests routing lifecycle ordering and exit handling.
containers/​api-proxy/​startup.js Starts, drains, and completes routing sessions.
containers/​api-proxy/​server.js Constructs and injects the production routing session.
containers/​api-proxy/​server-factory.test.js Tests request and upgrade enforcement wiring.
containers/​api-proxy/​server-factory.js Screens routed traffic and applies routing transforms.
containers/​api-proxy/​routing-runtime.test.js Tests secure file handling and session publication.
containers/​api-proxy/​routing-runtime.js Implements production routing orchestration.
containers/​api-proxy/​routing-enforcement.test.js Tests routing decision telemetry.
containers/​api-proxy/​routing-enforcement.js Adds structured admit/reject observations.
containers/​api-proxy/​Dockerfile Packages routing runtime modules.

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

Comment thread containers/api-proxy/routing-runtime.js Outdated
Comment on lines +266 to +269
if (!privateFs.existsSync(path.join(outputDir, 'selection.json')) &&
!privateFs.existsSync(path.join(outputDir, 'failure.json'))) {
publishRoutingResult(outputDir, 'failure.json', result.failure);
}
Comment on lines +150 to +157
safeRecordDecision(observer, {
decision: 'admit',
reason: 'selected_model_pinned',
method: req.method,
pathname,
selected_model: selection.choice.model,
selected_effort: selection.choice.effort ?? null,
});
@lpcox

lpcox commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

@copilot address the review feedback

…ody validation passes

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

Copilot AI commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@copilot address the review feedback

Addressed both review threads in 3dc... (see below commits): the bootstrap-failure publish is now guarded with fatalExit(78), and admit decisions are recorded only after bodyTransform validates the model/effort match, with mismatched bodies now logging a reject decision before throwing.

@copilot address the review feedback

Fixed in 1d980a1: bootstrap-failure publish is now guarded with fatalExit(78) when it fails, and the admit decision is recorded only after bodyTransform validates the model/effort match — a mismatched body now logs a reject decision before throwing instead of a false admit.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@copilot Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 92.80% 92.82% 📈 +0.02%
Statements 91.35% 91.36% 📈 +0.01%
Functions 89.78% 89.78% ➡️ +0.00%
Branches 84.63% 84.64% 📈 +0.01%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/log-directory-setup.ts 96.2% → 100.0% (+3.78%) 96.3% → 100.0% (+3.71%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot BYOK is testing direct BYOK mode on this pull request...

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

Warning

Firewall blocked 1 domain

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

  • o205451.ingest.us.sentry.io

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

network:
  allowed:
    - defaults
    - "o205451.ingest.us.sentry.io"

See Network Configuration for more information.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

🔌 Service connectivity validated by Smoke Services

@github-actions github-actions Bot added the smoke-copilot-network-isolation Copilot network-isolation egress smoke test label Sep 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode

✅ GitHub MCP: Connected (PR #8975, #8970 verified)
✅ GitHub.com: HTTP 200 OK
✅ File Write/Read: /tmp/gh-aw/agent/smoke-test-copilot-byok.txt confirmed
✅ BYOK Inference: Running direct BYOK mode (COPILOT_PROVIDER_API_KEY) → api-proxy → api.githubcopilot.com

Status: PASS 🟢
Triggered by @lpcox

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Cloud Hypervisor + Copilot

  1. list_pull_requests MCP call: PASS
  2. curl https://github.com: PASS (200)
  3. Write/read temp file in /tmp/gh-aw/agent/: PASS
  4. curl (example.com/redacted) blocked: PASS (000)

All checks passed.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • example.com
  • github.com

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

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

See Network Configuration for more information.

Cloud Hypervisor + Copilot smoke test by Smoke Cloud Hypervisor
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Services Connectivity

  • ✅ Redis PING → PONG
  • ✅ PostgreSQL pg_isready → accepting connections
  • ✅ PostgreSQL SELECT 1 → 1

Overall: PASS

🔌 Service connectivity validated by Smoke Services
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: API Proxy OpenTelemetry Tracing

# Scenario Result
1 Module Loading ✅ otel.js loads; isEnabled() → true; exports include startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled, exporters
2 Test Suite ✅ 3 suites / 68 tests passed (0 failed) — covers span creation, gen_ai.* attributes, OTLP serialization, ProxyAwareOtlpExporter, FileSpanExporter
3 Env Var Forwarding ✅ env-passthrough.ts forwards GITHUB_AW_OTEL_TRACE_ID/GITHUB_AW_OTEL_PARENT_SPAN_ID to agent; api-proxy-env-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, and trace context to api-proxy
4 Token Tracker Integration ✅ token-tracker-http.js exposes onUsage callback as the OTEL hook point
5 OTEL Diagnostics ✅ otel.jsonl present with 1 exported span (gh-aw.agent.setup, workflow-level span with valid traceId/spanId). No api-proxy request spans present — expected, since this smoke run doesn't drive an actual LLM call through the api-proxy sidecar

Overall: ✅ All scenarios passed. OTEL module initialization, span/attribute logic, env var propagation, and token-tracker hook points are all working as designed; graceful degradation confirmed (no errors, clean exports).

Warning

Firewall blocked 1 domain

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

  • o205451.ingest.us.sentry.io

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

network:
  allowed:
    - defaults
    - "o205451.ingest.us.sentry.io"

See Network Configuration for more information.

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot Engine — @lpcox

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@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

Warning

Firewall blocked 1 domain

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

  • api.anthropic.com

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

network:
  allowed:
    - defaults
    - "api.anthropic.com"

See Network Configuration for more information.

Generated by Smoke Claude for #8966 · claude · haiku45 · 56.5 AIC · ⊞ 4.7K · ◷
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Runtime Version Comparison

Runtime Host Version Chroot Version Match?
Python Python 3.12.14 Python 3.12.14 ✅ YES
Node.js v24.21.0 v22.23.2 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Result: ❌ Not all versions match — Node.js version differs between host and chroot environment. smoke-chroot label was not applied.

Tested by Smoke Chroot
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • msfeed25.pkgs.visualstudio.com

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

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "msfeed25.pkgs.visualstudio.com"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Gemini Smoke Test Results

  • GitHub MCP Testing: ✅
    • fix: download NVX release assets outside the agent sandbox
    • feat: add release verification workflow for NVX asset staging
  • GitHub.com Connectivity: ✅
  • File Writing Testing: ✅
  • Bash Tool Testing: ✅

Overall Status: PASS

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • github.com
  • play.googleapis.com

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

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

See Network Configuration for more information.

💎 Faceted by Smoke Gemini
Add label ready-for-aw to run again

@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 ✅ all passed ✅ PASS
Go env ✅ all passed ✅ PASS
Go uuid ✅ all passed ✅ PASS
Java gson ✅ 1/1 passed ✅ PASS
Java caffeine ✅ 1/1 passed ✅ PASS
Node.js clsx ✅ all passed ✅ PASS
Node.js execa ✅ all passed ✅ PASS
Node.js p-limit ✅ all passed ✅ PASS
Rust fd ✅ all passed ✅ PASS
Rust zoxide ✅ all passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

All 18 project builds/installs and test suites completed successfully. No errors encountered. Java required a local Maven repository path (-Dmaven.repo.local) due to a root-owned ~/.m2 directory in this environment; this is an environment-setup nuance unrelated to firewall correctness.

Warning

Firewall blocked 8 domains

The following domains were blocked by the firewall during workflow execution:

  • api.nuget.org
  • bun.sh
  • dc.services.visualstudio.com
  • deno.land
  • dl.deno.land
  • github.com
  • releaseassets.githubusercontent.com
  • repo.maven.apache.org

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

network:
  allowed:
    - defaults
    - "api.nuget.org"
    - "bun.sh"
    - "dc.services.visualstudio.com"
    - "deno.land"
    - "dl.deno.land"
    - "github.com"
    - "releaseassets.githubusercontent.com"
    - "repo.maven.apache.org"

See Network Configuration for more information.

Generated by Build Test Suite for #8966 · copilot · auto · 171.2 AIC · ⊞ 11.8K · ◷
Add label ready-for-aw to run again

@lpcox
lpcox merged commit 647dec0 into main Sep 24, 2026
145 of 149 checks passed
@lpcox
lpcox deleted the copilot/activate-routing-api-proxy-server branch September 24, 2026 22:59
github-actions Bot added a commit that referenced this pull request Sep 25, 2026
Section 13a said the routing candidate-pool foundation was present but not
called by the running proxy. PR #8966 (merged) wired the routing controller
and request enforcement into the live API proxy server: a routing session
now starts after key validation/model discovery and screens every inference
request against the selected model/effort. Clarify that host-side staging
and validation of apiProxy.routing input (PR #8985) is still open, so the
feature is not yet end-to-end functional despite the proxy-side wiring
being shipped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lpcox pushed a commit that referenced this pull request Sep 25, 2026
Section 13a said the routing candidate-pool foundation was present but not
called by the running proxy. PR #8966 (merged) wired the routing controller
and request enforcement into the live API proxy server: a routing session
now starts after key validation/model discovery and screens every inference
request against the selected model/effort. Clarify that host-side staging
and validation of apiProxy.routing input (PR #8985) is still open, so the
feature is not yet end-to-end functional despite the proxy-side wiring
being shipped.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
aoai-model — 1d980a1b Deployed Sep 24, 2026 by lpcox via conclusion #1758
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.

[Routing]: activate routing in the api proxy server

3 participants