# Re-check for a live server before commit; make the tie WAL-aware · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/commit/bc12b990a43b000f22ff99e5e6a94a457a018c9f)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

Requested revision: bc12b990a43b000f22ff99e5e6a94a457a018c9f

Requested commit: bc12b990a43b000f22ff99e5e6a94a457a018c9f

Commit: bc12b990a43b000f22ff99e5e6a94a457a018c9f

Tree: ff334230f243562dad9ea8e71fc04f596068ae46

Author: Theo Browne

Committer: Theo Browne

## Message

```
Re-check for a live server before commit; make the tie WAL-aware

Two findings from Macroscope review:

- The running-server guard was check-then-act. A copy takes seconds, and
  nothing stopped a server starting after the check returned None — the
  seed would then replace the projections and event log underneath it,
  which is exactly what the guard exists to prevent. `seedDevDatabase`
  now takes an optional probe and re-runs it immediately before COMMIT,
  where a rollback still costs nothing. This narrows the window to the
  commit itself rather than closing it: a filesystem read and a SQLite
  transaction share no lock, so a server starting in that last instant is
  still possible. Documented as such rather than claimed as airtight.
- The state-dir tiebreak read `state.sqlite` mtime, but the server runs
  SQLite in WAL mode, where writes land in `state.sqlite-wal` and the
  main file can stay untouched until a checkpoint. Verified: 50 writes
  left the main mtime unchanged while the sidecar advanced. So a busy
  directory lost the tie to a dormant one, and the seed overwrote the
  wrong database. Recency is now the newer of the two files.

Both verified end-to-end: a backdated main file with a fresh -wal now
wins the tie, and a probe returning a pid mid-copy leaves the target's
rows and event log intact.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

```

## Parents

- [974d68356e15df03584924c18f280991943c7fb9](https://git.cafe/pingdotgg/t3code/commit/974d68356e15df03584924c18f280991943c7fb9?format=markdown)

[Source at this commit](https://git.cafe/pingdotgg/t3code/tree/bc12b990a43b000f22ff99e5e6a94a457a018c9f?format=markdown)
