Skip to content

fix(dim_freshness): check WAL mtime to avoid false-stale freshness reports#22

Open
jsherlockppb wants to merge 2 commits into
dezgit2025:mainfrom
jsherlockppb:fix/dim-freshness-wal-mtime
Open

fix(dim_freshness): check WAL mtime to avoid false-stale freshness reports#22
jsherlockppb wants to merge 2 commits into
dezgit2025:mainfrom
jsherlockppb:fix/dim-freshness-wal-mtime

Conversation

@jsherlockppb
Copy link
Copy Markdown

@jsherlockppb jsherlockppb commented May 11, 2026

Problem

SQLite in WAL mode writes new data to session-store.db-wal first. The main .db file is only updated when a checkpoint occurs (periodically, not on every write).

The dim_freshness check was using os.path.getmtime(DB_PATH) — the main file only. This meant that even with active sessions being recorded, the freshness dimension would report AMBER or RED because the main file's mtime hadn't changed.

Fix

Take the most recent mtime across both the main DB and the WAL file:

wal_path = DB_PATH + "-wal"
mtime = max(
    os.path.getmtime(DB_PATH),
    os.path.getmtime(wal_path) if os.path.exists(wal_path) else 0,
)

This correctly reflects when data was last written, regardless of checkpoint timing.

Tests added

New file: src/session_recall/tests/test_dim_freshness.py (5 tests)

Test Scenario
test_green_when_db_recently_modified Recent DB → GREEN
test_red_when_db_missing No DB file → RED
test_wal_mtime_used_when_newer_than_db WAL is fresh, DB is 100h stale → GREEN (key regression test)
test_db_mtime_used_when_no_wal No WAL present → falls back to DB mtime
test_stale_when_both_db_and_wal_are_old Both DB and WAL are old → RED

Verified locally

  • Freshness now reports 0.0h old (GREEN) after active sessions, vs previously showing 68h old (AMBER)
  • All 95 tests pass (90 existing + 5 new)

…ports

SQLite in WAL mode writes to session-store.db-wal first; the main .db
file is only updated on checkpoint. The previous check used only the
main file's mtime, so the freshness dimension would report AMBER/RED
even when sessions were actively being recorded into the WAL.

Fix: take the most recent mtime across both files.
@jsherlockppb jsherlockppb marked this pull request as ready for review May 11, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant