Repository navigation
Record routed runs in an adaptive routing history (observe mode) - #80583
Conversation
adaptive-routing: observe (frontmatter, imports, or aw.json adaptive_routing) records every eligible run of a routed Copilot, Claude, or Codex workflow that enables tools.repo-memory, without changing which model runs. A push_routing_history job runs after conclusion with contents: write and actions: read, reads the routing verdict, the pair AWF selected and the AWF-priced cost from the unified session, and saves them to memory/adaptive-routing/<workflow>. - routing_history.cjs: the reducer, tested against the reference bandit's 222 oracle vectors. - push_routing_history.cjs: the writer, which charges earlier unsaved runs and seeds the branch with a root commit made through the API. - push_repo_memory.cjs: the save loop gains a reapply option that applies the change again to the newest files when the head moved, instead of rebasing with this run's copy winning. - gh aw routing status and reset. - Repo-memory branches under memory/adaptive-routing/ are reserved; workflows that do not opt in compile as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… not say AWF's token usage records keep each provider's own input count, which includes cached tokens for some responses and not others. Use AWF's flag when present; otherwise an input count smaller than the cache cannot include it, and any other count is taken to include it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
main.go's init sets every command's --help usage. Files' init functions run in file name order, so the routing command's file must sort before main.go, as analysis_value_command.go does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Critical deduplication, recovery, and workflow-identity flaws can permanently omit or double-count runs, while resolved branch expressions can expose routing history as writable agent memory.
11 open issues
Derive the generation boundary from workflow definitions · New Paginate recovery scans back to the recovery fence · New Exclude runs where history writing was disabled · New Track applied run IDs beyond the retained log · New Exclude unsupported reusable workflow invocations · New Validate the resolved memory branch before clone and save · New Quote workflow IDs when emitting YAML · New Filter recovery by workflow-definition provenance · New Resolve historical agent names before classifying failed saves · New Treat a missing history state as an empty state · New Surface history branch and state-read errors · New
What changed in this PR
Adds opt-in adaptive-routing observation to gh-aw, recording routing outcomes and costs for maintainers without changing the router’s ordinary model selection. This provides evidence for the later live-routing work described in #80554.
Changes:
- Adds workflow, import and repository-default configuration with eligibility validation.
- Adds a trusted history writer, bounded state reducer and concurrent-save replay support.
- Adds
gh aw routing statusandreset, with tests, documentation and release notes.
| File | Description |
|---|---|
pkg/workflow/workflow_data.go |
Stores the resolved observation mode. |
pkg/workflow/repo_config.go |
Reads the repository routing default. |
pkg/workflow/jobs.go |
Registers the history writer as built-in. |
pkg/workflow/compiler_orchestrator_workflow.go |
Applies routing settings and branch validation. |
pkg/workflow/compiler_jobs.go |
Adds the writer after conclusion. |
pkg/workflow/adaptive_routing.go |
Implements eligibility and writer-job generation. |
pkg/workflow/adaptive_routing_test.go |
Tests configuration precedence and compiled jobs. |
pkg/parser/schemas/repo_config_schema.json |
Validates the repository default. |
pkg/parser/schemas/main_workflow_schema.json |
Defines workflow observation settings. |
pkg/parser/import_processor.go |
Carries imported routing settings. |
pkg/parser/import_extract_engine.go |
Extracts first-wins imported settings. |
pkg/parser/import_accumulator.go |
Propagates accumulated import values. |
pkg/constants/job_constants.go |
Defines the writer’s name and dependency. |
pkg/cli/routing_command.go |
Implements history status and reset commands. |
pkg/cli/routing_command_test.go |
Tests CLI output and reset commits. |
docs/src/content/docs/setup/cli.md |
Documents routing commands and flags. |
docs/src/content/docs/reference/repo-memory.md |
Explains reserved branches and save behavior. |
docs/src/content/docs/reference/model-routing.md |
Links ordinary routing to observation. |
docs/src/content/docs/reference/frontmatter.md |
Introduces the observation setting. |
docs/src/content/docs/reference/frontmatter-full.md |
Adds the setting to the full reference. |
docs/src/content/docs/reference/compilation-process.md |
Documents the repository default. |
docs/src/content/docs/reference/adaptive-routing.md |
Explains history, permissions, retention and operation. |
cmd/gh-aw/routing_command.go |
Registers routing commands in the CLI. |
actions/setup/js/routing_history.test.cjs |
Checks reducer behavior against reference vectors. |
actions/setup/js/routing_history.cjs |
Maintains bounded routing evidence and fences. |
actions/setup/js/push_routing_history.test.cjs |
Tests evidence extraction, recovery and concurrent saves. |
actions/setup/js/push_routing_history.cjs |
Extracts run evidence and saves history. |
actions/setup/js/push_repo_memory.cjs |
Adds replay-on-new-head retry support. |
.prettierignore |
Preserves generated reference-vector formatting. |
.changeset/adaptive-routing-observe.md |
Announces the new observation feature. |
Review effort: Max (adaptive)
commented
Nov 24, 2026
|
✅ Excellent contribution, @rabeckett! This adaptive routing observe mode implementation is comprehensive and well-structured. Your PR demonstrates strong alignment with the project:
This is ready for review and merge. Well done!
|
- Exclude reusable workflows: each caller numbers its own runs. - Refuse memory/adaptive-routing/ branches in repo-memory's clone and save at run time, for branch-name expressions the compiler cannot see through. - Quote the routing job's env values so IDs like null stay strings. - Charge an unsaved run only if it had an enabled history job, so runs from while the repository default was off, or from dry runs, are not charged. - Read a history branch without state.json as empty, and fail the history list on read errors instead of dropping branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
|
✅ PR Specification Reviewer completed successfully!
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
❌ Ponytail Reviewer failed. Please review the logs for details. Incomplete workThe supplied PR patch is truncated, so the review could not cover all changed lines.
|
|
❌ Test Quality Sentinel failed during test quality analysis. Incomplete workTest Quality Sentinel could not review tests because pre-fetch PR data was unavailable: test file diff is missing or exceeds the 40 KB review limit. The PR metadata file (pr-meta.json) is empty, and test-diff.txt, test-files.txt, diff-numstat.txt and the Go/JS test-function extraction files are all empty. No test quality score was computed and no approval or noop is implied.
|
left a comment
There was a problem hiding this comment.
Reviewed head 63de0fe1e11dc2996b982a9cb413331307ee7f60 against the Unified Agent Session Specification v2.15.0, especially T-UAS-094. One blocking finding: push_routing_history.cjs:120 accepts any routing.observation event without requiring collector provenance and conclusion phase, allowing a non-conclusion event to supply the verdict and affect routing history. The inline comment requests filtering to the normative provenance.
Generated by PR Specification Reviewer for #80583 · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.8K
Comment /review-specs to run again
left a comment
There was a problem hiding this comment.
What this change does: Opted-in routed workflows record run outcomes and costs in a history branch. A new CLI shows or resets that history.
Should fix
The inline comments identify live-mode code with no production caller and a reset implementation used only by a test.
Verdict: fix 1 and 2 first.
Not checked: The supplied patch ends during adaptive_routing.go; the remaining changed lines were unavailable because the local checkout could not retrieve missing Git objects.
Lean: -40 lines possible.
Generated by ✂️ Ponytail Reviewer for #80583 · codex · routed: gpt61 medium · ~12 AIC · ⌖ ~1 AIC · ⊞ 176
Comment /ponytail to run again
commented
Nov 24, 2026
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR). 📄 Draft ADR committed:
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. ❓ Why ADRs Matter
ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
commented
Nov 24, 2026
Comment MemoryPeek at saved memory (spec-review-history)History |
left a comment
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd to the writer path, focusing on changed lines. One verified issue; the rest of the review is an observation, not a blocker.
📋 Key Themes & Highlights
Key Themes
- Prototype-key lookup:
pairNameinpush_routing_history.cjsreadsPROVIDER_NAMESwithout an own-property check (inline comment on line 149).
Positive Highlights
- ✅ Observe mode keeps the model choice unchanged, and live mode is rejected at compile time.
- ✅ The reapply path resets to the remote head before re-running
applyRun, which avoids lost updates on concurrent pushes. - ✅
aw.jsonadaptive_routingis schema-validated, so invalid values are rejected before the silent fallback.
⚠️ Remaining uncertainty
The pre-fetched diff is capped at 3000 lines, so adaptive_routing_test.go, compiler_jobs.go, and routing_command.go were not fully reviewed. Findings in those files are not covered here.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~11 AIC · ⌖ ~2 AIC · ⊞ 7.1K
Comment /matt to run again
commented
Nov 24, 2026
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
left a comment
There was a problem hiding this comment.
Found one correctness issue in unsaved-run recovery: eligible pull_request_target runs are excluded by their source head_branch, so failed history saves from those runs are never recovered. The inline comment describes the affected path.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~9 AIC · ⌖ ~2 AIC · ⊞ 1.7K
Comment /review to run again
commented
Nov 24, 2026
Comment MemoryPeek at saved memory (review-history)History |
- Accept routing.observation only with collector provenance and phase conclusion, as T-UAS-094 requires. - Recover failed saves from pull_request_target runs, listed under the pull request's branch, and charge a run only when its history job ran and did not succeed: a job that succeeded saved the run or declined it. - Name an unrenamed provider as AWF wrote it, even one that matches an inherited object property. - Remove the reducer's unused resetState; gh aw routing reset is the implementation, and its Go test checks the reset vector. - Finalize the ADR: accepted, with the re-apply alternative, the documented rulesets and retention bounds, and the recovery limits. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixed in bb6e52a: the writer accepts routing.observation only from the conclusion collector (T-UAS-094); the thread is answered and resolved.
commented
Nov 24, 2026
|
CI note for |


