perf(parser): single-pass resume detection in _first_pass (#955)#990
Merged
perf(parser): single-pass resume detection in _first_pass (#955)#990
Conversation
There was a problem hiding this comment.
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
_FirstPassResultwith rolling post-shutdown accumulators and track them during_first_pass()(single-pass resume detection). - Remove
_detect_resume()and its event-type prefilter; construct_ResumeInfodirectly from_FirstPassResultin_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. |
209648d to
97ec217
Compare
…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>
97ec217 to
5034015
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fold
_detect_resume()into_first_pass()so event processing is single-pass. Rolling post-shutdown accumulators reset on eachsession.shutdown; after the loop they hold the post-last-shutdown values.Closes #955
Changes
src/copilot_usage/parser.py_FirstPassResult(rolling accumulators)SESSION_RESUMEto_FIRST_PASS_EVENT_TYPES_first_passloop withif _shutdowns:guards_detect_resume()and_DETECT_RESUME_EVENT_TYPESentirely_ResumeInfofrom_FirstPassResultin_build_session_summary_with_metatests/copilot_usage/test_parser.pyTestDetectResumeDirect→TestResumeDetectionDirect(tests via_first_pass)TestDetectResumeNonIndicatorEvents→TestNonIndicatorEventsNoResume_FIRST_PASS_EVENT_TYPESassertion to includeSESSION_RESUMEDocs: architecture.md, implementation.md, changelog.md, test_docs.py updated
Verification