Repository navigation
Conversation
…econds Match database microsecond precision before returning a new session so MySQL rounding cannot make its first append appear stale. Cover timestamp rounding and the second boundary in regression tests.
|
Hi @ktsoator Thanks for the fix! I’ve verified the changes, and everything looks good. All tests are passing.
|
karolpiotrowicz
left a comment
There was a problem hiding this comment.
Must change before merge:
- The new test creates the session without
app:oruser:state, so the app and user rows written byCreateare never part of it. - It also stops at the first
AppendEventand never compares the returnedLastUpdateTime()with the storedUpdateTimeafterwards. That is the value the next stale check reads.
The change itself is correct:
I checked this against the merge base (6ede178) and against the PR merged into current main. The new test fails on the merge base in three of its four cases, and two of them fail with the stale-session error from the first AppendEvent. With the change applied, all four pass. Build, go vet, gofmt, staticcheck and the full test suite are clean on the merged tree, and the exported API of session/database is unchanged.
The truncated time reaches every value the stale check compares against: the session row's CreateTime and UpdateTime (storage_session.go#L51-L58), the app and user state rows, and the session Create returns (service.go#L140-L159). The earlier untruncated clock read at service.go#L116 is overwritten before the session is returned, so it never reaches the caller.
Extend the precision test to catch incorrect app and user state timestamps and mismatches between the returned session and storage after the first append.
|
Added Could you take another look when you have time? 🙂 |
Every item this review raised is fixed and verified on the current head.
karolpiotrowicz
left a comment
There was a problem hiding this comment.
This closes both gaps from my earlier review. The test now creates the session with app: and user: state and checks the UpdateTime of both state rows (service_test.go#L89-L102), and after the first AppendEvent it compares LastUpdateTime() with the stored UpdateTime (service_test.go#L118-L126).
I checked that each new assertion fails when the code it guards is broken. Writing an untruncated time into the app or user row at service.go#L140 or service.go#L147 fails the matching check in the three cases that are not already aligned. Removing the sess.updatedAt updates at service.go#L405 and service.go#L509 fails the post-append comparison in all four cases, and removing the truncation in AppendEvent at service.go#L385 fails the UpdateTime after append check.
The test still fails on the merge base and passes on this head. I re-ran the other checks on this head merged into current main, with the same results as before.
|
Thanks for checking again and verifying the tests! 🙂 |
|
hi @karolpiotrowicz Would you prefer that I update this PR to keep only the additional test coverage, or close it as superseded? |


Linked issue
Fixes #1928.
Problem: MySQL can round creation timestamps up when storing them in datetime(6), causing the first
AppendEventto incorrectly fail with a stale-session error.Solution: Truncate creation timestamps to microseconds before persistence, matching the existing
AppendEventbehavior.Python also uses microsecond-precision creation timestamps: database_session_service.py:698–708.
Behavior change
The first append succeeds when MySQL would previously have rounded the creation timestamp upward. Newly created database sessions now use microsecond precision, including on SQLite.
Testing Plan
TestDatabaseService_CreateMicrosecondPrecisioncovers timestamp rounding and first append, including the second boundary, and fails without the fix. Build, race tests, lint, and tidy checks pass across both modules.Verified on MySQL 8.4.8 in Docker with Go 1.26.10 and no
timeTruncateDSN parameter. The two previously failing cases now pass.Checklist