mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
Render host-owned V2 subagent rosters in environment context (#59531)
## What changed - Expose `AgentSessionReader` and `AgentRef` for read-only access to host-owned agent session membership. - Read direct children when rendering V2 environment context, using the existing roster size limits. Refresh membership when rebuilding context after compaction, and omit the roster if the provider is absent or the read fails. - Preserve unrecorded initial input across suspension or interruption while waiting for a roster read. Resolve the roster before advancing the compaction window. ## Testing Add coverage for roster refreshes after compaction, unchanged environments avoiding extra reads, unavailable rosters, recoverable input during blocked reads, and stale compaction results rejected after a concurrent history replacement. GitOrigin-RevId: 3c7e3822af09e9295d405e53dabb87b020c8f00c
This commit is contained in:
@@ -2,6 +2,7 @@ mod admission;
|
||||
mod invocation;
|
||||
mod mcp_metadata;
|
||||
mod ownership;
|
||||
mod session_reader;
|
||||
mod spawn;
|
||||
mod types;
|
||||
mod usage;
|
||||
@@ -17,6 +18,8 @@ pub(crate) use invocation::tool_invocation;
|
||||
pub use mcp_metadata::AgentMcpMetadataRecipient;
|
||||
pub use ownership::AgentRuntimeOwnership;
|
||||
pub(crate) use ownership::AgentRuntimeServices;
|
||||
pub use session_reader::AgentRef;
|
||||
pub use session_reader::AgentSessionReader;
|
||||
pub use types::HostThreadSpawnReservation;
|
||||
pub use types::InheritedSessionId;
|
||||
pub use types::PreparedChildContext;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Captures coordination providers once, after the thread's startup contributors finish.
|
||||
|
||||
use super::AgentSessionReader;
|
||||
use super::AgentTurnAdmission;
|
||||
use super::AgentUsageAccounting;
|
||||
use codex_extension_api::ExtensionData;
|
||||
@@ -14,8 +15,8 @@ pub enum AgentRuntimeOwnership {
|
||||
#[default]
|
||||
Controller,
|
||||
/// Requires an [`AgentTurnAdmission`] provider. Core skips controller rollout-budget
|
||||
/// accounting, budget reminders, and subagent roster context for this runtime.
|
||||
/// Install an [`AgentUsageAccounting`] provider to receive usage reports.
|
||||
/// accounting and budget reminders. Install an [`AgentUsageAccounting`] provider
|
||||
/// to receive usage reports and an [`AgentSessionReader`] to render the V2 subagent roster.
|
||||
Host,
|
||||
}
|
||||
|
||||
@@ -25,6 +26,7 @@ pub(crate) enum AgentRuntimeServices {
|
||||
}
|
||||
|
||||
pub(crate) struct HostAgentServices {
|
||||
pub(crate) session_reader: Option<Arc<dyn AgentSessionReader>>,
|
||||
pub(crate) turn_admission: Arc<dyn AgentTurnAdmission>,
|
||||
pub(crate) usage_accounting: Option<Arc<dyn AgentUsageAccounting>>,
|
||||
}
|
||||
@@ -40,6 +42,10 @@ impl AgentRuntimeServices {
|
||||
)
|
||||
})?;
|
||||
Ok(Self::Host(HostAgentServices {
|
||||
session_reader: data
|
||||
.get::<Arc<dyn AgentSessionReader>>()
|
||||
.as_deref()
|
||||
.cloned(),
|
||||
turn_admission: Arc::clone(turn_admission.as_ref()),
|
||||
usage_accounting: data
|
||||
.get::<Arc<dyn AgentUsageAccounting>>()
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//! Read-only host agent session membership for native context construction.
|
||||
|
||||
use codex_protocol::AgentPath;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::error::Result;
|
||||
use futures::future::BoxFuture;
|
||||
|
||||
/// An agent's identity in the selected owner's agent session.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct AgentRef {
|
||||
pub thread_id: ThreadId,
|
||||
pub path: AgentPath,
|
||||
}
|
||||
|
||||
/// An agent session view scoped to one runtime, installed before host-owned startup or resume.
|
||||
///
|
||||
/// Reads must not register, load, or restore agents. Return an error when membership
|
||||
/// is unavailable. Implementations may read a local cache or query their coordinator.
|
||||
/// Core reads child paths for its bounded V2 roster when rendering an environment fragment.
|
||||
/// If the read fails, Core renders the fragment without a roster.
|
||||
pub trait AgentSessionReader: Send + Sync {
|
||||
/// Returns the root, including self when this runtime is the root.
|
||||
fn root(&self) -> BoxFuture<'_, Result<AgentRef>>;
|
||||
|
||||
/// Returns the structural parent; only the root has no parent.
|
||||
fn parent(&self) -> BoxFuture<'_, Result<Option<AgentRef>>>;
|
||||
|
||||
/// Returns registered direct children, including unloaded members, excluding
|
||||
/// provisional reservations and historical/removed relationships. Return loaded
|
||||
/// children first, then alphabetical paths within each group, as native rosters do.
|
||||
fn children(&self) -> BoxFuture<'_, Result<Vec<AgentRef>>>;
|
||||
}
|
||||
Reference in New Issue
Block a user