Skip to content

perf(parser): single-pass resume detection in _first_pass (#955)#990

Merged
microsasa merged 1 commit intomainfrom
fix/955-single-pass-resume
Apr 19, 2026
Merged

perf(parser): single-pass resume detection in _first_pass (#955)#990
microsasa merged 1 commit intomainfrom
fix/955-single-pass-resume

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Summary

Fold _detect_resume() into _first_pass() so event processing is single-pass. Rolling post-shutdown accumulators reset on each session.shutdown; after the loop they hold the post-last-shutdown values.

Closes #955

Changes

src/copilot_usage/parser.py

  • Add 5 post-shutdown fields to _FirstPassResult (rolling accumulators)
  • Add SESSION_RESUME to _FIRST_PASS_EVENT_TYPES
  • Track post-shutdown state in _first_pass loop with if _shutdowns: guards
  • Remove _detect_resume() and _DETECT_RESUME_EVENT_TYPES entirely
  • Build _ResumeInfo from _FirstPassResult in _build_session_summary_with_meta

tests/copilot_usage/test_parser.py

  • Convert TestDetectResumeDirectTestResumeDetectionDirect (tests via _first_pass)
  • Convert TestDetectResumeNonIndicatorEventsTestNonIndicatorEventsNoResume
  • Add 3 new edge-case tests: assistant message without tokens, pre-shutdown resume ignored, stale resume time cleared across shutdowns
  • Remove 4 implementation-detail test classes (slice alloc, index access, elif chain, frozenset constant)
  • Update _FIRST_PASS_EVENT_TYPES assertion to include SESSION_RESUME

Docs: architecture.md, implementation.md, changelog.md, test_docs.py updated

Verification

  • All checks pass (ruff, pyright, bandit, 99% coverage, 86 e2e)
  • Triple adversarial review (Opus 4.6, Sonnet 4.6, Codex) — 0 bugs, 2 test gaps found and covered
  • Self-review caught and fixed a data-loss bug (assistant message without tokens not setting resumed)

Copilot AI review requested due to automatic review settings April 18, 2026 20:57
Copy link
Copy Markdown

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

This PR improves copilot_usage session summarization performance by folding resume detection into _first_pass(), eliminating an extra scan of events for sessions that contain shutdowns.

Changes:

  • Extend _FirstPassResult with rolling post-shutdown accumulators and track them during _first_pass() (single-pass resume detection).
  • Remove _detect_resume() and its event-type prefilter; construct _ResumeInfo directly from _FirstPassResult in _build_session_summary_with_meta.
  • Update/reshape unit tests and documentation to reflect the new single-pass behavior and edge cases.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/copilot_usage/parser.py Implements single-pass post-shutdown resume detection and removes _detect_resume().
tests/copilot_usage/test_parser.py Updates direct resume-detection tests to validate _first_pass()-tracked post-shutdown fields; removes tests tied to the deleted helper.
tests/test_docs.py Updates docs assertions to look for resume detection described under _first_pass() rather than _detect_resume().
src/copilot_usage/docs/implementation.md Updates implementation narrative to describe rolling post-shutdown tracking inside _first_pass().
src/copilot_usage/docs/architecture.md Updates architecture overview/pipeline to reflect single-pass resume detection in _first_pass().
src/copilot_usage/docs/changelog.md Removes _detect_resume() from the historical helper list in the refactor entry.

Comment thread src/copilot_usage/parser.py Outdated
Comment thread src/copilot_usage/docs/implementation.md Outdated
@microsasa microsasa force-pushed the fix/955-single-pass-resume branch from 209648d to 97ec217 Compare April 18, 2026 23:57
…ent processing (#955)

Eliminate the second pass over post-shutdown events by tracking rolling
accumulators in _first_pass that reset on each session.shutdown. After
the loop, these hold the post-last-shutdown values, making _detect_resume
unnecessary.

- Add 5 post-shutdown fields to _FirstPassResult
- Add SESSION_RESUME to _FIRST_PASS_EVENT_TYPES
- Remove _detect_resume and _DETECT_RESUME_EVENT_TYPES
- Build _ResumeInfo from _FirstPassResult in _build_session_summary_with_meta
- Convert correctness tests to use _first_pass directly
- Remove 6 implementation-detail test classes (slice, index, elif, frozenset)
- Update architecture.md, implementation.md, changelog.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa force-pushed the fix/955-single-pass-resume branch from 97ec217 to 5034015 Compare April 19, 2026 00:05
@microsasa microsasa merged commit 62106b4 into main Apr 19, 2026
4 checks passed
@microsasa microsasa deleted the fix/955-single-pass-resume branch April 19, 2026 00:07
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][perf] parser: _build_session_summary_with_meta iterates the event list twice for sessions with shutdown data

2 participants