Allow hosts to provide agent controllers through ThreadManager (#47808)

## What changed

- Add `ThreadManager::with_agent_control_factory` to select a host-owned controller asynchronously using the final thread ID for new and cold-resumed threads. Keep local control as the default, reuse live controllers on warm resume, and preserve parent controllers for internal sessions.
- Fail startup on factory errors or when a provided controller's identity does not match the session identity.
- Defer root service-tier updates to host controllers until thread registration succeeds, preventing failed starts from changing settings on a shared controller.

GitOrigin-RevId: 095afbecfee5d47329038d2a97d0cc0081f181df
This commit is contained in:
jif
2026-09-24 10:39:10 +00:00
committed by copyberry
parent c098f97e53
commit fdbe23da45
6 changed files with 97 additions and 23 deletions
+5 -5
View File
@@ -70,12 +70,12 @@ impl LocalAgentRuntime {
}
}
/// Local construction binds identity after reading history; internal children inherit
/// an already-bound controller without selecting a backend again.
/// Local construction binds identity after reading history. Hosts and internal children
/// provide an already-bound controller without selecting a backend again.
#[derive(Clone)]
pub(crate) enum AgentControlInit {
Local(LocalAgentControl),
Inherited {
Provided {
control: Arc<dyn AgentControl>,
runtime: LocalAgentRuntime,
},
@@ -91,14 +91,14 @@ impl AgentControlInit {
pub(crate) fn runtime(&self) -> &LocalAgentRuntime {
match self {
Self::Local(control) => &control.runtime,
Self::Inherited { runtime, .. } => runtime,
Self::Provided { runtime, .. } => runtime,
}
}
pub(crate) fn control(&self) -> &dyn AgentControl {
match self {
Self::Local(control) => control,
Self::Inherited { control, .. } => control.as_ref(),
Self::Provided { control, .. } => control.as_ref(),
}
}
}