Preserve tool declaration mode across resumed context windows (#51480)

## Why

Changing the incremental tools setting on resume should not move tool declarations and base instructions within an existing context window.

## What changed

- Determine the current window's tool declaration mode from its history, and apply the incremental tools setting when building a new window after compaction or a context reset.
- Use that mode consistently for sampling, remote compaction, startup prewarm, prompt debugging, and Guardian input budgeting.
- Preserve tool declarations alongside their comparison baseline in full-history agent forks, including compacted histories; remove them together when rebuilding context.

## Testing

Add request snapshots covering legacy resume, migration after remote compaction or a context reset, disabling incremental tools, and tool updates after restart. Extend agent fork and WebSocket startup prewarm tests to cover retained declarations and incremental tools.

GitOrigin-RevId: 7c46849a1788027a8435082e4d1f7e7f48d2700c
This commit is contained in:
pakrym-oai
2026-10-06 21:28:13 +00:00
committed by copyberry
parent 0b863c69f5
commit e79c498b5e
27 changed files with 723 additions and 75 deletions
@@ -6,6 +6,12 @@ use serde::Serialize;
#[serde(transparent)]
pub struct ContentItemKind(pub String);
impl ContentItemKind {
pub fn as_str(&self) -> &str {
&self.0
}
}
#[cfg(test)]
#[path = "item_metadata_tests.rs"]
mod tests;