Skip to content

Fix token usage step summary model attribution for inline sub-agent overrides#31538

Merged
pelikhan merged 4 commits into
mainfrom
copilot/fix-token-usage-summary
May 11, 2026
Merged

Fix token usage step summary model attribution for inline sub-agent overrides#31538
pelikhan merged 4 commits into
mainfrom
copilot/fix-token-usage-summary

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

  • Review new PR comment and determine required action
  • Harden token usage path probing against per-path stat/read errors
  • Make parse_token_usage tests hermetic for both token usage paths
  • Reduce duplicate JSON parse work in dedupe path
  • Run targeted tests for parse_token_usage
  • Reply to new PR comment with commit reference
  • Run final validation checks

Copilot AI and others added 2 commits May 11, 2026 16:42
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
Copilot AI requested a review from pelikhan May 11, 2026 16:44
@pelikhan pelikhan marked this pull request as ready for review May 11, 2026 16:50
Copilot AI review requested due to automatic review settings May 11, 2026 16:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_PATH and TOKEN_USAGE_PATHS, and updated parsing to read from all existing non-empty token usage files.
  • Implemented cross-path deduplication using request_id when 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 thread actions/setup/js/parse_token_usage.cjs Outdated
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 thread actions/setup/js/parse_token_usage.cjs Outdated
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);
}
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review comments

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

@copilot review comments

Addressed in commit 28ae239.

  • Hardened token usage path probing so per-path stat/read errors are skipped instead of failing the whole step.
  • Made parse_token_usage tests hermetic for both audit and legacy token usage paths.
  • Reduced duplicate JSON parse work by extracting request_id via lightweight matching during dedupe.
  • Added helper-focused tests for readable-path filtering and request_id deduplication.

@pelikhan pelikhan merged commit 9f7e44c into main May 11, 2026
@pelikhan pelikhan deleted the copilot/fix-token-usage-summary branch May 11, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Token usage step summary does not break down usage by model when inline sub-agents use model overrides

3 participants