Skip to content

refactor(core): tell a gone engine from an unfilled cell in both workers (P1-4 step 3b) - #170

Merged
n8watkins merged 2 commits into
mainfrom
refactor/p14-core-cell
Nov 28, 2026
Merged

n8watkins merged 2 commits into
mainfrom
refactor/p14-core-cell

Conversation

@n8watkins

Copy link
Copy Markdown
Owner

P1-4 step 3b (core-cell), as specified in docs/CORE-SPLIT.md, "Step 3b: core-cell".
No change to what the running app does: the Tauri shell still starts both workers with spawn(app), whose finders answer only NotFilled or Ready.

What changed, item by item

  1. Three-state cell. CoreCell::lookup() -> CoreLookup { NotFilled, Gone, Ready(Core) } (core.rs), one read of the cell, so a fill or drop that lands in between cannot be misread. CoreLookup<C = Core> is generic with map and ready, so a worker maps the Core to its executor. get() stays, now lookup().ready(). Gone is final: the cell keeps its first fill and a dropped Core cannot come back.
  2. Finders. DictationWorker::spawn_finding / wait_for_executor and NoteSyncWorker::start / wait_for_core take Fn() -> CoreLookup<_>. spawn(app) on both workers stays, answering NotFilled or Ready.
  3. Dictation loop. The found flag is gone. Each job asks the finder once; NotFilled waits (polling every 50 ms, jobs queue in order, none dropped); Gone answers the job dictation_worker_unavailable (and every later one, in order, including the backlog); a closed channel ends the thread as before.
  4. Note-sync loop. Gone ends the thread (with a log line) instead of waking every 50 ms until the last sender drops.
  5. Cell-driven test constructor. #[cfg(test)] DictationWorker::spawn_on_for_tests(cell, executor_for): finds the Core through the cell exactly as spawn_on does and builds a test executor from each Core.
  6. Core test builder. #[cfg(test)] core::test_core::TestCore: Database::open in a temporary folder, BackendState::new, WarmTranscriber::new_with, no DictationServer, NoteSyncWorker::spawn_with(cell) (or a caller-supplied note-sync worker via with_note_sync), a DictationWorker on TestExecutor (reads the real state machine, records commands, touches no microphone or clipboard), HotkeyRuntimeState::default(), ReplacementStore::open; it fills the cell. Every test that uses it calls core.shutdown().
  7. Tests (each wait has a deadline; no sleep is used to synchronize):
    • core::a_core_cell_on_a_real_core_answers_not_filled_then_ready_then_gone (also: no strong reference held, second fill keeps the first, a late fill after Gone stays Gone), a_lookup_maps_only_a_ready_value;
    • dictation regression a_core_dropped_before_any_job_answers_every_job_unavailable (call_async, call and a fire-and-forget start, pending_starts back to 0);
    • a_cell_driven_worker_runs_jobs_on_the_real_core_then_answers_unavailable_once_it_is_gone (covers the hazard: a job's Core is released before the next job is taken);
    • jobs_waiting_for_an_engine_that_goes_away_are_all_answered_in_order (backlog while NotFilled, then Gone);
    • note-sync regression a_signal_after_the_core_is_gone_ends_the_thread (a sender outlives the Core; one lookup, it is Gone, the thread ends);
    • syncing_launch_at_startup_on_the_main_thread_panics_in_debug_builds: settings_store::sync_launch_at_startup_with(&core) on a thread named "main" panics with the lock message, the lock is not poisoned, no scribe:settings-changed; the same path off the main thread succeeds.
    • a_worker_on_a_never_filled_core_cell_... no longer sleeps 120 ms; it waits for the worker's second lookup.
  8. Stale notes fixed: "kept in Tauri's managed state" on both workers, the "step 3 lets it tell them apart" note, and the CoreCell docs.

Tests

Locally (WSL, Linux), each through devguard slot: cargo fmt --all --check, cargo clippy --locked --workspace --all-targets -- -D warnings with and without --features e2e-audio, cargo test --locked --workspace.

Test binary main (52aeb3d) this branch
app_lib (unit) 19 19
app (main.rs) 0 0
models 3 3
tauri_host 4 4
scribe_core (unit) 613 passed, 3 ignored 620 passed, 3 ignored
doctests 0, 0 0, 0

The core::, dictation_worker:: and note_sync:: tests (44) ran 500 times in a loop with no failure.
Windows- and macOS-only code is not touched; CI covers those builds.

Left for later steps

  • DictationWorker::spawn(app) and NoteSyncWorker::spawn(app) stay (3c deletes them with their caller); spawn_on(cell, app) keeps its app (step 4).
  • CoreCell::get() keeps no caller in the engine; it is pub, kept as the spec asks.
  • No function lost its last caller.

For the reviewer

  • worker_loop / wait_for_executor in dictation_worker.rs: ordering of finished() (pending-start count) before the reply on the Gone path, and that the backlog drains in order.
  • CoreLookup is generic (CoreLookup<C = Core>), a small widening of the spec's example so the finders can carry executors.

🤖 Generated with Claude Code

CoreCell::lookup answers NotFilled, Gone or Ready, and the dictation and
note-sync workers find the Core through it. A cell filled and emptied
before any dictation job ran used to look unfilled, so the job polled
until the channel closed; it is now answered dictation_worker_unavailable,
and the note-sync thread ends on the next signal instead of polling.

Adds a Core test builder (core::test_core) and a cell-driven test
constructor for the dictation worker, with tests for the cell on a real
Core, both regressions and the settings-lock assertion on a real command
path.

Release-note: skip
@n8watkins
n8watkins merged commit ffecfd4 into main Nov 28, 2026
17 checks passed
@n8watkins
n8watkins deleted the refactor/p14-core-cell branch November 28, 2026 03:38
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