Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 3, 2026

The Copilot log parser accumulates token counts from multiple API responses (one per turn), but this behavior was undocumented and untested.

Changes

  • Added test (copilot_token_parsing_test.go) validating token accumulation:

    // Log with 2 responses: 1613 + 1712 tokens
    expectedTokens := 3325
    metrics := engine.ParseLogMetrics(logContent, false)
    // Verifies: metrics.TokenUsage == 3325
  • Documented ParseLogMetrics with accumulation behavior:

    // Example: If a run has 3 turns with token counts [1000, 1500, 800],
    // the total token usage will be 3300 (sum of all turns).
    //
    // This matches the behavior of the JavaScript parser in parse_copilot_log.cjs.
  • Added real-world test (copilot_token_parsing_real_test.go) validating parser with actual Copilot CLI logs:

    • Tests with real workflow run logs from GitHub Actions run 20680961415
    • Validates correct accumulation of 50 API responses totaling 2,484,450 tokens
    • Confirms parser handles production-scale logs accurately

This ensures consistency between Go and JavaScript parsers and prevents regression of the accumulation logic.

Original prompt

Reference: https://github.com/githubnext/gh-aw/actions/runs/20681216756/job/59375708286#step:6:1

Review token count parsing for copilot in go


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add comprehensive test for token count accumulation from multiple API responses
- Document token counting behavior in ParseLogMetrics function
- Verify that Go implementation matches JavaScript parser behavior
- Test confirms: 2 responses (1613 + 1712 tokens) = 3325 tokens total

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Review token count parsing for Copilot in Go Document and test Copilot token count accumulation behavior Jan 3, 2026
Copilot AI requested a review from pelikhan January 3, 2026 18:50
@pelikhan
Copy link
Contributor

pelikhan commented Jan 3, 2026

…961415

- Test validates token accumulation with actual Copilot CLI log
- Log contains 50 API responses totaling 2,484,450 tokens
- Test confirms parser correctly accumulates all tokens
- Addresses review comment to test with real workflow logs

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

Copilot AI commented Jan 3, 2026

@copilot test logs parser with https://github.com/githubnext/gh-aw/actions/runs/20680961415/job/59375124033

Added test with the real Copilot log from that workflow run. The parser correctly accumulates all 50 API responses totaling 2,484,450 tokens. Test passes: commit 1a289b4

@pelikhan pelikhan marked this pull request as ready for review January 3, 2026 19:14
@pelikhan pelikhan merged commit 7e4b8d3 into main Jan 3, 2026
4 checks passed
@pelikhan pelikhan deleted the copilot/review-token-count-parsing branch January 3, 2026 19:14
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.

2 participants