fix(core): optimize context pruning for large overflow (Issue #8402) #8426
+15
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses Issue #8402 (Context pruning hangs on large overflow) by implementing a "Smart Batch Pruning" strategy.
Problem
Previous logic removed history items one-by-one upon
ContextWindowExceeded. When the overflow was significant (e.g., due to a large tool output), this resulted in hundreds of inefficient retries, causing the system to hang.Fix
Modified
run_compact_task_innerincore/src/compact.rsto prune ~10% of history items (minimum 1) at once. This significantly speeds up convergence to a valid context size and helps clear "invisible" items (like Ghost Snapshots) that might accumulate at the head of the history.Testing Status
cargo check -p codex-corePASSED.