Skip to content

translator: fix stale async response race condition - #161

Open
fennstef wants to merge 1 commit into
noctalia-dev:mainfrom
fennstef:fix-translator-race-condition
Open

fennstef wants to merge 1 commit into
noctalia-dev:mainfrom
fennstef:fix-translator-race-condition

Conversation

@fennstef

@fennstef fennstef commented Nov 19, 2026 •

Copy link
Copy Markdown

Summary

onQuery fires a new HTTP request on every keystroke, and each async callback published its result unconditionally via launcher.setResults. Requests for successive keystrokes (e.g. for "de gossi" then "de gossip") can resolve out of order over the network, so a stale response could land after a newer one and silently overwrite it with a truncated translation — e.g. /tr de gossip sometimes translating as if only gossi had been typed.

Motivation

Fixes a user-visible correctness bug: fast typing in the translator launcher command can silently produce a truncated/stale translation with no indication anything went wrong. This patch tracks the most recently seen onQuery input in a module-level lastQuery variable (the same pattern the bitwarden plugin already uses for an analogous staleness problem in launcher.luau), and drops any async response whose originating query no longer matches it, instead of publishing it.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring
  • Build / packaging

Related Issue

None — found and fixed during local use, no tracking issue filed.

Testing

  • Rapidly typed /tr de gossip and other fast multi-word queries before the fix, reproducing missing-last-word translations
  • Applied the patch, repeated the same rapid-typing test, translations now always match the fully-typed text
  • Confirmed in-order responses (no race) still publish results exactly as before

Manual Coverage

  • Tested on Niri
  • Tested on Hyprland
  • Tested on Sway
  • Tested on another compositor:
  • Tested with different bar positions and density settings
  • Tested at different interface scaling values
  • Tested with multiple monitors

Not applicable beyond compositor: this is a launcher-command logic fix with no UI/bar/layout surface, so bar position/density, scaling, and multi-monitor coverage don't apply.

Screenshots / Videos

Not applicable — no UI, visual, animation, or layout change.

Checklist

  • This PR is ready for review, or it is marked as Draft.
  • I self-reviewed the changes.
  • I added or updated translations/en.json, or this PR adds no new user-facing strings.
  • I did not edit non-English translation files unless this PR is explicitly for translation tooling, an import/export sync, or a maintainer-requested locale change.

Additional Notes

None.

onQuery fires a new HTTP request on every keystroke, and each async
callback published its result unconditionally via launcher.setResults.
Requests for successive keystrokes (e.g. for "de gossi" then "de
gossip") can resolve out of order over the network, so a stale response
could land after a newer one and silently overwrite it with a truncated
translation -- e.g. "/tr de gossip" sometimes translating as if only
"gossi" had been typed.

Track the most recently seen onQuery input in a module-level lastQuery
variable (same pattern already used by this repo's bitwarden plugin),
and drop any async response whose originating query no longer matches
it, instead of publishing it.
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