Skip to content

Model routing on claude/codex/pi fails closed: AWF selection endpoint and effort are chosen for Copilot CLI, not the engine #66787

Closed

Description

@SivaKesava1

Summary

#66723 (fixing #66714) enabled engine.model-routing for the claude, codex and pi engines. We tested it in githubnext/gh-aw-routing-sandbox with gh-aw a4ca9f2 and the default AWF v0.28.44 (router gh-aw-router 0.1.3). Routing works for pi when the router picks a GPT model. Many common selections still fail closed, and the harnesses refuse to start the agent. There are two separate causes:

  1. Endpoint: AWF picks the selection's endpoint for Copilot CLI's single-wire BYOK session. Since gh-aw-firewall#9507, it prefers /chat/completions for Copilot Claude models. The Claude engine accepts only /v1/messages, and pi checks that endpoint against the API in its own model catalog. As a result, no routed Claude selection can run on the claude engine, and every Claude selection fails on pi.
  2. Effort: AWF and the router get candidate models, not the efforts each engine accepts. The router therefore ranks model × effort arms that the engine will reject. mapAWFRoutingEffort then fails closed, as the ADR intends. Codex rejects max and none, and gpt-5.6-luna at max is a frequent pick. Claude rejects none and minimal.

Evidence

All runs are in githubnext/gh-aw-routing-sandbox. Selections come from gh aw audit (model_routing) and sandbox/firewall/logs/api-proxy-logs/model-routing.jsonl.

Run Engine / task AWF selection Result
37728943601 pi, t01 (explain, trivial) gpt-5.6-luna high, /responses ✅ Success, with 7/7 requests as_selected
37728976483 pi, t10 (plan, hard) claude-opus-5 max, /chat/completions ❌ pi_models_json.cjs: Pi model "claude-opus-5" API metadata is "anthropic-messages", which does not match routed API "openai-completions"
37728986374 claude, t10 claude-opus-5 max, /chat/completions ❌ Stopped earlier on a separate AWF health-check bug, filed separately. claude_harness.cjs would reject this selection anyway (see repro below).
37728951894 claude, t01 claude-sonnet-5 medium, /chat/completions ❌ Same as the previous run
37728967888 codex, t04 (fix, medium) gpt-5.6-luna max, /responses ❌ codex_harness.cjs: AWF model routing effort "max" is not supported by the codex engine; refusing to start Codex

Local repro of the Claude-engine rejection. I ran resolveAWFModelRoutingSelection against the captured /reflect payload from run 37728976483, passing the Claude harness's CLAUDE_ROUTING_ENDPOINTS. It returns AWF /reflect selected endpoint /chat/completions, which is not supported by this engine. mapAWFRoutingEffort returns errors for codex with max and none, and for claude with none and minimal.

/reflect already has the data needed for a fix. In the same payload, the Copilot endpoint's routing_models lists claude-opus-5 and claude-sonnet-5 with supported_endpoints: ["/v1/messages", "/chat/completions"], and claude-haiku-4.5 with ["/chat/completions", "/v1/messages"]. The GPT‑5.x models list /responses. The Claude models support efforts low…max. The gpt-5.6-* models support none…max, and gpt-5.4-mini supports none…xhigh.

Impact by arm. These are the eligible_choices values from the selection records:

Engine Candidates Arms Arms the engine rejects
claude haiku-4.5, sonnet-5, opus-5 11 11 of 11. AWF's protocolFor assigns chat-completions to every effort-bearing Claude arm. It also assigns it to the effortless haiku arm, because it returns chat-completions whenever a model has no effort.
codex gpt-5.4-mini, gpt-5.6-luna/terra/sol 23 7 of 23: none ×4 and max ×3
pi all 7 34 11 of 34: every Claude arm

The router sends hard tasks to claude-opus-5 at high, xhigh or max. So these failures hit the hardest tasks, which are the tasks routing should handle best.

Root cause

1. The endpoint is chosen for Copilot CLI

In gh-aw-firewall, buildRoutingCandidates in containers/api-proxy/routing-candidates.js assigns one protocol to each arm through protocolFor. The order is responses, then chat-completions, then messages, and effortless arms get chat-completions. That order suits a single-wire Copilot CLI BYOK session. createSelection in routing-controller.js copies the protocol into selection.endpoint and hard-codes engine: 'copilot'. In gh-aw:

  • Claude: claude_harness.cjs passes CLAUDE_ROUTING_ENDPOINTS (/v1/messages) to resolveAWFModelRoutingSelection in awf_model_routing.cjs. That function treats allowedEndpoints as a hard filter on selection.endpoint, so it rejects any routed Claude selection that AWF puts on /chat/completions.
  • pi: pi_models_json.cjs permits all three endpoints. However, resolvePiModelRouting converts the selection endpoint to a Pi API through PI_ROUTING_ENDPOINT_APIS. main then passes that API to resolvePiApiForModel with strictOverrideApi. The check fails because the Pi catalog API for Claude models is anthropic-messages.
  • Codex: codex_harness.cjs uses CODEX_ROUTING_ENDPOINTS (/responses). This works today because every candidate GPT model is on /responses. It would break the same way for a GPT model that AWF routes to /chat/completions. That happens to any GPT model that has no effort metadata and also advertises /chat/completions.

Changing only the endpoint is safe. Since gh-aw-firewall#9507, AWF records an endpoint-only mismatch as as_selected with deviations: ["endpoint"], and only provider, model or effort mismatches count as deviated. The docs already mention this behavior (reference/model-routing.md, troubleshooting row for routed: "deviated").

2. Effort is not constrained before ranking

buildRoutingCandidates creates one arm for each model and each effort that model advertises, filtered against AWF's global EFFORTS set. apiProxy.routing takes only objective, task, provider and candidateModels. AWF's parseRoutingConfig treats the object as closed. candidateModels filters by model glob only. Neither gh-aw nor the router can exclude efforts that a given engine rejects. In gh-aw, the per-engine effort sets live only in mapAWFRoutingEffort (actions/setup/js/awf_model_routing.cjs) and in the effort table of reference/model-routing.md.

gh-aw alone cannot fix this safely. Clamping the effort was rejected in ADR-66723 (Alternative 2). If a harness took a lower-ranked arm, the traffic would count as deviated because the effort differs, and the audit would no longer match what ran.

Proposed fix

A. For non-Copilot engines, treat the selection endpoint as advisory and verify it against /reflect

This change needs only gh-aw and works with the current default AWF v0.28.44. Ship it first.

  • resolveAWFModelRoutingSelection in actions/setup/js/awf_model_routing.cjs. When selection.endpoint is not one of the engine's endpoints, look up the selected wire_model in the configured Copilot endpoint's routing_models in the same /reflect payload.
    • If its supported_endpoints includes an engine endpoint, return the first one in the engine's preference order as the effective endpoint. Keep AWF's original endpoint, for example as a separate selected_endpoint field, for logs and audit.
    • Fail closed if there is no overlap, or if the model has no routing_models entry or candidate_metadata_complete is not true. Older AWF versions then keep today's behavior.
    • The error should name the model, the endpoints it advertises, and the engine's API.
    • Model, effort and provider never change.
  • Claude (claude_harness.cjs). Keep CLAUDE_ROUTING_ENDPOINTS at /v1/messages. Both main and buildClaudeChildEnv already call the shared resolver, so they get the change automatically. Extend the inference routing: log line to show the endpoint, and state when gh-aw used the engine's endpoint instead of AWF's selection.
  • Codex (codex_harness.cjs, resolveCodexModelRouting). Keep CODEX_ROUTING_ENDPOINTS at /responses. The resolver change applies. Make the same log-line change.
  • pi (pi_models_json.cjs). pi's own API depends on the model, so the resolver change alone is not enough.
    • resolvePiModelRouting should stop deriving api from PI_ROUTING_ENDPOINT_APIS[selection.endpoint].
    • In main, move the routed API decision to after runtime.getModel. Take the API from the Pi catalog or the AWF catalog wire_api through resolvePiApiForModel, without a routing override.
    • Map that API back to its endpoint and require the endpoint to be in the model's supported_endpoints. For claude-opus-5 the result is anthropic-messages on /v1/messages, which /reflect advertises.
    • Keep failing closed when the catalog API's endpoint is not advertised. GPT selections are unchanged (openai-responses on /responses).
    • model-routing-selection.json and pi_runtime.cjs read only wire_model and mapped_effort, so they need no change.
  • Unverified assumption about effort per endpoint. routing_models.supported_reasoning_efforts is listed per model, not per endpoint. The live check below must confirm that the routed effort is accepted on /v1/messages. This covers claude-opus-5 at max through Claude Code's CLAUDE_CODE_EFFORT_LEVEL, and pi's anthropic-messages thinking level for the same arm.

B. Alternative or follow-up: have gh-aw tell AWF each engine's API

This is cleaner long-term. AWF would then never rank an arm that the engine cannot call, and observation would show no endpoint deviation. It needs a gh-aw-firewall change, so it fits well with part C.

  • AWF. Add an optional ordered list of acceptable protocols to apiProxy.routing. This needs updates to parseRoutingConfig in routing-config.js, src/awf-config-schema.json and docs/awf-config-spec.md. With the list, protocolFor and getModelRoutingChoices choose the first protocol each arm supports from the list and drop arms with none. createSelection then reports the endpoint the engine will actually call, and it should stop hard-coding engine: 'copilot'.
  • Suggested lists. Claude: messages. Codex: responses. pi: responses then messages, with chat-completions last if wanted. Copilot: omit the field to keep today's behavior.
  • gh-aw.
    • Add the field to AWFModelRoutingConfig in pkg/workflow/awf_config.go and emit it from the routing branch of BuildAWFConfigJSON in pkg/workflow/awf_config_build.go.
    • Gate it on a new AWF version constant in pkg/constants/version_constants.go, with a capability check modeled on apiProxySupportsRoutingCandidateModels.
    • Keep the runtime check from part A as defense in depth.

