agentscope-ai / agentscope-ai/agentscope-java

[Bug]:Unstable computeHash causes unnecessary MysqlSession rewrites

Abierto
#1,357 2 comentarios 0 reacciones 1 asignado Reclamado por @Alexxigang Ver en GitHub
area/ext/memory bug
Lenguaje dominante
Java
Estrellas
5.6k
Forks
1.3k
Merge medio
4 d 12 h
PR fusionados (30 d)
77

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.