Repository navigation
fix: unstick the anti-pattern "Why?" explanation and use Copilot Auto - #301
Conversation
The Why? explainer wrote its loading text with textContent and then
called Preact render() on the same container. Preact never removes nodes
it did not create, so "Asking AI for an explanation..." stayed after the
answer, and a repeat request patched detached nodes and never appeared.
Every explanation state now renders through Preact, and empty answers
surface as errors.
AI features and the natural-language rule compiler now use only GitHub
Copilot's Auto model ({ vendor: 'copilot', id: 'auto' }) instead of
hard-coded model families. callLlm no longer retries timeouts, denied
access, quota or not-found errors, treats empty replies as failures, and
keeps each call within a 120s budget.
getCapabilities now probes Copilot availability (bounded, optimistic on
timeout) instead of always reporting llm: true, and the panel pushes
capability changes on lm.onDidChangeChatModels so Why?, Skill Finder,
Level Up and Context Review follow Copilot sign-in and sign-out.
The contributes.languageModels entry proposed in the issue is not added:
VS Code has no such contribution point (languageModelChatProviders is for
providing models) and consuming vscode.lm needs no contribution.
Resolves #278
Co-authored-by: Copilot App <[email protected]>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
🟡 Changes recommended
Capability-triggered page replacement silently discards unsaved Rule Editor drafts.
1 open issue
What changed in this PR
Fixes stuck anti-pattern explanations and standardizes optional AI features on GitHub Copilot Auto.
Changes:
- Renders explanation states consistently through Preact.
- Adds bounded model selection and improved plain-text request error handling.
- Updates AI feature visibility when Copilot availability changes, with regression coverage.
| File | Description |
|---|---|
| tests/e2e/harness.html | Adds AI navigation markers. |
| tests/e2e/antipatterns.spec.ts | Tests explanations and capability changes. |
| src/webview/styles.css | Hides unavailable AI navigation items. |
| src/webview/panel.ts | Probes and pushes Copilot availability. |
| src/webview/panel.test.ts | Tests host capability responses and updates. |
| src/webview/panel-llm.ts | Updates model access, retries, and timeouts. |
| src/webview/panel-llm-model.ts | Centralizes model selection and failure classification. |
| src/webview/panel-llm-call.test.ts | Tests model access and request failures. |
| src/webview/page-config.ts | Uses host-specific availability guidance. |
| src/webview/page-antipatterns.ts | Delegates explanation rendering. |
| src/webview/occurrence-explain.ts | Manages explanation states through Preact. |
| src/webview/occurrence-explain.test.ts | Tests explanation rendering and recovery. |
| src/webview/dashboard-shell.ts | Marks AI-dependent navigation items. |
| src/webview/capabilities.ts | Handles capability updates and subscriptions. |
| src/webview/capabilities.test.ts | Tests capability state and notifications. |
| src/webview/app.ts | Refreshes navigation and pages on capability changes. |
| src/core/types/rpc-types.ts | Defines shared capability message types. |
| src/core/rule-compiler.ts | Uses Copilot Auto and consent justification. |
| src/core/copilot-model.ts | Defines shared selector and justification. |
| README.md | Documents Copilot requirements and availability. |
| CHANGELOG.md | Records explanation and model-access changes. |
Review effort: Balanced
Addresses review feedback on #301. Re-rendering the current page after a capability push cleared #content, which closed the Rule Editor modal and discarded unsaved drafts, along with other in-page state such as expanded findings and loaded Context Health review results. Capability changes no longer rebuild the page. capabilities.ts toggles an llm-unavailable class on the root element, and AI controls are always rendered with llm-only or llm-fallback markers that CSS shows or hides: Why? buttons, the Dashboard Skill Finder card, the Skill Finder and Level Up nav entries, and the Context Health review controls. Refs #278 Co-authored-by: Copilot App <[email protected]>
Addresses the high-severity review finding on #301. callLlm started its 120s budget after model selection, which can take up to 15s, so a request could run for about 135s. Generate SKILL.md was not in the webview's LLM_METHODS, so its RPC gave up at 120s and discarded the late reply or the host's actionable error. - The 120s budget (COPILOT_REQUEST_BUDGET_MS, now in core/copilot-model) starts before model selection, and selection is capped at the smaller of 15s and the remaining budget. - callLlm accepts a shared deadline. generateRule makes up to three model calls for one request, so it now passes one deadline to all of them and keeps the latest draft if a follow-up runs out of time. Its retry loop moved into generateRuleMarkdown so it can be unit tested. - generateSkillContent uses the 300s LLM RPC timeout like explainOccurrence and generateRule. The list is type-checked against the RPC method names. Refs #278 Co-authored-by: Copilot App <[email protected]>
Resolve the CHANGELOG conflict by keeping both Unreleased entries. Co-authored-by: Copilot App <[email protected]>
…suite Add a packaged-VSIX desktop test that runs with GitHub Copilot unavailable (the harness sets chat.disableAIFeatures) and checks, in real VS Code, that: - the Dashboard Skill Finder card and the Skill Finder and Level Up nav entries are rendered but hidden, - every anti-pattern Why? button is rendered but hidden, - Review Context Files is hidden and its disabled fallback carries the "Sign in to GitHub Copilot in VS Code to use this." hint. The test lives in its own describe block so the existing populated suite stays within the max-lines-per-function budget, and the Dashboard page object gains expectHidden and expectDisabled helpers. Also correct the README privacy note and CHANGELOG entry: they now list exactly which features are hidden or disabled without Copilot, include Level Up among the AI features, and note that rule generation falls back to a starter template instead of being hidden. Refs #278 Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Authenticated Copilot validation remains pending for Auto routing, first-use consent/denial, and real sign-in/out model events, which mocks, signed-out tests, and replayed messages do not verify.
No open issues 🎉
Review effort: Balanced
|
Aymen (@aymenfurter), I'm re-requesting your review: the branch rules require approval of the latest push, so your approval of 8e8b860 no longer counts. Changes since you approved:
All CI checks pass, including the new test on Windows, macOS and Ubuntu with VS Code 1.125.0 and the latest release. Copilot's re-review of b9a5780 found no issues. The signed-in Copilot checks listed in the description are still to do. |


