Skip to content

fix(sqlite): invalidate engine cache on snapshot restore#1833

Merged
chaliy merged 1 commit into
mainfrom
2026-06-02-fix-sqlite-engine-cache-invalidation
Jun 2, 2026
Merged

fix(sqlite): invalidate engine cache on snapshot restore#1833
chaliy merged 1 commit into
mainfrom
2026-06-02-fix-sqlite-engine-cache-invalidation

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Jun 2, 2026

Motivation

  • A session-scoped SQLite engine cache allowed cached connections to survive Bash::restore_snapshot(), enabling stale DB state to be read or flushed back into a restored VFS.
  • Restore must preserve the snapshot/VFS boundary so builtin caches cannot leak previous-session data or corrupt restored files.

Description

  • Add a builtin hook reset_session_state() (default no-op) to clear hidden per-instance state and wire it into the interpreter as reset_builtin_session_state() called from restore_snapshot after VFS restoration.
  • Implement reset_session_state() for the Sqlite builtin to clear the per-database engine_cache.
  • Harden the VFS-backed SQLite path by opening each Vfs engine with a unique Turso-internal path and a BashkitVfsIO alias that maps the Turso path back to the caller VFS path, preventing Turso's process-level registry from resurrecting stale engines.
  • Expose cached bytes from BashkitVfsIO and extend SqliteEngine::snapshot_bytes() to consult VFS-backed buffers so cache invalidation checks can compare current VFS bytes.
  • Add integration tests that restore a clean snapshot into an existing Bash and assert the SQLite cache is invalidated for both Memory and Vfs backends, and update specs/sqlite-builtin.md to document the new guarantee.

Testing

  • Ran cargo fmt --all -- --check and it succeeded.
  • Ran the targeted integration tests via cargo test --features sqlite -p bashkit --test integration snapshot_restore_into_existing_bash_clears_sqlite_cache -- --nocapture and they passed.
  • Ran the full SQLite integration suite via cargo test --features sqlite -p bashkit --test integration sqlite_integration_tests -- --nocapture and all tests passed.
  • Ran cargo clippy for the SQLite feature and it passed with zero warnings treated as errors.

Codex Task

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jun 2, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 20e2e90 Commit Preview URL Jun 02 2026, 09:32 AM

@chaliy chaliy force-pushed the 2026-06-02-fix-sqlite-engine-cache-invalidation branch from 838f83b to 20e2e90 Compare June 2, 2026 09:19
@chaliy chaliy merged commit 7953640 into main Jun 2, 2026
33 of 34 checks passed
@chaliy chaliy deleted the 2026-06-02-fix-sqlite-engine-cache-invalidation branch June 2, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant