Repository navigation
Commit 73f6808
fix(fetcher/claude_code_usage): address coderabbit review findings
Three nits surfaced by the bot review:
1. `Since::Days(n).includes()` was a rolling `now - n days` timestamp cutoff
while `daily_series` bucketed by calendar day. Near the n-day boundary,
partial-day events were counted in the totals but never appeared in the
per-day series. Swap to a calendar-day comparison (`today .. today-(n-1)`)
so both views agree on the window.
2. Dropped the brittle `line.contains("\"type\":\"assistant\"")` pre-filter.
`parse_event` already gates on `raw.kind == "assistant"` — the substring
guard was only a perf hack and would silently miss records if Claude
Code's JSONL formatter ever emitted `"type": "assistant"` with whitespace.
Cost is ~5% more parsing per refresh, absorbed by the 5-min cache TTL.
3. Empty-ID dedup collision: serde fills missing `message.id` / `requestId`
with `""`, so two unrelated assistant turns lacking those fields collapsed
into a single `("", "")` bucket and one would be discarded. Records with
either ID missing now pass through unmodified instead.
Two new tests pin the new invariants:
- `since_days_window_uses_calendar_day_boundary_not_rolling_timestamp`
- `dedup_passes_through_events_with_empty_ids_instead_of_collapsing_them`
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 59e3fdc commit 73f6808
1 file changed
Lines changed: 64 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
147 | 155 | | |
148 | 156 | | |
149 | 157 | | |
| |||
273 | 281 | | |
274 | 282 | | |
275 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
276 | 287 | | |
277 | 288 | | |
278 | 289 | | |
279 | | - | |
280 | 290 | | |
281 | 291 | | |
282 | 292 | | |
| |||
359 | 369 | | |
360 | 370 | | |
361 | 371 | | |
| 372 | + | |
362 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
363 | 381 | | |
364 | 382 | | |
365 | 383 | | |
| |||
372 | 390 | | |
373 | 391 | | |
374 | 392 | | |
375 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
376 | 396 | | |
377 | 397 | | |
378 | 398 | | |
| |||
755 | 775 | | |
756 | 776 | | |
757 | 777 | | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
758 | 819 | | |
759 | 820 | | |
760 | 821 | | |
| |||
0 commit comments