Skip to content

fix(stats): filter messages by creation time when --days is set#21933

Open
extrasmall0 wants to merge 1 commit intoanomalyco:devfrom
extrasmall0:fix/stats-days-message-time-filter
Open

fix(stats): filter messages by creation time when --days is set#21933
extrasmall0 wants to merge 1 commit intoanomalyco:devfrom
extrasmall0:fix/stats-days-message-time-filter

Conversation

@extrasmall0
Copy link
Copy Markdown

@extrasmall0 extrasmall0 commented Apr 10, 2026

Issue for this PR

Closes #21920

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

opencode stats --days=N filters sessions by their time.updated timestamp, but when computing costs and token counts it considers all messages in those sessions — including messages created weeks or months before the window.

Root cause: in aggregateSessionStats, the cutoff is applied to sessions but not to their messages. Every message in the session is accumulated unconditionally.

Fix: after fetching messages for a session, filter them to only include messages whose time.created >= cutoffTime before accumulating stats. One extra filter step per session batch, no change to the session-level filter or the no---days path (cutoffTime === 0).

How did you verify your code works?

Verified that Message.Info has a time.created: number field. The change is confined to a single file and does not affect the no---days path.

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The --days flag filtered sessions by their last-updated timestamp but
still counted all messages in those sessions when computing costs and
tokens. A session updated within the window could contain messages from
weeks earlier, inflating the reported totals.

Fix: after fetching messages for a session, filter them to only include
messages whose time.created falls within the cutoff window before
accumulating stats.

Fixes anomalyco#21920
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 10, 2026
@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: opencode stats --days=X command incorrectly considers messages outside the time window defined by X

1 participant