AI panel: abort the in-flight request when the rule changes - #23
Merged
Conversation
Changing the rule cleared the panel's result but left the request running and the button spinning, so a reply for the previous rule could land next to the new one, and the panel could read "Asking the model" beside "Classify a rule first" after a parse error. A RequestGuard now aborts the fetch and marks it stale when the rule changes or a new action starts; stale outcomes are ignored. Unit tests cover the guard. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
SonarCloud analysis · PR #23Quality gate: ❌ Failed · Open in SonarCloud
Open issues on new code: 1
Machine-readable issue list[
{
"key": "AaBtQgsYF4Lo6wYGnqYR",
"severity": "HIGH",
"qualities": [
"Maintainability"
],
"path": "frontend/src/components/AiPanel.tsx",
"line": 69,
"message": "Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed.",
"rule": "typescript:S3776",
"effort": "17min"
}
]Commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Changing the rule (typing, picking an example, loading a candidate) cleared the AI panel's result but did not stop the request already in flight. The button kept spinning, a reply for the previous rule could be shown next to the new one, and after a parse error the panel read "Asking the model" beside "Classify a rule first" (seen while capturing screenshots).
How
lib/inflight.ts: a smallRequestGuardthat hands each request anAbortSignaland anisCurrent()check; beginning a new request or cancelling aborts the previous one and marks it stale.AiPanel: the rule-change effect now cancels the guard and clearsbusy; every action passes the signal and only applies its outcome while still current. Abort errors are swallowed, and the streaming fallback no longer fires for an aborted stream.api.ts:llmExplain,llmSuggestAttack,llmCandidatesaccept an optional signal.Tests
inflight.test.tscovers supersede, cancel, idempotent cancel, and abort-error detection.tsc,vitest(26),oxlint,vite buildgreen. The one oxlint warning on the panel's effect predates this change.🤖 Generated with Claude Code