Description
Fixes the anti-pattern Why? button that stays on "Asking AI for an explanation…" forever (#278). It also makes every AI feature use GitHub Copilot's Auto model, fail fast with a clear message, and appear only when GitHub Copilot is available.
Code changes
src/core/copilot-model.ts(new){ vendor: 'copilot', id: 'auto' }selector, the consent-dialog justification text, and the 120s request budget (COPILOT_REQUEST_BUDGET_MS).src/webview/panel-llm-model.ts(new)selectModel()(Copilot Auto only; at most 15s and never past the request's deadline),isCopilotModelAvailable()probe,withTimeout(), and classification of errors that must not be retried.src/webview/panel-llm.tscallLlmgets a 120s budget that includes model selection and can be shared across calls (llmDeadline()and adeadlineoption), no retries for non-recoverable errors, empty reply treated as failure, and the justification.callLlmJsononly gains the justification.src/webview/panel-rpc.tsgenerateRulepasses one deadline to all of its model calls (up to three) and keeps the latest draft if a follow-up runs out of time. Its retry loop is now the testablegenerateRuleMarkdown.src/webview/shared.tsgenerateSkillContent) gets the 300s webview timeout used for Copilot-backed requests, like Why? and Generate rule. The list is type-checked against the RPC method names.src/core/rule-compiler.ts{ family: 'gpt-4.1' }replaced by the shared Auto selector, plus the justification.src/webview/occurrence-explain.ts(new)src/webview/page-antipatterns.tsexplainOccurrenceremoved; the page uses the new module. The Why? button is always rendered and markedllm-only.src/webview/panel.tsgetCapabilitiesactually probes Copilot. The panel pushescapabilitiesmessages onlm.onDidChangeChatModels.src/core/types/rpc-types.tsHostCapabilitiesandHostCapabilitiesMessagetypes.src/webview/capabilities.tsllm-unavailableclass on the root element, so CSS shows or hides AI controls without rebuilding the page. Adds a host-awarellmUnavailableNote()(replacesLLM_UNAVAILABLE_NOTE).src/webview/dashboard-shell.ts,page-dashboard.ts,page-config.ts,styles.cssllm-only: the Skill Finder and Level Up nav entries, the Dashboard Skill Finder card, and Review Context Files with its workspace count. A disabled Review Context Files carrying the sign-in hint is markedllm-fallback. Two CSS rules keyed on the root class show or hide them.panel-llm-call.test.ts,occurrence-explain.test.ts,capabilities.test.ts; extendedpanel.test.ts; newshared-rpc.test.ts; Playwright cases inantipatterns.spec.tsand the newcopilot-availability.spec.ts(harness.htmlmirrors the nav markers); a packaged-VSIX desktop test intests/vscode/suite/populated.spec.ts, with newexpectHiddenandexpectDisabledhelpers intests/vscode/dashboard.ts.Impacted functionality: before → after
<answer>Asking AI for an explanation…). An empty answer left only the loading text. Asking again after hiding the answer stuck on "Asking AI for an explanation…" forever, with no error.gpt-5.4-mini→gpt-5-mini→gpt-4.1-mini→gpt-4.1, then the first model from any vendor. A model could be selectable but disabled for the user's plan, which produced empty replies (#91).NoPermissions), quota or rate limits (Blocked) andNotFoundfail immediately with an actionable message (for example "Run 'Chat: Manage Language Model Access'…"). Transient errors and empty replies are retried within the budget.{ family: 'gpt-4.1' }only, falling back to the heuristic template when that model wasn't available.getCapabilitiesalways returnedllm: true. Why?, Skill Finder (nav entry and dashboard card), Level Up and Review Context Files were always shown, even without Copilot, and then failed or hung when used.lm.onDidChangeChatModelsand pushes the change. AI controls appear or disappear in place, with no need to reopen. The page isn't rebuilt, so an open Rule Editor and its unsaved draft, expanded findings, and loaded results are kept. If you're on Skill Finder or Level Up when Copilot becomes unavailable, you stay on the page and AI actions show the sign-in message.llm: false).call-failedfrom JSON calls.[panel-llm]lines:model-selected(vendor, id, family),model-unavailable,call-failed(with a retryable flag),empty-response,probe-inconclusive, plus[panel] capabilities-changed. Prompts and keys are never logged.Not changed:
callLlmJsonretry and JSON-repair logic;@aicoachchat participant, which uses the model selected in chat;Root cause (reproduced)
explainOccurrencewrote the loading text withtextContentand then called Preactrender()on the same element. Preact never removes DOM nodes it didn't create, and after atextContentwipe it keeps patching its old, detached nodes.The new tests reproduce the bug against the original code:
"The session ran long.Start a new chat per task.Asking AI for an explanation...""Asking AI for an explanation..."forever"First explanation.Asking AI for an explanation..."Not adopted from the issue
contributes.languageModels: VS Code has no such contribution point. The only one islanguageModelChatProviders, which is for providing models. Callingvscode.lmneeds no contribution; consent is an auth dialog shown on the firstsendRequest.gpt-4o/o1/o3-minifamily list: these models are retired too. Copilot Auto replaces hard-coded names.pendingMessagesflush: already fixed onmainbypublishReady()(68ceef6) and covered by an existingpanel.test.tscase.Validation
The branch is up to date with
main(merged at ea0163e). The only conflict wasCHANGELOG.md, resolved by keeping both entries. The PR'ssrc/changes are identical before and after the merge. Results below are for b9a5780.npm run check(CIverify)npm run check,build,package,check-sizevscode-compatibility)npm run check(local)main) · knip ✅ · lockfile-lint ✅ · tests ✅ 1736 passed, 5 skipped · spellcheck ✅ through the cspell API (282 files, 0 issues). The cspell CLI refuses this machine's prerelease Node (v27.0.0-alpha) before checking anything.npm run test:vscode(packaged VSIX, VS Code 1.125.0)npm run test:vscode -- --vscode-version latest(VS Code 1.144.0)npm run test:e2ecuriosity.spec.ts:353"reads and scrolls long escaped prompts from language previews at 1280x800", which is flaky onmaintoo: in alternating batches of repeated runs it failed 9 of 40 times onmainand 4 of 40 on this branch. This PR doesn't touch the Curiosity page.npm run check-sizeNew tests:
panel-llm-call.test.ts(18): selection, probe, retry, timeout and budget behaviour, including model selection counting toward the budget and deadlines shared across calls.shared-rpc.test.ts(4): every Copilot-backed RPC waits longer than the host budget plus a 60s delivery margin; other RPCs keep 120s.panel-rpc.test.ts(+5):generateRuleMarkdownretry feedback and keeping the latest draft.occurrence-explain.test.ts(6) andcapabilities.test.ts(5): jsdom.panel.test.ts.antipatterns.spec.ts, including a regression test that an unsaved Rule Editor draft survives a capability change.copilot-availability.spec.ts: the Dashboard Skill Finder card and the Context Health fallback button.tests/vscode/suite/populated.spec.ts, run in real VS Code with Copilot unavailable: the Skill Finder card, the Skill Finder and Level Up nav entries, and every Why? button are rendered but hidden, and Review Context Files shows the disabled fallback with the sign-in hint.Automated run in real VS Code (Copilot signed out)
Besides the desktop test, VS Code 1.144.0 itself was driven with Playwright's Electron automation. It ran in an isolated profile with the synthetic session logs from
tests/vscode, clicking through the real UI and reading the Output channel. GitHub Copilot was signed out, so no Copilot model was available.llm-unavailable. The Skill Finder and Level Up nav entries and the Dashboard Skill Finder card are hidden. All 90 Why? buttons are rendered but hidden. Review Context Files is replaced by a disabled button with "Sign in to GitHub Copilot in VS Code to use this."chat.allowAnonymousAccess: truewithout signing in, at runtime and after a reloadcapabilitiesmessage replayed inside the real webview)[panel-llm] model-unavailable | selector=copilot/auto.The automation doesn't sign in to GitHub or accept GitHub's Copilot terms on anyone's behalf, so the signed-in checks below still need a person.
Manual verification with real Copilot (still to do)
Launch an isolated dev host from the repo root with
code --user-data-dir "$env:TEMP\aiec-test" --extensionDevelopmentPath "$PWD". It starts with fresh GitHub sign-in and consent state and still reads your real session logs. Watch View → Output → AI Engineer Coach.[panel-llm] model-selectedline withvendor=copilot id=auto. Hide it, then ask again: a new explanation appears.Follow-ups (not in this PR)
page-antipatterns-editor.ts).cleanRuleMarkdown(panel-rpc.ts) removes the closing fence of a trailingdetectblock when the model's reply isn't wrapped in a fence. Validation then skips thedetectchecks without reporting anything.curiosity.spec.ts:353(language previews at 1280x800) is flaky onmainwhen run with 6 workers.Related Issues
Resolves #278. Related: #91 (empty responses from selectable-but-disabled models). This PR supersedes the model-selection part of #253, while #253's
callLlmJsonempty-response handling is still complementary. It is also compatible with #276 / #277.Checklist
npm run checkpasses (typecheck + lint + spellcheck + knip + tests). Green in CIverifyon b9a5780; see Validation for local notes.