Skip to content

fix(core): propagate agent state load failures - #2760

Merged
jujn merged 4 commits into
agentscope-ai:mainfrom
ordinary-s:fix/agent-state-load-failure-2741
Aug 28, 2026
Merged

jujn merged 4 commits into
agentscope-ai:mainfrom
ordinary-s:fix/agent-state-load-failure-2741

Conversation

@ordinary-s

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT

Summary

Prevent ReActAgent from silently replacing conversation state with a fresh session when AgentStateStore loading fails.

Root Cause

loadOrCreateAgentStateForSlot caught every Exception raised by versioned or legacy state loading and returned a fresh AgentState. 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

  • Remove the broad state-load exception handler.
  • Let the original load or decoding exception propagate to the caller.
  • Continue creating fresh state only after both versioned and legacy loads successfully report that no state exists.
  • Add regression coverage for versioned store failures, non-versioned legacy failures, genuinely missing state, existing state restoration, decoding failures, and cache/persisted-state integrity.
  • Update a harness test fixture so its mocked AgentStateStore delegates to a contract-compliant in-memory implementation.

Tests

  • mvn -pl agentscope-core -Dtest=ReActAgentStateLoadFailureTest -DfailIfNoTests=false test
    • 5 tests passed
  • mvn -pl agentscope-harness test
    • 830 tests run, 0 failures, 0 errors, 3 skipped
  • mvn spotless:check
    • all 88 reactor modules passed
  • mvn -pl agentscope-core test
    • 2,280 tests ran with 0 failures and 2 errors; both errors are pre-existing Windows symlink tests that cannot create symbolic links under the current user's permissions. The unrelated GracefulShutdownTest also 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

@CLAassistant

CLAassistant commented Aug 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.
@ordinary-s
ordinary-s force-pushed the fix/agent-state-load-failure-2741 branch from 4bd7f47 to da0faae Compare August 18, 2026 07:41
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Aug 19, 2026
} catch (Exception e) {
log.warn(
"Failed to load AgentState for slot (userId={}, sessionId={}): {}",
"Failed to load AgentState for slot (userId={}, sessionId={})",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议: 重新抛出异常的情况下,在这里不打印日志,调用方可能会 catch 或者做异常处理的时候重新打印 stack trace,导致二次打印 stack trace

@zouyx zouyx assigned jujn and zouyx and unassigned jujn and zouyx Aug 28, 2026
@jujn

jujn commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

@hexly666 不知道为啥Assign不了你(可能github bug),评论记录一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/agent Agent runtime, pipeline, hooks, plan bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ReActAgent silently resets conversation memory when AgentStateStore throws (and drops the stack trace)

6 participants