fix(stats): filter messages by creation time when --days is set#21933
Open
extrasmall0 wants to merge 1 commit intoanomalyco:devfrom
Open
fix(stats): filter messages by creation time when --days is set#21933extrasmall0 wants to merge 1 commit intoanomalyco:devfrom
extrasmall0 wants to merge 1 commit intoanomalyco:devfrom
Conversation
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
6 tasks
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #21920
Type of change
What does this PR do?
opencode stats --days=Nfilters sessions by theirtime.updatedtimestamp, 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 >= cutoffTimebefore accumulating stats. One extra filter step per session batch, no change to the session-level filter or the no---dayspath (cutoffTime === 0).How did you verify your code works?
Verified that
Message.Infohas atime.created: numberfield. The change is confined to a single file and does not affect the no---dayspath.Screenshots / recordings
N/A — not a UI change.
Checklist