fix(sessions): microsecond-safe DatabaseSessionService on SQL Server (mssql) - #6943
Open
anmolg1997 wants to merge 1 commit into
Open
fix(sessions): microsecond-safe DatabaseSessionService on SQL Server (mssql)#6943anmolg1997 wants to merge 1 commit into
anmolg1997 wants to merge 1 commit into
Conversation
…(mssql) Two defects break DatabaseSessionService on SQL Server today, both hit on the SECOND append_event of a session (i.e. essentially every real conversation's first turn): 1. PreciseTimestamp falls through to the plain DateTime impl, which maps to SQL Server's legacy DATETIME (~3.33ms precision). The optimistic- concurrency update marker is microsecond-precision, so the value read back never equals the value written and the session's own next append is rejected as a stale write. Fix: map to DATETIME2(6), the SQL Server type with microsecond precision (mirrors the existing mysql DATETIME(fsp=6) branch). 2. mssql is missing from _NAIVE_DATETIME_DIALECTS, so create_session writes timezone-aware datetimes while DATETIME2 reads back naive; the marker comparison then renders '...+00:00' vs '...' for the same instant and raises the same false stale-write error. Fix: include mssql, so tzinfo is stripped before storage exactly as for sqlite/postgresql/mysql/ mariadb (Spanner stays excluded - its TIMESTAMP is timezone-aware). Both fixes have been running in production for two months as downstream monkeypatches on Azure SQL (mssql+aioodbc, ~10^5 events); this upstreams them. Added a unit test for the DATETIME2(6) dialect mapping.
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
注册 for free
to join this conversation on GitHub.
Already have an account?
登录 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.
Problem
DatabaseSessionServicefails on SQL Server on the secondappend_eventof a session — i.e. essentially every real conversation's first turn — with the optimistic-concurrency error ("session has been modified in storage since it was loaded"). Two independent defects combine:PreciseTimestampmaps to legacyDATETIMEon mssql (the genericDateTimefallback). LegacyDATETIMEhas ~3.33 ms precision, so the microsecond update marker read back never equals the one written.mssqlis missing from_NAIVE_DATETIME_DIALECTS, socreate_sessionstores timezone-aware datetimes whileDATETIME2reads back naive — the marker comparison renders...+00:00vs...for the same instant and raises the same false stale-write error.Fix
PreciseTimestamptoDATETIME2(precision=6)on mssql (mirrors the existingmysql.DATETIME(fsp=6)branch).mssqlto_NAIVE_DATETIME_DIALECTS(Spanner stays excluded — its TIMESTAMP is timezone-aware).Validation
Both fixes have been running for ~2 months in production as downstream monkeypatches against Azure SQL (
mssql+aioodbc, per-env schemas, ~10^5 persisted events), on google-adk 1.36 → 2.6.3.tests/unittests/sessions/passes with the change (the handful of vertex-session failures in my environment reproduce identically on unpatchedmain— unrelated).Happy to extend test coverage if you'd like an mssql-dialect marker round-trip test as well.