Skip to content

fix(storage): concurrent CLI and daemon writes cause silent data divergence #741

Closed

Description

@Sinity

Problem

The daemon and the CLI can write to the same SQLite database simultaneously. WAL mode prevents corruption, but the daemon's cursor state and the CLI's parse state diverge silently. The CLI inserts raw records for conversations that the daemon already processed. When the daemon's watcher next inspects those files, the content fingerprint no longer matches the cursor — causing the watcher to skip unchanged files and silently miss new data.

No process-level advisory lock exists. No detection of external writes.

Acceptance criteria

  • Add file-based advisory lock (e.g. portalocker on the DB file) to prevent concurrent write access
  • OR have the daemon detect external writes by checking PRAGMA data_version on wakeup
  • OR route all CLI writes through the daemon (when running) and fall back to direct writes only when the daemon is down
  • Test: run daemon and CLI write simultaneously, verify no data loss or divergence

Found by

2026-05-03 pre-mortem analysis (wave 7). Related to discussion of daemon-only-writes model vs. library-first architecture.

Activity

  1. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    Scope absorbed into #717 (daemon architecture). Concurrent writer coordination is a daemon-vs-CLI architecture concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions