Skip to content

Fix race condition when toggling transcription via SIGUSR2#560

Merged
cjpais merged 2 commits intocjpais:mainfrom
y0usaf:fix/race-condition-toggle-state
Jan 10, 2026
Merged

Fix race condition when toggling transcription via SIGUSR2#560
cjpais merged 2 commits intocjpais:mainfrom
y0usaf:fix/race-condition-toggle-state

Conversation

@y0usaf
Copy link
Contributor

@y0usaf y0usaf commented Jan 9, 2026

Before Submitting This PR

Please confirm you have done the following:

Human Written Description

I noticed this happening during my usage and wanted to fix it, it seemed clear enough that pasting was happening before transcription was completed.

Related Issues/Discussions

May help fix #462 - The race condition described there (rapid toggling causing hangs) shares the same root cause: toggle state is updated immediately while async work is still running, allowing new operations to start before previous ones complete.

Community Feedback

Related to community-reported issue #462

Testing

Code review of the async flow. The fix ensures toggle state stays true until the async transcription task completes, preventing new operations from starting while previous ones are still running.

Summary

When using SIGUSR2 to toggle transcription, if signals are sent in quick succession, the previous transcription could paste at unexpected times.

The issue: Toggle state was set to false immediately on stop, but transcription runs asynchronously. A new recording could start while the old transcription was still running.

The fix: Keep toggle state true until the async transcription task completes (~10 lines changed).

The toggle state was being set to false immediately when stop was called,
but the actual transcription runs asynchronously. If another signal arrived
before transcription completed, a new recording could start while the old
transcription was still running, causing the old text to paste unexpectedly.

Now the toggle state stays true until the async transcription task completes.
@cjpais
Copy link
Owner

cjpais commented Jan 10, 2026

thanks merging

@cjpais cjpais merged commit ae9c33e into cjpais:main Jan 10, 2026
2 checks passed
h0lybyte added a commit to KBVE/Handy that referenced this pull request Jan 12, 2026
…, and UI improvements

Merged upstream features:
- feat: add Czech translation (cjpais#568)
- fix: keybinding changes failing silently due to incorrect key ordering (cjpais#524)
- fix: improve apple intelligence ui and add reusable alert component (cjpais#517)
- Fix race condition when toggling transcription via SIGUSR2 (cjpais#560)
- feat(linux): add ydotool support for text input (cjpais#557)
- feat: add Moonshine Base speech recognition model (cjpais#556)
- Prevent highlight and selection cursor hover on UI text items (cjpais#541)
- feat(ui): add reusable Tooltip component and integrate with settings (cjpais#538)
- PR guidelines for AI
- dont allow package-lock with a bun project for now

Conflicts resolved:
- src-tauri/src/shortcut.rs: Kept KBVE filler detection commands, adopted upstream's improved doc comment
- src/bindings.ts: Merged KBVE types (Discord, Memory, Filler) with upstream's Moonshine engine type
aidynamicsolutions pushed a commit to aidynamicsolutions/codictate that referenced this pull request Feb 21, 2026
Brings in latest main changes since PR cjpais#473 including:
- cjpais#524: keybinding ordering fix
- cjpais#517: Apple Intelligence UI improvements with Alert component
- cjpais#560: SIGUSR2 race condition fix
- cjpais#557: ydotool support for Linux
- cjpais#556: Moonshine Base model support
- cjpais#541: UI text selection prevention
- cjpais#538: Tooltip component
- cjpais#540: Portuguese language support
- cjpais#536: Ukrainian language support

Conflict resolutions:
- PostProcessingSettings.tsx: Combined MLX provider support with new Alert UI
- actions.rs: Fixed async block syntax issue
- Lock files: Regenerated
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.

[BUG] Race -> crash

2 participants