Use sequence_id for JDBC chat memory ordering#6284
Closed
sobychacko wants to merge 2 commits into
Closed
Conversation
sequence_id for JDBC chat memory ordering
Contributor
|
@sobychacko FYI I removed the RC1 milestone from the issue and removed "GH-4740: " from the PR description to have clean release notes. |
sdeleuze
requested changes
Jun 4, 2026
Contributor
sdeleuze
left a comment
There was a problem hiding this comment.
A discussed, I suggest to keep timestamp to expose it as a metadata and add the sequence ID as a new column, will be easier for migrating, and will allow users to display when the message has been created if needed.
Fixes spring-projects#4740 The timestamp column in the JDBC chat memory schema never held temporal data; it only preserved message order within a conversation. Typing it as TIMESTAMP tied ordering to each database's timestamp precision, which scrambled message order on MySQL and MariaDB, where the default second-level precision collapses same-second inserts to equal values. Replace it with sequence_id BIGINT, storing each message's position in the conversation. saveAll() already deletes and reinserts the whole conversation per save, so the batch index is a stable, portable ordering key written via setLong(). Update the eight dialect schemas and SQL, adjust the tests, and document the migration in the upgrade notes. This is a breaking schema change for existing JDBC chat memory tables. Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
Fixes spring-projects#5168 Ordering now uses the sequence_id column, so the timestamp column is no longer required for ordering. Rather than drop it, keep it as the message creation time and make it available to applications. Read the timestamp into the message metadata under the JdbcChatMemoryRepository.CONVERSATION_TS key as an Instant, so applications can display when a message was created. The value is preserved across saves: re-saving a conversation reuses the timestamp carried in each existing message's metadata and stamps the current time only for newly added messages. Keeping the column also eases migration, since existing tables only need the new sequence_id column added rather than a column replaced. Because read-back messages now carry timestamp metadata, a retrieved message is no longer equal to an otherwise-identical message constructed in code; tests that compared messages by value now compare by content. Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
sdeleuze
approved these changes
Jun 4, 2026
sdeleuze
pushed a commit
to sdeleuze/spring-ai
that referenced
this pull request
Jun 4, 2026
The timestamp column in the JDBC chat memory schema never held temporal data; it only preserved message order within a conversation. Typing it as TIMESTAMP tied ordering to each database's timestamp precision, which scrambled message order on MySQL and MariaDB, where the default second-level precision collapses same-second inserts to equal values. Replace it with sequence_id BIGINT, storing each message's position in the conversation. saveAll() already deletes and reinserts the whole conversation per save, so the batch index is a stable, portable ordering key written via setLong(). Update the eight dialect schemas and SQL, adjust the tests, and document the migration in the upgrade notes. This is a breaking schema change for existing JDBC chat memory tables. Fixes spring-projects#4740 See spring-projects#6284 Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4740
The timestamp column in the JDBC chat memory schema never held temporal data; it only preserved message order within a conversation. Typing it as TIMESTAMP tied ordering to each database's timestamp precision, which scrambled message order on MySQL and MariaDB, where the default second-level precision collapses same-second inserts to equal values.
Replace it with sequence_id BIGINT, storing each message's position in the conversation. saveAll() already deletes and reinserts the whole conversation per save, so the batch index is a stable, portable ordering key written via setLong(). Update the eight dialect schemas and SQL, adjust the tests, and document the migration in the upgrade notes.
This is a breaking schema change for existing JDBC chat memory tables.