Retain client-marked tool outputs across compaction (#52937)

## Why

Client-supplied tool outputs can carry task instructions. Even when marked with `retain: true`, these instructions could be trimmed before compaction and disappear from the compacted history.

## What changed

Add the disabled-by-default `retain_client_tool_outputs` feature to honor retention for explicitly marked, named `function_call_output` items without a `call_id`.

- Preserve eligible outputs in remote compaction v2 and when starting a new context window, keeping their original role.
- Stop emergency tool-output trimming at a retained output.
- Share the existing 64,000-token retention budget, keeping outputs whole and dropping an oversized output and older items rather than partially truncating it.
- Place initial context before retained standalone outputs and account for their images in retained-image counts.

## Testing

Add a scenario covering enabled and disabled retention, emergency trimming, oversized-output handling, and preservation of the latest instruction after compaction and cold resume. Verify that retention annotations stay out of model requests.

GitOrigin-RevId: 449179670e4d2be2623928700738758e43b5dc1a
This commit is contained in:
Won Park
2026-10-10 17:30:25 +00:00
committed by copyberry
parent be9060ff96
commit 6c0c6759d0
12 changed files with 452 additions and 31 deletions
+8
View File
@@ -423,6 +423,8 @@ pub enum Feature {
CompactionImageBudget,
/// Retain client-authored developer messages across compacted context windows.
RetainClientDeveloperMessages,
/// Honor client-requested tool-output retention across context windows.
RetainClientToolOutputs,
/// Use Agent Identity for ChatGPT-authenticated sessions.
UseAgentIdentity,
/// Enable workspace dependency support.
@@ -2052,6 +2054,12 @@ pub const FEATURES: &[FeatureSpec] = &[
stage: Stage::UnderDevelopment,
default_enabled: false,
},
FeatureSpec {
id: Feature::RetainClientToolOutputs,
key: "retain_client_tool_outputs",
stage: Stage::UnderDevelopment,
default_enabled: false,
},
FeatureSpec {
id: Feature::UseAgentIdentity,
key: "use_agent_identity",