Files
hermes-agent/tests/persistence_sqlite/admin
Adolanium 8cd489469f fix(backup): refuse the unlink+move restore fallback when the holder scan is inconclusive
When SQLite's backup() cannot write the snapshot into the live database (a
damaged destination header, for example), both restore paths fall back to
copying the snapshot beside the file, unlinking the database and its
-wal/-shm/-journal sidecars, and moving the copy into place. That swap is
only safe when no other process holds the file: a live holder keeps writing
the unlinked inode and the restore silently splits the database.

The guard in front of the swap asked _foreign_db_holder_pids(), a /proc scan
that returns None when it cannot run (every non-Linux host, or an unreadable
/proc). Both callers tested `if holders:`, so None passed as "no holders" and
the swap ran on macOS under a live gateway, dashboard or CLI. The helper's own
docstring says None means unknown.

The store admin path (state.db, shared-state.db) now uses
foreign_state_db_holders(), and the non-store path (projects.db,
cron/executions.db, ...) asks the file's store admin for the same scan. It
covers Linux, macOS (psutil) and Windows (Restart Manager), and reports a
scan it could not finish as a (-1, reason) holder, so unknown refuses like a
live holder does. With a clean scan the fallback still runs on every host.
The now-unused copy of the Linux-only scan in the store admin is removed.

The missing-target check in `hermes import` keeps the old scan: refusing on
unknown there would block importing into a fresh home on macOS and Windows.
2026-12-01 03:30:13 -08:00
..