Skip to content

fix(dictate): keep what the user copied, and never read another window's text after a dictation - #525

Merged
GeiserX merged 4 commits into
mainfrom
fix/dictation-helper-clipboard-and-readback
Nov 12, 2026
Merged

GeiserX merged 4 commits into
mainfrom
fix/dictation-helper-clipboard-and-readback

Conversation

@GeiserX

@GeiserX GeiserX commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Problem

Two things in the dictation helper could take data the user did not mean to give.

  • After a dictation, the helper reads the field again to learn from the user's edits. It does this read when the user moves away from the field. On Windows the read used the element that had focus at that moment. After Alt+Tab, that is a field in another app. On macOS the same happened with another window of the same app. With an empty chat box, the whole text of that other field became one edit hunk. The app logged it as dictation.edit and offered it to the learner.
  • On Windows, a clipboard that another program held open during the snapshot read as empty. Then the paste kept the dictation as a lasting copy. If the other program let go before the publish, the dictation replaced what the user had copied. No message said so.

Fix

  • Both backends read the field only while the window the dictation went into still has the keyboard. On Windows, the foreground window and process must still be the target's. On macOS, the target app's front window must still be the one the paste went into. Any other window reads as unreadable. On macOS, a move to another app still reads the original field, as before.
  • The clipboard snapshot now reports a clipboard it could not read. An empty clipboard is a different case. When the snapshot fails, the insert fails clipboard-busy before it publishes, so the clipboard is not touched. The app already opens the draft box when an insert fails.

Testing

  • dc_l2_a_read_goes_only_to_the_window_the_insert_went_into (readback.rs): this checks the window rule that both backends call. A rule that always allows the read fails it with "another window of the app".
  • dc_n6_a_clipboard_too_busy_to_read_is_never_replaced (insert.rs): when the clipboard is busy during the snapshot, no key is posted, and the old text and image are still there after 9 s. It fails when a busy clipboard is treated as empty: the insert comes back Inserted { method: "paste" }. The existing empty-clipboard test is the positive control.
  • cargo fmt --check, cargo clippy -D warnings (with and without simulate) and cargo test pass on macOS with the pinned toolchain. bun run check:static passes. The Windows code does not compile on macOS. The Windows helper job in CI is the check for it.

After a dictation the helper reads the field again when the target loses
the keyboard. Windows read whatever element had focus at that moment, and
macOS read the app's focused element, so after moving to another window
the new window's field was read and could leave the helper as an edit
hunk. Both backends now read only while the target's window still has
the keyboard, and answer unreadable otherwise.
On Windows a clipboard another program held open through the snapshot's
retries read as empty, so the paste kept the dictation as a lasting copy
and what the user had copied was lost once that program let go. The
snapshot now reports a clipboard it could not read, and the insert fails
clipboard-busy before it publishes, leaving the clipboard untouched.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d533ee4 and a943862.

Files selected for processing: 12

  • .github/workflows/ci.yml
  • docs/TRAPS.md
  • docs/ux/DICTATION.md
  • native/akou-capture/src/dictate/fake.rs
  • native/akou-capture/src/dictate/insert.rs
  • native/akou-capture/src/dictate/mac.rs
  • native/akou-capture/src/dictate/mac_insert.rs
  • native/akou-capture/src/dictate/readback.rs
  • native/akou-capture/src/dictate/selection.rs
  • native/akou-capture/src/dictate/win.rs
  • native/akou-capture/src/dictate/win_insert.rs
  • native/akou-capture/tests/mac_pasteboard.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

…ow the user moved to

The DC-L2 unit test checks only the predicate; nothing failed if a backend's read_field stopped
calling it. The real-desktop step now watches a second paste, raises another window of the same
process, and expects edit.unreadable with reason unreadable (reason lost without the check).
@GeiserX
GeiserX merged commit 6ff0bd3 into main Nov 12, 2026
35 checks passed
@GeiserX
GeiserX deleted the fix/dictation-helper-clipboard-and-readback branch November 12, 2026 05:17
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