Repository navigation
fix(parser): stop --provider filters from re-surfacing cached claude sessions - #872
Conversation
…sessions Claude is scanned via scanProjectDirs instead of parseProviderSources, and that call had no provider-filter guard. On a --provider <other> run discoverAllSessions correctly returns no claude sources, so claudeDirs is empty, but scanProjectDirs still ran: its orphan pass reads the whole cached claude section and treats every file as no-longer-discovered, re-injecting PR-bearing entries (and in read-only mode every cached entry) into the result. The headline stayed correct because it comes from the provider-sliced daily cache, so only the live-parse panels were wrong. By Model then listed Anthropic models under --provider cursor while the total showed cursor alone. Guard the scan with claudeInScope, mirroring the guard the durable-orphan loop already applies. Deliberately not a claudeDirs.length check: when claude is in scope but every transcript has been pruned, the orphan pass is what keeps PR-attributed spend from vanishing.
iamtoruk
left a comment
There was a problem hiding this comment.
Verified and clean. This fixes a real cross-panel money leak: under --provider <other>, scanProjectDirs's orphan pass re-injected the whole cached Claude section into By Model / By Project / By Activity ($2,038 leaked vs $3.79 correct in your repro), worst in readOnly mode where the prLinks gate is bypassed.
The claudeInScope guard is the right fix — gated on provider scope, not claudeDirs.length, so it preserves the never-lose-history invariant (a PR-bearing claude orphan with pruned transcripts still surfaces under --provider all/--provider claude). Mutation-checked: the leak test fails without the guard and passes with it; the invariant test passes both ways.
An adversarial pass came back clean across all five vectors I care about here: the claude session cache is byte-identical after a filtered run (no corruption/eviction), --provider claude with pruned transcripts still preserves the orphan, no dangling progress event (claudeSources is non-empty only when claude is in scope), provider-name matching agrees across assertProvider/discovery/guard, and both readOnly states hold. Full suite green apart from the two pre-existing parser.test.ts failures that reproduce on main. Good to merge.
…he all-provider view buildDurablePeriod derived the today slice of the multi-day, all-provider headline from the unsliced whole-range parse, so a turn spanning local midnight kept its category and turn count anchored on its yesterday start. The per-call cost and calls bucketed onto today correctly, but By Activity and the JSON daily turn count lost the post-midnight half — categories summed to only the pre-midnight cost while the headline, By Model and By Project were right. Slice the today parse with filterProjectsByDays first, which re-anchors the straddling turn to its surviving today calls, so today's category cost lands on today. Category cost is the sum of the slice's own calls, so day-N + day-N+1 still equals the whole-range total (no over-count); the per-day turn-count split matches the cache side and the documented per-day semantics. Adds a regression test in the straddling-turn conservation suite (mutation-checked: fails on the pre-fix code). Also fills in the CHANGELOG Unreleased entries for the batch (#853, #856, #872, #846/#859, #866/#867, #833).
Fixes #871
The bug
--provider <x>filters the headline but not the live-parse panels, soBy Modellists Anthropic models under--provider cursorwhile the total above it shows cursor alone.Why
Claude is scanned through
scanProjectDirsrather thanparseProviderSources, and that call had no provider-filter guard. On a--provider <other>rundiscoverAllSessionscorrectly returns no claude sources, soclaudeDirsis empty, butscanProjectDirsstill ran. Its orphan pass reads the whole cached claude section and, withallDiscoveredFilesempty, treats every cached file as no longer discovered, re-injecting PR-bearing entries into the result. In read-only mode (cache refresh lock unavailable, which is the normal state while the menubar app is running) theprLinksgate is bypassed and every cached claude file is re-injected.Every other provider already has this guard in the durable-orphan loop a few dozen lines below:
The fix
One guard on the claude scan, mirroring the one above.
This is deliberately not a
claudeDirs.length > 0check. When claude is in scope but every transcript has been pruned from disk, that orphan pass is exactly what keeps PR-attributed spend from vanishing, so gating on an empty dirs list would silently break the never-lose-history invariant. Gating on provider scope keeps both behaviours correct. The second test below locks that distinction in.Nothing changes for
--provider allor--provider claude. The paired eviction block already had adirs.length > 0guard, so no cache entries were ever wrongly deleted and none are now.Verification against real data
report -p all --provider cursor, same machine, before and after:overview.costprojectssummedmodelssummedmodelslistedprojectslisted--provider allbefore and after: identical model set, 489 projects in both, no rows dropped.--provider claudeafter the fix: no cursor-only models present.The residual
3.79vs2.63delta is the pre-existing durable-versus-live difference, not part of this bug. It is one cached day (2026-07-26, €1.16) that the cache retains and the live parse can no longer reproduce because the Cursor SQLite store rotated. That is the never-lose-history invariant working as intended, and it is the same effect #865 documented in its unfiltered control.Tests
Two new cases in
tests/parser.test.ts, using the existingtest-syntheticprovider harness:does not surface cached claude sessions when filtering to another providerseeds a claude transcript carrying apr-link, warms the cache with aprovider: allparse, then parses again filtered to the synthetic provider and asserts the result contains only that provider. It is self-calibrating on cost, since the pricing engine re-derives cost from tokens. Without the fix it fails withexpected [ 'claude', 'test-synthetic' ] to deeply equal [ 'test-synthetic' ].still preserves a PR-bearing claude orphan when claude IS in scopedeletes the transcript and reparses unfiltered, asserting the total holds. This is the case a naive dirs-length guard would break.Full suite: 2542 passing. Two failures in
tests/parser.test.ts((a) copilot JSONL file-purge monotonic,(f) durable orphans survive a parse-version bump) reproduce identically on unmodifiedmainin my environment, both failing on their first parse withexpected +0 to be 200, so they look environmental here rather than related to this change.tsc --noEmitis clean.