fix(pruning): allow pruning old image tool results to prevent context overflow#41863
fix(pruning): allow pruning old image tool results to prevent context overflow#41863smysle wants to merge 1 commit intoopenclaw:mainfrom
Conversation
… overflow Previously all tool results containing images were unconditionally skipped during context pruning. In screenshot-heavy sessions this caused unrecoverable context overflow since image results could never be removed. Now only the 3 most recent image tool results are protected from pruning; older ones are added to the prunable set like regular tool results. Closes openclaw#41789
Greptile SummaryThis PR fixes an unrecoverable context overflow bug in screenshot-heavy sessions by allowing older image tool results to be pruned, instead of unconditionally protecting all of them. The change is surgical: a pre-pass collects the indexes of all image tool results, then protects only the 3 most recent; the main pruning loop skips only those protected entries — older image results fall through into The logic is consistent and correct:
One finding: The module-level comment on lines 8–9 ("We currently skip pruning tool results that contain images") is now stale and should be updated to reflect the new partial-protection behaviour where only the most recent image results are shielded from pruning. Confidence Score: 4/5
|
Closes #41789
Problem
pruneContextMessages()unconditionally skips alltoolResultmessages that contain image blocks:In screenshot-heavy sessions (e.g., browser automation), image tool results accumulate indefinitely and can never be removed, causing unrecoverable context overflow.
Fix
Instead of protecting all image tool results, only protect the 3 most recent ones. Older image results are added to the prunable set like regular tool results.
Trade-off
Recent screenshots are typically the most relevant for ongoing tasks. Older ones have diminishing value and their ~8KB estimated size per image adds up quickly. The constant
MAX_PROTECTED_IMAGE_RESULTS = 3can be tuned or made configurable if needed.