Repository navigation
Description
Why
On main at 29b5ac2, the routing core modules in actions/setup/js/ are well covered (line coverage):
| Module | Lines |
|---|---|
awf_model_routing.cjs |
94% |
model_attribution.cjs |
97% |
parse_token_usage.cjs |
91% |
pi_models_json.cjs |
93% |
unified_session_payload.cjs |
96% |
The harnesses report much lower coverage:
| Harness | Lines |
|---|---|
claude_harness.cjs |
37% |
copilot_harness.cjs |
46% |
codex_harness.cjs |
55% |
Their tests run them with spawnSync, and vitest's v8 coverage doesn't follow child processes. So coverage can't show whether the harness routing paths are exercised.
Good per-module coverage also doesn't catch disagreements between modules. The F5 bug (#67012) was an interaction: the harness applied one endpoint rule (#66956) and attribution applied another (#66963). Each module passed its own tests.
Where one routing decision is evaluated today
At 29b5ac2, the same selection is derived or re-derived in several places:
- Harness selection.
resolveAWFModelRoutingSelection,getAWFModelRoutingPolicy, andmapAWFRoutingEffortinawf_model_routing.cjs.- Called from:
copilot_harness.cjs:main,applyCopilotRoutingSelection,applyCopilotRoutingArgsclaude_harness.cjs: insidemain, feedingbuildClaudeChildEnvcodex_harness.cjs:resolveCodexModelRouting- pi:
resolvePiModelRoutingandresolvePiRoutingEndpointinpi_models_json.cjs
- Each records an advisory outcome via
recordAWFModelRoutingOutcomeinagent/awf-routing-outcome.json.
- Post-run resolution.
resolveModelRoutingOutcomeinparse_token_usage.cjscombines the proxymodel-routing.jsonlrecord,agent/awf-reflect.json, and the harness advisory. For endpoint overrides it re-runsresolveAWFModelRoutingSelection. It then writes theaw_info.jsonmodel_routingblock throughrecordModelRoutinginmodel_attribution.cjs. - Consumers.
resolveEffectiveModelandgetEffectiveModelLabelinmodel_attribution.cjs, which drive the footer viamessages_footer.cjsandhandle_noop_message.cjs.unified_session.cjsemitsworkflow.infoandmodel_routing.outcomeand merges the outcome fields intoworkflow.info.modelRouting. The payload shapes come fromunified_session_payload.cjs.sendJobConclusionSpaninsend_otlp_span.cjsemitsgen_ai.request.model,gh-aw.model.requested,gh-aw.model.effort, andgh-aw.model_routing.status/.mode/.router_version.
Plan
1. Per-engine contract test
Add actions/setup/js/model_routing_contract.test.cjs, table-driven over copilot, claude, pi, and codex. Each row has one /reflect payload and one proxy model-routing.jsonl log, stored under actions/setup/js/fixtures/. Each row runs in a temp GH_AW_TMP_DIR with the engine ID and routing env set, and feeds the same inputs through every stage in-process:
- the harness's routing resolution, which writes the advisory through
recordAWFModelRoutingOutcome resolveModelRoutingOutcomeinparse_token_usage.cjs, which writes theaw_info.jsonmodel_routingblock- the footer label from
getEffectiveModelLabel(and the underlyingresolveEffectiveModel) - the unified session's
workflow.infoandmodel_routing.outcomeevents - the OTEL routing attributes from
send_otlp_span.cjs, with a mocked exporter
Assert that every stage agrees on model, effort, status, effective endpoint, and selected endpoint. Today the OTEL span carries model, effort, and status but no endpoints. Assert those three there, and add endpoint assertions if #67237 adds endpoint attributes. If an engine maps effort (pi maps none to off), assert that applied effort and requested effort stay consistent everywhere they appear.
Rows should include at least:
- Copilot on
/responsesand on/chat/completions - Claude with a selection on
/chat/completionsexecuted on/v1/messages(the Model routing: Claude-engine runs recorded as 'routing rejected (unsupported_endpoint)' although AWF routing succeeded #67012 shape) - Codex with an endpoint override to
/responses - pi with a Claude pick
- one negative row per engine where the endpoint isn't advertised, which must be
rejected/unsupported_endpointin every stage - one row where the harness and proxy disagree on wire model, which must be
harness_selection_mismatcheverywhere
The goal: changing an endpoint or effort rule in any one module fails this test. That includes a harness, awf_model_routing.cjs, parse_token_usage.cjs, model_attribution.cjs, unified_session.cjs, or send_otlp_span.cjs.
2. Engine effort matrix
Add a table test covering every value of ROUTING_REASONING_EFFORTS (none, minimal, low, medium, high, xhigh, max) for each engine. Each cell is classified as accepted, mapped, or fail-closed. Current mapAWFRoutingEffort behaviour at 29b5ac2:
- Copilot passes every value through. The SDK driver forwards it via
resolveRoutingReasoningEffortincopilot_routing_effort.cjs. - Claude accepts
lowthroughmaxand rejectsnoneandminimal. - Codex accepts
minimalthroughxhighand rejectsnoneandmax. - pi accepts every value and maps
nonetooff.
Check each cell end to end through the harness, not just through mapAWFRoutingEffort:
- Fail-closed cells: the harness records
rejected/unsupported_effortwith an error naming both effort and engine. Theaw_info.jsonblock, footer, session events, and OTEL then show no routed model. - Mapped cells: the applied effort is what reaches the engine and what downstream outputs report.
The test table is the reference for current behaviour. Any intentional change to a cell should be visible in the diff.
3. Non-routed OTEL assertion
send_otlp_span.test.cjs currently only asserts that routing attributes are present on a routed run. Add a case for a non-routed run: no model_routing block in aw_info.json and no GH_AW_MODEL_ROUTING_STATUS. That run must emit no gh-aw.model_routing.* attributes. Under current gating it must also emit no routing-only gh-aw.model.requested / gh-aw.model.effort. Coordinate with #67237 so this assertion matches the attribute set that issue settles on.
4. Make harness routing coverage measurable
Choose one of these approaches, or use both:
- Export routing helpers for in-process unit tests (preferred, since step 1 needs it anyway).
- Copilot already exports
resolveAWFModelRoutingSelection,applyCopilotRoutingSelection, andapplyCopilotRoutingArgs, but the selection call and the failure-pathrecordAWFModelRoutingOutcomecall sit inline inmain. - Codex already exports
resolveCodexModelRouting,applyCodexRoutingEffort, andremoveCodexRoutingOverrides. - Claude exports only
buildClaudeChildEnvandremoveClaudeRoutingOverrides. Its routing decision and outcome recording live insidemain. - Extract each harness's resolve-and-record step out of
maininto an exported function thatmaincalls, so tests and the contract test exercise exactly the production path.
- Copilot already exports
- Collect child-process coverage. Run the existing
spawnSyncharness tests withNODE_V8_COVERAGEand merge that output into thetest:js-coveragereport. The vitest v8 provider only reports the worker's own process, so this needs an explicit merge step.
Acceptance criteria
model_routing_contract.test.cjscovers copilot, claude, pi, and codex in-process, including the negative rows above.- The PR describes a mutation check that fails the contract test. Candidate changes:
- temporarily changing one engine's endpoints in
getAWFModelRoutingPolicy - changing the endpoint-override branch in
resolveModelRoutingOutcome - dropping a field from the
workflow.infomerge inunified_session.cjs
- temporarily changing one engine's endpoints in
- The effort matrix covers all 28 engine × effort cells.
send_otlp_span.test.cjsasserts that a non-routed run emits nogh-aw.model_routing.*attributes.npm run test:js-coverageshows the harness routing paths as covered. The PR reports before and after line coverage forclaude_harness.cjs,copilot_harness.cjs, andcodex_harness.cjs.
Activity