Skip to content

fix(session/database): auto-populate update_time for app/user state rows (#1177) - #1374

Closed
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-session-db-state-update-time
Closed

fix(session/database): auto-populate update_time for app/user state rows (#1177)#1374
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-session-db-state-update-time

Conversation

@rootkiller6788

Copy link
Copy Markdown
Contributor

What

Fixes #1177 — persisting app- or user-scoped state via session/database fails on MySQL with default strict mode:

Error 1292 (22007): Incorrect datetime value: '0000-00-00' for column 'update_time' at row 1

storageAppState / storageUserState declare UpdateTime without any auto-update tag, and neither write path (Create, AppendEvent) assigns it, so GORM writes Go's zero time.Time explicitly. MySQL's NO_ZERO_DATE/STRICT_TRANS_TABLES rejects that value. SQLite, PostgreSQL and Spanner happen to accept it, which is why the bug only shows up on MySQL.

Fix

Tag both state models with autoUpdateTime (mirroring adk-python, whose StorageAppState.update_time uses default=func.now(), onupdate=func.now()):

UpdateTime time.Time `gorm:"precision:6;autoUpdateTime:micro"`

GORM then fills the column with the current time on both INSERT (new app/user row) and UPDATE (state delta on an existing row), covering every save path instead of just the two call sites. precision:6 is preserved, so the DDL is unchanged (datetime(6)).

Testing

  • New regression test TestDatabaseService_StateTablesPopulateUpdateTime verifies update_time is populated after Create (app + user state) and refreshed after AppendEvent with a state delta. Confirmed it fails before the fix (zero update_time) and passes after.
  • go test ./session/database/... — all green.
  • go test ./session/...session, session/database, session/sessiontestsuite green; session/vertexai is not runnable in this environment (requires live gRPC/Vertex AI network access).
  • go build -mod=readonly work — passes.
  • go mod tidy -diff — no changes.

A note on -race: the race detector fails to start in this Windows sandbox (exit status 0xc0000139, missing runtime entry point), so -race runs are not available here; the change is limited to GORM struct tags and a test, with no new concurrency.

@rootkiller6788
rootkiller6788 marked this pull request as ready for review August 23, 2026 08:22
@wolo-lab

Copy link
Copy Markdown
Contributor

Thanks for the fix. It's solved by #1204.

@wolo-lab wolo-lab closed this Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session/database: persisting app/user state fails on MySQL (strict mode) — zero-value update_time

2 participants