Preserve paginated history for spawned subagents (#33432)

## What changed

- Inherit paginated history mode when spawning or forking a subagent from a paginated parent.
- Load the parent's model context when forking and persist it as an inherited rollout prefix, while excluding that prefix from the child's projected turns, items, and metadata.
- Record the boundary between inherited context and child history, and reject partially initialized paginated subagent rollouts on resume.
- Resume paginated subagents from their stored model context instead of legacy rollout history.

## Testing

Added coverage for fresh and forked paginated subagents, compacted-history forks, model-context resume, inherited-prefix projection, metadata isolation, and incomplete-prefix detection.

GitOrigin-RevId: e57dc37c29aa4aaaf57b052b991be591d730e5ba
This commit is contained in:
Owen Lin authored and copyberry committed 2026-07-15 21:25:24 +00:00
1 parent cb79b3cdf9
commit 2be648ba4a
36 files changed
+954 -73

No files matched your search

+19
View File
@@ -88,6 +88,7 @@ pub struct RolloutRecorder {
}
#[derive(Clone)]
#[allow(clippy::large_enum_variant)]
pub enum RolloutRecorderParams {
Create {
session_id: SessionId,
@@ -102,6 +103,7 @@ pub enum RolloutRecorderParams {
selected_capability_roots: Vec<SelectedCapabilityRoot>,
multi_agent_version: Option<MultiAgentVersion>,
history_mode: ThreadHistoryMode,
subagent_history_start_ordinal: Option<u64>,
initial_window_id: Option<String>,
},
Resume {
@@ -195,6 +197,7 @@ impl RolloutRecorderParams {
selected_capability_roots: Vec::new(),
multi_agent_version: None,
history_mode: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: None,
}
}
@@ -244,6 +247,20 @@ impl RolloutRecorderParams {
self
}
pub fn with_subagent_history_start_ordinal(
mut self,
subagent_history_start_ordinal: Option<u64>,
) -> Self {
if let Self::Create {
subagent_history_start_ordinal: ordinal,
..
} = &mut self
{
*ordinal = subagent_history_start_ordinal;
}
self
}
pub fn with_initial_window_id(mut self, initial_window_id: String) -> Self {
if let Self::Create {
initial_window_id: window_id,
@@ -773,6 +790,7 @@ impl RolloutRecorder {
selected_capability_roots,
multi_agent_version,
history_mode,
subagent_history_start_ordinal,
initial_window_id,
} => {
let ordinal_state = RolloutOrdinalState::for_new_rollout(history_mode);
@@ -813,6 +831,7 @@ impl RolloutRecorder {
selected_capability_roots,
memory_mode: (!config.generate_memories()).then_some("disabled".to_string()),
history_mode,
subagent_history_start_ordinal,
multi_agent_version,
context_window: initial_window_id.map(SessionContextWindow::new),
};