Remove partial-history subagent forks (#51329)

## What changed

- Limit multi-agent V2 `fork_turns` guidance to `all` and `none`. Accept legacy positive integer strings as full-history forks instead of truncating parent history.
- Remove partial-history fork handling and telemetry, and direct model override usage to `fork_turns: "none"`.
- Strip inherited `multi_agent.role_instructions` and `multi_agent.usage_hint` content by kind, including persisted hints whose wording predates the current bundled instructions.

## Testing

Update regression coverage for legacy `"1"` and `"3"` values inheriting full history, invalid and zero values being rejected, and stale parent hints being removed from compacted history with both marked and unmarked instructions.

GitOrigin-RevId: 8f6017dc66ad8deefd7745399ef76e1bb1435bb2
This commit is contained in:
jif
2026-10-06 10:39:16 +00:00
committed by copyberry
parent 822e58cc3d
commit 6221a217e2
37 changed files with 125 additions and 1065 deletions
@@ -92,7 +92,6 @@ pub(crate) fn record_collab_spawn_failure(
let fork_mode = match fork_mode {
None => "none",
Some(SpawnAgentForkMode::FullHistory) => "all",
Some(SpawnAgentForkMode::LastNTurns(_)) => "last_n",
};
let multi_agent_version = match multi_agent_version {
MultiAgentVersion::Disabled => "disabled",
@@ -664,8 +664,7 @@ fn spawn_agent_common_properties_v2(agent_type_description: &str) -> BTreeMap<St
(
"fork_turns".to_string(),
JsonSchema::string(Some(
"Optional number of turns to fork. Defaults to `all`. Use `none`, `all`, or a positive integer string such as `3` to fork only the most recent turns."
.to_string(),
"Parent history to inherit. Defaults to `all`; use `none` to start without parent history. Only `all` and `none` are supported.".to_string(),
)),
),
(
@@ -924,7 +924,7 @@ async fn multi_agent_v2_full_history_fork_inherits_root_service_tier() {
}
#[tokio::test]
async fn multi_agent_v2_spawn_partial_fork_turns_allows_agent_type_override() {
async fn multi_agent_v2_spawn_without_history_allows_agent_type_override() {
let (mut session, mut turn) = make_session_and_context().await;
let role_name = install_role_with_model_override(&mut turn).await;
let manager = thread_manager();
@@ -951,17 +951,17 @@ async fn multi_agent_v2_spawn_partial_fork_turns_allows_agent_type_override() {
"spawn_agent",
function_payload(json!({
"message": "inspect this repo",
"task_name": "partial_fork",
"task_name": "fresh_agent",
"agent_type": role_name,
"fork_turns": "1"
"fork_turns": "none"
})),
))
.await
.expect("partial fork should allow agent_type overrides");
.expect("fresh agent should allow agent_type overrides");
let (content, _) = expect_text_output(output);
let result: serde_json::Value =
serde_json::from_str(&content).expect("spawn_agent result should be json");
assert_eq!(result["task_name"], "/root/partial_fork");
assert_eq!(result["task_name"], "/root/fresh_agent");
let agent_id = manager
.captured_ops()
.into_iter()
@@ -1254,8 +1254,10 @@ async fn multi_agent_v2_spawn_rejects_legacy_fork_context() {
);
}
#[test_case::test_case("banana"; "invalid string")]
#[test_case::test_case("0"; "zero turns")]
#[tokio::test]
async fn multi_agent_v2_spawn_rejects_invalid_fork_turns_string() {
async fn multi_agent_v2_spawn_rejects_invalid_fork_turns_string(fork_turns: &str) {
let (mut session, mut turn) = make_session_and_context().await;
let manager = thread_manager();
let root = manager
@@ -1279,7 +1281,7 @@ async fn multi_agent_v2_spawn_rejects_invalid_fork_turns_string() {
function_payload(json!({
"message": "inspect this repo",
"task_name": "worker",
"fork_turns": "banana"
"fork_turns": fork_turns
})),
))
.await
@@ -1288,49 +1290,7 @@ async fn multi_agent_v2_spawn_rejects_invalid_fork_turns_string() {
assert_eq!(
err,
FunctionCallError::RespondToModel(
"fork_turns must be `none`, `all`, or a positive integer string".to_string()
)
);
}
#[tokio::test]
async fn multi_agent_v2_spawn_rejects_zero_fork_turns() {
let (mut session, mut 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");
set_agent_control(&mut session, manager.agent_control());
session.thread_id = root.thread_id;
let mut config = (*turn.config).clone();
config
.features
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
set_turn_config(&mut turn, config);
let err = SpawnAgentHandlerV2::default()
.handle(invocation(
Arc::new(session),
Arc::new(turn),
"spawn_agent",
function_payload(json!({
"message": "inspect this repo",
"task_name": "worker",
"fork_turns": "0"
})),
))
.await
.err()
.expect("zero turn count should be rejected");
assert_eq!(
err,
FunctionCallError::RespondToModel(
"fork_turns must be `none`, `all`, or a positive integer string".to_string()
)
FunctionCallError::RespondToModel("fork_turns must be `none` or `all`".to_string())
);
}
@@ -20,6 +20,7 @@ use codex_prompts::ResolvedModelMessages;
use codex_protocol::ThreadId;
use codex_protocol::protocol::MultiAgentVersion;
use codex_tools::ToolSpec;
use std::num::NonZeroUsize;
#[derive(Default)]
pub(crate) struct Handler {
@@ -288,22 +289,14 @@ impl SpawnAgentArgs {
if fork_turns.eq_ignore_ascii_case("none") {
return Ok(None);
}
if fork_turns.eq_ignore_ascii_case("all") {
// Accept legacy turn counts without limiting the inherited history.
if fork_turns.eq_ignore_ascii_case("all") || fork_turns.parse::<NonZeroUsize>().is_ok() {
return Ok(Some(SpawnAgentForkMode::FullHistory));
}
let last_n_turns = fork_turns.parse::<usize>().map_err(|_| {
FunctionCallError::RespondToModel(
"fork_turns must be `none`, `all`, or a positive integer string".to_string(),
)
})?;
if last_n_turns == 0 {
return Err(FunctionCallError::RespondToModel(
"fork_turns must be `none`, `all`, or a positive integer string".to_string(),
));
}
Ok(Some(SpawnAgentForkMode::LastNTurns(last_n_turns)))
Err(FunctionCallError::RespondToModel(
"fork_turns must be `none` or `all`".to_string(),
))
}
}