Skip to content

fix(harness): return lightweight pruning result when safe cutoff is zero - #3571

Merged
jujn merged 5 commits into
agentscope-ai:mainfrom
dargoner:fix/compaction-lightweight-result-return
Oct 18, 2026
Merged

jujn merged 5 commits into
agentscope-ai:mainfrom
dargoner:fix/compaction-lightweight-result-return

Conversation

@dargoner

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (based on main @ 5f7f8e6)

Description

Fixes #2970.

Background

ConversationCompactor.compactStandard performs lightweight, non-LLM pruning (argument truncation + tool-result pruning) before deciding whether to summarize. When pruning changes the conversation but the safe cutoff point ends up at 0 (nothing summarizable ahead), the method returns Optional.empty(). CompactionMiddleware then keeps the original ReasoningInput and skips the state update, so the next model request still carries the oversized content and can overflow again.

The other early-return branch (pruned below the trigger threshold) already returns the pruned messages; this PR aligns the cutoff <= 0 branch with that behavior.

Note: #2971 proposed a fix for the same issue but has been stalled; this is a minimal, rebased version of that idea.

Changes

  • ConversationCompactor: when cutoff <= 0, return the pruned messages when they differ from the input (Optional.of(messages)); keep Optional.empty() when pruning changed nothing.

Tests

  • ConversationCompactorTest 8 → 10: compactIfNeeded_returnsLightweightResultWhenCutoffIsZero, compactIfNeeded_keepsEmptyWhenCutoffZeroAndNothingChanged; suite 10/10 green.
  • mvn spotless:check passes.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.) — N/A for this change (internal early-return fix)
  • Code is ready for review

- compactStandard 在 determineCutoffIndex 得到 cutoff<=0 时直接返回
  Optional.empty(),把已完成的 prune/truncate 轻量结果一并丢弃,导致
  "触发压缩但无可摘要前缀" 场景下上下文体积没有任何下降。
- 改为与轻量分支一致:仅当 messages 与原列表不同才返回 Optional.of(messages),
  否则维持 Optional.empty(),不改变可摘要场景的原有行为。
- 回归:ConversationCompactorTest 新增 cutoff=0 返回轻量结果、以及无变化仍返回
  空的用例;修复前第一个用例断言失败(结果被丢弃)。

只调整 cutoff<=0 分支的返回值,不改 trigger/keep/prune/truncate 算法。
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jujn
jujn force-pushed the fix/compaction-lightweight-result-return branch from 0b1817d to 593366c Compare October 18, 2026 12:37
@jujn
jujn merged commit 40a4a57 into agentscope-ai:main Oct 18, 2026
5 checks passed
@dargoner
dargoner deleted the fix/compaction-lightweight-result-return branch October 18, 2026 13:06
chickenlj added a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Lightweight compaction results are discarded when summarization is skipped

3 participants