Fixes #80554
This adds
adaptive-routing: observe. A routed workflow that opts in keeps running the router's ordinary pick exactly as before, and gh-aw records every eligible run in a per-workflow history that maintainers can read withgh aw routing status. It is the evidence a later live mode would act on; observe mode never changes which model runs.Opting in
A workflow opts in with
adaptive-routing: observeand must enable repo-memory:A repository can make it the default with
"adaptive_routing": "observe"in.github/workflows/aw.json. The workflow's own value wins (includingfalse), then the first import that sets it, thenaw.json. Only workflows whose main model the router picks, on a Copilot, Claude or Codex engine, can take part; work-queue workers, reusable workflows (on: workflow_call) and workflows that run experiments cannot. An explicit opt-in that cannot work fails to compile with the reason, while the repository default skips such workflows silently. For example, without repo-memory:trueis reserved for live mode and fails to compile. A workflow that does not opt in compiles exactly as before; the gate's drift check found every lock file in the repository unchanged.What the compiled workflow gains
One job after
conclusion, shown here trimmed from the lock file of the example above:The agent job, its prompt and its permissions are unchanged. The agent never sees the history: its branch is not checked out for the agent, and a repo-memory entry with a branch under
memory/adaptive-routing/fails to compile. Repo-memory's clone and save also refuse such a branch at run time, in case a branch-name expression resolves to one.What gets recorded
The job reads three things from the run's unified session: AW-1's routing verdict, the model and effort AWF selected, and what AWF priced the run at. It saves them on
memory/adaptive-routing/<workflow>.runs.jsonlgets one line per run, including runs that did not count and why:{"run": "44156334376", "number": 812, "attempt": 1, "at": "2026-11-19T17:02:40Z", "generation": "<definition hash>", "scope": "copilot/cost/shared", "mode": "observe", "role": "observe", "pair": "github-copilot/model-a@high", "outcome": "failure", "credits": 12.0, "counted": true, "note": null}state.jsonkeeps each model and effort's newest 50 outcomes within 60 days, with their costs, its streak and a rate summary. A run counts only when the verdict says its result was about the selected model; otherwise its line says why, such asinfrastructure,cancelled,rate_limitedorno_agent. Only first attempts of runs whose definition comes from the default branch are recorded. If a run's history job fails to save it, a later save finds the run among the workflow's newest runs (includingpull_request_targetruns, which GitHub lists under the pull request's branch) and records it asunsaved. Editing the workflow starts a new generation that forgives earlier failures and keeps the successes, andgh aw routing resetfences off every run up to the latest.gh aw routing status <workflow>shows the history. On the test fixture (one proven model, one model after a failed test) it prints:Without a workflow it lists every history in the repository, and
--jsongives the same data for scripts.When runs finish together
The job has no concurrency group. Each save is a signed commit made through the API that lands only on the head it read. Repo-memory's save loop gains a
reapplyoption: when another run moved the branch first, the loop resets to the new head and applies this run again to the newer files. For example, runs 811 and 812 both read the history at sequence 40. Run 811 lands first as 41; run 812's commit is refused, so it re-reads, applies itself as 42 and lands. Neither run is lost or counted twice, and a run already inruns.jsonl, such as one whose acknowledgment was lost, is not applied again. Repo-memory's own saves do not use the option and behave as before.Token counts
The history also keeps each run's token counts, so that live mode can later estimate what an untried model would cost. AWF's token usage records keep each provider's own input count, which includes cached tokens for some responses and not others, and they do not say which. In run 39147795806 a request logged 23,799 input and 23,194 cache read tokens, so only 605 were new; in run 44156334376 a request logged 382 input next to 19,712 cached. Adding up 39147795806's logged input would record 94,950 new input tokens where there were 24,093.
So the writer counts new input as AWF's credit meter does. It follows the record's
input_tokens_include_cacheflag when AWF provides one. Otherwise an input count smaller than the cache cannot include it and is kept, and any other count is taken to include the cache, which is subtracted. That is right for every request in the fixture runs, and can only undercount a request whose new input exceeds its cached input; estimates do not need exact counts. Credits come straight from AWF and are not affected.Testing
aw.json, the reserved branch namespace, the job's shape, androuting statusandrouting reset(which commits only on the head it read). Against the real API: a repository with no histories lists none ([]with--json), and a missing or invalid workflow ID gives a clear error without writing.make agent-report-progresspasses atbb6e52a574onmain484b0b04e4, including the workflow drift check.Live mode and selection receipts come next (AW-3); they also need the firewall's adaptive selection (github/gh-aw-firewall#12027) in a release.