fix(viewer): detect DB changes under WAL so new assets load - #3062
Merged
Conversation
The viewer polls the database's mtime to decide when to reload its playlist, stat'ing only the main `anthias.db` file. Since #3015 the DB is opened with `journal_mode=WAL`, where commits land in the `anthias.db-wal`/`-shm` sidecars and leave the main file's mtime frozen until a (rare) checkpoint. So `get_db_mtime()` never advanced and `refresh_playlist()` never reloaded — most visibly, the first asset on a fresh install never displayed (its empty playlist also has a `None` deadline, so the deadline fallback can't recover it either). Take the newest mtime across `anthias.db`, `anthias.db-wal`, and `anthias.db-shm`: WAL commits move the sidecars and a checkpoint moves the main file, so the value advances on every write regardless of journal mode. Add a regression test that a write touching only the `-wal` sidecar is detected. Fixes #3061 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in the viewer’s playlist refresh logic when SQLite is running with journal_mode=WAL, where database commits update anthias.db-wal/anthias.db-shm without bumping the main anthias.db mtime—causing the viewer to miss asset changes and never reload an initially-empty playlist.
Changes:
- Update
Scheduler.get_db_mtime()to return the newest mtime acrossanthias.db,anthias.db-wal, andanthias.db-shm. - Add a regression test to ensure WAL-sidecar-only writes advance the detected DB mtime.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/anthias_viewer/scheduling.py |
Make DB change detection WAL-aware by stat’ing db, db-wal, and db-shm and taking the newest mtime. |
tests/test_scheduler.py |
Add a regression test asserting get_db_mtime() tracks -wal updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The new test created /tmp/fakedb-wal in the shared /tmp; with the now WAL-aware get_db_mtime(), that sidecar could leak into the concurrent test_check_get_db_mtime (asserting == 0 on /tmp/fakedb) under `pytest -n auto`. Use a unique tmp_path dir so the sidecar can't escape. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
On a freshly-flashed x86 testbed running
master, adding the first asset left the viewer stuck on the standby screen, loggingPlaylist is emptyforever — even though the asset was enabled, active, and visible to both the server and the viewer via the ORM. More broadly, the viewer's polling-based playlist refresh stopped detecting asset edits.Root cause
The viewer decides when to reload its playlist by polling the database file's mtime, stat'ing only the main
anthias.dbfile:Since #3015 the DB is opened with
PRAGMA journal_mode=WAL. Under WAL, commits are written to theanthias.db-walsidecar (and updateanthias.db-shm); the main file's mtime stays frozen until a checkpoint, which during normal operation is infrequent. Soget_db_mtime()never advanced andrefresh_playlist()never reloaded.The fallbacks don't save it: an empty starting playlist yields a
Nonedeadline (_compute_deadlinereturnsNonewith no candidates), so the deadline path can't recover the first asset; and for non-empty playlists the deadline is the soonestend_date, typically far in the future.This is a regression from #3015 — the viewer's change-detection wasn't updated for WAL's sidecar files.
Fix
Make
get_db_mtime()WAL-aware: take the newest mtime acrossanthias.db,anthias.db-wal, andanthias.db-shm. WAL commits move the sidecars and a checkpoint moves the main file, so the value advances on every write regardless of journal mode. This keeps the existing cheap filesystem-stat design (no per-loop DB query);PRAGMA data_versionwas considered but rejected for that reason.Testing
test_get_db_mtime_tracks_wal_sidecar: a write touching only the-walsidecar is now detected.touch ~/.anthias/anthias.dbwas required to make the first asset appear; with WAL-aware detection the viewer picks it up on its own.Fixes #3061