C. Restrict each engine to the efforts it supports before ranking

  • AWF. Add an optional allowed-effort set to apiProxy.routing, using the same schema surfaces as in part B.
    • buildRoutingCandidates should drop arms whose effort is not in the set before the /route request. The router then never ranks or selects an arm the engine would reject.
    • Effortless arms stay, because every engine accepts a null effort.
    • The classifier call runs inside AWF rather than through the engine. Decide whether the filter applies to the route pool only, which is preferable, or to the classifier pool as well.
    • If filtering leaves no arms, AWF returns no_route, which already maps to the documented exit code 78.
  • gh-aw, single source of truth.
    • Add a per-engine effort table to pkg/workflow/model_routing.go, next to modelRoutingEngineSupportsModel, and emit it for claude and codex. pi accepts every effort and copilot needs no field, so omit it for both.
    • Add a parity test that fails when the Go table and the table in mapAWFRoutingEffort differ. This addresses the drift risk listed in the consequences of docs/adr/66723-extend-model-routing-to-claude-codex-pi.md.
    • Check the Codex set again against the pinned Codex CLI's accepted model_reasoning_effort values, in particular whether none is now valid.
  • Fail-closed backstop. Keep mapAWFRoutingEffort failing closed as the backstop, so ADR Alternative 2 stays rejected.
  • Compile-time warning. When a claude or codex workflow compiles against an AWF version without the effort field, warn that some arms may be rejected at runtime. warnRoutedSubAgentModels uses the same pattern for candidateModels.

D. Documentation

  • docs/src/content/docs/reference/model-routing.md:
    • Correct the allowed-models row. "Codex accepts GPT models served on /responses" should describe endpoint compatibility checked at runtime.
    • Correct the compatibility paragraph, which says "each runtime verifies … the selected endpoint matches its API". Explain that non-Copilot engines verify through /reflect routing_models.supported_endpoints that the model supports the engine's API, and use that API.
    • Above the effort table, say that each engine's efforts are filtered before ranking, give the minimum AWF version, and note that fail-closed mapping remains as a backstop.
    • Update the log-line examples to include the endpoint.
    • Add troubleshooting rows for the new error messages, for example "model advertises no endpoint compatible with this engine".
  • ADR. Update docs/adr/66723-extend-model-routing-to-claude-codex-pi.md, or add a follow-up ADR. Record that the selection endpoint is advisory for non-Copilot engines, and update the negative consequence about fail-closed effort aborts.

E. Tests

  • Fixture. Add a redacted fixture built from the t10 /reflect payload (run 37728976483): Copilot endpoint, routing_models, and a routing.selection of claude-opus-5, max, /chat/completions.
  • awf_model_routing.test.cjs:
    • A Claude selection on /chat/completions resolves to /v1/messages when the model advertises it.
    • Resolution fails closed when it does not.
    • Resolution fails closed when routing_models is missing or incomplete, matching today's behavior.
    • The original AWF endpoint is preserved.
  • claude_harness.test.cjs. buildClaudeChildEnv with the t10 selection sets ANTHROPIC_MODEL=claude-opus-5 and CLAUDE_CODE_EFFORT_LEVEL=max and logs the endpoint override.
  • pi_models_json.test.cjs:
    • A routed claude-opus-5 selection on /chat/completions produces models.json with api: anthropic-messages.
    • The routed GPT case (/responses) is unchanged.
    • A catalog API whose endpoint /reflect does not advertise still fails.
  • codex_harness.test.cjs. Selecting a GPT model on /chat/completions resolves to /responses when advertised. The existing effort rejection for max and none stays.
  • Go (model_routing_test.go, awf_config_test.go):
    • claude and codex emit the effort set, plus the protocol list if part B ships, under apiProxy.routing when the AWF version supports them.
    • pi and copilot do not emit the effort set.
    • Older AWF versions get the warning.
    • The Go and JS effort tables match.

Live verification in githubnext/gh-aw-routing-sandbox

Run this after the separate health-check fix lands.

  • t10-plan-subagent-routing on claude-routed and pi-routed.
    • Expect a claude-opus-5 selection.
    • The harness should log /v1/messages (or anthropic-messages for pi), and the agent should complete.
    • model-routing.jsonl request records should be as_selected with deviations: ["endpoint"] before part B, and with no deviation after it. deviated_traffic_cost should be 0.
    • Upstream should accept the routed effort on the Messages API.
  • pi run that selects the effortless claude-haiku-4.5 arm.
  • t04-fix-local on codex-routed, repeated several times. After part C, eligible_choices should be 16 instead of 23, and no ranked choice should have none or max effort.
  • t01 on pi-routed as a regression check for the GPT path.

Out of scope

  • The AWF health-check failure that stopped both claude-engine runs before the harness started: Cannot connect to Anthropic API proxy at http://host.docker.internal:10002. It is filed separately.
  • Copilot engine routing. Copilot CLI's single-wire session is what AWF's endpoint choice is designed for.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions