Skip to content

AI panel: abort the in-flight request when the rule changes - #23

Merged
dgunter merged 1 commit into
mainfrom
fix/ai-panel-stale-request
Sep 4, 2026
Merged

AI panel: abort the in-flight request when the rule changes#23
dgunter merged 1 commit into
mainfrom
fix/ai-panel-stale-request

Conversation

@dgunter

@dgunter dgunter commented Sep 4, 2026

Copy link
Copy Markdown
Owner

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 small RequestGuard that hands each request an AbortSignal and an isCurrent() 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 clears busy; 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, llmCandidates accept an optional signal.

Tests

inflight.test.ts covers supersede, cancel, idempotent cancel, and abort-error detection. tsc, vitest (26), oxlint, vite build green. The one oxlint warning on the panel's effect predates this change.

🤖 Generated with Claude Code

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>
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

SonarCloud analysis · PR #23

Quality gate: ❌ Failed · Open in SonarCloud

Condition Actual Required Status
Reliability rating (new code) A ≤ A
Security rating (new code) A ≤ A
Maintainability rating (new code) A ≤ A
Coverage (new code) 22.4% ≥ 80.0%
Duplication (new code) 0.0% ≤ 3.0%
Security hotspots reviewed 100.0% ≥ 100.0%

Open issues on new code: 1

Severity Quality Location Message Rule
HIGH Maintainability frontend/src/components/AiPanel.tsx:69 Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed. typescript:S3776
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 f1c6bb6a5770 · analysis task · posted by the Build workflow; edited in place on every push.

@dgunter
dgunter merged commit 8f92116 into main Sep 4, 2026
1 check passed
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