Skip to content

fix: verify null token_usage jq division in Copilot Token Optimizer#24404

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/debug-copilot-token-optimizer
Closed

fix: verify null token_usage jq division in Copilot Token Optimizer#24404
Copilot wants to merge 1 commit intomainfrom
copilot/debug-copilot-token-optimizer

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

The Copilot Token Optimizer workflow failed because map(.token_usage) | add returns null when all runs in a group have zero token usage (Go's omitempty omits the field), causing null / length to throw a fatal jq error.

Root cause

jq: error (at copilot-runs.json:12310): null (null) and number (1) cannot be divided

Single-run group with no token data: [null] | addnull, then null / 1 → error.

Fix (applied in PR #24400)

Added // 0 fallbacks in .github/workflows/copilot-token-optimizer.md:

- total_tokens: (map(.token_usage) | add),
- total_cost: (map(.estimated_cost) | add),
- avg_tokens: ((map(.token_usage) | add) / length),
+ total_tokens: (map(.token_usage // 0) | add),
+ total_cost: (map(.estimated_cost // 0) | add),
+ avg_tokens: ((map(.token_usage // 0) | add) / length),

null // 0 converts absent fields to 0, so [0] | add0 and 0 / 10. The lock file was recompiled and is consistent.

Copilot AI linked an issue Apr 4, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Debug Copilot Token Optimizer workflow failure fix: verify null token_usage jq division in Copilot Token Optimizer Apr 4, 2026
Copilot AI requested a review from pelikhan April 4, 2026 01:03
@pelikhan pelikhan closed this Apr 4, 2026
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.

[aw] Copilot Token Optimizer failed

2 participants