Skip to content

fix: scan all events for first non-None timestamp in session_start fallback (#1182)#1184

Open
microsasa wants to merge 1 commit intomainfrom
fix/session-start-fallback-scan-all-events-1182-372fca57f2a941a1
Open

fix: scan all events for first non-None timestamp in session_start fallback (#1182)#1184
microsasa wants to merge 1 commit intomainfrom
fix/session-start-fallback-scan-all-events-1182-372fca57f2a941a1

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #1182

Problem

In render_session_detail, when summary.start_time is None and events[0].timestamp is None, the fallback was datetime.now(tz=UTC). This caused all past event timestamps to display +0:00 in the relative-time column — a silent data-loss bug.

Fix

Replace the events[0]-only check with next() to scan all events for the first non-None timestamp:

session_start = (
    ensure_aware(summary.start_time)
    if summary.start_time is not None
    else next(
        (ensure_aware(ev.timestamp) for ev in events if ev.timestamp is not None),
        datetime.now(tz=UTC),
    )
)

datetime.now(tz=UTC) remains the final fallback only when no event has a timestamp.

Test

Adds TestRenderSessionDetailFirstNoneTimestampFallback with a 3-event scenario:

  • events[0].timestamp = None
  • events[1].timestamp = T
  • events[2].timestamp = T + 5min

Asserts +5:00 and +0:00 appear in the rendered output, confirming events[1] anchors the timeline.

Warning

⚠️ Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • astral.sh
  • pypi.org
  • releaseassets.githubusercontent.com

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

network:
  allowed:
    - defaults
    - "astral.sh"
    - "pypi.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Issue Implementer · ● 9.5M ·

…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>
@microsasa microsasa added the aw Created by agentic workflow label May 4, 2026
Copilot AI review requested due to automatic review settings May 4, 2026 11:28
@microsasa microsasa enabled auto-merge May 4, 2026 11:28
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

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_detail to scan all events for the first non-None timestamp (via next(...)) before falling back to datetime.now(tz=UTC).
  • Add a regression test covering the “first event timestamp is None, later events have timestamps” scenario to ensure +5:00 renders 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow

Projects

None yet

2 participants