Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(ci): remove flaky SQLite teardown oracles

Louis Beaumont1fbada71dbe9
diff --git a/crates/screenpipe-db/src/db/setup.rs b/crates/screenpipe-db/src/db/setup.rs
index 5ed1009dc..c74016212 100644
--- a/crates/screenpipe-db/src/db/setup.rs
+++ b/crates/screenpipe-db/src/db/setup.rs
@@ -173,10 +173,14 @@ impl DatabaseManager {
// Run migrations after establishing the connection
Self::run_migrations(&db_manager.pool).await?;
- // Surface corruption proactively at boot with a recovery hint,
- // instead of only discovering it later via worker query errors
- // (which used to spin a CPU core retrying a malformed DB).
- db_manager.spawn_startup_integrity_check(Arc::from(database_path));
+ // Surface persistent-file corruption proactively at boot with a recovery
+ // hint, instead of only discovering it later via worker query errors.
+ // An in-memory database cannot carry corruption across startups, and a
+ // quick_check on SQLite's shared in-memory cache takes table read locks
+ // that can make concurrent writes fail immediately with SQLITE_LOCKED.
+ if !database_path.contains("mode=memory") && database_path != ":memory:" {
+ db_manager.spawn_startup_integrity_check(Arc::from(database_path));
+ }
// Periodic WAL checkpoint so the write-ahead log can't grow unbounded
// when passive auto-checkpoint is blocked by long-lived readers. An
diff --git a/crates/screenpipe-db/tests/close_severs_connections_test.rs b/crates/screenpipe-db/tests/close_severs_connections_test.rs
index ea37a3642..d9722480f 100644
--- a/crates/screenpipe-db/tests/close_severs_connections_test.rs
+++ b/crates/screenpipe-db/tests/close_severs_connections_test.rs
@@ -11,10 +11,14 @@
//! These tests model the incident directly:
//! * a "leaked" pool clone must be SEVERED by `DatabaseManager::close()`
//! (fail fast, not pin the WAL-index),
-//! * after `close()` SQLite must have dropped the `-wal`/`-shm` sidecars —
-//! the file-level proof that zero connections survived teardown,
//! * a fresh `DatabaseManager` on the same file must then init and write,
//! * repeated restart cycles (the engine-respawn path) must stay clean.
+//!
+//! Do not use `-wal`/`-shm` file existence as a connection-leak oracle here.
+//! SQLite may retain both files when the last connection to disconnect is
+//! read-only; this manager closes independent read and write pools concurrently.
+//! A closed leaked clone plus a successful same-process reopen and write tests
+//! the recovery invariant directly.
use screenpipe_config::{DbConfig, DeviceTier};
use screenpipe_db::DatabaseManager;
@@ -26,29 +30,6 @@ fn temp_db_path(tag: &str) -> String {
dir.join("db.sqlite").to_string_lossy().into_owned()
}
-/// Wait (bounded) for SQLite to unlink the WAL sidecars after the last
-/// connection closes. `close()` resolves when the pools are closed; the OS
-/// unlink is usually immediate after that, but Linux CI can lag under load.
-async fn assert_wal_sidecars_gone(db_path: &str) {
- let wal_path = format!("{db_path}-wal");
- let shm_path = format!("{db_path}-shm");
- for _ in 0..200 {
- let wal = std::path::Path::new(&wal_path).exists();
- let shm = std::path::Path::new(&shm_path).exists();
- if !wal && !shm {
- return;
- }
- tokio::time::sleep(std::time::Duration::from_millis(100)).await;
- }
- let wal = std::path::Path::new(&wal_path).exists();
- let shm = std::path::Path::new(&shm_path).exists();
- panic!(
- "-wal/-shm still present after close() — a SQLite connection survived teardown \
- (the exact leak that made the 2026-07-02 wedge unrecoverable in-process); \
- wal={wal}, shm={shm}"
- );
-}
-
#[tokio::test]
async fn close_severs_leaked_pool_clones_and_allows_reinit() {
let db_path = temp_db_path("sever");
@@ -76,10 +57,6 @@ async fn close_severs_leaked_pool_clones_and_allows_reinit() {
"leaked pool clone must be unusable after DatabaseManager::close()"
);
- // File-level proof that ZERO connections survived: SQLite only deletes
- // -wal/-shm when the LAST connection to the db closes.
- assert_wal_sidecars_gone(&db_path).await;
-
// And the same process can re-open the db cleanly — the step that failed
// with (code: 522) disk I/O error for hours on 2026-07-02.
let db2 = DatabaseManager::new(&db_path, config)
@@ -113,7 +90,6 @@ async fn repeated_restart_cycles_reopen_cleanly() {
.await
.unwrap_or_else(|e| panic!("cycle {cycle}: write failed: {e}"));
db.close().await;
- assert_wal_sidecars_gone(&db_path).await;
}
// All five cycles' writes survived the churn.