Repository navigation
Commit e39ed83
authored
fix(claude): keep the cache TTL split when deduping equal copies (ccusage#2060)
* fix(claude): keep the cache TTL split when deduping equal copies
Both Claude dedup comparators (daily and the session loader) settle a
tie between duplicates with equal token totals, and in daily also equal
cost, by preferring the copy that reports `speed`. Otherwise the first
copy seen survives. When one copy of a message reports the 5m/1h
`cache_creation` split and the other only the flat
`cache_creation_input_tokens`, the split was dropped whenever the flat
copy was read first, so `cacheCreation1hTokens` went missing or was
undercounted in `modelBreakdowns`.
Move the tie-break into one shared `carries_more_usage_detail` helper
that ranks the speed tier first (it changes cost) and the TTL split
second, and use it from both comparators. Sidechain, token-total and
daily cost priorities are unchanged, and inputs without such a pair
produce the same output.
In calculate mode the split copy never costs less than the flat one for
equal tokens, because 1h writes are priced above 5m ones. Daily's cost
comparison therefore already kept it whenever 1h tokens were non-zero.
The session loader does not compare cost and kept the flat copy, so the
same data reported a lower session cost than daily. Preferring the
split resolves that tie in the same direction as the cost order.
* fix(claude): rank Fast above Standard when deduping equal copies
`carries_more_usage_detail` ranked the speed tier with
`speed.is_some()`, the same check the comparators used on main. That
treats `Standard` and `Fast` as equal, so a Standard copy that also
carried the cache TTL split could replace a Fast copy, or a Standard
copy seen first could survive a later Fast one. Only `Fast` carries the
fast-mode price multiplier, so the session loader (which does not
compare cost) could undercount the request's cost.
Rank the tiers explicitly as None < Standard < Fast, before the TTL
split tie-break.
Reported by Cubic on ccusage#2060.
* test(claude): cover the TTL split of equal duplicates in CLI JSON
Assert `cacheCreation1hTokens` and `totalCost` for `claude daily` and
`claude session` in calculate mode when one copy of a message carries
the 5m/1h split and the other does not, in both orders. On main, daily
already kept the split through its cost comparison while session kept
the unsplit copy, so session reported no 1h tokens and a lower cost.
Requested by Cubic on ccusage#2060.1 parent c17c591 commit e39ed83
3 files changed
Lines changed: 161 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
655 | | - | |
| 655 | + | |
656 | 656 | | |
657 | 657 | | |
658 | 658 | | |
| |||
992 | 992 | | |
993 | 993 | | |
994 | 994 | | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
995 | 1029 | | |
996 | 1030 | | |
997 | 1031 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
298 | 314 | | |
299 | 315 | | |
300 | 316 | | |
| |||
990 | 1006 | | |
991 | 1007 | | |
992 | 1008 | | |
993 | | - | |
| 1009 | + | |
| 1010 | + | |
994 | 1011 | | |
995 | 1012 | | |
996 | 1013 | | |
| |||
1347 | 1364 | | |
1348 | 1365 | | |
1349 | 1366 | | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
1350 | 1438 | | |
1351 | 1439 | | |
1352 | 1440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1127 | 1127 | | |
1128 | 1128 | | |
1129 | 1129 | | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
0 commit comments