Repository navigation
fix: release dictation session listeners when speech workers exit - #23077
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe worker exit handler now sends a stopped event to the captured event sink after handling an unexpected worker failure. It suppresses that event when an explicit stop is already in flight. New tests cover repeated exits, cleanup, startup and stop behavior, error delivery, mobile dictation completion, and replacement-session isolation. The profile state writer timeout test now uses fake timers. The Japanese and Korean translations for an AI note label are updated. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No actionable merge risk remains in the reviewed changes; the worker lifecycle and timeout behavior have focused coverage. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Out of Scope Changes checkExplanation The pull request includes changes unrelated to speech-worker lifecycle handling. Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the 4-line behavior change in stt-session-start.ts plus its new 9-case suite.
stoppedon unexpected worker exit —onExitnow capturesstate.eventSinkbeforehandleSttWorkerFailureclears it, skips emission when a stop is already in flight, and otherwise emits{ type: 'stopped' }. This lets the desktop IPC sink detach its per-sessionwindow.once('closed')listener.- New regression suite —
speech-worker-exit-lifetime.test.tscovers exit codes 0/1, 15-cycle listener retention, no duplicate stopped during an in-flight stop, warm reuse, failed startup, error delivery, cancellation, mobile partial/completion, and reentrant restart ordering.
The suppression guard is sound: during an explicit stop the lifecycle exit listener runs before waitForSttWorkerStop's listener, so the stop waiter owns the single notification; unexpected exits with no stop in flight deliver exactly one. Teardown and terminate paths remove listeners before terminate(), so warm/idle teardown cannot produce a spurious event. Mobile's acceptEvent ignores stopped (partial/final text preserved), and the renderer's recordStoppedSession already handles early stopped events for abandoned startups.
Verified locally: vitest run …speech-worker-exit-lifetime.test.ts stt-service.test.ts → 31 passed (9 + 22).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
033e732 to
847b605
Compare
|
Reviewed the CodeRabbit docstring-coverage warning. This repository explicitly requires concise comments limited to non-obvious reasoning (AGENTS.md), so I am declining the generic 80% docstring suggestion. The existing ownership/behavior comments and focused regression tests cover the decisions in this change. No code change is warranted for that style-only warning. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the incremental delta since the prior pullfrog review is one catalog-restoration commit (21741ca353) merged in by f8d7c66c73; the speech-worker fix under stt-session-start.ts and its 288-line suite are byte-for-byte unchanged from the reviewed 0ce7c69 content.
- Restored missing diff-note catalog entries — re-adds
DiffCommentPopover.{f6c449191e, 5fa4bfebaa, 5e9b3d0c2e}with translations across all six locales.DiffCommentDraftCard.tsxalready referenced all three andorigin/main'sen.jsonlacked them, so this closes a real localization gap rather than duplicating an existing entry. - Speech-worker exit cleanup unchanged —
onExitstill captures the sink beforehandleSttWorkerFailureand emitsstoppedexactly once; the merge did not regress it.
ℹ️ The i18n restore is unrelated to this PR's stated purpose
The title and body describe only the speech-worker exit fix, but the head now also carries a diff-note catalog restore and a merge of that branch. It is a correct, needed fix — origin/main references the keys without having them — so there is nothing to change in the code; the flag is only that reverting this PR would also revert that catalog fix, and a reviewer reading the body would not expect locale changes.
Technical details
# Unrelated catalog fix bundled into the speech PR
## Affected sites
- `src/renderer/src/i18n/locales/{en,es,fr,ja,ko,zh}.json` — restored `auto.components.diff.comments.DiffCommentPopover.{f6c449191e,5fa4bfebaa,5e9b3d0c2e}`.
- commit `21741ca353` — the restoration; merged by `f8d7c66c73`.
- `src/renderer/src/components/diff-comments/DiffCommentDraftCard.tsx:220,246,254` — consumer that already referenced these keys on `main`.
## Required outcome
- No code change required. Confirm whether the catalog restore should ride along here or land in its own PR; if it stays, a line in the PR body would spare reviewers the surprise.
## Open questions for the human
- Was the restore folded in to unblock a catalog check that `main` was failing?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When a speech worker exits, remove the finished session's window-close callback instead of leaving it attached until the window closes.
What Changed
Unexpected worker exits now send the existing stopped event after clearing that worker's state and listeners. Desktop IPC uses it to remove its session callback. Previously the worker vanished without that notification, and even a later explicit stop left the callback attached.
The persistence worker test now waits for real worker startup before advancing its simulated write deadline. The former 150 ms limit could expire during initialization instead of exercising the intended dispatched-write failure; production timeouts are unchanged.
Why
The current worker's exit is the lifecycle boundary that already owns cleanup. Reusing its stopped event avoids a second desktop-only cleanup mechanism. An explicit stop in flight remains the sole owner of its notification, and cleanup runs before notifying so a synchronous restart cannot reuse the exiting worker.
Linked Issue
Fixes #23076
Visual Proof
N/A — internal session-listener cleanup. No normal dictation controls, layout or transcript rendering change. This does not automatically stop microphone capture or reset the UI on unexpected exit: the existing desktop stopped consumer records completion for its waits.
Performance proof
Actual speech IPC and SttService with synthetic EventEmitter workers/windows; 15 successful starts followed by unexpected exits:
An independent reviewer repeated the 15-cycle result. This removes retained callbacks and their later close-time work; heap bytes, latency and unexpected-exit frequency were not measured.
Persistence test prerequisite
The branch also fixes a CI-only race in the existing writer-worker timeout test. Worker initialization now uses the normal startup deadline; only the deliberately non-responding command is timed with a fake clock. The test still verifies an indeterminate timeout, actual worker exit and unchanged persisted state, and now also checks the timeout error code. This changes no production persistence behavior. All 13 writer-worker tests pass on the exact revised head under Bun 1.4.2 on macOS; final-head platform CI remains required.
Testing
ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/speech-worker-exit-lifetime.test.ts src/main/ipc/speech.test.ts src/main/speech/stt-service.test.ts src/main/speech/speech-model-deletion.test.ts.The 13 persistence worker tests pass under Node and Bun 1.4.2. A controlled 250 ms startup delay reproduces the original initialization failure; all three corrected fault cases pass with that delay. The timeout case also requires the exact timeout error code, real worker exit, and unchanged SQLite contents. Fresh hosted validation is pending.
Review
Merge risk: low. Independent review found no blocker at the published hashes. The current-worker guard and explicit stop waiter retain ownership, and cleanup precedes potentially reentrant notification.
Negative user-facing trade-offs: none identified. One existing stopped event is newly delivered on unexpected exit, including a startup exit before its existing promise rejection. The desktop's completion cache is already capped at 16 entries. Current normal/error/stop behavior remains covered; no hot audio-loop work is added.
Agent skill upstream boundary
Notes
CI prerequisite: this branch also restores the three diff-note catalog entries missing from the updated main baseline (the correction tracked in #23256), with Japanese and Korean wording clarified to make AI the recipient. The strict localization checks remain enabled. These entries are shared baseline maintenance and will drop out of this diff once they land on main.
The actual mobile controller ignores stopped events; partial text and finish replies stay unchanged in the regression test. No wire fields, opcodes, mobile publications, cloud transcription, provider paths, folder/worktree assumptions or execution-host authority change. An exit is reported by the current local worker, never inferred from remote connection loss.
Checklist