Skip to content

Fix/mcp error handling - #128

Merged
Amazing-Stardom merged 24 commits into
masterfrom
fix/mcp-error-handling
Oct 10, 2026
Merged

Amazing-Stardom merged 24 commits into
masterfrom
fix/mcp-error-handling

Conversation

@Amazing-Stardom

@Amazing-Stardom Amazing-Stardom commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds error handling for LLM Provider connections. It improves the frontend parsing logic and the backend parsing logic for chat payloads. These changes remove extra work and extra memory allocations.

Backend Changes:

  • LLM Error Categorization: I updated internal/aiconnectors/errors.go to intercept langchaingo normalizations. It detects network timeouts. It combines the HTTP status code interfaces (StatusCode and HTTPStatusCode). This removes duplicate code branches.
  • Chat Payload Parsing: I updated internal/api/chat_conversations_handler.go and webchat_handler.go. I replaced the full JSON marshal loop with direct map access and interface type assertions. It falls back to marshaling only when necessary. I restored the error logging for this fallback.
  • Agent Slice Safety: I added strict initialization and slice bounds checks inside internal/mcpagent/agent.go. This fixes static analysis warnings about potential map accesses or nil pointer accesses. I do this when I append Action Cards and debug artifacts to the history.

Frontend Changes:

  • Action Card Efficiency: I replaced array mutations inside ChatActionCard.tsx with a backwards for loop. The loop uses no extra memory allocations.
  • Type Safety and Bounds Checks: I removed the React.SyntheticEvent type union from handleSend in ChatConversation.tsx. I added missing boundary checks for array accesses in ChatErrorHandling.tsx. These checks prevent crashes on empty error states.
  • Native Entity Decoding: I updated extractPlainText in slideshowParser.js to use DOMParser. This completely strips HTML tags and decodes HTML entities (like &).

Validation

I checked all MCP cases and verified that everything works.

Checklist

  • This PR fulfills an agreed issue.
  • I kept the change narrow and scoped.
  • I ran the most specific relevant validation and described it above.
  • If I changed behavior, I called that out clearly in this PR.
  • If I touched UI, I attached a GIF or video walkthrough. This is required.
  • If this change touches security, disclosure flow, credentials, storage, network behavior, or licensing/entitlement enforcement, I reviewed SECURITY.md and updated related documentation if needed.
  • I have read and accept the Contributor License Agreement.

@LiveReview-Bot

Copy link
Copy Markdown

Integrate Centralized LLM Error Handling and Offline Preact Dashboard UI

Overview

This update introduces centralized LLM error categorization, standardized UI fallback error templates, and ActionCard support across agent integrations. Additionally, it ships a complete offline Preact and HTM frontend dashboard export with static JSON data shims.

Technical Highlights

  • internal/aiconnectors/errors.go: Implements CategorizeLLMError to map raw SDK errors into standardized categories and UI fallback messages.
  • internal/mcpagent/provider.go: Adds LLMErrorTemplates containing structured action cards and messages for various error types.
  • internal/api/webchat_handler.go: Enhances web chat responses with markdown error callouts and action card unmarshaling.
  • scripts/blast-radius-demo-export/static/app.js: Implements the core Preact UI application for managing review states, event streaming, and filtering.
  • scripts/blast-radius-demo-export/static/api-shim.js: Overrides global fetch and EventSource to enable a fully offline read-only demo experience using static JSON.

Impact

  • Functionality: Standardizes error handling across LLM integrations and delivers a standalone offline dashboard for exploring code reviews and blast radius metrics.
  • Risk: Relies on raw SQL string formatting in demo storage queries and static shims that may drift from live backend behavior.

Comment thread internal/api/webchat_handler.go
Comment thread internal/mcpagent/provider_test.go Outdated
Comment thread scripts/blast-radius-demo-export/static/app.js
Comment thread scripts/blast-radius-demo-export/static/app.js
Comment thread scripts/blast-radius-demo-export/static/components/Comment.js
Comment thread scripts/blast-radius-demo-export/static/components/FeedbackPopup.js
Comment thread scripts/blast-radius-demo-export/static/components/FeedbackPopup.js
@LiveReview-Bot

