Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.agentscope.core.session;

import io.agentscope.core.state.State;
import io.agentscope.core.util.JsonUtils;
import java.util.List;

/**
Expand Down Expand Up @@ -88,7 +89,7 @@ public static String computeHash(List<? extends State> values) {

for (int idx : sampleIndices) {
State item = values.get(idx);
int itemHash = item != null ? item.hashCode() : 0;
int itemHash = item != null ? JsonUtils.getJsonCodec().toJson(item).hashCode() : 0;
sb.append(idx).append(":").append(itemHash).append(",");
Comment on lines 89 to 92
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.agentscope.core.message.Msg;
import io.agentscope.core.message.MsgRole;
import io.agentscope.core.message.TextBlock;
import io.agentscope.core.session.ListHashUtil;
import io.agentscope.core.state.SessionKey;
import io.agentscope.core.state.SimpleSessionKey;
import io.agentscope.core.state.State;
Expand Down Expand Up @@ -282,6 +286,45 @@ void testSaveAndGetListState() throws SQLException {
assertEquals("value2", loaded.get(1).value());
}

@Test
@DisplayName("Should compute same hash for equivalent message lists")
void testComputeHashEquivalentMessageLists() {
List<Msg> first =
List.of(
Comment thread
Weilong-Qin marked this conversation as resolved.
Outdated
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);

assertEquals(h1, h2);
}

@Test
@DisplayName("Should commit incremental list save when connection auto-commit is disabled")
void testSaveListIncrementalAppendCommitsWhenAutoCommitDisabled() throws SQLException {
Expand Down
Loading