Repository navigation
fix(session/database): delete a session's events explicitly in Delete - #1774
Merged
wolo-lab merged 4 commits intoNov 5, 2026
Merged
Conversation
Delete relied on the ON DELETE CASCADE foreign key to remove a session's events. SQLite enforces foreign keys only when the connection enables them, so on a default SQLite connection Delete removed the session row and left its events, tool output included, in the events table.
prami25r
reviewed
Oct 10, 2026
prami25r
reviewed
Oct 10, 2026
Create sessions that share the session ID with a different user and a different app, and assert their events survive deleting the target session, so a delete that drops app_name or user_id from its condition fails the test.
wolo-lab
added a commit
that referenced
this pull request
Nov 16, 2026
, #1919, #2189, #2285) (#2346) * fix(session/vertexai): drop temp: keys from the initial state on Create (#2100) (cherry picked from commit 0c109f7) * fix(session): keep in-memory Get from returning events before After (#2089) (cherry picked from commit 10395f0) * fix(session/database): lock app and user state rows in Create (#1930) (cherry picked from commit 2f3b2c2) * fix(session/database): delete a session's events explicitly in Delete (#1774) (cherry picked from commit 7af0f5f) * fix(session): define List order as last update time ascending (#1919) (cherry picked from commit 8be7e25) * fix(session): skip nil parts in IsFinalResponse classification (#2189) (cherry picked from commit 75ae920) * fix(session): count a final error event as a final response (#2285) (cherry picked from commit d9ecb34)
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.
Closes: #1773
Problem
Deleterelied on theON DELETE CASCADEforeign key to remove a session's events. SQLite enforces foreign keys only when the connection enables them (PRAGMA foreign_keys), so on a default SQLite connectionDeleteremoved the session and left its events, tool responses included, in theeventstable. adk-python enables the pragma for SQLite, so the Go implementation diverged.Solution
Inside the existing transaction, delete the session's events explicitly before deleting the session. This works on every dialect and does not depend on how the caller configured the connection, which matters for
NewSessionServiceFromDB, where the*gorm.DBcomes from the user. Enabling the pragma inside ADK would not cover that case: the pragma is per connection and the pool belongs to the caller.Behavior change for existing users
PRAGMA foreign_keys:Deletenow removes the session's events, which it previously left behind. Events already orphaned by earlier deletes are not cleaned up.Testing plan
TestDatabaseService_DeleteRemovesSessionEvents: two sessions with one event each, delete one, assert its events are gone and the other session's event remains. The test database is SQLite without the pragma, like the existing helpers. Without the source change it fails withevents left for deleted session = 1, want 0; with it, it passes.go test -race -count=1 -shuffle=on ./session/...passes.golangci-lint run(v2.3.1) reports 0 issues,golangci-lint fmt --diffis empty,go mod tidy -diffis clean.replacedirective) now leaves no events behind: