Commit b4f479b
committed
fix(ccr): scope the continuation-usage fold to the cost view
The fold added the dropped CCR continuation rounds onto the RequestOutcome, but
three consumers of the outcome funnel are not cost surfaces:
- metrics.record_request forwards cache_read_tokens to SavingsTracker, which
credits it as cache *savings* (cache_savings_usd -> SavingsSnapshot
.total_savings and `headroom doctor`), so retrieval overhead RAISED the
reported savings: 80k continuation cache reads on a 1k-read turn moved
cache_savings_usd from $0.0027 to $0.2187 in a synthetic check.
- the output-shaper counterfactual reads outcome.output_tokens as this turn's
completion length; folded continuation output biased the per-arm estimate
(the recorder saw 1180 tokens for an 80-token turn).
- the RequestLog row and the PERF line describe the single round the client
received.
Move the fold to the cost_tracker.record_tokens call, which is where the billed
input breakdown behind cost_with_headroom_usd lands and where _costs is appended
for budget enforcement. Cost accounting keeps the original fix's intent; the
savings, log and PERF surfaces stay on the final round.
Also:
- clear both pending side channels in the caller's context after the shielded
emit. asyncio.shield runs the funnel in a child task with a copied context, so
its consume_* cleared the copy, and a second outcome emitted from the same
context re-booked the same continuation usage and proactive drawback.
- keep the original_tokens floor on the Responses-path usage recompute. Falling
to 0 priced that round's input at nothing, because the folded continuation
tokens keep record_tokens' "no breakdown -> use tokens_sent" fallback from
firing.
- cover the Responses recompute end-to-end (initial round 50/10, final 60/5) and
pin each non-cost surface against re-folding.1 parent 086d7c8 commit b4f479b
6 files changed
Lines changed: 295 additions & 80 deletions
File tree
- headroom/proxy
- handlers
- tests
- test_proxy
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
683 | 686 | | |
684 | 687 | | |
685 | 688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5255 | 5255 | | |
5256 | 5256 | | |
5257 | 5257 | | |
5258 | | - | |
5259 | | - | |
5260 | | - | |
| 5258 | + | |
| 5259 | + | |
| 5260 | + | |
| 5261 | + | |
| 5262 | + | |
| 5263 | + | |
| 5264 | + | |
| 5265 | + | |
| 5266 | + | |
| 5267 | + | |
5261 | 5268 | | |
5262 | 5269 | | |
5263 | | - | |
| 5270 | + | |
| 5271 | + | |
| 5272 | + | |
| 5273 | + | |
5264 | 5274 | | |
5265 | 5275 | | |
5266 | 5276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
88 | 103 | | |
89 | 104 | | |
90 | 105 | | |
| |||
391 | 406 | | |
392 | 407 | | |
393 | 408 | | |
394 | | - | |
395 | | - | |
396 | 409 | | |
397 | 410 | | |
398 | 411 | | |
| |||
417 | 430 | | |
418 | 431 | | |
419 | 432 | | |
420 | | - | |
| 433 | + | |
421 | 434 | | |
422 | 435 | | |
423 | 436 | | |
| |||
440 | 453 | | |
441 | 454 | | |
442 | 455 | | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
461 | 478 | | |
462 | 479 | | |
463 | 480 | | |
| |||
513 | 530 | | |
514 | 531 | | |
515 | 532 | | |
516 | | - | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
517 | 538 | | |
518 | 539 | | |
519 | 540 | | |
520 | 541 | | |
521 | 542 | | |
522 | 543 | | |
523 | | - | |
524 | | - | |
| 544 | + | |
| 545 | + | |
525 | 546 | | |
526 | 547 | | |
527 | | - | |
528 | | - | |
| 548 | + | |
| 549 | + | |
529 | 550 | | |
530 | 551 | | |
531 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1940 | 1940 | | |
1941 | 1941 | | |
1942 | 1942 | | |
1943 | | - | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
1944 | 1947 | | |
1945 | 1948 | | |
1946 | 1949 | | |
| |||
1953 | 1956 | | |
1954 | 1957 | | |
1955 | 1958 | | |
1956 | | - | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
1957 | 1967 | | |
1958 | 1968 | | |
1959 | 1969 | | |
| |||
0 commit comments