Avoid cloning rollout history when truncating forks (#35982)

## What changed

- Consume owned rollout vectors when truncating fork and subagent history, reusing their allocations instead of copying slices.
- Project ephemeral fork responses and token-usage ownership before moving the source history into the new thread.
- Preserve canonical `beforeTurnId` validation for rolled-back and synthetic legacy turns.

## Testing

- Add truncation tests covering rolled-back and synthetic legacy `beforeTurnId` values.

GitOrigin-RevId: 5785d004b74d7e057b82379a172676b023bcfb4f
This commit is contained in:
Charlie Marsh authored and copyberry committed 2026-07-29 15:41:39 +00:00
1 parent 3725f02cf3
commit 1ae2b9880e
7 files changed
+211 -110

No files matched your search

+1 -1
View File
@@ -655,7 +655,7 @@ impl AgentControl {
.unwrap_or_default();
if let SpawnAgentForkMode::LastNTurns(last_n_turns) = fork_mode {
forked_rollout_items =
truncate_rollout_to_last_n_fork_turns(&forked_rollout_items, *last_n_turns);
truncate_rollout_to_last_n_fork_turns(forked_rollout_items, *last_n_turns);
}
let multi_agent_v2_usage_hint_texts_to_filter: Vec<String> =
if multi_agent_version == MultiAgentVersion::V2 {