Skip to content

Model routing: aw_info.json, footers, audit/logs and OTEL report the placeholder model (auto/agent) instead of the AWF-routed model and effort #66962

Closed

Description

@SivaKesava1

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's pi_models_json logged mode=awf-routed model=gpt-5.6-luna effort=high.
    • sandbox/firewall/awf-reflect.json in the agent artifact has routing.status: selected and the full selection.
    • Every main-agent request in model-routing.jsonl is as_selected.
  • aw_info.json contains no routing fields at all.
  • The agent job already knows the real model. In all three runs, parse_token_usage.cjs wrote agent_usage.json with primary_model: gpt-5.6-luna, and the safe_outputs job downloads that file. Nothing in safe_outputs reads it.
  • gh aw audit already parses the selection into its top-level model_routing block (status, selected model and effort, deviations, costs). Its engine_config.model still reports auto / agent.

Root cause

  1. aw_info.json is written too early. generate_aw_info.cjs runs in the activation job and writes GH_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.

  2. Later jobs inherit the placeholder. The agent job's model output is a passthrough of needs.activation.outputs.model (buildMainJobCoreOutputs in pkg/workflow/compiler_main_job_helpers.go). safe_outputs sets GH_AW_ENGINE_MODEL from that output (addJobLevelEngineMetadata in pkg/workflow/compiler_safe_outputs_envvars.go and buildEngineMetadataEnvVars in pkg/workflow/safe_outputs_env.go). If a routed workflow also sets model:, warnRoutedModelOverrides only warns, and that literal gets baked into GH_AW_ENGINE_MODEL. That is equally wrong.

  3. The harnesses use the selection but don't save it. Each harness resolves and applies the selection with resolveAWFModelRoutingSelection and mapAWFRoutingEffort, logs it, and keeps it only in memory:

    • Copilot: main and applyCopilotRoutingSelection in copilot_harness.cjs
    • Claude: buildClaudeChildEnv in claude_harness.cjs
    • Codex: resolveCodexModelRouting in codex_harness.cjs
    • pi: resolvePiModelRouting and main in pi_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.

  4. 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 the agent artifact nor the agent-output-fallback artifact. It was missing from the safe_outputs file listing in all three runs. In the conclusion job, collect_usage_artifact_files.sh logged MISSING: /tmp/gh-aw/aw_info.json.
    • GH_AW_PRIMARY_MODEL is exported only inside the agent job, and primary_model isn't an agent job output.
    • So getAICFromEnv and generateXMLMarker in messages_footer.cjs, generateXMLMarker in generate_footer.cjs, and buildAICSuffix in handle_noop_message.cjs all fall through to GH_AW_ENGINE_MODEL. In these lock files, the conclusion job (noop and agent-failure footers) doesn't set GH_AW_ENGINE_MODEL at 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.
  5. Consumers read only aw_info.model.

    • extractEngineConfigWithInferredEngine (pkg/cli/audit_expanded.go) and buildCachedLogsJSONLRunData (pkg/cli/logs_cached_json.go) read AwInfo.Model. AwInfo (pkg/cli/logs_models.go) has no fallback or routing fields, and findAwInfoPath reads the activation copy.
    • send_otlp_span.cjs takes the span model from getFallbackModel() or awInfo.model, so gen_ai.request.model would be auto / 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 through validateModelIdentifier, 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.cjs is the natural place because it already records the fallback model and sets primary_model; awf_reflect_summary.cjs would also work.
    • Source of truth: the stage: selection record in model-routing.jsonl. AWF's api-proxy writes it outside the agent's reach, and pkg/cli/model_routing.go already parses it.
    • Fallback: routing in the saved awf-reflect.json, validated with resolveAWFModelRoutingSelection and the engine's allowed endpoints.
  • Have each harness persist its routing outcome next to awf-reflect.json (path from awf_reflect_paths.cjs). On success that's the applied wire model and engine-mapped effort; on refusal it's the error, the AWF status, and the failure_code.
  • Fields to record:
    • status: selected, pending, failed, rejected, or unavailable
    • source: awf-routing
    • provider, qualified model, and wire model
    • AWF effort, plus the applied effort when the engine mapping differs (for example pi maps none to off)
    • endpoint, routing mode, selected_id, and router version
    • failure code and detail
  • Patch the agent job's /tmp/gh-aw/aw_info.json:
    • add a model_routing object
    • add requested_model holding the placeholder
    • set model to the routed wire model only when the status is selected, the same way recordFallbackModel already overwrites model

