Add host-owned turn admission to the agent runtime (#58963)

## What changed

Add `AgentRuntimeOwnership::Host` and an `AgentTurnAdmission` provider so hosts can acquire execution capacity before runtime tasks run, including root turns. Require the provider at startup and retain its execution guard for the task lifetime. Controller ownership remains the default; host ownership skips controller rollout-budget accounting, budget reminders, and subagent roster context.

Keep pending admission interruptible without blocking input submission. Report admission failures through the turn lifecycle, record accepted input before exposing the error, and unwind task setup such as review mode. Preserve recoverable input during suspension. On interruption, skip prompts that still require a `UserPromptSubmit` hook rather than recording them without inspection.

## Testing

Add integration tests for missing-provider startup cleanup, denial and immediate retry, steering during admission, cancellation, execution guard lifetime, submit-hook handling, suspension recovery, and review-mode cleanup. Add a context snapshot verifying retained input reaches the next admitted turn.

GitOrigin-RevId: 9ee85fad2ecfbfb38735bac8ef88888fb179a967
This commit is contained in:
rhan-oai
2026-11-02 20:10:37 +00:00
committed by copyberry
parent 9ede2e87ce
commit d893b14475
25 changed files with 822 additions and 98 deletions
+4
View File
@@ -1408,6 +1408,10 @@ impl CodexThread {
&self,
control: &dyn AgentControl,
) -> CodexResult<()> {
// The host checks and reserves capacity when the task starts.
if self.session.host_turn_admission().is_some() {
return Ok(());
}
if self.session.active_turn.lock().await.is_some() {
return Ok(());
}