Skip to content

fix(harness): align compaction with final input accounting - #3847

Merged
Buktal merged 1 commit into
agentscope-ai:mainfrom
Buktal:codex/unify-compaction-budget
Oct 29, 2026
Merged

Buktal merged 1 commit into
agentscope-ai:mainfrom
Buktal:codex/unify-compaction-budget

Conversation

@Buktal

@Buktal Buktal commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Compaction can skip oversized media history because it uses a different estimator from final request validation. This change uses the configured ContextPolicy.estimator() throughout compaction triggering, tail retention, lightweight reductions, and final validation.

Refs #3834 — slice 02 of the shared tracking issue. The remaining slices stay open; slice 03 depends on this change.

Summary

ContextPolicy.estimator()
  complete projected candidate - already-budgeted fixed inputs
    -> compaction trigger, tail retention, reduction metrics
  individual tool-result message - fixed request overhead
    -> output protection and pruning thresholds
  complete final request
    -> validation before history replacement

TokenCounterUtil retains its public integer API and delegates to the existing default estimator, removing duplicate text/tool/media accounting. Existing public compactor and middleware entry points remain available.

Single-result accounting excludes unrelated task projections. Tail selection checks suffixes in order: removing a full Todo receipt can expand the task-state projection, so suffix costs are not necessarily monotonic. English and Chinese context documentation describe these scopes.

The budgeting references are ZCode's effective input window and DeepSeek Harness's full-envelope measurement, which also exposes single-message estimation. The nonmonotonic Todo case is reproduced against AgentScope's own projection implementation.

Evidence

  • Before: A fixture with 24 image messages and a 1,024-token input limit skipped summarization and failed final validation. A configured custom estimator also failed to govern tail retention.
    After: The media fixture summarizes once, retains the current message, and fits the limit. The custom-estimator fixture retains the expected tail and finishes at 510 estimated tokens.
  • Before: A visible full Todo receipt caused unrelated read output to lose protection; binary tail selection missed a fitting suffix containing that receipt. These regressions produced two failing tests.
    After: Both Todo display forms preserve the same protected outputs, and the fitting receipt/tail is retained. A custom-cost regression also excludes request/schema overhead from each output.
  • Validation: 106 targeted tests passed. mvn -B -T1C clean verify succeeded across 99 modules: 11,350 passed, 243 skipped, zero failures/errors, including Spotless. Skips include disabled integration/E2E suites and unavailable credentials/Docker.
  • Docs: 13 tests and npm run validate passed. npm run broken-links reports the same 2,222 links in 328 files as before this follow-up; this PR changes no links or anchors.

Merge Danger

Door: two-way

No dependency or persisted-state migration. Existing estimator defaults are reused; legacy message-token estimates intentionally change to match final input accounting.

Blast Radius: Harness

Compaction timing and retained history can change for media, custom estimators, and task projections. Sequential suffix checks may require O(n) estimator calls; latency has not been benchmarked. Validation uses local fixtures, with no live provider or sandbox E2E run.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All executed Java tests pass (mvn -B -T1C clean verify; skips noted above)
  • Javadoc comments describe counter scopes and project conventions
  • Related English and Chinese documentation has been updated
  • Code is ready for review

@mintlify

mintlify Bot commented Oct 29, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 7825c59.

Approve preview

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.

2 participants