Skip to content

Conversation

djzager
Copy link
Member

@djzager djzager commented Aug 27, 2025

Fixes #716
Fixes #719

Summary by CodeRabbit

  • Bug Fixes
    • Consolidated GenAI configuration error handling to display only the most recent relevant error, preventing duplicates or lingering messages during initialization and configuration updates.
    • Improved reliability of error updates when provider connectivity issues occur, replacing outdated errors with the latest status.
    • Updated the Analysis page to hide the Agent Mode toggle when GenAI is disabled, preventing interaction with unavailable features and reducing confusion.

@djzager djzager requested a review from a team as a code owner August 27, 2025 17:11
Copy link

coderabbitai bot commented Aug 27, 2025

Walkthrough

The VS Code extension now clears all GenAI-related config errors ("genai-disabled", "provider-not-configured", "provider-connection-failed") before setting a new one during initialization and on configuration changes. Catch blocks uniformly clear these errors and set a fresh provider-connection-failed error with the caught message. In the webview AnalysisPage, a new isGenAIDisabled flag is derived from rawConfigErrors, and the Agent Mode toggle is conditionally hidden when isGenAIDisabled is true.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Hide or disable Agent mode button when GenAI is disabled (#716)

Possibly related PRs

Suggested reviewers

  • pranavgaikwad
  • ibolton336

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
vscode/src/extension.ts (1)

253-270: Prevent duplicate GenAI errors at startup.

During initialize(), updateConfigErrors(...) runs first, then you push the result of setupModelProvider(...). If GenAI is disabled, this can add a second genai-disabled entry. Apply the same “clear GenAI-related errors” filter here before pushing.

 this.setupModelProvider(paths().settingsYaml)
   .then((configError) => {
     this.state.mutateData((draft) => {
-      if (configError) {
-        draft.configErrors.push(configError);
-      }
+      // Clear GenAI-related config errors to avoid duplicates at startup
+      draft.configErrors = draft.configErrors.filter(
+        (e) =>
+          e.type !== "genai-disabled" &&
+          e.type !== "provider-not-configured" &&
+          e.type !== "provider-connection-failed",
+      );
+      if (configError) draft.configErrors.push(configError);
     });
   })
   .catch((error) => {
     this.state.logger.error("Error setting up model provider:", error);
     this.state.mutateData((draft) => {
-      if (error) {
-        const configError = createConfigError.providerConnnectionFailed();
-        configError.error = error instanceof Error ? error.message : String(error);
-        draft.configErrors.push(configError);
-      }
+      // Clear GenAI-related config errors to avoid duplicates at startup
+      draft.configErrors = draft.configErrors.filter(
+        (e) =>
+          e.type !== "genai-disabled" &&
+          e.type !== "provider-not-configured" &&
+          e.type !== "provider-connection-failed",
+      );
+      const configError = createConfigError.providerConnnectionFailed();
+      configError.error = error instanceof Error ? error.message : String(error);
+      draft.configErrors.push(configError);
     });
   });
♻️ Duplicate comments (1)
vscode/src/extension.ts (1)

347-361: Intentional full rebuild on settings save is preserved.

Clearing configErrors before updateConfigErrors matches the prior design decision (see retrieved learnings). No action needed.

🧹 Nitpick comments (3)
webview-ui/src/components/AnalysisPage/AnalysisPage.tsx (2)

91-91: Derive a more general “GenAI unavailable” guard (optional).

Today you only hide the toggle when genai-disabled is present. Consider also guarding on provider-not-configured and provider-connection-failed to prevent an ON toggle when the provider is unusable.

-  const isGenAIDisabled = rawConfigErrors.some((error) => error.type === "genai-disabled");
+  const isGenAIUnavailable = rawConfigErrors.some(
+    (e) =>
+      e.type === "genai-disabled" ||
+      e.type === "provider-not-configured" ||
+      e.type === "provider-connection-failed",
+  );

155-171: LGTM: Toggle is hidden when GenAI is disabled.

This meets #716's objective. If you adopt the broader guard above, replace !isGenAIDisabled with !isGenAIUnavailable. Also consider adding data-testid="agent-mode-switch" to simplify Playwright assertions.

- {!isGenAIDisabled && (
+ {!isGenAIUnavailable && (
   <ToolbarItem>
     <div>
       <div className="agent-mode-wrapper">
         <Switch
           id="agent-mode-switch"
+          data-testid="agent-mode-switch"
           isChecked={isAgentMode}
           label="Agent Mode"
           onChange={(_event) => handleAgentModeToggle()}
           aria-label="Toggle Agent Mode"
           isReversed
         />
       </div>
     </div>
   </ToolbarItem>
 )}
vscode/src/extension.ts (1)

392-404: Align error message truncation with setupModelProvider (optional).

setupModelProvider() truncates messages to 150 chars; here you don’t. Consider consistent truncation to avoid noisy toasts.

-                  const configError = createConfigError.providerConnnectionFailed();
-                  configError.error = error instanceof Error ? error.message : String(error);
+                  const configError = createConfigError.providerConnnectionFailed();
+                  const msg = error instanceof Error ? error.message : String(error);
+                  configError.error = msg.length > 150 ? msg.slice(0, 150) + "..." : msg;
                   draft.configErrors.push(configError);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 30903a4 and d29d186.

📒 Files selected for processing (2)
  • vscode/src/extension.ts (1 hunks)
  • webview-ui/src/components/AnalysisPage/AnalysisPage.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: pranavgaikwad
PR: konveyor/editor-extensions#581
File: vscode/src/extension.ts:243-251
Timestamp: 2025-07-23T12:10:46.399Z
Learning: In vscode/src/extension.ts, clearing all configErrors in the onDidSaveTextDocument listener for settings YAML is intentional behavior. The setupModelProvider and updateConfigErrors functions are designed to work together to rebuild the entire configuration error state.
📚 Learning: 2025-08-05T16:16:56.005Z
Learnt from: abrugaro
PR: konveyor/editor-extensions#657
File: tests/global.setup.ts:22-27
Timestamp: 2025-08-05T16:16:56.005Z
Learning: In the Playwright test framework for konveyor/editor-extensions, the global setup in tests/global.setup.ts is designed to handle only essential initialization like extension installation verification. Individual tests are responsible for configuring GenAI when needed, rather than doing it globally. The openAnalysisView() method is used as a fast verification mechanism to ensure the extension was successfully installed, which is more efficient than configuring GenAI globally for all tests.

Applied to files:

  • webview-ui/src/components/AnalysisPage/AnalysisPage.tsx
📚 Learning: 2025-07-23T12:10:46.399Z
Learnt from: pranavgaikwad
PR: konveyor/editor-extensions#581
File: vscode/src/extension.ts:243-251
Timestamp: 2025-07-23T12:10:46.399Z
Learning: In vscode/src/extension.ts, clearing all configErrors in the onDidSaveTextDocument listener for settings YAML is intentional behavior. The setupModelProvider and updateConfigErrors functions are designed to work together to rebuild the entire configuration error state.

Applied to files:

  • vscode/src/extension.ts
🧬 Code graph analysis (1)
vscode/src/extension.ts (1)
shared/src/types/types.ts (1)
  • createConfigError (202-242)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build (windows)
  • GitHub Check: Build (macos)
  • GitHub Check: Build (linux)
🔇 Additional comments (1)
vscode/src/extension.ts (1)

375-383: Good: de-dup GenAI-related config errors on config change.

Filtering genai-disabled, provider-not-configured, and provider-connection-failed before pushing the new one prevents stacked/stale errors. Nice.

@ibolton336 ibolton336 merged commit dc90f73 into konveyor:main Aug 27, 2025
15 checks 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.

Toggling Gen AI settings requires inconsistent restart behavior in VS Code Agent mode button can be switched ON when the Gen AI is disabled .
2 participants