Repository navigation
Description
Problem
On main 7653eb7ec8fd6763dc7af501355f4951b36632bf (2.1.0-SNAPSHOT), an arbitrary tool can return more content than the next model request allows. Final budget validation detects this but can leave the turn unable to continue. Provider-side context errors also occur when an unknown/optimistic window permits a result below the normal 80,000-character eviction threshold. Retrying the same session can encounter the oversized result again.
This is broader than read_file pagination (#2951, #2942, PR #3821): external browser/MCP/custom tools cannot all be trusted to bound their outputs, and summary generation also needs bounded input.
Reproduction
Use a credential-free model fixture that rejects serialized message input above 55,000 characters and a read-only external tool returning "evidence ".repeat(7000). Report an unknown model window, disable ordinary tool-result eviction, and ask the agent to invoke the tool. Repeat for call/streamEvents and native/legacy history. Also exercise a known 16,000-token window with a 630,000-character result.
At the final request boundary, independently test read_file exclusion, an arbitrary 60,000-character result, disabled eviction, and denied artifact writes against a 4,096-token model.
All 10 regression scenarios fail on this main commit: four final-budget errors and six integration failures (provider context errors, emergency compaction failure, or final-budget errors). The proposed patch makes them pass, including next messages and file-backed agent recreation without rerunning the tool.
Expected
Harness should deterministically reduce tool outputs before inference or summarization when the complete request does not fit, regardless of tool name. Prefer storing complete outputs and exposing bounded previews; explicitly disclose a lossy fallback if storage is unavailable. Commit only validated history. On a provider context rejection, attempt bounded recovery without reexecuting tools or dropping the current user turn.
This does not require an impossible guarantee for infinite allocation, oversized fixed prompts/user input/schemas, or arbitrary unknown provider tokenizers. The proposed provider recovery is a single bounded retry, not an unlimited retry loop.
Environment
Java 21 (Java 17 compilation target), Windows; source-level tests with synthetic models, no live provider credentials. Benben integration reproduces the browser artifact/readback and subsequent-message behavior as well.
Activity