agent: Set WAL mode and busy_timeout on threads database

Richard Feldman created

The threads SQLite database was opened without setting journal_mode or
busy_timeout. Without WAL mode, readers block writers and vice versa.
Without busy_timeout, SQLite returns SQLITE_BUSY immediately instead of
retrying when it encounters a lock.

This caused a flood of "database is locked" errors in the logs, especially
when save_thread and list_threads (triggered by reload) overlapped, or
when multiple Zed windows shared the same threads.db file.

Set journal_mode=WAL so readers and writers can proceed concurrently, and
busy_timeout=1000 so SQLite retries for up to one second before giving up.

Change summary

crates/agent/src/db.rs | 3 +++
1 file changed, 3 insertions(+)

Detailed changes

crates/agent/src/db.rs 🔗

@@ -382,6 +382,9 @@ impl ThreadsDatabase {
             Connection::open_file(&sqlite_path.to_string_lossy())
         };
 
+        connection.exec("PRAGMA journal_mode=WAL;")?()?;
+        connection.exec("PRAGMA busy_timeout=1000;")?()?;
+
         connection.exec(indoc! {"
             CREATE TABLE IF NOT EXISTS threads (
                 id TEXT PRIMARY KEY,