Add thread and child retention policies for injected items (#62654)

## Why

The `always` policy ties retention across context windows to inheritance by
spawned agents. Callers need to control those behaviors independently.

## What changed

- `alwaysInThread` carries items across context windows in the current thread
  and excludes them from spawned agents, including full-history forks.
- `alwaysInChildren` passes items still in the parent's context to spawned
  agents and leaves each thread's context-window retention to the usual rules.
- `always` continues to apply in both scopes, including for items saved by
  older versions. Retained tool calls and outputs must be adjacent, with the
  call first and the same retention policy on both items.

## Testing

Extend integration coverage for retention across remote compaction, inheritance
by spawned agents, and injection through the app server.

GitOrigin-RevId: aafede69cfbe149aa52292e6029d248d4bdf6401
This commit is contained in:
Vivian Fang
2026-11-20 02:59:58 +00:00
committed by copyberry
parent e787cf7024
commit a0a30c40e8
12 changed files with 120 additions and 37 deletions
@@ -130,8 +130,8 @@ async fn thread_inject_items_adds_raw_response_items_to_thread_history(
items: vec![
serde_json::to_value(&injected_item)?,
json!({"item": injected_developer_item, "retention": "default"}),
json!({"item": marker_shaped_developer_item, "retention": "always"}),
json!({"item": named_tool_output, "retention": "always"}),
json!({"item": marker_shaped_developer_item, "retention": "alwaysInThread"}),
json!({"item": named_tool_output, "retention": "alwaysInChildren"}),
],
})
.await?;
@@ -198,7 +198,7 @@ async fn thread_inject_items_adds_raw_response_items_to_thread_history(
(injected_item.clone(), false, None),
(injected_developer_item.clone(), false, Some(false)),
(marker_shaped_developer_item.clone(), false, Some(true)),
(named_tool_item, false, Some(true)),
(named_tool_item, false, Some(false)),
(agent_mail.clone(), false, None),
]
);