fix: ignore stale mention search responses#272
Conversation
|
Submitted for the active Ugig testing/fix gig: https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e\n\nScope: real mention-suggestion race bug, issue #271, focused fix plus regression coverage and validation listed in the PR body. |
Greptile SummaryThis PR adds a request sequence guard to
Confidence Score: 5/5Safe to merge — the change is well-scoped, all three mutation paths (success, HTTP error, thrown exception) are guarded by the sequence check, and the debounce-cancellation path correctly invalidates in-flight requests. The sequence guard logic is sound: requestSeqRef is incremented before each debounced fetch and again when the cursor leaves mention context, ensuring any concurrently-resolving fetch from a prior sequence finds the counter has advanced and discards its result. Both previously-flagged concerns (timer flakiness in tests and the error path not hiding the dropdown) are resolved in this PR. No incorrect state transitions or missed guard conditions were found. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant detectMention
participant debounce
participant fetchSuggestions
participant API
User->>detectMention: "type @a"
detectMention->>detectMention: "seq = ++requestSeqRef (=1)"
detectMention->>debounce: setTimeout fetchSuggestions a 1 300ms
User->>detectMention: "type @ad"
detectMention->>debounce: "clearTimeout cancel seq=1"
detectMention->>detectMention: "seq = ++requestSeqRef (=2)"
detectMention->>debounce: setTimeout fetchSuggestions ad 2 300ms
debounce->>fetchSuggestions: fetchSuggestions ad 2
fetchSuggestions->>API: "GET /api/users/search?q=ad"
Note over fetchSuggestions: Old fetch seq=1 resolves late
API-->>fetchSuggestions: "response seq=1"
fetchSuggestions->>fetchSuggestions: "requestSeqRef 2 != seq 1 discard"
API-->>fetchSuggestions: "response seq=2"
fetchSuggestions->>fetchSuggestions: "requestSeqRef 2 = seq 2 apply"
fetchSuggestions->>fetchSuggestions: setSuggestions setShowDropdown
User->>detectMention: cursor leaves mention context
detectMention->>debounce: clearTimeout
detectMention->>detectMention: "requestSeqRef++ =3"
detectMention->>fetchSuggestions: setSuggestions empty setShowDropdown false
Reviews (3): Last reviewed commit: "fix: clear mention suggestions on failed..." | Re-trigger Greptile |
|
Addressed Greptile's follow-up notes.\n\nChanges pushed in 96ec180:\n- close the suggestions dropdown on the current error path\n- switch the stale-response regression to fake timers so it no longer waits on real debounce time\n\nValidation after the follow-up:\n- node_modules/.bin/vitest.cmd run src/components/ui/mention-textarea.test.tsx -> 2 passed\n- node_modules/.bin/eslint.cmd --quiet -- src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed\n- node_modules/.bin/tsc.cmd --noEmit -> passed\n- node_modules/.bin/prettier.cmd --check src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed\n- git diff --check -- src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed |
|
Addressed the latest Greptile note on the non-ok HTTP path.\n\nChanges pushed in d1c3954:\n- clear stale suggestions and close the dropdown when the active mention search returns a non-2xx response\n- add a regression test that first renders a successful suggestion, then verifies a failed active search clears it\n\nValidation after the follow-up:\n- node_modules/.bin/vitest.cmd run src/components/ui/mention-textarea.test.tsx -> 3 passed\n- node_modules/.bin/eslint.cmd --quiet -- src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed\n- node_modules/.bin/tsc.cmd --noEmit -> passed\n- node_modules/.bin/prettier.cmd --check src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed\n- git diff --check -- src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed |
|
Final automated review state is green on d1c3954.\n\n- Greptile Review -> success, confidence 5/5, safe to merge\n- Socket Security: Project Report -> success\n- Socket Security: Pull Request Alerts -> success\n\nNo remaining review action is open from my side. |
Summary\n- Fixes #271.\n- Adds a request sequence guard to MentionTextarea so only the latest active mention search can update suggestions.\n- Clears and invalidates pending mention searches when the cursor leaves mention context.\n- Adds regression coverage for stale response ordering and pending debounce cancellation.\n\n## Validation\n- node_modules/.bin/vitest.cmd run src/components/ui/mention-textarea.test.tsx -> 2 passed\n- node_modules/.bin/eslint.cmd --quiet -- src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed\n- node_modules/.bin/tsc.cmd --noEmit -> passed\n- node_modules/.bin/prettier.cmd --check src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed\n- git diff --check -- src/components/ui/mention-textarea.tsx src/components/ui/mention-textarea.test.tsx -> passed\n\nNote: I used direct local binaries for validation because the current base branch postinstall still hits the known Windows || true issue tracked by PR #262.