Files
codex/codex-rs/core/src/session/rollout_budget.rs
T
jif 27969c0ae9 Route session agent operations through AgentControl (#47520)
## What changed

- Store `Arc<dyn AgentControl>` in session services and route agent tools, turn admission, usage accounting, completion notifications, and shared settings through the trait.
- Add `AgentControlInit` so delegated and guardian sessions inherit the parent's controller and local runtime.
- Move local registry and context helpers to `LocalAgentRuntime`, keep resume, close, inspection, and status subscriptions on the local controller, and simplify synchronous and infallible trait methods.

GitOrigin-RevId: ad3f213eb483ac524bde56d769f20a78f20989a0
2026-09-23 09:39:30 +00:00

41 lines
1.2 KiB
Rust

use super::session::Session;
use super::turn_context::TurnContext;
use crate::context::ContextualUserFragment;
use codex_protocol::error::Result as CodexResult;
use codex_protocol::protocol::TokenUsage;
pub(super) async fn maybe_record_reminder(
sess: &Session,
turn_context: &TurnContext,
window_id: &str,
) {
let agent_control = &sess.services.agent_control;
let Some(reminder) = agent_control
.pending_budget_reminder(sess.thread_id(), window_id)
.await
else {
return;
};
let response_item = ContextualUserFragment::into(crate::context::RolloutBudgetContext {
remaining_tokens: reminder.remaining_tokens,
});
sess.record_conversation_items(
turn_context,
turn_context.model_info(),
std::slice::from_ref(&response_item),
)
.await;
agent_control
.mark_budget_reminder_delivered(sess.thread_id(), window_id, reminder)
.await;
}
impl Session {
pub(crate) async fn record_rollout_budget_usage(&self, usage: &TokenUsage) -> CodexResult<()> {
self.services
.agent_control
.record_usage(usage.clone())
.await
}
}