fix(parser): range-filter calls inside turns instead of dropping day-spanning turns - #853
Open
KENSHI601 wants to merge 2 commits into
Open
fix(parser): range-filter calls inside turns instead of dropping day-spanning turns#853KENSHI601 wants to merge 2 commits into
KENSHI601 wants to merge 2 commits into
Conversation
…spanning turns parseProviderSources keyed the dateRange check on a turn's first call timestamp, so a long autonomous turn starting before midnight was excluded from the next day's view entirely and every post-midnight call in it was lost. Filter calls inside the turn instead and keep the turn when any call falls in range. Fixes getagentseal#852
Extends the per-call range filter so multi-day periods stop losing usage (review on getagentseal#857): - Re-anchor a sliced turn's timestamp to its first surviving call in parseProviderSources, so every turn slicer shares one split rule. - scanProjectDirs (Claude Code path): slice per call instead of dropping the whole turn on its first assistant timestamp; category/ subCategory/retries/hasEdits stay classified from the full turn. - aggregateProjectsIntoDays: bucket cost/calls/tokens (and the model, project, provider-slice rollups built from them) under each call's own day; turn-level stats (categories, editTurns, oneShotTurns) stay turn-anchored. This is the conservation fix: cache (<= yesterday) + live (today) unions now sum to the whole range for straddling turns. - buildJsonReport's dailyMap fallback follows the same per-call rule so the no-durable path can't diverge from durable.days. - filterProjectsByDateRange (dashboard) and filterProjectsByDays (menubar/history) slice per call instead of dropping whole turns. Adds the straddling-turn buildDurablePeriod case to the durable-totals parity suite (day-N + day-N+1 == whole-range calls/cost/tokens, verified to fail without the fix), covers the today view and the surface filters, and makes the suite hermetic on machines with real provider data.
Author
|
@iamtoruk Thanks for the thorough review on #857 — this update (7591e68) lands the conservation-correct version here, point by point:
Verification: |
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.
Fixes #852.
Bug:
parseProviderSourcesrange-filtered turns by the turn's first call timestamp (turn.calls[0]?.timestamp). A long autonomous turn that starts before midnight (e.g. a 30h Codex run) was therefore dropped wholesale from the next day's view —today/ single-day exports lost every post-midnight call in the turn.Fix: filter calls inside the turn against the range instead. A turn is skipped only when none of its calls fall in range; otherwise it is kept with just the in-range calls, and downstream derivation (classified turn, project, sessionId, projectPath) uses the filtered turn. Applied to both identical filter blocks (served-sources loop and durable-orphans loop) in
src/parser.ts.Tests:
tests/provider-turn-grouping.test.ts: a synthetic Codex rollout whose single turn hastoken_countevents straddling midnight; querying the next day's range now keeps the turn with only the post-midnight call. Verified the test fails without the fix and passes with it.tsc --noEmitandtsupbuild are green; parser-related suites (parser, session-cache, codex, date-range, export, durable-totals) pass. Full suite diffed againstmain: identical failure sets (pre-existing Windows-environment issues — missing jsdom, 5s-timeout flakes,os.homedir()fixtures), no new failures.