Copy link
Copy Markdown

Implement Centralized LLM Error Categorization and Action Card UI

Overview

This change introduces a centralized LLM error categorization system and maps error templates to UI action cards. It standardizes error handling across backend agent loops and improves frontend chat rendering with graceful failure messages.

Technical Highlights

  • internal/aiconnectors/errors.go: Implements centralized error inspection and categorization mapping SDK failures to specific constant types.
  • internal/mcpagent/provider.go: Defines backend LLM error templates containing pre-baked UI messages and action card targets.
  • internal/mcpagent/agent.go: Refactors the agent loop to use centralized error categorization and removes legacy duplicate code.
  • ui/src/pages/Chatbot/ChatConversation.tsx: Integrates structured action card rendering, error phrase matching, and collapsible debug artifacts.

Impact

  • Functionality: Replaces raw internal error strings with user-friendly Markdown messages and renders actionable UI components during agent failures.
  • Risk: Mismatched error categories or unmapped SDK errors could fall back to generic messages if new failure modes arise.

Comment thread internal/api/webchat_handler.go
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx Outdated
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx Outdated
@LiveReview-Bot

Copy link
Copy Markdown

Centralize LLM Error Handling and Structured Action Cards

Overview

This update centralizes LLM error categorization in backend connectors to map raw SDK failures into standard UI states. It introduces structured action cards and collapsible debug logs across chat handlers and frontend components.

Technical Highlights

  • internal/aiconnectors/errors.go: Implements error categorization logic to map raw SDK errors and HTTP status codes into uniform UI categories.
  • internal/mcpagent/agent.go: Replaces local heuristic checks with centralized error categorization to attach recovery action cards automatically.
  • internal/api/webchat_handler.go: Formats web chat failures with graceful markdown messages and extracts action cards from execution entries.
  • ui/src/pages/Chatbot/ChatConversation.tsx: Renders structured action cards and adds a collapsible debug log viewer for raw LLM errors.

Impact

  • Functionality: Users now see structured recovery action cards and collapsible debug logs instead of raw stack traces on LLM errors.
  • Risk: Missing fallback error templates for unmapped SDK error categories may still expose raw error strings to the UI.

Comment thread internal/api/webchat_handler.go
Comment thread internal/mcpagent/agent.go Outdated
Comment thread internal/mcpagent/agent.go Outdated
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx Outdated
@LiveReview-Bot

Copy link
Copy Markdown

Implement Structured AI Error Handling and Action Cards

Overview

This change introduces a standardized system for categorizing AI model errors and presenting user-friendly feedback. It integrates structured action cards into chat responses. This provides clear, actionable error messages and interactive elements for users.

Technical Highlights

  • internal/aiconnectors/errors.go: Defines standard LLM error categories and implements logic to classify raw LLM SDK errors.
  • internal/mcpagent/provider.go: Establishes a map of LLMErrorTemplate structs, linking error categories to localized messages and action card definitions.
  • internal/mcpagent/agent.go: Refactors agent execution loops to use the new centralized error classification and structured error templates.
  • internal/api/webchat_handler.go: Updates web chat responses to include ActionCard structures and user-friendly Markdown error messages.
  • ui/src/pages/Chatbot/ChatConversation.tsx: Implements rendering for action cards and displays categorized AI failure messages in the chat UI.
  • internal/api/chat_conversations_handler.go: Updates conversation history retrieval to parse and populate ActionCard structures from persisted entries.

Impact

  • Functionality: Users now receive structured error messages and interactive action cards when AI models encounter issues.
  • Risk: Changes to chat history parsing and persistence may introduce regressions in existing conversation retrieval or display.

Comment thread internal/mcpagent/agent.go Outdated
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx Outdated
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx Outdated
@LiveReview-Bot

Copy link
Copy Markdown

Implement Centralized LLM Error Handling and Action Cards

Overview

This update centralizes LLM error categorization, introduces structured action cards, and updates UI components to render rich error feedback. Backend modules now map provider errors into standardized templates, while frontend chat views safely display raw debug data and interactive UI actions.

