Repository navigation
Keep credits and model_credits paired on fully priced runs in routing history - #80784
Conversation
… history Emit `model_credits: null` in `runCost` whenever total `credits` is `null` so partial bills never record a standalone main-model share while still preserving main-conversation token counts. In `averages()`, fold `model_credits` only on entries with a non-null total `credits` (falling back to total `credits` when `model_credits` is `null`), keeping both EMAs over the same sample set and guaranteeing `0 <= model_credits <= credits` even for legacy partial-bill history entries. Fixes #80782 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
✅ Test Quality Sentinel completed test quality analysis.
|
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. The No-op messageCompleted PR #80784 review: submitted one overall COMMENT review with no findings, and recorded the no_findings outcome for head 8abe4b2.
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. The No-op messagePR #80784 reviewed at head 8abe4b2: no applicable specification regression or synchronization proposal found; no GitHub review action was needed.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. The No-op messageLean already. Ship.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
Reviewed the changed lines in the cost pairing and legacy averaging updates. I found no actionable correctness, regression, performance, or maintainability issues blocking merge. The specialist pass completed; its only suggestion relied on malformed legacy entries with model_credits greater than total credits, which is outside the demonstrated data contract and was not retained as a finding.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.7K
Comment /review to run again
Comment MemoryPeek at saved memory (review-history)History |
🧪 Test Quality Sentinel Report✅ Test Quality Score: 90/100 — Excellent
📊 Metrics (2 tests)
|
There was a problem hiding this comment.
✅ Test Quality Sentinel: 90/100. 0% implementation tests (threshold: 30%). No guideline violations.
🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 7.4K
Comment /review to run again
Comment MemoryPeek at saved memory (spec-review-history)History |
There was a problem hiding this comment.
🔵 Needs a closer look
The writer and legacy-history reducer changes affect cost evidence used by AWF’s live challenger selection and budget decisions, creating cross-component operational consequences beyond limited-impact automated approval scope.
No open issues 🎉
What changed in this PR
This PR fixes adaptive routing cost accounting so total credits and model_credits are averaged over the same fully priced runs, preventing legacy partial bills from skewing challenger cost estimates.
Changes:
- Emit null
model_creditswhen total credits are unknown, while preserving main-conversation token counts. - Ignore standalone model costs from partially priced runs in the reducer.
- Add regression tests for unpriced sub-agent requests and legacy partial-bill histories.
| File | Description |
|---|---|
actions/setup/js/routing_history.test.cjs |
Tests that legacy partial bills do not affect either cost average. |
actions/setup/js/routing_history.cjs |
Pairs both cost averages on fully priced entries and exports averages. |
actions/setup/js/push_routing_history.test.cjs |
Tests null cost pairing while retaining main-conversation tokens. |
actions/setup/js/push_routing_history.cjs |
Makes model credits null whenever total credits are unknown. |
Review effort: Balanced (adaptive)
There was a problem hiding this comment.
Review summary
No blocking issues. credits and model_credits are now paired on the same fully priced runs in both the writer (runCost) and the reducer (averages), which keeps the stated invariant 0 is at most model_credits is at most credits.
Verified against head 8abe4b2:
- Replayed all 30 run-bearing oracle cases and 8 timelines in aw2-reducer.json through applyRun with Node. All pass, including the synced partial-bill-ignores-standalone-model-share vector (credits 10, model_credits 10, bills 1).
- runCost on the PR scenario returns credits null, model_credits null, tokens [600,400,0,200,null], matching the new test expectation.
- Fuzzed averages over 20,000 random histories with zero violations of the invariant.
- pkg/cli/routing_command.go already models model_credits as a nullable float, so the new null is handled downstream.
Non-blocking note: a run with any unpriced sub-agent now contributes nothing to a pair model-share average, not only to credits. This follows the fully-priced rule the PR documents, so no change is requested.
Limitation
node_modules is absent on this runner, so vitest and npm run typecheck were not executed here. The checks above call the modules directly. CI should run routing_history.test.cjs and push_routing_history.test.cjs.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~7 AIC · ⌖ ~2 AIC · ⊞ 5.1K
Comment /matt to run again
Fixes #80782
In adaptive routing (#79102),
push_routing_history.cjs(runCost) previously accumulated totalcreditsacross all non-classifier agent requests andmodel_creditsacross main-conversation requests independently. When a sub-agent request lackedaic, totalcreditsbecamenullwhilemodel_creditsstill recorded the main conversation's spend. Inrouting_history.cjs,averages()foldedmodel_creditswheneverentry[4]was non-null, even whenentry[3](credits) wasnull. Computing the two EMAs over different run subsets allowedmodel_creditsto exceedcredits, which causes AWF's challenger cost estimation (credits + model_credits * (ratio - 1)) to produce negative credit estimates.This PR keeps
creditsandmodel_creditspaired on the same fully priced runs in both the writer and the reducer, so0 <= model_credits <= creditsholds both for new runs and when re-reading legacy history entries.Example
Suppose a pair records two runs:
[1, "2026-11-01T00:00:00Z", true, null, 30.0, [40000, 300000, 0, 9000, null]].[2, "2026-11-02T00:00:00Z", true, 10.0, 10.0, null].state.jsonafter Run 2credits10.010.0model_credits28.0(0.9 * 30.0 + 0.1 * 10.0)10.0bills11-15.2credits1.0creditsFor new runs like Run 1,
runCostnow emitscredits: nullandmodel_credits: null, while still preserving main-conversationtokens.Changes
actions/setup/js/push_routing_history.cjs:runCostemitsmodel_credits: nullwhenever totalcreditsisnull(while keeping main-conversationtokensintact).actions/setup/js/routing_history.cjs:averagesfoldsmodel_creditsonly on entries where totalcreditsis non-null (falling back to totalcreditswhenmodel_creditsisnull, as before), and exportsaveragesalongsidecounts,memory, andrate.actions/setup/js/fixtures/routing-history/aw2-reducer.json: syncs thepartial-bill-ignores-standalone-model-shareoracle vector from the shared adaptive-routing oracle.actions/setup/js/push_routing_history.test.cjsandactions/setup/js/routing_history.test.cjs: adds focused tests for a priced main request paired with an unpriced sub-agent request and for legacy[null, 30.0]followed by[10.0, 10.0]histories.Verification
Validated on
8abe4b2dda:npx vitest run --no-file-parallelism --testTimeout=30000 routing_history.test.cjs push_routing_history.test.cjs: 2 test files, 63 passed.npm run typecheck: passed.npx prettier --check: passed on all modified.cjsfiles (aw2-reducer.jsonis in.prettierignore).