Repository navigation
refactor(core): tell a gone engine from an unfilled cell in both workers (P1-4 step 3b) - #170
Merged
Merged
Conversation
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
Release-note: skip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
P1-4 step 3b (
core-cell), as specified indocs/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 onlyNotFilledorReady.What changed, item by item
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 withmapandready, so a worker maps theCoreto its executor.get()stays, nowlookup().ready().Goneis final: the cell keeps its first fill and a droppedCorecannot come back.DictationWorker::spawn_finding/wait_for_executorandNoteSyncWorker::start/wait_for_coretakeFn() -> CoreLookup<_>.spawn(app)on both workers stays, answeringNotFilledorReady.foundflag is gone. Each job asks the finder once;NotFilledwaits (polling every 50 ms, jobs queue in order, none dropped);Goneanswers the jobdictation_worker_unavailable(and every later one, in order, including the backlog); a closed channel ends the thread as before.Goneends the thread (with a log line) instead of waking every 50 ms until the last sender drops.#[cfg(test)] DictationWorker::spawn_on_for_tests(cell, executor_for): finds theCorethrough the cell exactly asspawn_ondoes and builds a test executor from eachCore.Coretest builder.#[cfg(test)] core::test_core::TestCore:Database::openin a temporary folder,BackendState::new,WarmTranscriber::new_with, noDictationServer,NoteSyncWorker::spawn_with(cell)(or a caller-supplied note-sync worker viawith_note_sync), aDictationWorkeronTestExecutor(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 callscore.shutdown().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 afterGonestaysGone),a_lookup_maps_only_a_ready_value;a_core_dropped_before_any_job_answers_every_job_unavailable(call_async,calland a fire-and-forget start,pending_startsback to 0);a_cell_driven_worker_runs_jobs_on_the_real_core_then_answers_unavailable_once_it_is_gone(covers the hazard: a job'sCoreis released before the next job is taken);jobs_waiting_for_an_engine_that_goes_away_are_all_answered_in_order(backlog whileNotFilled, thenGone);a_signal_after_the_core_is_gone_ends_the_thread(a sender outlives theCore; one lookup, it isGone, 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, noscribe: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.CoreCelldocs.Tests
Locally (WSL, Linux), each through
devguard slot:cargo fmt --all --check,cargo clippy --locked --workspace --all-targets -- -D warningswith and without--features e2e-audio,cargo test --locked --workspace.The
core::,dictation_worker::andnote_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)andNoteSyncWorker::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 ispub, kept as the spec asks.For the reviewer
worker_loop/wait_for_executorindictation_worker.rs: ordering offinished()(pending-start count) before the reply on theGonepath, and that the backlog drains in order.CoreLookupis generic (CoreLookup<C = Core>), a small widening of the spec's example so the finders can carry executors.🤖 Generated with Claude Code