Conversation
_parse_vscode_log_from_offset now calls .astimezone(UTC) on parsed timestamps so VSCodeRequest.timestamp, VSCodeLogSummary.first_timestamp, and VSCodeLogSummary.last_timestamp are timezone-aware, consistent with the rest of the codebase. Add tests verifying parsed timestamps are aware and comparable with session-level aware datetimes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a datetime consistency bug in the VS Code Copilot Chat log parser by converting parsed timestamps into timezone-aware UTC datetimes, aligning the VS Code subsystem with the rest of copilot_usage’s aware-UTC datetime convention.
Changes:
- Convert VS Code log timestamps from naive
datetimeto aware UTCdatetimeduring parsing. - Add tests asserting parsed timestamps are timezone-aware and comparable with other aware datetimes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/copilot_usage/vscode_parser.py |
Parses VS Code log timestamps as aware UTC datetimes to avoid naive/aware comparison errors. |
tests/copilot_usage/test_vscode_parser.py |
Adds regression tests for awareness/comparability of parsed VS Code timestamps. |
Contributor
|
Commit pushed:
|
Strengthen timezone assertions in TestParsedTimestampsAreAware from `tzinfo is not None` to `tzinfo == UTC` to lock in the UTC contract and catch regressions. Updated docstring to say 'aware UTC timestamps'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Quality Gate: APPROVED ✅
Low-impact bug fix with good coverage. Auto-approving for merge.
What was evaluated:
- Production change: 2-line fix in
vscode_parser.py— addsUTCimport and convertsdatetime.fromisoformat(ts_str)→.astimezone(UTC)to produce aware datetimes, matching the codebase convention. - Tests: 3 new tests in
TestParsedTimestampsAreAwareverify request timestamps are aware, summary timestamps are aware, and parsed timestamps are comparable with other aware datetimes withoutTypeError. - CI: All 9 checks passed (lint, typecheck, security, tests, CodeQL, coverage).
- Guidelines compliance: Follows coding guidelines — proper imports, type annotations, pytest patterns, no banned constructs.
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.
Closes #993
Problem
_parse_vscode_log_from_offsetparsed timestamps withdatetime.fromisoformat(ts_str), producing naive datetimes (notzinfo). The rest of the codebase uses aware UTC datetimes throughout, so mixing these would raiseTypeError: can't compare offset-naive and offset-aware datetimes.Fix
In
vscode_parser.py:UTCfromdatetimedatetime.fromisoformat(ts_str)withdatetime.fromisoformat(ts_str).astimezone(UTC)This converts local-time log timestamps to aware UTC datetimes at parse time, matching the codebase convention.
Tests added
Three new tests in
TestParsedTimestampsAreAware:test_parsed_request_timestamp_is_aware— parsed request hastzinfotest_vscode_summary_timestamps_are_aware— summaryfirst_timestamp/last_timestamphavetzinfotest_vscode_timestamps_comparable_with_session_timestamps— noTypeErrorwhen comparing with aware datetimesAll existing tests continue to pass (99% coverage).