Skip to content

[Bug]:Unstable computeHash causes unnecessary MysqlSession rewrites #1357

@luowanghaoyun

Description

@luowanghaoyun

AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the bug
MysqlSession.save(SessionKey, String, List<? extends State>) may trigger unnecessary full list rewrites for List<Msg> even when messages are logically identical.
ListHashUtil.computeHash() relies on element hashCode(). For nested message content, semantically equivalent lists can still produce different hashes, causing needsFullRewrite(...) to evaluate to true.

To Reproduce
Steps to reproduce the behavior:

  1. Use two newly created List<Msg> instances with logically identical messages:
    • user: "hello"
    • assistant: "hello"
  2. Ensure all visible fields are set identically (e.g., same id, timestamp, role, and text content), then call:
    • ListHashUtil.computeHash(firstList)
    • ListHashUtil.computeHash(secondList)
  3. Compare the two hash strings.

Minimal example:

List<Msg> first = List.of(
    Msg.builder().id("m-user-1").timestamp("2026-05-08 14:00:00.000")
        .role(MsgRole.USER).content(TextBlock.builder().text("hello").build()).build(),
    Msg.builder().id("m-assistant-1").timestamp("2026-05-08 14:00:01.000")
        .role(MsgRole.ASSISTANT).content(TextBlock.builder().text("hello").build()).build()
);

List<Msg> second = List.of(
    Msg.builder().id("m-user-1").timestamp("2026-05-08 14:00:00.000")
        .role(MsgRole.USER).content(TextBlock.builder().text("hello").build()).build(),
    Msg.builder().id("m-assistant-1").timestamp("2026-05-08 14:00:01.000")
        .role(MsgRole.ASSISTANT).content(TextBlock.builder().text("hello").build()).build()
);

String h1 = ListHashUtil.computeHash(first);
String h2 = ListHashUtil.computeHash(second);

Expected behavior
For logically equivalent message lists, computeHash should be stable and equal, so needsFullRewrite(...) does not force delete + rewrite.

Error messages
No runtime exception in normal flow.
Observed behavioral mismatch in hash values for equivalent lists, e.g.:

  • h1 = de9291ea
  • h2 = 68bb1c12

This leads to unnecessary full rewrites (DELETE + INSERT all) in session persistence paths.

Environment (please complete the following information):

  • AgentScope-Java Version: 1.0.13-SNAPSHOT
  • Java Version: 17
  • OS: macOS

Additional context

  • Related files:
    • agentscope-core/src/main/java/io/agentscope/core/session/ListHashUtil.java
    • agentscope-extensions/agentscope-extensions-session-mysql/src/main/java/io/agentscope/core/session/mysql/MysqlSession.java
    • agentscope-core/src/main/java/io/agentscope/core/state/State.java
    • agentscope-core/src/main/java/io/agentscope/core/message/Msg.java

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions