Skip to content

Fix zero token usage in the logs MCP tool run schema - #60424

Merged
pelikhan merged 5 commits into
mainfrom
copilot/deep-report-fix-token-usage-field
Sep 12, 2026
Merged

Fix zero token usage in the logs MCP tool run schema#60424
pelikhan merged 5 commits into
mainfrom
copilot/deep-report-fix-token-usage-field

Conversation

Copilot AI commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

The logs MCP tool registered its schema with artifacts: ["info"], which only downloads aw_info.json. The compact usage artifact carrying token_usage.jsonl / agent_usage.json was never fetched, so every run had TokenUsage == 0 and — thanks to omitempty — the token_usage key disappeared from the JSON entirely. Any report averaging token usage over the run list computed exactly 0.

Changes

  • pkg/cli/mcp_tools_privileged.go
    • Default artifact sets for the logs tool are now info,usage.
    • New effectiveMCPLogsToolArtifacts appends the compact usage set to explicit selections too (no-op when all or usage is already present), so token usage survives whichever sets a report requests.
    • Tool description documents that each run record carries token_usage/aic and why usage is always downloaded.
  • pkg/cli/logs_report.gotoken_usage and aic are always serialized on RunData, so the field is discoverable and 0 unambiguously means "no tokens recorded" rather than "field absent".
  • Tests for the new default and set normalization; existing artifact pass-through test now expects the added usage set. Changeset included.
// artifacts: ["agent", "firewall"]  ->  --artifacts agent,firewall,usage
// artifacts: omitted                ->  --artifacts info,usage

The usage artifact is the compact conclusion artifact, so the extra download is cheap relative to the metric it restores.

Copilot AI and others added 2 commits September 12, 2026 14:58
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 missing token-usage field in agenticworkflows logs schema Fix zero token usage in the logs MCP tool run schema Sep 12, 2026
Copilot AI requested a review from pelikhan September 12, 2026 15:01
@pelikhan
pelikhan marked this pull request as ready for review September 12, 2026 15:05
Copilot AI balanced review requested due to automatic review settings September 12, 2026 15:05
@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com
  • raw.githubusercontent.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"
    - "raw.githubusercontent.com"

See Network Configuration for more information.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Design Decision Gate 🏗️. Review the logs for details.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • github.com
  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"
    - "proxy.golang.org"

See Network Configuration for more information.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by Ponytail Reviewer for #60424

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new combined default bypasses the activation-artifact fallback for legacy runs, and zero-value serialization lacks regression coverage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes missing token-usage metrics in MCP logs output by ensuring usage artifacts are downloaded and zero values remain serialized.

Changes:

  • Adds usage to default and explicit artifact selections.
  • Always serializes token_usage and aic.
  • Adds normalization tests and a patch changeset.
