fix(stats): set busy_timeout on agent snapshot reader so a concurrent write can't blank the page

This commit is contained in:
müde 2026-07-05 21:43:25 +02:00
commit d004fdc0eb

View file

@ -229,11 +229,15 @@ fn empty_snapshot(window: Window) -> Snapshot {
}
fn snapshot(path: &Path, window: Window) -> Result<Snapshot> {
// Read-only open so an in-flight writer (the harness's own
// turn_stats sink) never blocks us and we can't corrupt the db
// via a query bug.
// Read-only open so we can't corrupt the db via a query bug.
let conn = Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_ONLY)
.with_context(|| format!("open {} read-only", path.display()))?;
// turn_stats is rollback-journal (not WAL): a read landing while the
// harness's own sink is mid-INSERT gets SQLITE_BUSY, which propagates up
// and blanks the whole stats page. Wait out the brief write instead —
// matches hive-c0re's host-side reader (`hive_stats::read_agent`).
conn.busy_timeout(std::time::Duration::from_millis(500))
.with_context(|| format!("set busy_timeout on {}", path.display()))?;
let now = now_secs();
// Fixed windows look back a constant span; `all` starts at the earliest
// recorded turn (`MIN(started_at)`, falling back to `now` on an empty