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(db): start WAL checkpoint maintenance in DatabaseManager::new (app got none) (#4200)

Louis Beaumont3f563071095d
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index cf2f281a2..15e26086a 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -420,6 +420,16 @@ impl DatabaseManager {
// (which used to spin a CPU core retrying a malformed DB).
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
+ // oversized WAL (observed at 650MB on a heavy 24/7 install) is the main
+ // driver of the WAL-index / `-shm` desync that corrupts the DB. Started
+ // here in `new()` — next to the integrity check — so EVERY caller gets
+ // it: the desktop app runs the engine in-process and previously never
+ // started it (only the standalone `screenpipe-engine` CLI did), so app
+ // users got no periodic checkpointing at all.
+ db_manager.start_wal_maintenance();
+
Ok(db_manager)
}
diff --git a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
index e4adbc744..165a1bc91 100644
--- a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
+++ b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
@@ -1796,8 +1796,8 @@ async fn main() -> anyhow::Result<()> {
// Start calendar-assisted speaker identification
let _speaker_id_handle = start_speaker_identification(db.clone(), config.user_name.clone());
- // Periodic WAL checkpoint to prevent unbounded WAL growth
- db.start_wal_maintenance();
+ // WAL checkpoint maintenance now starts inside DatabaseManager::new(), so
+ // every caller (CLI + in-process desktop app) gets it — no explicit call here.
let server_future = server.start();
pin_mut!(server_future);