mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Reject overflowing rollout budget charges before posting (#62559)
## Why An overflowing hook total could send a partial charge to the host, and an overflow in native accounting could leave the posted balance infinite. ## What changed Reject overflowing hook totals before reporting usage. Check both the combined provider and hook charge and the cumulative rollout balance before posting, preserving the previous balance on overflow. Native budgets with limit enforcement enabled still stop new work on overflow. ## Testing Update the hook overflow integration case to verify that the response's tool is blocked and the host receives no usage report. GitOrigin-RevId: 2ac80a6aa1d857924a8807df7bb70c6b7c107cd2
This commit is contained in:
@@ -151,14 +151,27 @@ impl Session {
|
||||
usage: Option<&TokenUsage>,
|
||||
hook_charge: codex_hooks::HookCharge,
|
||||
) -> CodexResult<()> {
|
||||
if usage.is_none() && hook_charge == codex_hooks::HookCharge::default() {
|
||||
let hook_units = match hook_charge {
|
||||
codex_hooks::HookCharge::Units(units) => units,
|
||||
codex_hooks::HookCharge::Overflow => {
|
||||
if let Some(account) = self.native_rollout_budget()
|
||||
&& account.config().is_some_and(|config| config.enforce_limit)
|
||||
{
|
||||
account.stop_on_overflow();
|
||||
}
|
||||
return Err(CodexErr::UsageAccountingFailed(
|
||||
"responseChargeAmount: total hook cost exceeds f64 range".into(),
|
||||
));
|
||||
}
|
||||
};
|
||||
if usage.is_none() && hook_units == 0.0 {
|
||||
return Ok(());
|
||||
}
|
||||
let stop_new_work = match &self.agent_runtime {
|
||||
AgentRuntimeServices::Controller => match self
|
||||
.services
|
||||
.agent_control
|
||||
.record_usage(usage.cloned(), hook_charge)
|
||||
.record_usage(usage.cloned(), hook_units)
|
||||
.await
|
||||
{
|
||||
Ok(()) => false,
|
||||
@@ -180,8 +193,7 @@ impl Session {
|
||||
thread_id: self.thread_id(),
|
||||
turn_id: turn_id.to_owned(),
|
||||
usage: usage.cloned(),
|
||||
additional_budget_units: hook_charge.units,
|
||||
additional_budget_units_overflowed: hook_charge.overflowed,
|
||||
additional_budget_units: hook_units,
|
||||
})
|
||||
.await
|
||||
.map_err(|error| {
|
||||
|
||||
Reference in New Issue
Block a user