Technical Highlights

  • internal/aiconnectors/errors.go: Implements robust error classification to map Langchain errors, status codes, and strings into fallback categories.
  • internal/mcpagent/provider.go: Defines LLMErrorTemplates and helper functions to supply actionable UI metadata for specific error states.
  • ui/src/pages/Chatbot/ChatConversation.tsx: Refactors chat message rendering to support dynamic action cards and collapsible raw error debug artifacts.
  • scripts/blast-radius-demo-export/static/components/SummarySlideshow/slideshowParser.js: Replaces DOM manipulation with regex in extractPlainText for server-side rendering compatibility.

Impact

  • Functionality: Replaces ad-hoc error checks with unified error categorization and enables rich frontend action cards.
  • Risk: Regex-based text extraction or text-prefix error matching could fail if provider error formats shift unexpectedly.

Comment thread internal/api/webchat_handler.go
Comment thread internal/mcpagent/provider.go Outdated
Comment thread internal/mcpagent/provider.go Outdated
Comment thread internal/mcpagent/provider.go Outdated
const url = msg.actionCard?.action_url;
if (url === ACTION_RETRY) {
// Find the most recent user message before this error
let prevUserMsg = undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Consider iterating backwards through the messages to find the most recent user message.

}
}

if (prevUserMsg?.text) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: warning

Please check if prevUserMsg?.text is defined before calling the handleSend function.

Suggestions:

  1. Add null check for prevUserMsg?.text before calling handleSend to prevent potential errors.

{msg.actionCard.button_text}
</button>
</div>
{msg.debugArtifacts?.raw_llm_error && (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Display the raw LLM error in the debug logs.

import { isDailyTrendChart, buildTrendSpec, formatAxisDate, Granularity } from './rebucketChart';
import { buildJsonExport, downloadJsonExport } from './jsonExport';
import ProductionUrlWarning from '../../components/ProductionUrlWarning';
import { ChatActionCard } from './ChatActionCard';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Import the ChatActionCard component.

import { buildJsonExport, downloadJsonExport } from './jsonExport';
import ProductionUrlWarning from '../../components/ProductionUrlWarning';
import { ChatActionCard } from './ChatActionCard';
import { ChatErrorBlockquote } from './ChatErrorHandling';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Import the ChatErrorBlockquote component.

const LiviLogo: React.FC<{ className?: string }> = ({ className = '' }) => (
<div className={`w-12 flex-shrink-0 flex justify-center ${className}`}>
<img src="/assets/lrbot/lrbot.png" alt="Bot" width={32} height={32} decoding="async" className="w-8 h-8 rounded-full" />
</div>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Refactor the LiviLogo component to directly return the img element.

repaired_sql?: string;
}>;
}>;
raw_llm_error?: string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Add a raw_llm_error field to the DebugArtifacts interface.

}

interface ChatEntry {
export interface ChatEntry {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Export the ChatEntry interface to allow for external use.

files?: ChatFile[];
suggestedQuestions?: SuggestedQuestionCategory[];
debugArtifacts?: DebugArtifacts | null;
isError?: boolean;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Add an isError field to the ChatEntry interface.

suggestedQuestions?: SuggestedQuestionCategory[];
debugArtifacts?: DebugArtifacts | null;
isError?: boolean;
actionCard?: {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Add an actionCard field to the ChatEntry interface.

}

function formatText(rawText: string): React.ReactNode[] {
function formatText(rawText: string, isErrorMsg: boolean = false): React.ReactNode[] {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Add an isErrorMsg parameter to the formatText function.

const isError = blockquoteLines.length > 0 && blockquoteLines[0].includes('Action Required:');

if (isError) {
if (isErrorMsg) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Conditionally render the ChatErrorBlockquote component when the message is an error.

files: m.files && m.files.length > 0 ? m.files : undefined,
suggestedQuestions: m.suggested_questions,
debugArtifacts: m.debug_artifacts as DebugArtifacts | undefined,
isError: m.is_error,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: info

Map the is_error field from the API response to the ChatEntry.

Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
Comment thread ui/src/pages/Chatbot/ChatConversation.tsx
@Amazing-Stardom
Amazing-Stardom merged commit 7c86ad6 into master Oct 10, 2026
17 of 18 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.

4 participants