feat(compaction): add dormant hard compaction planner#2838
Conversation
There was a problem hiding this comment.
Hmbown has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Code Review
This pull request introduces a default-disabled hard-compaction planner that identifies the summarizable middle of a long conversation while preserving the recent tail, tool-call/result pairs, and working-set pinning. Feedback suggests optimizing the generation of preserved_indices in plan_hard_compaction by directly collecting soft_plan.pinned_indices instead of manually computing the complement of summarize_indices, which reduces complexity and avoids unnecessary allocations.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let summarized: BTreeSet<_> = soft_plan.summarize_indices.iter().copied().collect(); | ||
| let preserved_indices = (0..messages.len()) | ||
| .filter(|idx| !summarized.contains(idx)) | ||
| .collect(); |
There was a problem hiding this comment.
The preserved_indices are the exact complement of summarize_indices in the compaction plan, which is already computed and stored in soft_plan.pinned_indices. Instead of collecting summarize_indices into a temporary BTreeSet and performing a linear scan with .contains() checks, you can directly consume and collect soft_plan.pinned_indices into a Vec. This avoids unnecessary allocations and reduces the complexity from O(N log N) to O(N).
| let summarized: BTreeSet<_> = soft_plan.summarize_indices.iter().copied().collect(); | |
| let preserved_indices = (0..messages.len()) | |
| .filter(|idx| !summarized.contains(idx)) | |
| .collect(); | |
| let preserved_indices = soft_plan.pinned_indices.into_iter().collect(); |
Summary
HardCompactionConfigand pureplan_hard_compactionhelperplan_compactionmachinery so recent tail, working-set pins, user-text fallback, and tool-call/result pair guarantees stay intactStewardship
Refs #2522. This harvests the safe planning layer from @HUQIANTAO's hard-compaction proposal without enabling hard compaction, adding user config, or adding a message-rewrite/LLM execution path. The broader runtime behavior remains deferred until tool-pair atomicity, anchors, working-set preservation, and cache/prefix metadata semantics are fully specified and tested.
Verification
cargo test -p codewhale-tui compaction --lockedcargo fmt --all./scripts/release/check-versions.sh./scripts/release/check-ohos-deps.shcargo clippy -p codewhale-tui --bin codewhale-tui --locked -- -D warningscargo fmt --all -- --checkgit diff --checkcargo check --workspace --all-features --locked