Skip to content

fix(harness): count pruning budgets per tool result - #3538

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/prune-batched-tool-result-budgets
Oct 14, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/prune-batched-tool-result-budgets

Conversation

@pengmoubuaixuexi

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT, based on main c2ff087.

Description

Fixes #3537.

When a TOOL message contains several results, pruneToolResults counts the whole message for each result. This exhausts the recent-output protection budget too early and can trigger pruning below the configured minimum. With six 1,000-character results, batching them in one message protects fewer recent results than six separate messages; it also incorrectly exceeds a 3,000-token minimum.

Count each result using a message copy containing only that block. This preserves single-result estimates without changing the token estimator or mutating the original history. Two public compactIfNeeded regressions cover the protection window and minimum threshold, and the English/Chinese context docs clarify the budget. This applies to batched/custom histories; the default ReAct tool-message builder normally emits one result per message.

Validation

  • Unmodified production code: both new regressions fail; the existing five pruning tests pass.
  • Related compaction, middleware, token counting, and async-wait tests: 50 run, no failures/errors/skips.
  • Full Harness suite: Tests run: 1240, Failures: 0, Errors: 0, Skipped: 18.
  • Spotless checks and git diff --check pass.
  • Docs: 13 tests pass; npm run validate passes (430 pages / 584 redirects and Mint build validation).
  • Full Core/Harness reactor attempted: Core stops before Harness on two Windows symlink privilege errors. A second run excluding just those methods encountered an unchanged GracefulShutdownTest failure (defaultConfig: expected null, got PT0.1S); that test passed in the first run. Core source/tests are untouched. The full reactor is not claimed green.
  • mint broken-links reports 2,208 links in 326 files on both original HEAD docs and this patch, with identical reported paths. No new links are introduced.

Commands:

mvn -B -T1 -pl agentscope-harness -am -Dtest=ConversationCompactor*,TokenCounterUtilTest,CompactionMiddlewareTest,WaitAsyncResultsToolTest -Dsurefire.failIfNoSpecifiedTests=false test
mvn -B -T1 -pl agentscope-harness -am -Dtest=io.agentscope.harness.** -Dsurefire.failIfNoSpecifiedTests=false test

AI assistance was used for source review, implementation, and tests. The reproductions were executed locally and the final diff was checked against the surrounding code and documented contract.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test) — full reactor limitations described above
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated
  • Code is ready for review

Copilot AI balanced review requested due to automatic review settings October 14, 2026 00:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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!

@guslegend0510 guslegend0510 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pengmoubuaixuexi

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I checked the Windows failure: JevTraceManagedAgentTest.browserCannotBypassMissingServicePermissionPolicy in service-dataplane exceeded the 10-second blocking-read deadline at validateManagedBuild (line 372).

The Windows Harness suite completed with 1,240 tests, 0 failures/errors and 18 skipped; all seven pruning tests, including both new regressions, passed. The Ubuntu build also passed. Failed Windows job.

Could a maintainer rerun the failed Windows job to check whether this is intermittent? I have not changed the service test's timeout based on this single failure.

@jujn
jujn merged commit 9776a37 into agentscope-ai:main Oct 14, 2026
6 of 7 checks passed
@CryoThrust

Copy link
Copy Markdown
Contributor

Checked ce78d894 on JDK 17 with two extra mixed-message controls: a large ordinary text block beside an eligible tool result, and a large excluded read_file result beside an eligible execute result. Neither sibling should inflate the eligible result's pruning budget. Both remain below the 3,000-token minimum, and the original message/block references and payload stay unchanged.

Both controls and the seven pruning tests pass on this head. Reverting only the per-result counting line produces four failures: both added controls and your two batching regressions. After restoring the line, the related compaction/middleware/token/async-wait slice passes all 52 tests, with no failures/errors/skips. Production is restored; this is focused verification, not a full Service/Windows reactor result.

The two extra tests are available in 32c71750 as a test-only commit for adoption if useful.

chickenlj pushed a commit that referenced this pull request Nov 13, 2026
Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs.

(cherry picked from commit 9776a37)
Backport-review-patch: da6f99255cc58a07360717e447a9a04de01091a9
Constraint: No AgentScope Service or SDK migration
Confidence: high
Not-tested: Whole-repository verification pending after lane integration
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]: Batched tool results are counted repeatedly in compaction pruning budgets

5 participants