Fix token usage step summary model attribution for inline sub-agent overrides#31538
Merged
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix token usage step summary for model breakdown
Fix token usage step summary model attribution for inline sub-agent overrides
May 11, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes missing per-model attribution in Token Usage step summaries when token usage records are emitted to the firewall audit logs path (e.g., inline sub-agent model: overrides), by ingesting token usage from both the audit and legacy locations and deduplicating overlaps.
Changes:
- Added
TOKEN_USAGE_AUDIT_PATHandTOKEN_USAGE_PATHS, and updated parsing to read from all existing non-empty token usage files. - Implemented cross-path deduplication using
request_idwhen available. - Expanded unit tests to validate audit-path ingestion, exported constants, and deduplication behavior.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/parse_token_usage.cjs | Reads token usage from both audit + legacy paths, dedupes entries, and generates the step summary + agent_usage.json. |
| actions/setup/js/parse_token_usage.test.cjs | Adds tests covering new constants, audit-path ingestion, and overlap deduplication across both token usage files. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 3
Comment on lines
+27
to
+28
| const tokenUsagePaths = TOKEN_USAGE_PATHS.filter(path => fs.existsSync(path) && fs.statSync(path).size > 0); | ||
| if (tokenUsagePaths.length === 0) { |
Comment on lines
+206
to
+208
| fs.existsSync = vi.fn(p => (p === TOKEN_USAGE_AUDIT_PATH ? true : originalExistsSync(p))); | ||
| fs.statSync = vi.fn(p => (p === TOKEN_USAGE_AUDIT_PATH ? { size: multiEntry.length } : originalStatSync(p))); | ||
| fs.readFileSync = vi.fn((p, enc) => (p === TOKEN_USAGE_AUDIT_PATH ? multiEntry : originalReadFileSync(p, enc))); |
Comment on lines
+43
to
+48
| try { | ||
| const parsed = JSON.parse(trimmed); | ||
| if (parsed && typeof parsed === "object") { | ||
| dedupeKey = typeof parsed.request_id === "string" && parsed.request_id.length > 0 ? `request_id:${parsed.request_id}` : trimmed; | ||
| normalizedLine = JSON.stringify(parsed); | ||
| } |
Collaborator
|
@copilot review comments |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Addressed in commit 28ae239.
|
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.
Uh oh!
There was an error while loading. Please reload this page.