agentscope-ai / agentscope-ai/agentscope-java

[Bug]:Unstable computeHash causes unnecessary MysqlSession rewrites

Aperta
#1,357 2 commenti 0 reazioni 1 assegnatario Rivendicata da @Alexxigang Vedi su GitHub
area/ext/memory bug
Lingua principale
Java
Stelle
5.6k
Fork
1.3k
Merge medio
4g 12h
PR unite (30g)
77

Descrizione

**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`

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.