Skip to content

fix: convert VS Code log timestamps to aware UTC datetimes (#993)#995

Merged
microsasa merged 2 commits intomainfrom
fix/vscode-naive-timestamps-993-91dcd72e52e70ece
Apr 19, 2026
Merged

fix: convert VS Code log timestamps to aware UTC datetimes (#993)#995
microsasa merged 2 commits intomainfrom
fix/vscode-naive-timestamps-993-91dcd72e52e70ece

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #993

Problem

_parse_vscode_log_from_offset parsed timestamps with datetime.fromisoformat(ts_str), producing naive datetimes (no tzinfo). The rest of the codebase uses aware UTC datetimes throughout, so mixing these would raise TypeError: can't compare offset-naive and offset-aware datetimes.

Fix

In vscode_parser.py:

  • Import UTC from datetime
  • Replace datetime.fromisoformat(ts_str) with datetime.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:

  1. test_parsed_request_timestamp_is_aware — parsed request has tzinfo
  2. test_vscode_summary_timestamps_are_aware — summary first_timestamp/last_timestamp have tzinfo
  3. test_vscode_timestamps_comparable_with_session_timestamps — no TypeError when comparing with aware datetimes

All existing tests continue to pass (99% coverage).

Generated by Issue Implementer · ● 6.7M ·

_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>
@microsasa microsasa added the aw Created by agentic workflow label Apr 19, 2026
Copilot AI review requested due to automatic review settings April 19, 2026 05:30
@microsasa microsasa enabled auto-merge April 19, 2026 05:30
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 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 datetime to aware UTC datetime during 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.

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

Commit pushed: bf1c638

Generated by Review Responder

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>
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 2 out of 2 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 19, 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: APPROVED

Low-impact bug fix with good coverage. Auto-approving for merge.

What was evaluated:

  • Production change: 2-line fix in vscode_parser.py — adds UTC import and converts datetime.fromisoformat(ts_str).astimezone(UTC) to produce aware datetimes, matching the codebase convention.
  • Tests: 3 new tests in TestParsedTimestampsAreAware verify request timestamps are aware, summary timestamps are aware, and parsed timestamps are comparable with other aware datetimes without TypeError.
  • 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.

@microsasa microsasa merged commit 467c72d into main Apr 19, 2026
9 checks passed
@microsasa microsasa deleted the fix/vscode-naive-timestamps-993-91dcd72e52e70ece branch April 19, 2026 05:45
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][code health] VS Code log timestamps are naive (no tzinfo), diverging from the codebase's aware-datetime convention

2 participants