File summaries
File Description
pkg/cli/mcp_tools_privileged.go Updates MCP logs artifact selection and documentation.
pkg/cli/mcp_tools_privileged_test.go Tests artifact defaults and normalization.
pkg/cli/logs_report.go Preserves zero-valued usage fields in JSON.
.changeset/logs-mcp-token-usage-default-artifacts.md Documents the patch.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +133 to +135
func effectiveMCPLogsToolArtifacts(artifacts []string) []string {
if len(artifacts) == 0 {
return slices.Clone(defaultMCPLogsToolArtifacts)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 2b71844: added isInfoWithOptionalUsageArtifactFilter, which treats info and info+usage filters the same for the activation-artifact fallback (used at the ErrNoArtifacts checks and the post-download aw_info.json check). Legacy runs missing both compact artifacts now fall back to the activation artifact as before.

Comment thread pkg/cli/logs_report.go
Comment on lines +156 to +159
// TokenUsage is always emitted (even when 0) so consumers of the run list can
// discover the field and distinguish "no tokens recorded" from "field absent".
TokenUsage int `json:"token_usage" console:"header:Tokens,format:number,omitempty"`
AIC float64 `json:"aic"`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added TestRunDataJSONIncludesZeroTokenUsageAndAIC in 2b71844, which marshals a zero-metric RunData and asserts both "token_usage":0 and "aic":0 are present in the output.

@github-actions

Copy link
Copy Markdown
Contributor
🏗️ ADR Required — draft added for PR #60424

I enforced the design-decision gate for this PR because it adds more than 100 new lines in business-logic directories (pkg/: 103 additions in the prefetch summary).

Evidence reviewed

  • PR title: Fix zero token usage in the logs MCP tool run schema
  • Changed implementation files:
    • pkg/cli/mcp_tools_privileged.go
    • pkg/cli/logs_report.go
    • pkg/cli/mcp_tools_privileged_test.go
  • PR description explains the architectural decision: the logs MCP tool must always fetch the compact usage artifact so per-run token_usage/aic remain part of the run-data contract.
  • Existing ADRs on the branch did not cover this specific decision.

Action taken

  • Added draft ADR: docs/adr/60424-ensure-logs-tool-downloads-usage-artifacts.md

Next action for the author

Please review and refine the draft ADR, especially the rationale and trade-offs, before merging this PR.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • github.com
  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"
    - "proxy.golang.org"

See Network Configuration for more information.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · gpt54 · 16.4 AIC · ⊞ 9.7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs — solid regression fix and test coverage, but the generated schemas were not refreshed.

📋 Key Themes & Highlights

Key Themes

  • Stale generated schema: dropping omitempty from RunData.TokenUsage/AIC (pkg/cli/logs_report.go) changes the JSON Schema required list, but schemas/logs.schema.json and schemas/logs-jsonl.schema.json weren't regenerated. TestGeneratedOutputSchemasAreCurrent fails as-is; running make schemas (or make recompile) reproduces and fixes the diff. Left an inline comment with the exact repro.

Positive Highlights

  • ✅ Root cause is correctly diagnosed (missing usage artifact download, not a downstream aggregation bug) and the fix addresses it directly rather than papering over symptoms.
  • effectiveMCPLogsToolArtifacts is well-covered: default case, explicit-set augmentation, and both no-op cases (usage, all) each have a dedicated test.
  • TestLogsToolDefaultsToUsageArtifact is a genuine regression guard that exercises the full tool registration + handler path, not just the helper function in isolation.

Requesting changes only for the stale schema files — regenerate and commit them and this is good to merge.

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com
  • raw.githubusercontent.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"
    - "raw.githubusercontent.com"

See Network Configuration for more information.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 111.2 AIC · ⌖ 15 AIC · ⊞ 10.4K
Comment /matt to run again

Comment thread pkg/cli/logs_report.go
ActionMinutes float64 `json:"action_minutes,omitempty" console:"header:Action Minutes,omitempty"`
// TokenUsage is always emitted (even when 0) so consumers of the run list can
// discover the field and distinguish "no tokens recorded" from "field absent".
TokenUsage int `json:"token_usage" console:"header:Tokens,format:number,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/diagnosing-bugs] Removing omitempty here makes token_usage/aic required in the generated JSON Schema, but schemas/logs.schema.json and schemas/logs-jsonl.schema.json weren't regenerated — make schemas (or make recompile) still produces a diff adding "token_usage" and "aic" to the required array. TestGeneratedOutputSchemasAreCurrent fails on this branch.

💡 Verification
$ ./gh-aw json-schema logs > /tmp/new.json
$ diff /tmp/new.json schemas/logs.schema.json
1000,1001d999
<               "token_usage",
<               "aic",

Same delta for logs-jsonl.schema.json. Run make schemas (or make recompile) and commit the regenerated files.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regenerated in 2b71844 via make schemas; TestGeneratedOutputSchemasAreCurrent passes now.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finishers skill

…/aic

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finishers skill

Ran the pr-finisher pass:

  • ✅ Reviews — addressed all 3 open review threads (activation-fallback bypass fix, zero-value JSON regression test, regenerated schemas) in 2b71844 and replied to each. Thread resolution itself requires reviewer/maintainer action since I don't have a GraphQL resolve-thread credential in this sandbox.
  • ✅ Checks (local) — make fmt, targeted go test, and make agent-report-progress (schema regen + impacted tests) all pass.
  • ❓ Checks (CI) — stale after this push; a maintainer needs to re-trigger CI (my push doesn't trigger workflows).
  • ❓ Mergeable — GitHub reported mergeable_state: blocked (pending required review), which isn't something I can change from here.

Nothing else actionable remains on my side; ready for maintainer review/merge.

@pelikhan
pelikhan merged commit f1829ef into main Sep 12, 2026
32 checks passed
@pelikhan
pelikhan deleted the copilot/deep-report-fix-token-usage-field branch September 12, 2026 16:01
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.89.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[deep-report] agenticworkflows logs run schema lacks a token-usage field, causing multiple reports to show 0 average token usage

3 participants