2. Propagate to later jobs

  • Job outputs. The agent job's model output should come from the post step and fall back to needs.activation.outputs.model. Add outputs for effort and routing status.

    • Wire them through buildMainJobCoreOutputs, addJobLevelEngineMetadata, and buildEngineMetadataEnvVars as GH_AW_ENGINE_MODEL plus two new variables, GH_AW_ENGINE_MODEL_EFFORT and GH_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: into GH_AW_ENGINE_MODEL.
  • Artifact. Use one of these options:

    • Upload the patched aw_info.json with the agent artifact, under a name that doesn't collide with the activation info artifact in gh aw audit downloads.
    • Or carry the routing block in agent_usage.json, which every downstream job already downloads.

    Either option makes the record available to getFallbackModel and the new reader in safe_outputs and conclusion, to collect_usage_artifact_files.sh for the usage artifact, and to audit and logs.

3. What aw_info.json and the footer should show

  • Routing not enabled: nothing changes. There's no model_routing key, and footers and markers stay byte-for-byte identical.
  • Routing selected:
    • aw_info.json: model is the routed wire model, requested_model is the placeholder, and model_routing.status is selected.
    • 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 through reduceModelNameToIdentifier.
    • Hidden marker: keeps a parseable model: gpt-5.6-luna and appends effort: xhigh, routed: true. The existing marker parsers in generate_footer.cjs, label_apply_safe_outputs.cjs, and expired_entity_search_helpers.cjs match only id:, run:, and workflow_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.
    • model stays the placeholder, and model_routing records 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:

    • getAICFromEnv and generateXMLMarker in messages_footer.cjs, which also covers the agent-failure footer in handle_agent_failure.cjs
    • generateXMLMarker in generate_footer.cjs
    • buildAICSuffix in handle_noop_message.cjs
    • primary_model and GH_AW_PRIMARY_MODEL in parse_token_usage.cjs
    • send_otlp_span.cjs

    Detection and other non-agent phases keep their phase-scoped attribution; detection isn't routed.

  • Go audit:

    • Extend AwInfo with the routing and requested-model fields, plus fallback_model, which Go ignores today.
    • extractEngineConfigWithInferredEngine should 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 is selected, use its wire model and selected effort. That corrects historical routed runs without new artifacts.
  • Go logs: buildCachedLogsJSONLRunData and any per-model grouping in gh 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.model to the effective model.
    • Add gh-aw.model.requested, gh-aw.model.effort, gh-aw.model_routing.status, gh-aw.model_routing.mode, and gh-aw.model_routing.router_version.
    • The safe_outputs and conclusion spans get the same values from the new job outputs.

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.

6. Tests

JS (vitest)

  • model_attribution_usage.test.cjs and model_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 from model-routing.jsonl, selection from reflect only, proxy and harness disagreeing, pending, failed, no record, and a non-routed run that stays unchanged. Check both the aw_info.json fields and the step outputs.
  • messages.test.cjs, generate_footer.test.cjs, handle_noop_message.test.cjs, and handle_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, and pi_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, and engine_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.
  • 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.json fields
    • routed legacy, with only model-routing.jsonl
    • routed and failed
    • non-routed

    Redacted artifacts from the three runs above make good fixtures.

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

Metadata

Metadata

Labels

bugclimodel-routingsafe-outputs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions