Add configurable goal token budget limits (#37878)

## What changed

- Add `goals.max_goal_token_budget` as a positive-integer configuration setting.
- Use the configured maximum as the default budget for new goals and when `tokenBudget` is reset to `null`.
- Reject goal creation and updates whose token budget exceeds the configured maximum, including requests through goal tools and `thread/goal/set`.
- Respect managed configuration precedence and per-thread configuration overrides.

## Testing

- Cover configuration parsing and managed overrides.
- Cover defaulting, resetting, and rejecting oversized budgets through the goal service, goal tools, and app-server API.

GitOrigin-RevId: f8d7e6418cdc237d454c8cf47bb32ba0d44a60cf
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-10 21:00:00 +00:00
1 parent a603d7ca5c
commit a9dee37f9c
14 files changed
+391 -26

No files matched your search

+7 -3
View File
@@ -54,6 +54,7 @@ pub struct GoalSetRequest<'a> {
pub objective: GoalObjectiveUpdate<'a>,
pub status: Option<ThreadGoalStatus>,
pub token_budget: GoalTokenBudgetUpdate,
pub max_goal_token_budget: Option<i64>,
}
#[derive(Clone, Debug)]
@@ -150,6 +151,7 @@ impl GoalService {
objective,
status,
token_budget,
max_goal_token_budget,
} = request;
let status = status.map(state_status_from_protocol);
let objective = match objective {
@@ -158,14 +160,16 @@ impl GoalService {
};
let token_budget = match token_budget {
GoalTokenBudgetUpdate::Keep => None,
GoalTokenBudgetUpdate::Set(token_budget) => Some(token_budget),
GoalTokenBudgetUpdate::Set(token_budget) => {
Some(token_budget.or(max_goal_token_budget))
}
};
if let Some(objective) = objective {
validate_thread_goal_objective(objective).map_err(GoalServiceError::InvalidRequest)?;
}
if objective.is_some() || token_budget.is_some() {
validate_goal_budget(token_budget.flatten())
validate_goal_budget(token_budget.flatten(), max_goal_token_budget)
.map_err(GoalServiceError::InvalidRequest)?;
}
@@ -225,7 +229,7 @@ impl GoalService {
thread_id,
objective,
status.unwrap_or(codex_state::ThreadGoalStatus::Active),
token_budget.flatten(),
token_budget.flatten().or(max_goal_token_budget),
)
.await
.map_err(|err| {