Skip to content

fix(translator): discard stale fetch responses from an outdated query - #159

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

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

Conversation

@fennstef

Copy link
Copy Markdown

Summary

  • Fast typing in the launcher can have more than one translation request in flight at once (e.g. /tr de goss then /tr de gossip).
  • HTTP responses aren't guaranteed to resolve in request order, so the response for an earlier, shorter query can land after the response for the current one, overwriting the result row with an outdated — and often incomplete — translation (e.g. showing the translation of goss instead of gossip).
  • onQuery's async fetch callback always calls launcher.setResults(query, ...) with the query it closed over at request time, with no check for whether that query is still current.

Fix

Track the query onQuery was last called with (currentQuery), and have the fetch callback bail out if the query it's responding to is no longer current — the same lastQuery guard pattern already used in the bitwarden plugin in this repo.

Test plan

  • luau-analyze --defs=noctalia.d.luau translator/translator.luau — no new type errors introduced (23 pre-existing Unknown global notices from the host-injected noctalia/launcher globals, unchanged before/after)
  • Not yet exercised against a live Noctalia launcher session — happy to, or defer to maintainer review/CI if this repo has an existing harness for that

Fast typing can leave more than one translation request in flight at
once. Since responses aren't guaranteed to resolve in request order, a
slower response for an earlier (shorter) query can land after the
response for what the user has since typed, overwriting the result row
with an outdated - and often incomplete - translation.

Track the query onQuery was last called with and have the async fetch
callback drop its result if that query has since moved on, following
the same lastQuery guard pattern already used in the bitwarden plugin.
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