Add pre-run token usage estimation - #341
Open
Aaron Aspinwall (AaronAspinwall123) wants to merge 5 commits into
Open
Add pre-run token usage estimation#341Aaron Aspinwall (AaronAspinwall123) wants to merge 5 commits into
Aaron Aspinwall (AaronAspinwall123) wants to merge 5 commits into
Conversation
Add stage-aware local token estimation with resume, force, tool, conversation, and judge accounting. Persist provider usage coverage and estimate accuracy while avoiding misleading comparisons for partial or incomplete runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 64b5af06-d5d7-45c4-a340-3173531f4ec7
Aaron Aspinwall (AaronAspinwall123)
requested review from
Chang Liu (changliu2),
Jake Present (jakepresent) and
tangym
as code owners
September 1, 2026 23:39
Read token telemetry from run metrics and surface the pre-run estimate, likely range, provider-reported usage, stage breakdown, and comparison status on run pages and HTML exports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 64b5af06-d5d7-45c4-a340-3173531f4ec7
Aaron Aspinwall (AaronAspinwall123)
requested a review
from sooyeonni (sooyeonni)
as a code owner
September 2, 2026 01:52
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 64b5af06-d5d7-45c4-a340-3173531f4ec7
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 64b5af06-d5d7-45c4-a340-3173531f4ec7
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 64b5af06-d5d7-45c4-a340-3173531f4ec7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
metrics.jsononly when the run and telemetry are completeViewer
The Summary & submit step now estimates usage before the evaluation starts. The compact row shows the conservative total, likely range, and tracked call count. It uses the same normalized payload as submission, makes no provider calls, and does not reserve a run directory. Submission waits while the estimate is loading; superseded or abandoned requests terminate their estimator process and clean up the temporary config.
Completed runs now use a single compact Token usage row instead of the previous three-card layout. It shows:
Older token metrics without the newer accuracy
statusfield remain readable. Runs without token telemetry show a small unavailable state rather than a large empty card.CLI
assert-ai estimate --config PATHexposes the same read-only estimate without starting a run;--output jsonis used by the viewer endpoint.assert-ai runprints the estimate before uncached stages execute and reports provider usage plus estimate accuracy after completion. Zero tracked-token estimates still emit explicit text and preserve notes for opaque callable, endpoint, connector, or sandbox usage.Validation
npm run check(0 errors; 6 existing warnings in unrelated files)npm run build/api/runs/estimatecheck: 83,242 estimated tokens, likely 54,107-112,377, 28 tracked calls, and no suite directory createdAzure calibration
Ran 12 fresh
azure/gpt-5.4-minievaluations after the conservative tuning, covering prompt length, requested output length, batching, one-to-four-turn conversations, long conversational context, a simulated tool loop, and a generated end-to-end pipeline. Generated calibration artifacts remain local and are not committed.Difference is
(actual - estimate) / estimate; negative values mean the estimate was conservative.The high-side bias is intentional: compared with the earlier tuning, mean absolute error increases from 14.0% to 20.0%, while underestimates drop from 2/12 runs to 0/12. A separate CLI/viewer demo estimated 4,453 tokens (likely 2,894-6,012) and reported 3,913 actual tokens, 12.1% below the estimate.