Support fractional rollout budgets and configurable context reminders (#61579)

## What changed

- Add a positive, finite `features.rollout_budget.limit_budget` allowance while retaining `limit_tokens` compatibility. Reject configurations that specify both.
- Preserve fractional balances in reminders and compare thresholds without rounding the balance down.
- Accumulate charges with compensated summation and allow spending exactly the allowance, including floating-point rounding tolerance for cases such as `0.1 + 0.2` against `0.3`.
- Add `reminder_at_context_start`, defaulting to `true`. Set it to `false` to suppress reminders at thread start and after compaction; combine it with an empty threshold list to disable budget reminders entirely.

## Testing

Extend configuration and rollout-budget tests to cover fractional allowances, legacy integer persistence, invalid limits, threshold-only reminders, and enforcement at decimal equality and after overspending.

GitOrigin-RevId: b8e7a2faa8d39e562bcae196364de419698bc67d
This commit is contained in:
tongzhou wang
2026-11-14 23:53:23 +00:00
committed by copyberry
parent f226c9ccfb
commit c8e4cbcd94
17 changed files with 279 additions and 93 deletions
+11
View File
@@ -4815,7 +4815,14 @@
"description": "Stop when the shared budget is exhausted. Defaults to true.",
"type": "boolean"
},
"limit_budget": {
"description": "Positive, finite allowance in budget units. Set either limit_tokens or limit_budget. Spending exactly this amount is allowed.",
"exclusiveMinimum": 0.0,
"format": "double",
"type": "number"
},
"limit_tokens": {
"description": "Positive whole-token allowance. Set either limit_tokens or limit_budget.",
"format": "int64",
"minimum": 1.0,
"type": "integer"
@@ -4825,6 +4832,10 @@
"minimum": 0.0,
"type": "number"
},
"reminder_at_context_start": {
"description": "Restate the balance when a thread starts or its context is compacted. Defaults to true. Set false with an empty threshold list for no budget reminders.",
"type": "boolean"
},
"reminder_at_remaining_tokens": {
"description": "Remaining weighted-token values that trigger reminders when crossed.",
"items": {