You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: HarnessAgent context-overflow recovery appends the user input twice since #2799 (and likely loses the emergency compaction) #3626
Since #2799, a failed call persists the state, and that state already contains the current turn's input (ReActAgent.java#L1227 → saveStateAfterCallFailure).
HarnessAgent recovers from a context-overflow error with forceCompactAndRetry (HarnessAgent.java#L1058-L1104). It compacts the in-memory state (state.contextMutable().clear(); addAll(compacted), L1090-1091) and then retries with the same msgs via delegate.call(msgs, effective) (L1092).
On the retry:
activateSlotForContext (ReActAgent.java#L659-L681) reloads the state from the state store. HarnessAgent always configures one (JsonFileAgentStateStore by default). The reloaded state already contains the input, because the failed attempt persisted it.
doCallInner → addToContext(msgs) (ReActAgent.java#L1838) appends the same input again.
So after a recovered overflow, the user's input appears twice in the context.
There is also a second consequence, inferred from reading the code and not verified at runtime: the reload replaces the in-memory compacted context with the persisted, uncompacted one. That would make the retry run against the original oversized context and likely overflow again. This happens with any store that returns a copy. A store that returns the same reference would keep the compaction, but the input would still be duplicated.
To Reproduce
Build a HarnessAgent with compaction enabled and the default state store.
Make the model throw a context-overflow error on the first call and succeed on the second.
Call the agent with a single user message, then inspect the persisted context: that user message appears twice.
Expected behavior
Overflow recovery retries once with the compacted context, and the turn's input appears exactly once.
Suggested fix
Persist the compacted state before retrying, so that the reload picks it up.
Do not re-send input that is already in the context. For example, remove the trailing occurrence of msgs (matched by id) from the context before compacting, or retry with an empty input when msgs is already the tail of the context.
Environment
AgentScope-Java Version: 2.0.4 (also on main @035487e)
Activity
fix(harness): persist compacted state and avoid duplicate input on ov…
fix(harness): persist compacted state and avoid duplicate input on ov…