mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
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:
@@ -455,9 +455,20 @@ pub struct RolloutBudgetConfigToml {
|
||||
pub enforce_limit: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
// TODO: Remove limit_tokens once clients write limit_budget and persisted thread configs have migrated.
|
||||
/// Positive whole-token allowance. Set either limit_tokens or limit_budget.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1))]
|
||||
pub limit_tokens: Option<i64>,
|
||||
/// Positive, finite allowance in budget units. Set either limit_tokens or limit_budget.
|
||||
/// Spending exactly this amount is allowed.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(schema_with = "positive_budget_limit_schema")]
|
||||
pub limit_budget: Option<f64>,
|
||||
/// 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reminder_at_context_start: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Remaining weighted-token values that trigger reminders when crossed.
|
||||
pub reminder_at_remaining_tokens: Option<Vec<i64>>,
|
||||
@@ -469,6 +480,14 @@ pub struct RolloutBudgetConfigToml {
|
||||
pub prefill_token_weight: Option<f64>,
|
||||
}
|
||||
|
||||
fn positive_budget_limit_schema(
|
||||
generator: &mut schemars::r#gen::SchemaGenerator,
|
||||
) -> schemars::schema::Schema {
|
||||
let mut schema = f64::json_schema(generator).into_object();
|
||||
schema.number().exclusive_minimum = Some(0.0);
|
||||
schema.into()
|
||||
}
|
||||
|
||||
impl FeatureConfig for RolloutBudgetConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
|
||||
Reference in New Issue
Block a user