Repository navigation
Description
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:
- Endpoint: AWF picks the selection's
endpointfor Copilot CLI's single-wire BYOK session. Since gh-aw-firewall#9507, it prefers/chat/completionsfor 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. - 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.
mapAWFRoutingEffortthen fails closed, as the ADR intends. Codex rejectsmaxandnone, andgpt-5.6-lunaatmaxis a frequent pick. Claude rejectsnoneandminimal.
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.cjspassesCLAUDE_ROUTING_ENDPOINTS(/v1/messages) toresolveAWFModelRoutingSelectioninawf_model_routing.cjs. That function treatsallowedEndpointsas a hard filter onselection.endpoint, so it rejects any routed Claude selection that AWF puts on/chat/completions. - pi:
pi_models_json.cjspermits all three endpoints. However,resolvePiModelRoutingconverts the selection endpoint to a Pi API throughPI_ROUTING_ENDPOINT_APIS.mainthen passes that API toresolvePiApiForModelwithstrictOverrideApi. The check fails because the Pi catalog API for Claude models isanthropic-messages. - Codex:
codex_harness.cjsusesCODEX_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.
resolveAWFModelRoutingSelectioninactions/setup/js/awf_model_routing.cjs. Whenselection.endpointis not one of the engine's endpoints, look up the selectedwire_modelin the configured Copilot endpoint'srouting_modelsin the same/reflectpayload.- If its
supported_endpointsincludes 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 separateselected_endpointfield, for logs and audit. - Fail closed if there is no overlap, or if the model has no
routing_modelsentry orcandidate_metadata_completeis 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.
- If its
- Claude (
claude_harness.cjs). KeepCLAUDE_ROUTING_ENDPOINTSat/v1/messages. BothmainandbuildClaudeChildEnvalready call the shared resolver, so they get the change automatically. Extend theinference 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). KeepCODEX_ROUTING_ENDPOINTSat/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.resolvePiModelRoutingshould stop derivingapifromPI_ROUTING_ENDPOINT_APIS[selection.endpoint].- In
main, move the routed API decision to afterruntime.getModel. Take the API from the Pi catalog or the AWF catalogwire_apithroughresolvePiApiForModel, without a routing override. - Map that API back to its endpoint and require the endpoint to be in the model's
supported_endpoints. Forclaude-opus-5the result isanthropic-messageson/v1/messages, which/reflectadvertises. - Keep failing closed when the catalog API's endpoint is not advertised. GPT selections are unchanged (
openai-responseson/responses). model-routing-selection.jsonandpi_runtime.cjsread onlywire_modelandmapped_effort, so they need no change.
- Unverified assumption about effort per endpoint.
routing_models.supported_reasoning_effortsis listed per model, not per endpoint. The live check below must confirm that the routed effort is accepted on/v1/messages. This coversclaude-opus-5atmaxthrough Claude Code'sCLAUDE_CODE_EFFORT_LEVEL, and pi'santhropic-messagesthinking 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 toparseRoutingConfiginrouting-config.js,src/awf-config-schema.jsonanddocs/awf-config-spec.md. With the list,protocolForandgetModelRoutingChoiceschoose the first protocol each arm supports from the list and drop arms with none.createSelectionthen reports the endpoint the engine will actually call, and it should stop hard-codingengine: 'copilot'. - Suggested lists. Claude:
messages. Codex:responses. pi:responsesthenmessages, withchat-completionslast if wanted. Copilot: omit the field to keep today's behavior. - gh-aw.
- Add the field to
AWFModelRoutingConfiginpkg/workflow/awf_config.goand emit it from the routing branch ofBuildAWFConfigJSONinpkg/workflow/awf_config_build.go. - Gate it on a new AWF version constant in
pkg/constants/version_constants.go, with a capability check modeled onapiProxySupportsRoutingCandidateModels. - Keep the runtime check from part A as defense in depth.
- Add the field to
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.buildRoutingCandidatesshould drop arms whose effort is not in the set before the/routerequest. 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 tomodelRoutingEngineSupportsModel, 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
mapAWFRoutingEffortdiffer. This addresses the drift risk listed in the consequences ofdocs/adr/66723-extend-model-routing-to-claude-codex-pi.md. - Check the Codex set again against the pinned Codex CLI's accepted
model_reasoning_effortvalues, in particular whethernoneis now valid.
- Add a per-engine effort table to
- Fail-closed backstop. Keep
mapAWFRoutingEffortfailing 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.
warnRoutedSubAgentModelsuses the same pattern forcandidateModels.
D. Documentation
docs/src/content/docs/reference/model-routing.md:- Correct the
allowed-modelsrow. "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
/reflectrouting_models.supported_endpointsthat 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".
- Correct the
- 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
/reflectpayload (run 37728976483): Copilot endpoint,routing_models, and arouting.selectionofclaude-opus-5,max,/chat/completions. awf_model_routing.test.cjs:- A Claude selection on
/chat/completionsresolves to/v1/messageswhen the model advertises it. - Resolution fails closed when it does not.
- Resolution fails closed when
routing_modelsis missing or incomplete, matching today's behavior. - The original AWF endpoint is preserved.
- A Claude selection on
claude_harness.test.cjs.buildClaudeChildEnvwith the t10 selection setsANTHROPIC_MODEL=claude-opus-5andCLAUDE_CODE_EFFORT_LEVEL=maxand logs the endpoint override.pi_models_json.test.cjs:- A routed
claude-opus-5selection on/chat/completionsproducesmodels.jsonwithapi: anthropic-messages. - The routed GPT case (
/responses) is unchanged. - A catalog API whose endpoint
/reflectdoes not advertise still fails.
- A routed
codex_harness.test.cjs. Selecting a GPT model on/chat/completionsresolves to/responseswhen advertised. The existing effort rejection formaxandnonestays.- 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.routingwhen 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.
- claude and codex emit the effort set, plus the protocol list if part B ships, under
Live verification in githubnext/gh-aw-routing-sandbox
Run this after the separate health-check fix lands.
- t10-plan-subagent-routing on
claude-routedandpi-routed.- Expect a
claude-opus-5selection. - The harness should log
/v1/messages(oranthropic-messagesfor pi), and the agent should complete. model-routing.jsonlrequest records should beas_selectedwithdeviations: ["endpoint"]before part B, and with no deviation after it.deviated_traffic_costshould be 0.- Upstream should accept the routed effort on the Messages API.
- Expect a
- pi run that selects the effortless
claude-haiku-4.5arm. - t04-fix-local on
codex-routed, repeated several times. After part C,eligible_choicesshould be 16 instead of 23, and no ranked choice should havenoneormaxeffort. - t01 on
pi-routedas 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.
Activity