Repository navigation
Open
Labels
status/needs-researchDeep multi-source research required before committing to an approach
Description
Post-Batch-C (commit 3ff4c45), production code constructs multiple SqliteWriter actors per process:
crates/cli/src/main.rs:233—build_containercrates/cli/src/main.rs:314— watch event-handler buildercrates/cli/src/main.rs:392— scan sentinel-migration closurecrates/desktop/src/lib.rs:151— Tauri.setup()watch writercrates/desktop/src/lib.rs:234—build_containercrates/desktop/src/commands.rs:{392, 513, 644}—_innerlegacy helpers (deferred separately)
Each SqliteWriter::start opens a writable rusqlite::Connection and spawns an OS thread. The Batch-C design doc and the writer module doc state "one writer actor per process, owning the sole writable Connection for its lifetime." Multiple writer threads hold multiple writable connections, even though SQLite WAL serialises them at the OS lock level.
Why it's currently not a defect
Each extra callsite exists because the current construction order needs an already-constructed repo before the AppContainer is built:
- CLI
build_watch_db_handlerbuilds aDbEventHandlerthat needs aSqliteFileRepositorythat needs a writer. Happens beforeAppContainer::new. - CLI scan sentinel closure is handed to
ScanUseCaseand executes on the scan worker thread beforeAppContaineris visible to it. - Desktop Tauri
.setup()builds the watch event handler beforeAppContainerexists.
The WHY comments on each callsite acknowledge this.
What to investigate
- Restructure so that
AppContainer::newis the single construction site that callsSqliteWriter::startexactly once, and the resultingSender<WriteCmd>+ReadPoolflow out to every caller (including the sentinel closure, watch event handler,_innerhelpers). - Alternatively: amend the design doc to permit auxiliary writer threads per logical component, with the proof-of-correctness argument that WAL +
BEGIN IMMEDIATE+busy_timeoutenforces the invariant at the SQL layer.
Acceptance
rg 'SqliteWriter::start\(' crates/{cli,desktop}/src/returns exactly two production hits (one per binary), both insideAppContainer::newor the wiring layer immediately adjacent.- Or: design doc amended to document the multi-writer posture and explain the WAL-based serialisation contract.
Not blocking any future batch; surfaced by a code review.
Metadata
Metadata
Assignees
Labels
status/needs-researchDeep multi-source research required before committing to an approach
Activity
fix(desktop): clear 11 latent clippy errors blocking CI