Skip to content

fix(session): don't reset the session DB on transient open errors#3534

Merged
Sayt-0 merged 1 commit into
mainfrom
fix/session-transient-error-preserve-db
Jul 8, 2026
Merged

fix(session): don't reset the session DB on transient open errors#3534
Sayt-0 merged 1 commit into
mainfrom
fix/session-transient-error-preserve-db

Conversation

@dgageot

@dgageot dgageot commented Jul 8, 2026

Copy link
Copy Markdown
Member

The SQLite session store's backup-and-reset recovery path in NewSQLiteSessionStore fired on any open or migration error, including transient ones. A canceled context (e.g. Ctrl-C during slow startup on a large DB) or SQLITE_BUSY/SQLITE_LOCKED from a second running docker-agent instance would silently rename a perfectly healthy session.db to session.db.bak and 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.IsTransientError helper that matches canceled or expired contexts alongside SQLite primary result codes SQLITE_BUSY and SQLITE_LOCKED, including extended codes like SQLITE_BUSY_SNAPSHOT. The recovery path in pkg/session/store.go is 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 .bak file nor discards existing session data.

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)
@dgageot
dgageot requested a review from a team as a code owner July 8, 2026 12:27
@aheritier aheritier added area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Jul 8, 2026
@Sayt-0
Sayt-0 merged commit d085629 into main Jul 8, 2026
14 checks passed
@Sayt-0
Sayt-0 deleted the fix/session-transient-error-preserve-db branch July 8, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants