Skip to content

fix: shorten write transaction lifetimes to resolve sync lock contention#7

Merged
abpai merged 1 commit into
mainfrom
fixes/shorten-watcher-tx-lifetime
Apr 9, 2026
Merged

fix: shorten write transaction lifetimes to resolve sync lock contention#7
abpai merged 1 commit into
mainfrom
fixes/shorten-watcher-tx-lifetime

Conversation

@abpai

@abpai abpai commented Apr 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • The watcher pipeline held write transactions open across async yields and idle periods, preventing WAL checkpointing (51MB WAL) and causing periodic sync to fail with database is locked on every cycle
  • Flush after each event in processDue(), after on_checkpoint writes, and at the start of syncOnce() so no transaction is ever held across an async boundary
  • Sync-side flush is an intentional cross-subsystem commit: each pipeline event is independent, so force-committing partial pipeline work is safe

Test plan

  • bun test — 95 tests pass
  • wildcard launchd restart + wildcard status — initial sync succeeds, pending: none
  • After 2-3 sync intervals (~10 min): tail -30 ~/.wildcard/launchd.err.log shows no new database is locked errors
  • sqlite3 ~/.wildcard/timeline.db "SELECT key, value FROM state WHERE key LIKE 'sync%'" — cursors advancing, last_error empty

The watcher pipeline held write transactions open across async yields
and idle periods, preventing WAL checkpointing and causing periodic
sync to fail with "database is locked" on every cycle.

- Flush after each event in processDue() so no transaction spans an
  await boundary
- Flush after on_checkpoint writes so no transaction lingers for up
  to 60s
- Flush at start of syncOnce() to commit any pending pipeline work
  before sync reads/writes (intentional cross-subsystem commit)
@abpai abpai merged commit bd33dab into main Apr 9, 2026
1 check passed
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