Skip to content

Commit 9b8dfa2

Browse files
rabeckettCopilotgithub-actions[bot]
authored
Record whether a routed run's result counts (#80468)
* Record whether a routed run's result counts For each run AWF routed whose agent made requests, the conclusion job's unified session now records routing.observation: success or failure when the result counts as evidence about the model and effort AWF selected, or skip with the reason it does not. The verdict uses only engine-neutral evidence: AWF's request records, attributed with the rule routing analytics already applies, the job results and the validated safe outputs. The selected pair and its cost stay in AWF's records. gh aw audit and gh aw logs --json show the verdict, and version 2.13.0 of the unified agent session specification defines it as T-UAS-093. Fixes #79103 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Tighten the routing verdict's evidence rules Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Trust only runner-owned evidence in the routing verdict Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Apply filtered changes * Count a failed detection job without a result as inconclusive Also finalize ADR-80468. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4766f80 commit 9b8dfa2

27 files changed

Lines changed: 951 additions & 28 deletions

‎.changeset/routing-run-observation.md‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎actions/setup/js/collect_ndjson_output.cjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ async function main() {
198198

199199
core.info(`[INGESTION] Output file path: ${outputFile}`);
200200
const collectionErrors = [];
201+
let collectorInfrastructureCause;
201202
if (!outputFile || !fs.existsSync(outputFile)) {
202203
core.info(outputFile ? `Output file does not exist: ${outputFile}` : "GH_AW_SAFE_OUTPUTS not set, no output to collect");
203204
const runnerTemp = process.env.RUNNER_TEMP || "/home/runner/work/_temp";
@@ -208,6 +209,7 @@ async function main() {
208209
`This is a gateway infrastructure failure, not a normal no-op. ` +
209210
`Check the MCP gateway startup logs for ECONNRESET errors or delayed backend registration and re-run the workflow.`;
210211
collectionErrors.push(reason);
212+
collectorInfrastructureCause = "safeoutputs_gateway_empty";
211213
// eslint-disable-next-line gh-aw-custom/require-return-after-core-setfailed
212214
core.setFailed(reason);
213215
}
@@ -432,6 +434,7 @@ async function main() {
432434
...(collectorDriverExitCode !== undefined ? { collectorDriverExitCode } : {}),
433435
...(collectorRetryCount !== undefined ? { collectorRetryCount } : {}),
434436
...(collectorEngineErrorType ? { collectorEngineErrorType } : {}),
437+
...(collectorInfrastructureCause ? { collectorInfrastructureCause } : {}),
435438
};
436439
const path = require("path");
437440
const agentOutputFile = path.join(TMP_GH_AW_PATH, AGENT_OUTPUT_FILENAME);

‎actions/setup/js/collect_ndjson_output.test.cjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ describe("collect_ndjson_output.cjs", () => {
262262
const output = JSON.parse(mockCore.setOutput.mock.calls.find(call => call[0] === "output")[1]);
263263
expect(output.items[0].type).toBe("report_incomplete");
264264
expect(output.items[0].details).toContain("Safe-output tools: unavailable (gateway registered zero tools)");
265+
expect(output.collectorInfrastructureCause).toBe("safeoutputs_gateway_empty");
265266
expect(fs.existsSync(path.join(TMP_GH_AW_PATH, AGENT_OUTPUT_FILENAME))).toBe(true);
266267
} finally {
267268
if (originalRunnerTemp === undefined) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "items": [{ "type": "create_issue" }], "errors": [] }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{"_schema":"model-routing/v0.28.62","timestamp":"2026-10-18T17:05:38.963Z","event":"model_routing","stage":"classification","purpose":"routing_classification","attempt":1,"classifier_model":"github-copilot/gpt-5.6-luna","classifier_effort":"high"}
2+
{"_schema":"model-routing/v0.28.62","timestamp":"2026-10-18T17:05:45.104Z","event":"model_routing","stage":"selection","objective":{"goal":"cost","mode":"economy"},"provider":"copilot","selected_provider":"copilot","wire_model":"gpt-5.6-luna","endpoint":"/responses","labels":{"task_type":"chore","scope":"cross_system","task_complexity":"trivial"},"mode":"economy","classifier_model":"github-copilot/gpt-5.6-luna","classifier_effort":"high","router":{"name":"gh-aw-router","version":"0.1.3"},"ranked_choices":[{"model":"github-copilot/gpt-5.6-luna","effort":"max"},{"model":"github-copilot/gpt-5.6-luna","effort":"xhigh"},{"model":"github-copilot/gpt-5.6-luna","effort":"high"},{"model":"github-copilot/gpt-5.6-luna","effort":"medium"},{"model":"github-copilot/gpt-5.4-mini","effort":"xhigh"},{"model":"github-copilot/gpt-5.4-mini","effort":"high"},{"model":"github-copilot/gpt-5.4-mini","effort":"medium"},{"model":"github-copilot/gpt-5.6-luna","effort":"low"},{"model":"github-copilot/gpt-5.4-mini","effort":"low"},{"model":"github-copilot/claude-haiku-4.5","effort":null},{"model":"github-copilot/gpt-5.6-luna","effort":"none"},{"model":"github-copilot/gpt-5.4-mini","effort":"none"}],"conversation_sha256":"7af299df550a5bfe2ae9f80ccae3e5cb3a68c7d60b5b0c159f727ef364241498","selected_id":"choice-0009","selected_model":"github-copilot/gpt-5.6-luna","selected_effort":"max","degraded_classification":false,"degraded_reason":null,"classifier_attempts":1,"eligible_choices":12,"catalogue_overlap":12,"latency_ms":6156,"interaction_id":"39147795806-1","github_repository":"github/gh-aw","github_workflow_ref":"github/gh-aw/.github/workflows/smoke-copilot-routed.lock.yml@refs/heads/main"}
3+
{"_schema":"model-routing/v0.28.62","timestamp":"2026-10-18T17:05:56.986Z","event":"model_routing","stage":"request","routed":"as_selected","deviations":[],"unavailable":[],"method":"POST","pathname":"/responses","provider":"copilot","requested_model":"gpt-5.6-luna","requested_effort":"max","selected_provider":"copilot","selected_model":"gpt-5.6-luna","selected_effort":"max","selected_endpoint":"/responses","requested_endpoint":"/responses","upstream_endpoint":"/responses","request_id":"350154af-d6ed-4d8c-b176-b93da7144bdd","outcome":"completed","status":200}
4+
{"_schema":"model-routing/v0.28.62","timestamp":"2026-10-18T17:05:58.589Z","event":"model_routing","stage":"request","routed":"as_selected","deviations":[],"unavailable":[],"method":"POST","pathname":"/responses","provider":"copilot","requested_model":"gpt-5.6-luna","requested_effort":"max","selected_provider":"copilot","selected_model":"gpt-5.6-luna","selected_effort":"max","selected_endpoint":"/responses","requested_endpoint":"/responses","upstream_endpoint":"/responses","request_id":"79b45ef3-a365-4e5e-9e39-89c48698f37e","outcome":"completed","status":200}
5+
{"_schema":"model-routing/v0.28.62","timestamp":"2026-10-18T17:06:01.270Z","event":"model_routing","stage":"request","routed":"as_selected","deviations":[],"unavailable":[],"method":"POST","pathname":"/responses","provider":"copilot","requested_model":"gpt-5.6-luna","requested_effort":"max","selected_provider":"copilot","selected_model":"gpt-5.6-luna","selected_effort":"max","selected_endpoint":"/responses","requested_endpoint":"/responses","upstream_endpoint":"/responses","request_id":"c2453852-d56d-4964-b514-3536a525afda","outcome":"completed","status":200}
6+
{"_schema":"model-routing/v0.28.62","timestamp":"2026-10-18T17:06:05.354Z","event":"model_routing","stage":"request","routed":"as_selected","deviations":[],"unavailable":[],"method":"POST","pathname":"/responses","provider":"copilot","requested_model":"gpt-5.6-luna","requested_effort":"max","selected_provider":"copilot","selected_model":"gpt-5.6-luna","selected_effort":"max","selected_endpoint":"/responses","requested_endpoint":"/responses","upstream_endpoint":"/responses","request_id":"8fcd367d-53d6-48ac-b56f-620c1a1a6a80","outcome":"completed","status":200}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{"_schema":"token-usage/v0.28.62","timestamp":"2026-10-18T17:05:45.096Z","event":"token_usage","request_id":"78a3c387-fe05-4ad8-9e8a-ccd5806dc19c","provider":"copilot","model":"gpt-5.6-luna","path":"/responses","status":200,"streaming":false,"input_tokens":941,"output_tokens":549,"cache_read_tokens":0,"cache_write_tokens":0,"duration_ms":6129,"response_bytes":20133,"purpose":"routing_classification","x_initiator":"agent","ai_credits_this_response":0.0847,"ai_credits_total":0.0847,"ai_credits_pricing_source":"provider","ai_credits_pricing_tier":"default","ai_credits_accounting_policy":"concrete_model","ai_credits_fallback_pricing_used":false,"ai_credits_pricing_observed_at":"2026-10-18T17:05:38.926Z","ai_credits_pricing_api_version":"2026-07-01"}
2+
{"_schema":"token-usage/v0.28.62","timestamp":"2026-10-18T17:05:56.985Z","event":"token_usage","request_id":"350154af-d6ed-4d8c-b176-b93da7144bdd","provider":"copilot","model":"gpt-5.6-luna","path":"/responses","status":200,"streaming":true,"input_tokens":23197,"output_tokens":400,"cache_read_tokens":0,"cache_write_tokens":0,"duration_ms":6725,"response_bytes":237349,"x_initiator":"user","ai_credits_this_response":0.51194,"ai_credits_total":0.59664,"ai_credits_pricing_source":"provider","ai_credits_pricing_tier":"default","ai_credits_accounting_policy":"concrete_model","ai_credits_fallback_pricing_used":false,"ai_credits_pricing_observed_at":"2026-10-18T17:05:38.926Z","ai_credits_pricing_api_version":"2026-07-01"}
3+
{"_schema":"token-usage/v0.28.62","timestamp":"2026-10-18T17:05:58.589Z","event":"token_usage","request_id":"79b45ef3-a365-4e5e-9e39-89c48698f37e","provider":"copilot","model":"gpt-5.6-luna","path":"/responses","status":200,"streaming":true,"input_tokens":23799,"output_tokens":45,"cache_read_tokens":23194,"cache_write_tokens":0,"duration_ms":1536,"response_bytes":225482,"x_initiator":"agent","ai_credits_this_response":0.063888,"ai_credits_total":0.660528,"ai_credits_pricing_source":"provider","ai_credits_pricing_tier":"default","ai_credits_accounting_policy":"concrete_model","ai_credits_fallback_pricing_used":false,"ai_credits_pricing_observed_at":"2026-10-18T17:05:38.926Z","ai_credits_pricing_api_version":"2026-07-01"}
4+
{"_schema":"token-usage/v0.28.62","timestamp":"2026-10-18T17:06:01.270Z","event":"token_usage","request_id":"c2453852-d56d-4964-b514-3536a525afda","provider":"copilot","model":"gpt-5.6-luna","path":"/responses","status":200,"streaming":true,"input_tokens":23870,"output_tokens":196,"cache_read_tokens":23796,"cache_write_tokens":0,"duration_ms":2614,"response_bytes":261689,"x_initiator":"agent","ai_credits_this_response":0.072592,"ai_credits_total":0.73312,"ai_credits_pricing_source":"provider","ai_credits_pricing_tier":"default","ai_credits_accounting_policy":"concrete_model","ai_credits_fallback_pricing_used":false,"ai_credits_pricing_observed_at":"2026-10-18T17:05:38.926Z","ai_credits_pricing_api_version":"2026-07-01"}
5+
{"_schema":"token-usage/v0.28.62","timestamp":"2026-10-18T17:06:05.354Z","event":"token_usage","request_id":"8fcd367d-53d6-48ac-b56f-620c1a1a6a80","provider":"copilot","model":"gpt-5.6-luna","path":"/responses","status":200,"streaming":true,"input_tokens":24084,"output_tokens":109,"cache_read_tokens":23867,"cache_write_tokens":0,"duration_ms":3844,"response_bytes":298553,"x_initiator":"agent","ai_credits_this_response":0.065154,"ai_credits_total":0.798274,"ai_credits_pricing_source":"provider","ai_credits_pricing_tier":"default","ai_credits_accounting_policy":"concrete_model","ai_credits_fallback_pricing_used":false,"ai_credits_pricing_observed_at":"2026-10-18T17:05:38.926Z","ai_credits_pricing_api_version":"2026-07-01"}

‎actions/setup/js/fixtures/routing_analytics_runs.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
* https://github.com/github/gh-aw/actions/runs/39499464895 (usage 12300520074,
2929
* agent 12298393979). Selected claude-haiku-4.5, then failed closed:
3030
* `mini-whoami` requested unavailable gpt-5.4-mini.
31+
* - run-39147795806: Smoke Copilot Routed, AWF v0.28.62,
32+
* https://github.com/github/gh-aw/actions/runs/39147795806/attempts/1. Selected
33+
* gpt-5.6-luna at max; four main requests and one classifier request. It keeps
34+
* only the api-proxy logs and `agent_output.json`, reduced to its item types:
35+
* the agent created its required report, but a later check failed its job.
3136
*
3237
* `routing-analytics/awf-10211/` holds records produced by the gh-aw-firewall
3338
* writers at b5c683e116470e0aa579ec9bf30a675fcdb66f76 (github/gh-aw-firewall#10211)

‎actions/setup/js/routing_analytics.cjs‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,40 @@ function matchesDeclaredSubAgent(requested, provider, declarations) {
249249
});
250250
}
251251

252+
/**
253+
* AWF's per-request routing records by request ID. Conflicting records for one
254+
* request are ambiguous and map to null.
255+
* @param {unknown[]} routing firewall.model_routing records
256+
* @returns {Map<string, Record<string, any> | null>}
257+
*/
258+
function routedRequests(routing) {
259+
/** @type {Map<string, Record<string, any> | null>} */
260+
const requests = new Map();
261+
for (const record of routing) {
262+
if (!isObject(record) || record.stage !== "request" || typeof record.request_id !== "string" || !record.request_id) continue;
263+
const previous = requests.get(record.request_id);
264+
requests.set(record.request_id, previous === undefined || (previous && previous.routed === record.routed && previous.requested_model === record.requested_model) ? record : null);
265+
}
266+
return requests;
267+
}
268+
269+
/**
270+
* Attribute one proxy request from AWF's record of it and the runner-declared
271+
* sub-agents: `main` ran as selected, `subagent` is a declared sub-agent's model
272+
* that AWF recorded as deviated, `deviated` ran another model or effort, and
273+
* anything else, including a missing or conflicting record, is `unattributed`.
274+
* @param {Record<string, any> | null | undefined} route
275+
* @param {unknown} provider
276+
* @param {unknown} subAgentModels aw_info.sub_agent_models
277+
* @returns {"main" | "subagent" | "deviated" | "unattributed"}
278+
*/
279+
function attributeRequest(route, provider, subAgentModels) {
280+
const requested = route?.requested_model;
281+
const declared = typeof requested === "string" && matchesDeclaredSubAgent(requested, route?.provider ?? provider, subAgentModels);
282+
if (route?.routed === "deviated") return declared ? "subagent" : "deviated";
283+
return route?.routed === "as_selected" && !declared ? "main" : "unattributed";
284+
}
285+
252286
/** @param {unknown} value @returns {number | undefined} */
253287
const tokenCount = value => (value === undefined || value === null ? 0 : typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined);
254288

@@ -270,14 +304,7 @@ const tokenCount = value => (value === undefined || value === null ? 0 : typeof
270304
function estimateBaseline({ config, subAgentModels, tokenUsage, routing }) {
271305
if (config?.routing?.enabled !== true) return undefined;
272306
const baseline = config.baselineModel;
273-
/** @type {Map<string, Record<string, any> | null>} */
274-
const requests = new Map();
275-
for (const record of routing) {
276-
if (!isObject(record) || record.stage !== "request" || typeof record.request_id !== "string" || !record.request_id) continue;
277-
// Conflicting proxy records for one request are ambiguous.
278-
const previous = requests.get(record.request_id);
279-
requests.set(record.request_id, previous === undefined || (previous && previous.routed === record.routed && previous.requested_model === record.requested_model) ? record : null);
280-
}
307+
const requests = routedRequests(routing);
281308
const seen = new Set();
282309
let mainRequests = 0;
283310
let pricedRequests = 0;
@@ -295,11 +322,9 @@ function estimateBaseline({ config, subAgentModels, tokenUsage, routing }) {
295322
if (seen.has(id)) continue;
296323
seen.add(id);
297324
if (record.purpose === "routing_classification") continue;
298-
const route = requests.get(id);
299-
const requested = route?.requested_model;
300-
const declared = typeof requested === "string" && matchesDeclaredSubAgent(requested, route?.provider ?? record.provider, subAgentModels);
301-
if (route?.routed === "deviated" && declared) continue;
302-
if (route?.routed !== "as_selected" || declared) {
325+
const role = attributeRequest(requests.get(id), record.provider, subAgentModels);
326+
if (role === "subagent") continue;
327+
if (role !== "main") {
303328
unattributedRequests++;
304329
continue;
305330
}
@@ -353,5 +378,7 @@ module.exports = {
353378
persistModelConfigBaseline,
354379
projectModelConfig,
355380
matchesDeclaredSubAgent,
381+
routedRequests,
382+
attributeRequest,
356383
estimateBaseline,
357384
};

0 commit comments

Comments
 (0)