Skip to content

Fix Copilot CLI shutdown metric segmentation#157

Open
zhangzqs wants to merge 1 commit intoPiebald-AI:mainfrom
zhangzqs:fix/copilot-cli-shutdown-segments
Open

Fix Copilot CLI shutdown metric segmentation#157
zhangzqs wants to merge 1 commit intoPiebald-AI:mainfrom
zhangzqs:fix/copilot-cli-shutdown-segments

Conversation

@zhangzqs
Copy link
Copy Markdown
Contributor

@zhangzqs zhangzqs commented May 5, 2026

Summary

  • apply Copilot CLI shutdown modelMetrics to each completed segment in a single events.jsonl instead of overwriting the whole file with the last shutdown snapshot
  • keep a segment open when session.shutdown has no modelMetrics, so later valid shutdown totals still account for earlier turns
  • add regression tests for multi-shutdown session files and empty-shutdown boundaries

Test Plan

  • cargo fmt --all --quiet
  • cargo build --quiet
  • cargo test --quiet
  • cargo clippy --quiet -- -D warnings
  • cargo doc --quiet

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced usage metrics attribution across multiple session shutdown events in Copilot CLI analyzer, improving per-turn accounting accuracy.
  • Tests

    • Added test coverage for multiple shutdown event handling and empty metadata edge cases.

Handle multiple session.shutdown blocks in a single Copilot CLI events.jsonl by applying modelMetrics to each completed segment instead of only the final shutdown snapshot. Also keep segments open across empty shutdown events and add regression coverage for both cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9a34967-9836-49ef-839e-4d631ed5485b

📥 Commits

Reviewing files that changed from the base of the PR and between eb7ef03 and 768c2bc.

📒 Files selected for processing (2)
  • src/analyzers/copilot_cli.rs
  • src/analyzers/tests/copilot_cli.rs

📝 Walkthrough

Walkthrough

The Copilot CLI parser now tracks message indices across multiple session.shutdown events using a cursor variable rather than a single stored metrics option, enabling correct attribution of shutdown metrics to their corresponding segments throughout a session file.

Changes

Multi-Shutdown Segment Tracking

Layer / File(s) Summary
State Tracking
src/analyzers/copilot_cli.rs (line 688–692)
Introduces shutdown_segment_start: usize cursor to mark the beginning of entries after the most recent shutdown event.
Shutdown Event Handler
src/analyzers/copilot_cli.rs (line 998–1005)
When session.shutdown includes non-empty modelMetrics, applies metric fill and token distribution only to entries[shutdown_segment_start..], then advances the cursor to entries.len().
Finalization Logic
src/analyzers/copilot_cli.rs (line 1065–1068)
Applies apply_copilot_cli_live_prompt_overhead only to the tail segment entries[shutdown_segment_start..], eliminating the prior conditional branch that selected between stored metrics or overhead-only paths.
Test Coverage
src/analyzers/tests/copilot_cli.rs (line 213–352)
Adds two tests: one validating per-turn token accounting across two shutdown events in a single session, and another verifying correct segment handling when early shutdown metadata is empty.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Piebald-AI/splitrail#141: Directly modifies the same parse_copilot_cli_session_file function and shutdown-metrics handling in the Copilot CLI analyzer.

Suggested reviewers

  • mike1858

Poem

🐰 A cursor hops through shutdowns bright,
Each segment tracked with pure delight,
No more one metrics lost in time,
Multiple shutdowns tracked in rhyme! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix Copilot CLI shutdown metric segmentation' clearly and specifically describes the main change: fixing how shutdown metrics are segmented across multiple shutdown events in the Copilot CLI analyzer.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant