Skip to content

fix: redirect parse_events to _parse_events_from_offset (#987)#989

Merged
microsasa merged 5 commits intomainfrom
fix/987-parse-events-delegates-to-offset-4cf92f847d6533d5
Apr 18, 2026
Merged

fix: redirect parse_events to _parse_events_from_offset (#987)#989
microsasa merged 5 commits intomainfrom
fix/987-parse-events-delegates-to-offset-4cf92f847d6533d5

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #987

Changes

parse_events now delegates to _parse_events_from_offset — the same binary-mode implementation used by the production cache layer (get_cached_events). This eliminates the divergence where tests exercised a text-mode code path that was never used in production.

src/copilot_usage/parser.py

  • Added include_partial_tail keyword argument to _parse_events_from_offset (mirrors the existing pattern in vscode_parser.py). When True, a final non-newline-terminated line is included rather than triggering an early break.
  • Rewrote parse_events body to delegate: events, _ = _parse_events_from_offset(events_path, 0, include_partial_tail=True)

src/copilot_usage/docs/architecture.md

  • Updated pipeline step 2 to describe the actual implementation: _parse_events_from_offset accessed via get_cached_events, with caching and incremental parsing.

tests/copilot_usage/test_parser.py

  • Regression test (TestParseEventsPartialTailParity): writes a file whose last line is valid JSON without a trailing newline, asserts that parse_events and get_cached_events return the same events.
  • Updated 2 warning-format tests to check byte offsets (the canonical implementation reports offsets, not line numbers).
  • Updated 1 embedded-UTF-8 test to reflect binary-mode behavior (malformed bytes cause a JSON-skip, not a UnicodeDecodeError crash — strictly better recovery).

All existing tests pass. make check clean (lint, typecheck, security, 99% coverage).

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • astral.sh

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "astral.sh"

See Network Configuration for more information.

Generated by Issue Implementer · ● 15.3M ·

Redirect parse_events to delegate to _parse_events_from_offset with
include_partial_tail=True, aligning tests with the production code
path. Add include_partial_tail keyword arg to _parse_events_from_offset
(matching the vscode_parser pattern). Update architecture.md step 2 to
describe the actual pipeline. Add regression test verifying parse_events
and get_cached_events agree on partial-tail files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Apr 18, 2026
Copilot AI review requested due to automatic review settings April 18, 2026 20:09
@microsasa microsasa enabled auto-merge April 18, 2026 20:09
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 aligns the public parse_events() API with the production parsing path by delegating to the binary-mode _parse_events_from_offset() implementation, reducing behavioral drift between tests and real-world usage.

Changes:

  • Added include_partial_tail to _parse_events_from_offset() to control how malformed, non-newline-terminated tail lines are handled.
  • Rewrote parse_events() to delegate to _parse_events_from_offset(..., include_partial_tail=True).
  • Updated architecture docs and adjusted/added tests to validate offset-based warnings and partial-tail parity with the cache layer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/copilot_usage/parser.py Adds include_partial_tail and redirects parse_events() to the canonical binary-mode parser.
src/copilot_usage/docs/architecture.md Updates pipeline docs to describe the actual parsing/caching implementation.
tests/copilot_usage/test_parser.py Updates warning expectations to byte offsets, adjusts invalid-UTF-8 behavior tests, and adds a partial-tail parity regression test.

Comment thread tests/copilot_usage/test_parser.py Outdated
Comment thread src/copilot_usage/parser.py Outdated
Comment thread src/copilot_usage/parser.py Outdated
Comment thread tests/copilot_usage/test_parser.py
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Commit pushed: 5c80a0c

Generated by Review Responder

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread tests/copilot_usage/test_parser.py Outdated
@github-actions
Copy link
Copy Markdown
Contributor

Commit pushed: 0cd3bd4

Generated by Review Responder

Rename test methods with stale UnicodeDecodeError names to reflect
actual binary-mode behavior (invalid UTF-8 bytes cause JSON skip):

- test_unicode_decode_error_returns_partial
  → test_invalid_utf8_line_skipped_valid_event_returned
- test_unicode_decode_error_full_file
  → test_entirely_invalid_utf8_returns_empty_list

Update docstrings and inline comments accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

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

Comment thread tests/copilot_usage/test_parser.py Outdated
Comment thread src/copilot_usage/parser.py
@microsasa microsasa added the aw-review-response-attempted Responder has attempted to address review comments label Apr 18, 2026
- Strengthen test_invalid_utf8_line_skipped_valid_event_returned to assert
  exactly 1 event instead of allowing 0 (binary mode is deterministic)
- Document UnicodeDecodeError partial-return behavior in parse_events docstring

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

Commit pushed: 6f12e4e

Generated by Review Responder

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread tests/copilot_usage/test_parser.py
@microsasa microsasa added aw-review-response-1 Review response round 1 and removed aw-review-response-attempted Responder has attempted to address review comments labels Apr 18, 2026
Add test for malformed partial tail with include_partial_tail=True to
regression-protect the flag's warn-and-skip behavior when the final
non-newline-terminated line fails JSON decoding.

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

Commit pushed: f6ee872

Generated by Review Responder

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Apr 18, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quality Gate: APPROVE (Medium impact — auto-merge eligible)

Evaluated across code quality and blast radius:

  • Refactoring: parse_events now delegates to _parse_events_from_offset (the production binary-mode path), eliminating a divergent text-mode code path that was only exercised in tests.
  • Minimal impl change: Single condition addition (and not include_partial_tail) with clear docstring.
  • Tests: Regression test for partial-tail parity between parse_events and get_cached_events, malformed-tail coverage, byte-offset assertion updates — all meaningful.
  • Docs: Architecture doc updated to reflect actual implementation.
  • CI: All 9 checks green. All 8 review threads resolved.
  • No API contract changes, no new dependencies, no security-sensitive code.

@microsasa microsasa merged commit 3400b28 into main Apr 18, 2026
9 checks passed
@microsasa microsasa deleted the fix/987-parse-events-delegates-to-offset-4cf92f847d6533d5 branch April 18, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow aw-quality-gate-approved Quality gate approved the PR aw-review-response-1 Review response round 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][code health] parse_events diverges from the production code path — test coverage misaligned with actual behavior

2 participants