fix(session): resolve list modification detection bug in incremental updates#1228
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #1225 by changing list change-detection in session persistence to use a prefix-hash comparison, so append-only updates can be applied incrementally without triggering delete-and-reinsert.
Changes:
- Update
ListHashUtil.needsFullRewriteto compare the hash of the existing persisted prefix (0..existingCount) against the stored hash. - Adjust session implementations (MySQL / Redis / JSON) to call the updated
needsFullRewritesignature. - Expand unit tests to validate the new prefix-hash behavior for modified, shrunk, and grown lists.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/jedis/JedisSession.java | Switches full-rewrite decision to the new needsFullRewrite(values, storedHash, existingCount) API. |
| agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/RedisSession.java | Same as above for the adapter-based Redis session. |
| agentscope-extensions/agentscope-extensions-session-mysql/src/main/java/io/agentscope/core/session/mysql/MysqlSession.java | Uses prefix-based rewrite detection for incremental DB inserts. |
| agentscope-core/src/test/java/io/agentscope/core/session/ListHashUtilTest.java | Updates tests to exercise prefix-hash rewrite rules. |
| agentscope-core/src/main/java/io/agentscope/core/session/ListHashUtil.java | Implements prefix-hash comparison in needsFullRewrite. |
| agentscope-core/src/main/java/io/agentscope/core/session/JsonSession.java | Updates full-rewrite decision logic to match the new needsFullRewrite API. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
LearningGp
left a comment
There was a problem hiding this comment.
computeHash only samples 5 positions for lists with more than 5 elements. This could be problematic if historical messages are modified, but since this was not introduced in this PR, it's out of scope for now.
…updates (agentscope-ai#1228) ## Description Close agentscope-ai#1225 This PR fixes the session overwrite bug by implementing prefix hash comparison for incremental database inserts. ## Checklist Please check the following items before code is ready to be reviewed. - [ ] Code has been formatted with `mvn spotless:apply` - [ ] All tests are passing (`mvn test`) - [ ] Javadoc comments are complete and follow project conventions - [ ] Related documentation has been updated (e.g. links, examples, etc.) - [ ] Code is ready for review

Description
Close #1225
This PR fixes the session overwrite bug by implementing prefix hash comparison for incremental database inserts.
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)