Repository navigation
fix(harness): persist compacted state and avoid duplicate input on overflow retry - #3661
Merged
jujn merged 1 commit intoOct 22, 2026
Conversation
…erflow retry Since agentscope-ai#2799 a failed call persists its state, including the turn's input. forceCompactAndRetry compacted only the in-memory state and retried with the same msgs; the retry reloads the session from the state store, so the input was appended twice and, with stores that return a copy, the compaction was lost. Persist the compacted context via updateAgentState before retrying, and retry with an empty input when the turn's input is already in the context, so the retry continues from the persisted progress without re-running tools. Fixes agentscope-ai#3626
littlebird69
force-pushed
the
fix/harness-overflow-recovery-duplicate-input
branch
from
October 20, 2026 03:40
fdcfbbc to
86ef22b
Compare
Contributor
Author
|
Hi @jujn @xzxiaoshan, could one of you take a look when you have time? CI is green and the branch merges cleanly into current |
jujn
approved these changes
Oct 22, 2026
xzxiaoshan
added a commit
to xzxiaoshan/agentscope-java
that referenced
this pull request
Oct 23, 2026
Conflict resolution in HarnessAgent#forceCompactAndRetry: keep main's overflow-retry rework (agentscope-ai#3661 — persist compacted state via updateAgentState, retry with retryInput to avoid duplicate input) and re-apply the capability-surface re-prepare on the retry call so the grant surface survives the overflow path. Adapt HarnessSkillMiddlewareGrantTest to main's agentscope-ai#3691 change: the skills block now rides a tail runtime material (harness:skills) instead of the system prompt, so grant-visibility assertions move there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
AgentScope-Java Version
2.1.0-SNAPSHOT (main @ 2c6d0eb)
Description
Fixes #3626.
Since #2799 a failed call persists its state, and that state already contains the turn's input.
HarnessAgent#forceCompactAndRetrycompacted only the in-memory state and then retried with the samemsgs. On the retry,activateSlotForContextreloads the session from the state store, so:addToContext(msgs)), andJsonFileAgentStateStore), the compacted context was replaced by the persisted, uncompacted one, so the retry ran against the original oversized context.Both were reproduced with the new tests. Consequence 2 was only inferred in the issue; on the unfixed code the JSON-file variant fails on it while the in-memory variant (which returns the same reference) does not, as predicted.
On current
mainthe native Session Log mode is the default and skips this recovery path, so the bug affectslegacySessionHistory(true)/SessionHistoryMode.LEGACY, and the 2.0.x line, where legacy is the default.Changes
ReActAgent#updateAgentState(onboundedElastic, since stores may block) before retrying, so the reload picks it up. Without a state store the cached state is updated in place, as before.Retrying with an empty input matches what the docs describe for the native Session Log mode ("does not resubmit the user task and does not re-run tools that already completed"). It also follows the empty-input continuation
doCallInneralready uses for shutdown recovery. If the overflow happens after a tool step, the tool result is kept and the tool is not executed again.Tests
New
HarnessAgentOverflowRecoveryTest(legacy mode, scripted model):recoveredOverflowKeepsTheInputOnceAndRetriesWithTheCompactedContext, parameterized overJsonFileAgentStateStoreandInMemoryAgentStateStore: the input is persisted once and sent to the model once, and the retry request no longer contains the folded prefix.overflowAfterAToolStepContinuesWithoutRerunningTheTool: the tool runs once, and the input and tool result are each persisted once.Each half of the fix was checked by reverting it: removing the persist step fails the compaction assertion for both stores; removing the input check fails the "input once" assertion. All three cases fail on the unfixed code.
Validation (JDK 25, Windows 11):
mvn -pl agentscope-harness spotless:check test: 1,257 tests, 0 failures/errors, 18 skipped; Spotless check passed. The new test class was also run against the unfixed code (all 3 cases fail there). Full-projectclean verifywas not run locally.Checklist
mvn spotless:applymvn test) (harness module, see above)