Conversation
…llback (#1182) When summary.start_time is None and events[0].timestamp is None, the renderer now scans all events for the first non-None timestamp using next() instead of only checking events[0]. This prevents the silent data-loss bug where datetime.now(tz=UTC) was used as session_start, causing all past event timestamps to display +0:00. Adds regression test covering the mixed-timestamp case. Closes #1182 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a rendering bug in copilot_usage session detail output where, if SessionSummary.start_time is None and the first event has timestamp=None, the timeline anchor incorrectly fell back to datetime.now(tz=UTC), causing past events’ relative-time deltas to clamp to +0:00.
Changes:
- Update
render_session_detailto scan all events for the first non-Nonetimestamp (vianext(...)) before falling back todatetime.now(tz=UTC). - Add a regression test covering the “first event timestamp is None, later events have timestamps” scenario to ensure
+5:00renders correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/copilot_usage/render_detail.py |
Fixes session_start fallback to use the first available event timestamp (not just events[0]). |
tests/copilot_usage/test_render_detail.py |
Adds regression coverage to confirm relative-time anchoring uses the first non-None event timestamp. |
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 #1182
Problem
In
render_session_detail, whensummary.start_timeisNoneandevents[0].timestampisNone, the fallback wasdatetime.now(tz=UTC). This caused all past event timestamps to display+0:00in the relative-time column — a silent data-loss bug.Fix
Replace the
events[0]-only check withnext()to scan all events for the first non-Nonetimestamp:datetime.now(tz=UTC)remains the final fallback only when no event has a timestamp.Test
Adds
TestRenderSessionDetailFirstNoneTimestampFallbackwith a 3-event scenario:events[0].timestamp = Noneevents[1].timestamp = Tevents[2].timestamp = T + 5minAsserts
+5:00and+0:00appear in the rendered output, confirmingevents[1]anchors the timeline.Warning
The following domains were blocked by the firewall during workflow execution:
astral.shpypi.orgreleaseassets.githubusercontent.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.