Repository navigation
refactor(incremental): concentrate incremental orchestration in the shared module - #55
Merged
Merged
Conversation
…al scheduling policy module CAND-1 (#47) step 1/3: build the deep module both worker loops will route through. src/engine/incremental.rs now owns: - SchedulingConfig: target/max/overlap/backlog clamps (target >= 1000ms, overlap <= half target, backlog = max_ms * max_queue), centralized from two duplicated copies. - next_step/choose_segment_end/after_boundary/classify_slice: the pure segment-cut decisions (250ms residual tail, stop-before-first-segment, empty/failed slice handling) previously duplicated verbatim in src/bin/pickscribe.rs and src-tauri/src/engine.rs. - IncrementalHost + run(): the driver loop, generic over an adapter trait for STT execution, live segment cleanup, and progress publication. run() owns progress state (the RecordingSession and when to publish it), the fallback/completion decision, and the final drain. - Unifies the one live policy divergence between the two production loops: live backlog overflow now always stops scheduling immediately (the CLI's existing behavior) instead of desktop's prior behavior of flagging fallback_required and continuing to schedule segments a fallback will discard. Documented on next_step(). CancelToken and cleanup_session_dir (used outside incremental scheduling) are unchanged. IncrementalRunner/SegmentTranscriber/EnqueueResult/ IncrementalSession are removed: grep confirms nothing outside this module's own tests ever constructed them, so they characterized an orchestration path production never ran. Neither production loop routes through this module yet (next commits).
…emental CAND-1 (#47) step 2/3: src/bin/pickscribe.rs's run_incremental_worker_loop now drives segment scheduling through engine::incremental::run instead of its own copy of the state machine. CliIncrementalHost adapts the module's IncrementalHost trait to the CLI's file-based control signals (stop/ stopping/cancel paths, parent recorder pid liveness) and subprocess STT execution (transcribe_incremental_segment, still polling the same is-cancelled condition via Control::Abandoned | Control::Cancelled). Process files, exit codes, worker-output.json shape, and orphan/parent- death handling are unchanged: CliIncrementalHost::control() reproduces the exact precedence (cancel > stop > stopping-grace > orphan-with-startup- deadline) that run_incremental_worker_loop had inline. The one intentional behavior shift is upstream: live backlog overflow now stops immediately rather than flagging-and-continuing, which was already the CLI's own behavior pre-refactor (see b0e8c13) and only changes desktop's loop (next commit). queue_segment_cleanup/drain_segment_cleanup_results are folded into CliIncrementalHost::try_queue_cleanup/drain_cleanup, which is what the module's run() calls instead. growing_audio_duration_ms and the CLI's choose_segment_end are now dead code (equivalent functions live in the shared module); left in place for the step 4 cleanup commit alongside desktop's duplicates so each adapter's dedup lands together. Next: route the Tauri worker loop in src-tauri/src/engine.rs through the same module.
…cremental CAND-1 (#47) step 3/3: src-tauri/src/engine.rs's run_incremental_worker now drives segment scheduling through engine::incremental::run instead of its own copy of the state machine. TauriIncrementalHost adapts the module's IncrementalHost trait to the desktop worker's in-process signals (worker_cancel_token, the recording session's CancelToken via is_session_current, stop_requested) and in-process STT execution (stt::transcribe_with_cancel). Preserved exactly: - Tauri events: publish() still calls emit_incremental_session, so segment status transitions (Transcribing/RawReady/Cleaning/Failed) reach the frontend at the same points. - Stage transitions: unchanged, driven by run_pipeline/incremental_result which don't change here. - The IncrementalResult::Partial salvage path (PR #49): incremental_result and segments::salvage_completed_prefix are untouched; run_incremental_worker still returns an IncrementalDone with the same session/complete/ fallback_required shape. - keep_audio retention: host.keep_audio() and cleanup_session_dir calls use the same worker.cfg.general.keep_audio. - The extra TOCTOU guard desktop had around `complete` (re-checking worker_cancel_token/is_session_current after the module returns, since a cancel/supersession can race in during the last segment's STT call) is kept in the run_incremental_worker wrapper rather than the shared module. Behavior change (intentional, per b0e8c13): live backlog overflow now stops scheduling immediately instead of flagging fallback_required and continuing to schedule segments a fallback would discard. This was already the CLI's behavior; desktop's loop now matches it. See engine::incremental::next_step docs for the full rationale. choose_segment_end here is now dead code (the module owns the equivalent logic); left in place for the step 4 cleanup commit. Next: delete the now-duplicate loop internals/helpers from both adapters.
…adapters CAND-1 (#47) step 4/4: growing_audio_duration_ms and choose_segment_end in src/bin/pickscribe.rs, and choose_segment_end in src-tauri/src/engine.rs, were left as dead code by the previous two commits once each worker loop routed through engine::incremental (audio_segments::duration_ms and incremental::choose_segment_end are the equivalents the module now owns). Removed, along with the now-unused audio_segments import in the CLI binary (src-tauri/src/engine.rs still uses audio_segments::slice_wav directly for its fallback-tail slicing, so its import stays). Both worker loops now contain zero scheduling policy of their own; all of it lives in src/engine/incremental.rs, exercised by that module's own test suite plus each adapter's existing integration coverage.
7 tasks
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.
CAND-1 (#47) — PR 1: Incremental orchestration
Concentrates CLI and desktop incremental scheduling/fallback/finalization
policy into
src/engine/incremental.rs. Closes out the "PR 1 — Incrementalorchestration" item from #47's dependency-ordered plan; #47 completes when
this merges (the other CAND items are separate PRs).
What changed
src/engine/incremental.rs(b0e8c13, prior commit on this branch) grewfrom a tests-only
IncrementalRunnernobody constructed in productioninto the real deep module:
SchedulingConfig(target/max/overlap/backlogclamps), the pure decision functions (
next_step,choose_segment_end,after_boundary,classify_slice), and theIncrementalHosttrait +run()driver that owns the scheduling loop, progress state, and thefallback/completion decision.
src/bin/pickscribe.rs'srun_incremental_worker_loopnow drivesthrough
incremental::runviaCliIncrementalHost, an adapter over theCLI's file-based control signals (stop/stopping/cancel paths, parent
recorder pid liveness) and subprocess STT execution.
src-tauri/src/engine.rs'srun_incremental_workernow drives throughthe same
incremental::runviaTauriIncrementalHost, an adapter overthe desktop worker's
CancelToken/session-current signals and in-processSTT execution.
(
growing_audio_duration_ms,choose_segment_end× 2) now that themodule owns the equivalent logic (
audio_segments::duration_ms,incremental::choose_segment_end).Preserved exactly
stop/stopping/cancel/worker-output.json),exit codes, and orphan/parent-death handling.
CliIncrementalHost::control()reproduces the same precedence the inline loop had: cancel > stop >
stopping-grace > orphan-with-startup-deadline.
publish()still callsemit_incremental_sessionat the same points), stage transitions (
run_pipeline/incremental_resultuntouched), the
IncrementalResult::Partialsalvage path from fix: unblock the UI thread and stop tray subprocess churn #49(
segments::salvage_completed_prefixuntouched), andkeep_audioretention. Desktop's extra TOCTOU guard around
complete(re-checkingcancellation/supersession after the module returns, since a cancel can
race in during the last segment's STT call) is kept in the
run_incremental_workerwrapper rather than folded into the sharedmodule, since it's specific to how desktop's session-current check works.
Where CLI and desktop diverged, and why the CLI's behavior won
Before this refactor, live backlog overflow (buffered-but-unsegmented audio
exceeding the backlog limit before a final drain was requested) was
handled differently by each adapter:
fallback_requiredand kept scheduling more segmentsuntil the final drain or cancellation — segments a fallback would end up
discarding anyway.
next_step()in the shared module now always stops immediately (the CLI'sprior behavior), for two reasons: it stops burning CPU/STT time on segments
a fallback will discard, and it maximizes the contiguous finished prefix
available to
segments::salvage_completed_prefix(#49) by not letting moresegments race the fallback decision. This is a real, intentional behavior
change for desktop — see
next_step()'s doc comment for the fullrationale, and
run_stops_immediately_on_live_backlog_overflow_without_transcribing_morein
incremental.rs's test suite for the characterization.Final backlog overflow (after a final drain was requested) already stopped
both loops immediately; that policy is unchanged, just centralized.
Validation
cargo test --workspace --locked --all-targets: 100 lib + 10 CLI-bin +7 pickscribe-cleanup-bin + 29 src-tauri-lib tests, all green, run after
each of the three routing/cleanup commits.
bun run build(Vite/Tauri frontend build) andbun run test(install-script smoke + vitest) both green.
pickscribe start --incremental/stopagainst realpw-record+whisper-cli— segments scheduled at the configuredtarget/max boundaries,
worker-output.jsonprogressed throughtranscribing→rawReady, final output reportedcomplete: true, fallback_required: false, andkeep_audioretainedsegment WAVs.
pickscribe start --incremental/cancelmid-recordingleft no residual worker/temp-dir artifacts.
that the duplicate helpers are gone.
Refs #47.