Repository navigation
fix(core): propagate agent state load failures - #2760
Conversation
Remove the broad exception handler that converted state-store and deserialization failures into fresh agent state. Keep fresh-state creation limited to successful not-found results, add regression coverage for versioned and legacy load paths, and update the harness fixture to honor the AgentStateStore contract.
4bd7f47 to
da0faae
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a data-loss bug in ReActAgent.loadOrCreateAgentStateForSlot where a broad try-catch (Exception) silently swallowed state store failures (network errors, deserialization failures, etc.) and returned a fresh empty state. This could cause the agent to "forget" persisted conversation history and even overwrite it on the next save. The fix removes the catch block so exceptions propagate to callers, causing the agent call to fail instead of silently losing state. The change is correct, well-scoped, and backed by comprehensive regression tests covering versioned store failures, legacy store failures, decoding failures, and happy-path scenarios. The harness test fix (replacing bare mocks with delegate-backed mocks) is a necessary adaptation. One minor suggestion: preserve the structured userId/sessionId logging that was removed with the catch block.
| } catch (Exception e) { | ||
| log.warn( | ||
| "Failed to load AgentState for slot (userId={}, sessionId={}): {}", | ||
| "Failed to load AgentState for slot (userId={}, sessionId={})", |
There was a problem hiding this comment.
建议: 重新抛出异常的情况下,在这里不打印日志,调用方可能会 catch 或者做异常处理的时候重新打印 stack trace,导致二次打印 stack trace
|
@hexly666 不知道为啥Assign不了你(可能github bug),评论记录一下 |
AgentScope-Java Version
2.0.3-SNAPSHOT
Summary
Prevent
ReActAgentfrom silently replacing conversation state with a fresh session whenAgentStateStoreloading fails.Root Cause
loadOrCreateAgentStateForSlotcaught everyExceptionraised by versioned or legacy state loading and returned a freshAgentState. This made backend, connection, I/O, and deserialization failures indistinguishable from a successful not-found result.The fresh state could then enter the per-slot cache and be saved with a zero or unversioned baseline, potentially overwriting valid persisted conversation history.
Changes
AgentStateStoredelegates to a contract-compliant in-memory implementation.Tests
mvn -pl agentscope-core -Dtest=ReActAgentStateLoadFailureTest -DfailIfNoTests=false testmvn -pl agentscope-harness testmvn spotless:checkmvn -pl agentscope-core testGracefulShutdownTestalso passed 49/49 when rerun independently after one shared-static-state flaky failure in an exclusion run.Risk
The intentional behavior change is that a turn now fails when persisted state cannot be restored. Valid missing-state, existing-state, versioned, non-versioned, and legacy paths remain unchanged. No public API or storage format changes are introduced.
Fixes #2741