Commit 6e51874
committed
feat(chutes): sliding window tracking with snapshot + local delta
The 4-hour window is a true sliding window (usage ages out), not a
fixed window with resets. This requires the API to be authoritative
(force=True) so aging is reflected.
Key changes:
- force=True: API values overwrite local state each refresh so that
usage going DOWN (aging) is correctly reflected
- int() → round(): Fix precision loss that truncated sub-cent API
values to 0 (e.g. $0.007 → 0 cents, now correctly rounds to 1)
- Local cost delta: Track per-request costs between API refreshes
in _cost_since_refresh accumulator, added to API baseline on push
- 60s refresh interval (was 300s) for responsiveness
- record_request_cost() hook on provider, called by executor after
calculate_cost() for both streaming and non-streaming paths1 parent bbd0f64 commit 6e51874
4 files changed
Lines changed: 91 additions & 16 deletions
File tree
- src/rotator_library
- client
- providers
- utilities
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
596 | 606 | | |
597 | 607 | | |
598 | 608 | | |
| |||
803 | 813 | | |
804 | 814 | | |
805 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
806 | 819 | | |
807 | 820 | | |
808 | 821 | | |
| |||
811 | 824 | | |
812 | 825 | | |
813 | 826 | | |
| 827 | + | |
814 | 828 | | |
815 | 829 | | |
816 | 830 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
263 | 270 | | |
264 | 271 | | |
265 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
| |||
120 | 125 | | |
121 | 126 | | |
122 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
123 | 151 | | |
124 | 152 | | |
125 | 153 | | |
| |||
281 | 309 | | |
282 | 310 | | |
283 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
284 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
285 | 329 | | |
286 | 330 | | |
287 | 331 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | 332 | | |
292 | 333 | | |
293 | 334 | | |
294 | 335 | | |
295 | 336 | | |
296 | 337 | | |
297 | 338 | | |
298 | | - | |
| 339 | + | |
299 | 340 | | |
300 | 341 | | |
301 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
302 | 347 | | |
303 | 348 | | |
304 | 349 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | 350 | | |
309 | 351 | | |
310 | 352 | | |
| |||
313 | 355 | | |
314 | 356 | | |
315 | 357 | | |
316 | | - | |
| 358 | + | |
317 | 359 | | |
318 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
319 | 364 | | |
320 | 365 | | |
321 | 366 | | |
322 | 367 | | |
323 | 368 | | |
324 | | - | |
| 369 | + | |
| 370 | + | |
325 | 371 | | |
326 | 372 | | |
327 | 373 | | |
| |||
Lines changed: 14 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
379 | | - | |
380 | | - | |
381 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
382 | 387 | | |
383 | | - | |
384 | | - | |
| 388 | + | |
| 389 | + | |
385 | 390 | | |
386 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
387 | 395 | | |
388 | 396 | | |
389 | 397 | | |
| |||
0 commit comments