fix(core): save agent state on user interrupt to prevent session loss#1970
Open
Buktal wants to merge 2 commits into
Open
fix(core): save agent state on user interrupt to prevent session loss#1970Buktal wants to merge 2 commits into
Buktal wants to merge 2 commits into
Conversation
When a user interrupt (InterruptedException) occurs during ReActAgent execution, saveStateToSession is skipped because the flatMap chain in doCall() never fires. This causes the in-memory session changes to be lost on restart. The fix adds saveStateToSession in handleInterrupt's USER branch, after the recovery message is appended, with an onErrorResume fallback to ensure the user still receives the recovery message even if persistence fails. Closes agentscope-ai#1968
HarnessAgentTest.runtimeContextConcreteFilesystemSurvivesSessionDefaulting fails intermittently when JUnit can't delete @tempdir because the OS hasn't released file handles. Pre-deleting child files before JUnit's own cleanup reduces the race condition window.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
itxaiohanglover
approved these changes
Jun 30, 2026
itxaiohanglover
left a comment
Contributor
There was a problem hiding this comment.
Clean fix — saving state before returning the recovery message prevents session loss on interrupt. The onErrorResume fallback to log and continue is the right call; a failed save shouldn't block the user. The temp dir cleanup in tests is a nice addition.
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.0.0-SNAPSHOT
Description
When a user interrupt (
InterruptedException) occurs during ReActAgent execution,saveStateToSessionis skipped because theflatMapchain indoCall()never firesafter the exception. This causes all in-memory session changes (user input, partial
agent replies) to be lost if the process is restarted or the session migrates to
another instance.
The fix adds
saveStateToSession(scope)inhandleInterrupt()'s USER branch, afterthe recovery message is appended to context. If persistence fails (e.g. network
timeout), the error is logged and the user still receives the recovery message.
Changes:
ReActAgent.java: USER interrupt branch now saves agent state before returning therecovery message, with
onErrorResumefallbackCloses #1968
Checklist
mvn spotless:applymvn test— 2177 tests, 0 failures)