Repository navigation
Description
Summary
When engine.model-routing is enabled, AWF picks the model and reasoning effort at runtime, inside the agent job. Everything gh-aw reports as "the model" still comes from the activation job's compile-time placeholder: auto for Copilot and agent for pi. That includes aw_info.json, safe-output footers and their hidden markers, gh aw audit engine_config.model, the gh aw logs run model, and the OTEL gen_ai.request.model attribute. A reader of a created issue or PR can't tell which model produced it. Per-model reporting across runs is wrong for every routed run.
Evidence
| Run | Engine | AWF selection (model-routing.jsonl and /reflect) |
aw_info.json model |
Created issue: footer / marker |
|---|---|---|---|---|
| 37813720288 | copilot, AWF v0.28.49 | github-copilot/gpt-5.6-luna, effort xhigh, /responses |
auto |
githubnext/gh-aw-routing-sandbox#94: · copilot · auto · / engine: copilot, model: auto |
| 37728943601 | pi, AWF v0.28.44 | github-copilot/gpt-5.6-luna, effort high |
agent |
githubnext/gh-aw-routing-sandbox#82: · pi · agent · / engine: pi, model: agent |
| 37733661322 | pi, AWF v0.28.44 | github-copilot/gpt-5.6-luna, effort high |
agent |
githubnext/gh-aw-routing-sandbox#90: · pi · agent · / engine: pi, model: agent |
- The harness applied the selection in every run.
- The Copilot harness logged
inference routing: mode=awf-routed model=gpt-5.6-luna effort=xhigh wire_api=responses, and pi'spi_models_jsonloggedmode=awf-routed model=gpt-5.6-luna effort=high. sandbox/firewall/awf-reflect.jsonin the agent artifact hasrouting.status: selectedand the full selection.- Every main-agent request in
model-routing.jsonlisas_selected.
- The Copilot harness logged
aw_info.jsoncontains no routing fields at all.- The agent job already knows the real model. In all three runs,
parse_token_usage.cjswroteagent_usage.jsonwithprimary_model: gpt-5.6-luna, and the safe_outputs job downloads that file. Nothing in safe_outputs reads it. gh aw auditalready parses the selection into its top-levelmodel_routingblock (status, selected model and effort, deviations, costs). Itsengine_config.modelstill reportsauto/agent.
Root cause
-
aw_info.jsonis written too early.generate_aw_info.cjsruns in the activation job and writesGH_AW_INFO_MODEL, which compiles to a placeholder for routed workflows:- Copilot:
vars.GH_AW_MODEL_AGENT_COPILOT || vars.GH_AW_DEFAULT_MODEL_COPILOT || 'auto' - pi:
vars.GH_AW_MODEL_AGENT_CUSTOM || 'agent'
No routing selection exists yet at that point.
- Copilot:
-
Later jobs inherit the placeholder. The agent job's
modeloutput is a passthrough ofneeds.activation.outputs.model(buildMainJobCoreOutputsinpkg/workflow/compiler_main_job_helpers.go). safe_outputs setsGH_AW_ENGINE_MODELfrom that output (addJobLevelEngineMetadatainpkg/workflow/compiler_safe_outputs_envvars.goandbuildEngineMetadataEnvVarsinpkg/workflow/safe_outputs_env.go). If a routed workflow also setsmodel:,warnRoutedModelOverridesonly warns, and that literal gets baked intoGH_AW_ENGINE_MODEL. That is equally wrong. -
The harnesses use the selection but don't save it. Each harness resolves and applies the selection with
resolveAWFModelRoutingSelectionandmapAWFRoutingEffort, logs it, and keeps it only in memory:- Copilot:
mainandapplyCopilotRoutingSelectionincopilot_harness.cjs - Claude:
buildClaudeChildEnvinclaude_harness.cjs - Codex:
resolveCodexModelRoutingincodex_harness.cjs - pi:
resolvePiModelRoutingandmaininpi_models_json.cjs
When routing isn't
selected, the harness refuses to start the agent, and the reason isn't recorded anywhere downstream jobs can read. - Copilot:
-
Post-run attribution stays inside the agent job.
- The only post-run mechanism is the fallback-model path in
model_attribution.cjs(recordFallbackModel/getFallbackModel). It patches the agent job's local/tmp/gh-aw/aw_info.json, but that file is in neither theagentartifact nor theagent-output-fallbackartifact. It was missing from the safe_outputs file listing in all three runs. In the conclusion job,collect_usage_artifact_files.shloggedMISSING: /tmp/gh-aw/aw_info.json. GH_AW_PRIMARY_MODELis exported only inside the agent job, andprimary_modelisn't an agent job output.- So
getAICFromEnvandgenerateXMLMarkerinmessages_footer.cjs,generateXMLMarkeringenerate_footer.cjs, andbuildAICSuffixinhandle_noop_message.cjsall fall through toGH_AW_ENGINE_MODEL. In these lock files, the conclusion job (noop and agent-failure footers) doesn't setGH_AW_ENGINE_MODELat all. - The same gap probably means that an AWF fallback model recorded in the agent job never reaches safe-output footers either. A fallback run would confirm it.
- The only post-run mechanism is the fallback-model path in
-
Consumers read only
aw_info.model.extractEngineConfigWithInferredEngine(pkg/cli/audit_expanded.go) andbuildCachedLogsJSONLRunData(pkg/cli/logs_cached_json.go) readAwInfo.Model.AwInfo(pkg/cli/logs_models.go) has no fallback or routing fields, andfindAwInfoPathreads the activation copy.send_otlp_span.cjstakes the span model fromgetFallbackModel()orawInfo.model, sogen_ai.request.modelwould beauto/agent. No span carries effort or routing status.
Proposed plan
1. Record the routed selection in the agent job
- Add routed-model helpers next to the fallback helpers in
actions/setup/js/model_attribution.cjs: a recorder, a reader, and a single effective-model resolver that every consumer uses. Every field goes throughvalidateModelIdentifier, and effort is checked against the known effort values. These values end up in footer markers, so they must not be able to forge marker fields. - Record the selection in a post-run step on the runner, not inside the sandbox.
parse_token_usage.cjsis the natural place because it already records the fallback model and setsprimary_model;awf_reflect_summary.cjswould also work.- Source of truth: the
stage: selectionrecord inmodel-routing.jsonl. AWF's api-proxy writes it outside the agent's reach, andpkg/cli/model_routing.goalready parses it. - Fallback:
routingin the savedawf-reflect.json, validated withresolveAWFModelRoutingSelectionand the engine's allowed endpoints.
- Source of truth: the
- Have each harness persist its routing outcome next to
awf-reflect.json(path fromawf_reflect_paths.cjs). On success that's the applied wire model and engine-mapped effort; on refusal it's the error, the AWFstatus, and thefailure_code.- The post step treats this record as advisory. It can mark a run as rejected, for example when AWF picked an endpoint or effort the engine refuses (Model routing on claude/codex/pi fails closed: AWF selection endpoint and effort are chosen for Copilot CLI, not the engine #66787), and it can supply the applied effort.
- It can never introduce a model the proxy didn't select.
- Fields to record:
- status:
selected,pending,failed,rejected, orunavailable - source:
awf-routing - provider, qualified model, and wire model
- AWF effort, plus the applied effort when the engine mapping differs (for example pi maps
nonetooff) - endpoint, routing mode,
selected_id, and router version - failure code and detail
- status:
- Patch the agent job's
/tmp/gh-aw/aw_info.json:- add a
model_routingobject - add
requested_modelholding the placeholder - set
modelto the routed wire model only when the status isselected, the same wayrecordFallbackModelalready overwritesmodel
- add a
2. Propagate to later jobs
-
Job outputs. The agent job's
modeloutput should come from the post step and fall back toneeds.activation.outputs.model. Add outputs for effort and routing status.- Wire them through
buildMainJobCoreOutputs,addJobLevelEngineMetadata, andbuildEngineMetadataEnvVarsasGH_AW_ENGINE_MODELplus two new variables,GH_AW_ENGINE_MODEL_EFFORTandGH_AW_MODEL_ROUTING_STATUS. - Do this for safe_outputs and for the conclusion job's handlers (noop, agent failure, missing tool, incomplete), which get no model today.
- When routing is enabled, the compiler must not bake a literal
model:intoGH_AW_ENGINE_MODEL.
- Wire them through
-
Artifact. Use one of these options:
- Upload the patched
aw_info.jsonwith the agent artifact, under a name that doesn't collide with the activationinfoartifact ingh aw auditdownloads. - Or carry the routing block in
agent_usage.json, which every downstream job already downloads.
Either option makes the record available to
getFallbackModeland the new reader in safe_outputs and conclusion, tocollect_usage_artifact_files.shfor theusageartifact, and to audit and logs. - Upload the patched
3. What aw_info.json and the footer should show
- Routing not enabled: nothing changes. There's no
model_routingkey, and footers and markers stay byte-for-byte identical. - Routing selected:
aw_info.json:modelis the routed wire model,requested_modelis the placeholder, andmodel_routing.statusisselected.- Footer: the visible text says the model was routed, for example
copilot · routed: gpt-5.6-luna xhigh · 2.64 AIC · …. Effort is omitted when AWF selected none, and model names still go throughreduceModelNameToIdentifier. - Hidden marker: keeps a parseable
model: gpt-5.6-lunaand appendseffort: xhigh, routed: true. The existing marker parsers ingenerate_footer.cjs,label_apply_safe_outputs.cjs, andexpired_entity_search_helpers.cjsmatch onlyid:,run:, andworkflow_id:, so new keys must not collide with those patterns.
- Routing failed, pending, rejected, or unavailable: never show a model that didn't run, and never show a bare
auto/agent, which reads like a real model name.modelstays the placeholder, andmodel_routingrecords the status and failure code.- The harness refuses to start in these cases, so these footers mostly appear on conclusion-job outputs such as failure issues and noop reports. Examples:
copilot · routing failed (no_route),copilot · routing pending,pi · routing rejected. The marker has, for example,model: auto, routed: failed.
- Routing plus an AWF model fallback:
- The model that actually served the requests wins. The precedence everywhere is: AWF fallback model, then routed selection, then token-usage primary model, then configured model.
- The footer still says the run was routed, for example
fallback: gpt-5.4 (routed: gpt-5.6-luna).
- Sub-agent requests: requests that deviate to declared sub-agent models don't change the footer, which describes the main agent. Per-model detail stays in audit and usage
by_model.
4. Make consumers prefer the routed model
-
JS: send every consumer through the single resolver in
model_attribution.cjs:getAICFromEnvandgenerateXMLMarkerinmessages_footer.cjs, which also covers the agent-failure footer inhandle_agent_failure.cjsgenerateXMLMarkeringenerate_footer.cjsbuildAICSuffixinhandle_noop_message.cjsprimary_modelandGH_AW_PRIMARY_MODELinparse_token_usage.cjssend_otlp_span.cjs
Detection and other non-agent phases keep their phase-scoped attribution; detection isn't routed.
-
Go audit:
- Extend
AwInfowith the routing and requested-model fields, plusfallback_model, which Go ignores today. extractEngineConfigWithInferredEngineshould report the effective model, the effort, the routing status, and the requested model.- For runs that predate the fix, like the three above, fall back to the already-parsed
ModelRoutingSummary: when the status isselected, use its wire model and selected effort. That corrects historical routed runs without new artifacts.
- Extend
-
Go logs:
buildCachedLogsJSONLRunDataand any per-model grouping ingh aw logs, cross-run audit, and audit diff should use the same precedence and group by effective model and effort, not the placeholder. -
OTEL:
- Set
gen_ai.request.modelto the effective model. - Add
gh-aw.model.requested,gh-aw.model.effort,gh-aw.model_routing.status,gh-aw.model_routing.mode, andgh-aw.model_routing.router_version. - The safe_outputs and conclusion spans get the same values from the new job outputs.
- Set
5. Engines
validateModelRouting (pkg/workflow/model_routing.go) accepts copilot, claude, codex, and pi, so this covers all four, including codex, which wasn't in the runs above.
- Recording in the post step is engine-agnostic.
- Per-engine work is limited to the harness outcome record and the applied-effort mapping from
mapAWFRoutingEffort. - Routed claude, codex, and pi runs that currently fail closed (Model routing on claude/codex/pi fails closed: AWF selection endpoint and effort are chosen for Copilot CLI, not the engine #66787) should show the routing-failed state instead of the placeholder.
6. Tests
JS (vitest)
model_attribution_usage.test.cjsandmodel_attribution_security.test.cjs:- recording and reading a routed selection
- precedence: fallback, then routed, then primary, then configured
- rejecting forged model and effort values (newlines,
-->, commas, over-length strings) - an advisory harness record can downgrade the status but can't introduce a model
parse_token_usage.test.cjs: selection frommodel-routing.jsonl, selection from reflect only, proxy and harness disagreeing, pending, failed, no record, and a non-routed run that stays unchanged. Check both theaw_info.jsonfields and the step outputs.messages.test.cjs,generate_footer.test.cjs,handle_noop_message.test.cjs, andhandle_agent_failure.test.cjs: footer text and hidden marker for:- selected with effort
- selected without effort
- failed
- pending
- fallback plus routing
- non-routed, which must stay unchanged
send_otlp_span.test.cjs: span attributes for routed and non-routed runs.copilot_harness.test.cjs,claude_harness.test.cjs,codex_harness.test.cjs, andpi_models_json.test.cjs: the outcome record on success (including the mapped effort) and on refusal, and no record when routing is disabled.
Go
-
pkg/workflow/model_routing_test.go,safe_output_helpers_test.go,compiler_safe_outputs_job_test.go, andengine_config_test.go:- For copilot, claude, codex, and pi with
engine.model-routing, check the new agent outputs and the safe_outputs and conclusion env wiring. - A literal
model:must not be baked in. - Non-routed workflows must compile exactly as they do today.
- For copilot, claude, codex, and pi with
-
pkg/cli/audit_expanded_test.go,pkg/cli/model_routing_test.go, and the logs JSONL tests, using four fixtures:- routed, with the new
aw_info.jsonfields - routed legacy, with only
model-routing.jsonl - routed and failed
- non-routed
Redacted artifacts from the three runs above make good fixtures.
- routed, with the new
Manual check: do one routed run per engine in githubnext/gh-aw-routing-sandbox, then check the footer, gh aw audit engine_config.model, and the model field in gh aw logs --json.
Related
- Model routing: show AWF routing decisions in
gh aw logsandgh aw audit#66638: added routing decisions togh aw logsandgh aw audit; this issue uses that data for the model fields. - Model routing on claude/codex/pi fails closed: AWF selection endpoint and effort are chosen for Copilot CLI, not the engine #66787: routed claude, codex, and pi runs that fail closed should show the routing-failed state.
- audit: sub-agent rows hide failures, ignore model aliases and dated ids, and have no per-agent spend (follow-up to #66740) #66960: in run 37813720288, three
claude-haiku-4.5sub-agent requests failed with 400 (Responses to Chat Completions translation), but audit reports that model as effective undersubagent_model_requests. - Feature request: fallback model for engine.model when the primary model is unavailable #64528: introduced the fallback-model attribution that this plan extends.
- Out of scope:
aw_info.jsonsub_agent_modelslists the declared models, not the ones that actually ran.
Activity