Preserve delegated tasks across remote compaction (#36128)

## What changed

- Retain bounded, non-completion agent messages in remote v2 compaction history so delegated tasks remain available on follow-up turns.
- Account for encrypted agent-message content when estimating token usage and place restored initial context before the latest real user or agent message.
- Exclude child completion messages from retained follow-up history and strip inherited parent agent messages when forking a child.

## Testing

- Extend compaction, history-estimation, and agent-fork tests to cover encrypted delegated tasks, child completions, context ordering, and fork sanitization.

GitOrigin-RevId: ba4392e9cfdf4ecbcdc9c7d8581d58a8d2d78260
This commit is contained in:
jif authored and copyberry committed 2026-07-30 10:11:46 +00:00
1 parent 89a0eed93c
commit 4f6d06d485
8 files changed
+180 -23

No files matched your search

+3
View File
@@ -696,6 +696,9 @@ impl AgentControl {
// Compaction stores response items separately, so sanitize both top-level messages and
// compacted replacement histories with the same policy.
let retain_forked_item = |response_item: &mut ResponseItem, replaced: &mut bool| {
if matches!(response_item, ResponseItem::AgentMessage { .. }) {
return false;
}
if is_multi_agent_v2_usage_hint_message(
response_item,
&multi_agent_v2_usage_hint_texts_to_filter,