agentscope-ai / agentscope-ai/agentscope-java
[Bug]:Unstable computeHash causes unnecessary MysqlSession rewrites
- 主要語言
- Java
- 星號
- 5.6k
- 分支
- 1.3k
- 平均合併
- 4 天 12 小時
- 30 天內合併 PR
- 77
描述
**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)` may trigger unnecessary full list rewrites for `List` 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` 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:
```java
List 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 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`
貢獻指南
評估
這個 Issue 還沒有評估資料。