Add opt-in history prefix preservation for full agent forks (#52535)

## What changed

Add `preserve_fork_prefix` to the multi-agent v2 configuration, defaulting to `false`. When enabled, full forks retain the parent's model-visible history, including commentary and tool records, and append the child's instructions. Legacy compaction without a reusable context baseline still rebuilds the child context.

Mark copied history as inherited, complete unfinished tool calls in the fork snapshot, and exclude inherited manual approvals from authorization review while retaining them in model context.

## Testing

Add coverage for preserved request prefixes, child instructions, legacy and paginated histories, Code Mode, missing inherited tool outputs, compaction fallback, and approval isolation across checkpoint replay. Update the noisy helper failure test to read its response before starting cleanup.

GitOrigin-RevId: ce9235dfa111c88d6ce66cb93d564fb63b326489
This commit is contained in:
jif
2026-10-09 11:08:24 +00:00
committed by copyberry
parent 2351d9e1b6
commit a06545b311
19 changed files with 438 additions and 66 deletions
@@ -67,7 +67,7 @@ async fn noisy_failing_helper_preserves_exit_status_and_bounded_stderr() {
let mut command = {
let mut command = Command::new("sh");
command.arg("-c").arg(
"printf 'expected helper diagnostic' >&2; i=0; while [ \"$i\" -lt 1024 ]; do printf '%0128d' 0 >&2; i=$((i + 1)); done; exit 7",
"printf 'expected helper diagnostic' >&2; i=0; while [ \"$i\" -lt 1024 ]; do printf '%0128d' 0 >&2; i=$((i + 1)); done; printf 'response before failure\\n'; exit 7",
);
command
};
@@ -83,17 +83,19 @@ async fn noisy_failing_helper_preserves_exit_status_and_bounded_stderr() {
command
.arg("-NoProfile")
.arg("-Command")
.arg("[Console]::Error.Write('expected helper diagnostic' + ('x' * 131072)); exit 7");
.arg("[Console]::Error.Write('expected helper diagnostic' + ('x' * 131072)); [Console]::Out.WriteLine('response before failure'); exit 7");
command
};
command.envs(std::env::vars_os());
let mut child = command.spawn().expect("noisy helper process");
let stdout = child.stdout.take().expect("helper stdout");
let stderr = drain_helper_stderr(&mut child);
let error = tokio::time::timeout(
Duration::from_secs(/*secs*/ 8),
reap_helper_after_response(child, stderr),
)
let error = tokio::time::timeout(Duration::from_secs(/*secs*/ 8), async {
// Cleanup starts after the response, not during slow helper startup.
read_helper_response(stdout).await?;
reap_helper_after_response(child, stderr).await
})
.await
.expect("helper stderr must be drained during bounded cleanup")
.expect_err("nonzero helper exit should fail after its stderr pipe fills");