fix(pinch): cap outsized tool results even inside the protected window #44
Reference in New Issue
Block a user
Delete Branch "fix/pinch-protected-window-size-cap"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
keep_last_turns has no size limit inside it: an entire autonomous tool-call loop with no new user message counts as one protected turn, so one outsized tool result inside it -- a full verbose test run, a huge file read -- shipped verbatim regardless of size.
Measured live 2026-09-06: a 324k-token conversation only shrank ~8% because nearly all of it sat inside the protected window, and even after pruning was still ~6x
pinch.budget_tokens. This matters beyond raw token cost too -- the pruned size is what feedsrequired_context_tokens(dispatcher.py measures it post-prune before tier/candidate selection), so a poorly-pruned conversation can also keep a request above a smaller, cheaper model's context ceiling that a properly-pruned one would have dropped below.New
pinch.protected_max_chars(default 20000, null to disable): any tool result inside the protected window over this many characters still gets the same head/tail elision candidates already get. Deliberately a much higher bar thanmax_summarize_chars(4000) -- recent results are more likely to still matter -- so this only catches true outliers, never ordinary recent tool output.The pure
prune_contextfunction's own default staysNone, so every existing caller/test is unaffected unless it opts in;PinchConfigsupplies the real production default.New regression tests confirmed failing (TypeError, param didn't exist) on the unfixed code, passing after. Full suite: 1473 passed, 0 failures.