mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Make subagents follow the root service tier (#41308)
## What changed - Share the root thread's current service tier across its agent tree. - Apply that tier to each subagent request when the selected child model supports it, including remote compaction requests. - Propagate root service-tier updates to existing and newly spawned subagents without rewriting child-owned settings. - Remove per-spawn and role-level service-tier overrides so routing remains controlled by the root thread. ## Testing - Cover supported and unsupported child models, full-history forks, live tier changes, remote compaction, new subagents, and reloaded subagents. GitOrigin-RevId: 6c299e224e90b41a558788fb7aa4d5f336fa383a
This commit is contained in:
@@ -25,6 +25,7 @@ use crate::thread_manager::ThreadManagerState;
|
||||
use crate::thread_manager::default_thread_id_generator;
|
||||
use crate::thread_rollout_truncation::truncate_rollout_to_last_n_fork_turns;
|
||||
use crate::turn_timing::now_unix_timestamp_ms;
|
||||
use arc_swap::ArcSwapOption;
|
||||
use codex_history::InitialHistory;
|
||||
use codex_history::ResumedHistory;
|
||||
use codex_history::RolloutItem;
|
||||
@@ -72,6 +73,7 @@ use self::residency::V2Residency;
|
||||
mod execution;
|
||||
mod legacy;
|
||||
mod residency;
|
||||
mod service_tier;
|
||||
mod spawn;
|
||||
mod user_authorization;
|
||||
|
||||
@@ -128,6 +130,8 @@ pub(crate) struct AgentControl {
|
||||
agent_execution_limiter: Arc<AgentExecutionLimiter>,
|
||||
/// Session-scoped state shared by the root thread and every cloned sub-agent control handle.
|
||||
rollout_budget: Arc<RolloutBudget>,
|
||||
/// The user-selected root routing tier, shared by the entire agent tree.
|
||||
root_service_tier: Arc<ArcSwapOption<String>>,
|
||||
}
|
||||
|
||||
impl Default for AgentControl {
|
||||
@@ -155,6 +159,7 @@ impl AgentControl {
|
||||
v2_residency: Arc::default(),
|
||||
agent_execution_limiter: Arc::default(),
|
||||
rollout_budget: Arc::default(),
|
||||
root_service_tier: Arc::new(ArcSwapOption::from(None)),
|
||||
};
|
||||
if let Some(rollout_budget) = rollout_budget {
|
||||
control.rollout_budget.configure(rollout_budget);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//! Shares the root user's selected routing tier across the entire agent tree.
|
||||
|
||||
use super::AgentControl;
|
||||
use std::sync::Arc;
|
||||
|
||||
impl AgentControl {
|
||||
/// Returns the latest user-selected tier for this root and all its descendants.
|
||||
pub(crate) fn root_service_tier(&self) -> Option<String> {
|
||||
self.root_service_tier
|
||||
.load_full()
|
||||
.map(|service_tier| (*service_tier).clone())
|
||||
}
|
||||
|
||||
/// Publishes a root-owned tier without mutating individual child sessions.
|
||||
pub(crate) fn set_root_service_tier(&self, service_tier: Option<String>) {
|
||||
self.root_service_tier.store(service_tier.map(Arc::new));
|
||||
}
|
||||
}
|
||||
@@ -415,6 +415,7 @@ impl AgentControl {
|
||||
CodexErr::InvalidRequest(format!("permission_profile is invalid: {err}"))
|
||||
})?;
|
||||
}
|
||||
config.service_tier = self.root_service_tier();
|
||||
if let Some(model) = stored_model {
|
||||
config.model = Some(model);
|
||||
}
|
||||
|
||||
@@ -311,11 +311,7 @@ pub(crate) mod spawn_tool_spec {
|
||||
let reasoning_effort = role_toml
|
||||
.get("model_reasoning_effort")
|
||||
.and_then(TomlValue::as_str);
|
||||
let service_tier = role_toml
|
||||
.get("service_tier")
|
||||
.and_then(TomlValue::as_str);
|
||||
|
||||
let model_and_reasoning_note = match (model, reasoning_effort) {
|
||||
match (model, reasoning_effort) {
|
||||
(Some(model), Some(reasoning_effort)) => format!(
|
||||
"\n- This role's model is set to `{model}` and its reasoning effort is set to `{reasoning_effort}`. These settings cannot be changed."
|
||||
),
|
||||
@@ -330,15 +326,7 @@ pub(crate) mod spawn_tool_spec {
|
||||
)
|
||||
}
|
||||
(None, None) => String::new(),
|
||||
};
|
||||
let service_tier_note = service_tier
|
||||
.map(|service_tier| {
|
||||
format!(
|
||||
"\n- This role's service tier is set to `{service_tier}`. If it is supported by the resolved model, it takes precedence over a valid spawn request service tier."
|
||||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
format!("{model_and_reasoning_note}{service_tier_note}")
|
||||
}
|
||||
})
|
||||
.unwrap_or_default();
|
||||
format!("{name}: {{\n{description}{locked_settings_note}\n}}")
|
||||
|
||||
@@ -711,7 +711,7 @@ fn spawn_tool_spec_marks_role_locked_reasoning_effort_only() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawn_tool_spec_marks_role_locked_service_tier() {
|
||||
fn spawn_tool_spec_omits_role_service_tier() {
|
||||
let tempdir = TempDir::new().expect("create temp dir");
|
||||
let role_path = tempdir.path().join("tiered.toml");
|
||||
fs::write(
|
||||
@@ -730,9 +730,7 @@ fn spawn_tool_spec_marks_role_locked_service_tier() {
|
||||
|
||||
let spec = spawn_tool_spec::build(&user_defined_roles);
|
||||
|
||||
assert!(spec.contains(
|
||||
"Stay fast.\n- This role's service tier is set to `priority`. If it is supported by the resolved model, it takes precedence over a valid spawn request service tier."
|
||||
));
|
||||
assert!(spec.contains("tiered: {\nStay fast.\n}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -88,7 +88,7 @@ pub(super) async fn run_remote_compact_attempt(
|
||||
service_tier: if sess.services.auth_manager.auth_mode() == Some(AuthMode::ApiKey) {
|
||||
None
|
||||
} else {
|
||||
turn_context.config.service_tier.clone()
|
||||
step_context.settings.service_tier.clone()
|
||||
},
|
||||
},
|
||||
&turn_context.session_telemetry,
|
||||
|
||||
@@ -367,11 +367,12 @@ struct RemoteCompactionV2Output {
|
||||
|
||||
async fn run_remote_compaction_request_v2(
|
||||
sess: &Session,
|
||||
turn_context: &TurnContext,
|
||||
step_context: &StepContext,
|
||||
client_session: &mut ModelClientSession,
|
||||
prompt: &Prompt,
|
||||
responses_metadata: &CodexResponsesMetadata,
|
||||
) -> CodexResult<RemoteCompactionV2Output> {
|
||||
let turn_context = &step_context.turn;
|
||||
let max_retries = turn_context
|
||||
.provider
|
||||
.info()
|
||||
@@ -386,7 +387,7 @@ async fn run_remote_compaction_request_v2(
|
||||
&turn_context.session_telemetry,
|
||||
turn_context.reasoning_effort().cloned(),
|
||||
turn_context.reasoning_summary(),
|
||||
turn_context.config.service_tier.clone(),
|
||||
step_context.settings.service_tier.clone(),
|
||||
responses_metadata,
|
||||
&InferenceTraceContext::disabled(),
|
||||
)
|
||||
|
||||
@@ -104,7 +104,7 @@ pub(super) async fn run_remote_compact_v2_attempt(
|
||||
};
|
||||
let compaction_output_result = run_remote_compaction_request_v2(
|
||||
sess,
|
||||
turn_context.as_ref(),
|
||||
step_context,
|
||||
client_session,
|
||||
&prompt,
|
||||
&responses_metadata,
|
||||
|
||||
@@ -1649,6 +1649,9 @@ impl Session {
|
||||
previous_permission_profile != updated_permission_profile;
|
||||
let mcp_inputs_changed =
|
||||
self.mcp_inputs_differ(&state.session_configuration, &updated, &updates);
|
||||
let root_service_tier_changed = updated.parent_thread_id.is_none()
|
||||
&& state.session_configuration.step_settings.service_tier
|
||||
!= updated.step_settings.service_tier;
|
||||
if mcp_inputs_changed {
|
||||
self.mark_mcp_runtime_dirty();
|
||||
}
|
||||
@@ -1665,6 +1668,15 @@ impl Session {
|
||||
.update_thread_config(&environment_config);
|
||||
}
|
||||
state.session_configuration = updated;
|
||||
if root_service_tier_changed {
|
||||
self.services.agent_control.set_root_service_tier(
|
||||
state
|
||||
.session_configuration
|
||||
.step_settings
|
||||
.service_tier
|
||||
.clone(),
|
||||
);
|
||||
}
|
||||
let new_config = notify_config_contributors
|
||||
.then(|| self.build_effective_session_config(&state.session_configuration));
|
||||
let commit = SessionSettingsCommit {
|
||||
@@ -3320,7 +3332,22 @@ impl Session {
|
||||
) -> CodexResult<Arc<StepContext>> {
|
||||
// Capture once before asynchronous planning; all request consumers
|
||||
// retain this immutable settings version even if the turn is updated.
|
||||
let settings = turn_context.current_settings.load_full();
|
||||
let mut settings = turn_context.current_settings.load_full();
|
||||
if matches!(
|
||||
turn_context.session_source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
) {
|
||||
let root_service_tier = self.services.agent_control.root_service_tier();
|
||||
if settings.selected().service_tier != root_service_tier {
|
||||
let mut selected = settings.selected().clone();
|
||||
selected.service_tier = root_service_tier;
|
||||
settings = Arc::new(ResolvedStepSettings::new(
|
||||
Arc::new(selected),
|
||||
Arc::clone(&settings.model_info),
|
||||
self.features.enabled(Feature::FastMode),
|
||||
));
|
||||
}
|
||||
}
|
||||
let token_budget = token_budget::resolve_token_budget(
|
||||
turn_context.configured_token_budget.as_ref(),
|
||||
turn_context.use_model_token_budget_defaults,
|
||||
|
||||
@@ -715,6 +715,15 @@ impl Session {
|
||||
.parent_thread_id
|
||||
.or_else(|| initial_history.get_resumed_parent_thread_id());
|
||||
session_configuration.parent_thread_id = parent_thread_id;
|
||||
if parent_thread_id.is_none() {
|
||||
agent_control.set_root_service_tier(
|
||||
session_configuration
|
||||
.step_settings
|
||||
.service_tier
|
||||
.clone()
|
||||
.or_else(|| config.service_tier.clone()),
|
||||
);
|
||||
}
|
||||
let is_paginated_subagent = matches!(
|
||||
session_configuration.history_mode,
|
||||
ThreadHistoryMode::Paginated
|
||||
|
||||
@@ -91,9 +91,6 @@ async fn handle_spawn_agent(
|
||||
.await;
|
||||
let mut config =
|
||||
build_agent_spawn_config(&session.get_base_instructions().await, turn.as_ref())?;
|
||||
if let Some(service_tier) = args.service_tier.as_ref() {
|
||||
config.service_tier = Some(service_tier.clone());
|
||||
}
|
||||
if args.fork_context {
|
||||
reject_full_fork_agent_type_override(role_name)?;
|
||||
}
|
||||
@@ -108,13 +105,7 @@ async fn handle_spawn_agent(
|
||||
if !args.fork_context {
|
||||
apply_spawn_agent_role(&session, &mut config, role_name).await?;
|
||||
}
|
||||
apply_spawn_agent_service_tier(
|
||||
&session,
|
||||
&mut config,
|
||||
turn.config.service_tier.as_deref(),
|
||||
args.service_tier.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
apply_spawn_agent_service_tier(&session, &mut config).await?;
|
||||
apply_spawn_agent_runtime_overrides(&mut config, turn.as_ref())?;
|
||||
|
||||
let result = Box::pin(session.services.agent_control.spawn_agent_with_metadata(
|
||||
@@ -237,7 +228,6 @@ struct SpawnAgentArgs {
|
||||
agent_type: Option<String>,
|
||||
model: Option<String>,
|
||||
reasoning_effort: Option<ReasoningEffort>,
|
||||
service_tier: Option<String>,
|
||||
#[serde(default)]
|
||||
fork_context: bool,
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::tools::context::ToolPayload;
|
||||
use codex_models_manager::manager::RefreshStrategy;
|
||||
use codex_protocol::AgentPath;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::SERVICE_TIER_DEFAULT_REQUEST_VALUE;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::CodexErrorDetails;
|
||||
use codex_protocol::models::BaseInstructions;
|
||||
@@ -321,17 +322,14 @@ pub(crate) async fn apply_requested_spawn_agent_model_overrides(
|
||||
pub(crate) async fn apply_spawn_agent_service_tier(
|
||||
session: &Session,
|
||||
config: &mut Config,
|
||||
parent_service_tier: Option<&str>,
|
||||
requested_service_tier: Option<&str>,
|
||||
) -> Result<(), FunctionCallError> {
|
||||
let candidate_service_tiers = [
|
||||
config.service_tier.clone(),
|
||||
requested_service_tier.map(str::to_string),
|
||||
parent_service_tier.map(str::to_string),
|
||||
];
|
||||
if candidate_service_tiers.iter().all(Option::is_none) {
|
||||
let Some(service_tier) = session.services.agent_control.root_service_tier() else {
|
||||
config.service_tier = None;
|
||||
return Ok(());
|
||||
};
|
||||
if service_tier == SERVICE_TIER_DEFAULT_REQUEST_VALUE {
|
||||
config.service_tier = Some(service_tier);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let model = config.model.clone().ok_or_else(|| {
|
||||
@@ -345,31 +343,9 @@ pub(crate) async fn apply_spawn_agent_service_tier(
|
||||
.get_model_info(model.as_str(), &config.to_models_manager_config())
|
||||
.await;
|
||||
|
||||
if let Some(requested_service_tier) = requested_service_tier
|
||||
&& !model_info.supports_service_tier(requested_service_tier)
|
||||
{
|
||||
let supported_service_tiers = if model_info.service_tiers.is_empty() {
|
||||
"none".to_string()
|
||||
} else {
|
||||
model_info
|
||||
.service_tiers
|
||||
.iter()
|
||||
.map(|tier| tier.id.as_str())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
return Err(FunctionCallError::RespondToModel(format!(
|
||||
"Service tier `{requested_service_tier}` is not supported for model `{model}`. Supported service tiers: {supported_service_tiers}"
|
||||
)));
|
||||
}
|
||||
|
||||
config.service_tier =
|
||||
candidate_service_tiers
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.find(|candidate_service_tier| {
|
||||
model_info.supports_service_tier(candidate_service_tier.as_str())
|
||||
});
|
||||
config.service_tier = model_info
|
||||
.supports_service_tier(service_tier.as_str())
|
||||
.then_some(service_tier);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ const SPAWN_AGENT_INHERITED_MODEL_GUIDANCE: &str = "Spawned agents inherit your
|
||||
const SPAWN_AGENT_TYPE_OVERRIDE_DESCRIPTION_V1: &str = "Agent type override for the new agent. Omit to inherit the parent agent type with a full-history fork; otherwise, `default` is used.";
|
||||
const SPAWN_AGENT_MODEL_OVERRIDE_DESCRIPTION: &str =
|
||||
"Model override for the new agent. Omit unless an explicit override is needed.";
|
||||
const SPAWN_AGENT_SERVICE_TIER_OVERRIDE_DESCRIPTION: &str =
|
||||
"Service tier override for the new agent. Omit unless explicitly requested.";
|
||||
const MAX_REASONING_EFFORT_CHARS_IN_SPAWN_AGENT_DESCRIPTION: usize = 64;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -110,9 +108,6 @@ pub fn create_spawn_agent_tool_v2(options: SpawnAgentToolOptions) -> ToolSpec {
|
||||
if !options.expose_agent_type {
|
||||
properties.remove("agent_type");
|
||||
}
|
||||
if options.hide_agent_type_model_reasoning {
|
||||
properties.remove("service_tier");
|
||||
}
|
||||
if !options.expose_spawn_agent_model_overrides {
|
||||
properties.remove("model");
|
||||
properties.remove("reasoning_effort");
|
||||
@@ -619,12 +614,6 @@ fn spawn_agent_common_properties_v1(agent_type_description: &str) -> BTreeMap<St
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"service_tier".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
SPAWN_AGENT_SERVICE_TIER_OVERRIDE_DESCRIPTION.to_string(),
|
||||
)),
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -663,12 +652,6 @@ fn spawn_agent_common_properties_v2(agent_type_description: &str) -> BTreeMap<St
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"service_tier".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
SPAWN_AGENT_SERVICE_TIER_OVERRIDE_DESCRIPTION.to_string(),
|
||||
)),
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -676,7 +659,6 @@ fn hide_spawn_agent_metadata_options(properties: &mut BTreeMap<String, JsonSchem
|
||||
properties.remove("agent_type");
|
||||
properties.remove("model");
|
||||
properties.remove("reasoning_effort");
|
||||
properties.remove("service_tier");
|
||||
}
|
||||
|
||||
fn spawn_agent_tool_description(
|
||||
|
||||
@@ -115,12 +115,7 @@ fn spawn_agent_tool_v2_requires_task_name_and_lists_visible_models() {
|
||||
.and_then(|schema| schema.description.as_deref()),
|
||||
Some("Reasoning effort override for the new agent. Omit to inherit the parent effort.")
|
||||
);
|
||||
assert_eq!(
|
||||
properties
|
||||
.get("service_tier")
|
||||
.and_then(|schema| schema.description.as_deref()),
|
||||
Some(SPAWN_AGENT_SERVICE_TIER_OVERRIDE_DESCRIPTION)
|
||||
);
|
||||
assert!(!properties.contains_key("service_tier"));
|
||||
assert_eq!(
|
||||
parameters.required.as_ref(),
|
||||
Some(&vec!["task_name".to_string(), "message".to_string()])
|
||||
@@ -181,12 +176,7 @@ fn spawn_agent_tool_v1_keeps_legacy_fork_context_field() {
|
||||
.and_then(|schema| schema.description.as_deref()),
|
||||
Some(SPAWN_AGENT_MODEL_OVERRIDE_DESCRIPTION)
|
||||
);
|
||||
assert_eq!(
|
||||
properties
|
||||
.get("service_tier")
|
||||
.and_then(|schema| schema.description.as_deref()),
|
||||
Some(SPAWN_AGENT_SERVICE_TIER_OVERRIDE_DESCRIPTION)
|
||||
);
|
||||
assert!(!properties.contains_key("service_tier"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -407,106 +407,31 @@ async fn multi_agent_v2_spawn_fork_turns_all_applies_agent_type_override() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn spawn_agent_service_tier_override_validates_the_effective_child_model() {
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SpawnAgentResult {
|
||||
agent_id: String,
|
||||
}
|
||||
async fn spawn_agent_service_tier_uses_root_preference_when_root_model_cannot_support_it() {
|
||||
let (_session, turn) = make_session_and_context().await;
|
||||
let mut config = (*turn.config).clone();
|
||||
config.model = Some("gpt-5.4-mini".to_string());
|
||||
config.service_tier = Some(ServiceTier::Fast.request_value().to_string());
|
||||
let manager = thread_manager();
|
||||
let root = manager
|
||||
.start_thread(StartThreadOptions::new(config.clone()))
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
assert_eq!(root.thread.config_snapshot().await.service_tier, None);
|
||||
|
||||
{
|
||||
let (mut session, turn) = make_session_and_context().await;
|
||||
let manager = thread_manager();
|
||||
let root = manager
|
||||
.start_thread(StartThreadOptions::new((*turn.config).clone()))
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.thread_id = root.thread_id;
|
||||
config.model = Some("gpt-5.4".to_string());
|
||||
apply_spawn_agent_service_tier(root.thread.session.as_ref(), &mut config)
|
||||
.await
|
||||
.expect("root preference should be resolved against the child model");
|
||||
|
||||
let output = SpawnAgentHandler::default()
|
||||
.handle(invocation(
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"model": "gpt-5.4",
|
||||
"service_tier": ServiceTier::Fast.request_value()
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.expect("spawn_agent should accept a supported explicit service tier");
|
||||
let (content, _) = expect_text_output(output);
|
||||
let result: SpawnAgentResult =
|
||||
serde_json::from_str(&content).expect("spawn_agent result should be json");
|
||||
let snapshot = manager
|
||||
.get_thread(parse_agent_id(&result.agent_id))
|
||||
.await
|
||||
.expect("spawned agent thread should exist")
|
||||
.config_snapshot()
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
snapshot.service_tier,
|
||||
Some(ServiceTier::Fast.request_value().to_string())
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let (session, turn) = make_session_and_context().await;
|
||||
let err = SpawnAgentHandler::default()
|
||||
.handle(invocation(
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"model": "gpt-5.4",
|
||||
"service_tier": "turbo"
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.err()
|
||||
.expect("unknown service tier should be rejected");
|
||||
|
||||
assert_eq!(
|
||||
err,
|
||||
FunctionCallError::RespondToModel(
|
||||
"Service tier `turbo` is not supported for model `gpt-5.4`. Supported service tiers: priority"
|
||||
.to_string()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let (session, turn) = make_session_and_context().await;
|
||||
let err = SpawnAgentHandler::default()
|
||||
.handle(invocation(
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"model": "gpt-5.4-mini",
|
||||
"service_tier": ServiceTier::Fast.request_value()
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.err()
|
||||
.expect("tier unsupported by the final child model should be rejected");
|
||||
|
||||
assert_eq!(
|
||||
err,
|
||||
FunctionCallError::RespondToModel(
|
||||
"Service tier `priority` is not supported for model `gpt-5.4-mini`. Supported service tiers: none"
|
||||
.to_string()
|
||||
)
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
config.service_tier,
|
||||
Some(ServiceTier::Fast.request_value().to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn spawn_agent_service_tier_inheritance_preserves_supported_or_configured_tiers() {
|
||||
async fn spawn_agent_service_tier_inheritance_uses_root_preference_and_child_model() {
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SpawnAgentResult {
|
||||
agent_id: String,
|
||||
@@ -525,7 +450,7 @@ async fn spawn_agent_service_tier_inheritance_preserves_supported_or_configured_
|
||||
.start_thread(StartThreadOptions::new((*turn.config).clone()))
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.services.agent_control = root.thread.session.services.agent_control.clone();
|
||||
session.thread_id = root.thread_id;
|
||||
|
||||
let output = SpawnAgentHandler::default()
|
||||
@@ -566,7 +491,7 @@ async fn spawn_agent_service_tier_inheritance_preserves_supported_or_configured_
|
||||
.start_thread(StartThreadOptions::new((*turn.config).clone()))
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.services.agent_control = root.thread.session.services.agent_control.clone();
|
||||
session.thread_id = root.thread_id;
|
||||
|
||||
let output = SpawnAgentHandler::default()
|
||||
@@ -643,7 +568,7 @@ service_tier = "priority"
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.expect("spawn_agent should preserve the child role service tier");
|
||||
.expect("spawn_agent should ignore the child role service tier");
|
||||
let (content, _) = expect_text_output(output);
|
||||
let result: SpawnAgentResult =
|
||||
serde_json::from_str(&content).expect("spawn_agent result should be json");
|
||||
@@ -654,15 +579,12 @@ service_tier = "priority"
|
||||
.config_snapshot()
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
snapshot.service_tier,
|
||||
Some(ServiceTier::Fast.request_value().to_string())
|
||||
);
|
||||
assert_eq!(snapshot.service_tier, None);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn spawn_agent_role_service_tier_falls_back_to_supported_parent_tier() {
|
||||
async fn spawn_agent_role_service_tier_cannot_override_root_preference() {
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SpawnAgentResult {
|
||||
agent_id: String,
|
||||
@@ -702,7 +624,7 @@ service_tier = "turbo"
|
||||
.start_thread(StartThreadOptions::new((*turn.config).clone()))
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.services.agent_control = root.thread.session.services.agent_control.clone();
|
||||
session.thread_id = root.thread_id;
|
||||
|
||||
let output = SpawnAgentHandler::default()
|
||||
@@ -734,72 +656,25 @@ service_tier = "turbo"
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn spawn_agent_role_service_tier_does_not_hide_invalid_spawn_request() {
|
||||
let (session, mut turn) = make_session_and_context().await;
|
||||
tokio::fs::create_dir_all(&turn.config.codex_home)
|
||||
.await
|
||||
.expect("codex home should be created");
|
||||
let role_config_path = turn.config.codex_home.as_path().join("tiered-role.toml");
|
||||
tokio::fs::write(
|
||||
&role_config_path,
|
||||
r#"model = "gpt-5.4"
|
||||
service_tier = "priority"
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
.expect("role config should be written");
|
||||
|
||||
let role_name = "tiered-role".to_string();
|
||||
let mut config = (*turn.config).clone();
|
||||
config.agent_roles.insert(
|
||||
role_name.clone(),
|
||||
AgentRoleConfig {
|
||||
description: Some("Role with a supported child tier".to_string()),
|
||||
config_file: Some(role_config_path),
|
||||
nickname_candidates: None,
|
||||
},
|
||||
);
|
||||
turn.config = Arc::new(config);
|
||||
|
||||
let result = SpawnAgentHandler::default()
|
||||
.handle(invocation(
|
||||
Arc::new(session),
|
||||
Arc::new(turn),
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"agent_type": role_name,
|
||||
"service_tier": "turbo"
|
||||
})),
|
||||
))
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
result.err(),
|
||||
Some(FunctionCallError::RespondToModel(
|
||||
"Service tier `turbo` is not supported for model `gpt-5.4`. Supported service tiers: priority"
|
||||
.to_string()
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn spawn_agent_full_history_fork_accepts_explicit_service_tier() {
|
||||
async fn spawn_agent_full_history_fork_inherits_root_service_tier() {
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SpawnAgentResult {
|
||||
agent_id: String,
|
||||
}
|
||||
|
||||
let (mut session, turn) = make_session_and_context().await;
|
||||
let turn = turn
|
||||
let mut turn = turn
|
||||
.with_model("gpt-5.4".to_string(), &session.services.models_manager)
|
||||
.await;
|
||||
let mut config = (*turn.config).clone();
|
||||
config.service_tier = Some(ServiceTier::Fast.request_value().to_string());
|
||||
turn.config = Arc::new(config);
|
||||
let manager = thread_manager();
|
||||
let root = manager
|
||||
.start_thread(StartThreadOptions::new((*turn.config).clone()))
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.services.agent_control = root.thread.session.services.agent_control.clone();
|
||||
session.thread_id = root.thread_id;
|
||||
|
||||
let output = SpawnAgentHandler::default()
|
||||
@@ -809,12 +684,11 @@ async fn spawn_agent_full_history_fork_accepts_explicit_service_tier() {
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"fork_context": true,
|
||||
"service_tier": ServiceTier::Fast.request_value()
|
||||
"fork_context": true
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.expect("full-history fork should accept explicit service tier");
|
||||
.expect("full-history fork should inherit the root service tier");
|
||||
let (content, _) = expect_text_output(output);
|
||||
let result: SpawnAgentResult =
|
||||
serde_json::from_str(&content).expect("spawn_agent result should be json");
|
||||
@@ -832,7 +706,7 @@ async fn spawn_agent_full_history_fork_accepts_explicit_service_tier() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn multi_agent_v2_full_history_fork_accepts_explicit_service_tier() {
|
||||
async fn multi_agent_v2_full_history_fork_inherits_root_service_tier() {
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SpawnAgentResult {
|
||||
task_name: String,
|
||||
@@ -843,6 +717,7 @@ async fn multi_agent_v2_full_history_fork_accepts_explicit_service_tier() {
|
||||
.with_model("gpt-5.4".to_string(), &session.services.models_manager)
|
||||
.await;
|
||||
let mut config = (*turn.config).clone();
|
||||
config.service_tier = Some(ServiceTier::Fast.request_value().to_string());
|
||||
config
|
||||
.features
|
||||
.enable(Feature::MultiAgentV2)
|
||||
@@ -853,7 +728,7 @@ async fn multi_agent_v2_full_history_fork_accepts_explicit_service_tier() {
|
||||
.start_thread(StartThreadOptions::new((*turn.config).clone()))
|
||||
.await
|
||||
.expect("root thread should start");
|
||||
session.services.agent_control = manager.agent_control();
|
||||
session.services.agent_control = root.thread.session.services.agent_control.clone();
|
||||
session.thread_id = root.thread_id;
|
||||
let session = Arc::new(session);
|
||||
let turn = Arc::new(turn);
|
||||
@@ -865,12 +740,11 @@ async fn multi_agent_v2_full_history_fork_accepts_explicit_service_tier() {
|
||||
"spawn_agent",
|
||||
function_payload(json!({
|
||||
"message": "inspect this repo",
|
||||
"task_name": "fork_with_tier",
|
||||
"service_tier": ServiceTier::Fast.request_value()
|
||||
"task_name": "fork_with_tier"
|
||||
})),
|
||||
))
|
||||
.await
|
||||
.expect("multi-agent v2 full-history fork should accept explicit service tier");
|
||||
.expect("multi-agent v2 full-history fork should inherit the root service tier");
|
||||
let (content, _) = expect_text_output(output);
|
||||
let result: SpawnAgentResult =
|
||||
serde_json::from_str(&content).expect("spawn_agent result should be json");
|
||||
|
||||
@@ -124,9 +124,6 @@ async fn handle_spawn_agent(
|
||||
let child_depth = next_thread_spawn_depth(&session_source);
|
||||
let mut config =
|
||||
build_agent_spawn_config(&session.get_base_instructions().await, turn.as_ref())?;
|
||||
if let Some(service_tier) = args.service_tier.as_ref() {
|
||||
config.service_tier = Some(service_tier.clone());
|
||||
}
|
||||
let is_full_history_fork = matches!(fork_mode, Some(SpawnAgentForkMode::FullHistory));
|
||||
apply_requested_spawn_agent_model_overrides(
|
||||
&session,
|
||||
@@ -144,13 +141,7 @@ async fn handle_spawn_agent(
|
||||
.clone_from(&turn.developer_instructions);
|
||||
}
|
||||
}
|
||||
apply_spawn_agent_service_tier(
|
||||
&session,
|
||||
&mut config,
|
||||
turn.config.service_tier.as_deref(),
|
||||
args.service_tier.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
apply_spawn_agent_service_tier(&session, &mut config).await?;
|
||||
apply_spawn_agent_runtime_overrides(&mut config, turn.as_ref())?;
|
||||
|
||||
// Remember an applied configured default so cold reload reapplies its restrictions.
|
||||
@@ -288,7 +279,6 @@ struct SpawnAgentArgs {
|
||||
agent_type: Option<String>,
|
||||
model: Option<String>,
|
||||
reasoning_effort: Option<ReasoningEffort>,
|
||||
service_tier: Option<String>,
|
||||
fork_turns: Option<String>,
|
||||
fork_context: Option<bool>,
|
||||
}
|
||||
|
||||
@@ -2658,7 +2658,7 @@ async fn multi_agent_feature_selects_one_agent_tool_family() {
|
||||
.properties
|
||||
.as_ref()
|
||||
.expect("spawn_agent should use object params");
|
||||
for property in ["model", "reasoning_effort", "service_tier"] {
|
||||
for property in ["model", "reasoning_effort"] {
|
||||
assert!(
|
||||
properties.contains_key(property),
|
||||
"expected v1 spawn_agent to expose `{property}`"
|
||||
|
||||
Reference in New Issue
Block a user