fix(session): don't reset the session DB on transient open errors#3534
Merged
Conversation
Backup-and-reset recovery was firing on canceled contexts and SQLITE_BUSY/LOCKED errors, silently discarding healthy session history. New sqliteutil.IsTransientError gates the recovery path; regression tests added in pkg/sqliteutil and pkg/session. Assisted-By: Claude (Anthropic)
gtardif
approved these changes
Jul 8, 2026
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.
The SQLite session store's backup-and-reset recovery path in
NewSQLiteSessionStorefired on any open or migration error, including transient ones. A canceled context (e.g. Ctrl-C during slow startup on a large DB) orSQLITE_BUSY/SQLITE_LOCKEDfrom a second running docker-agent instance would silently rename a perfectly healthysession.dbtosession.db.bakand start fresh, causing users to lose access to all their old sessions. This was reproduced locally: a 708 MB database with 3342 sessions was moved aside by a single interrupted startup.The fix introduces a
sqliteutil.IsTransientErrorhelper that matches canceled or expired contexts alongside SQLite primary result codesSQLITE_BUSYandSQLITE_LOCKED, including extended codes likeSQLITE_BUSY_SNAPSHOT. The recovery path inpkg/session/store.gois now gated on this helper, so backup-and-reset only runs for genuinely corrupt or unrecoverable databases, never for errors that would resolve on retry.Regression tests cover the new helper directly (
TestIsTransientError,TestIsTransientError_SQLiteBusy) and the store behavior (TestNewSQLiteSessionStore_TransientErrorPreservesDB), verifying that a canceled context neither creates a.bakfile nor discards existing session data.