Skip to content

feat(chat): classify and surface generation errors inline - #1782

Merged
AnishSarkar22 merged 8 commits into
MODSetter:devfrom
AnishSarkar22:fix/local-app-ui
Sep 15, 2026
Merged

AnishSarkar22 merged 8 commits into
MODSetter:devfrom
AnishSarkar22:fix/local-app-ui

Conversation

@AnishSarkar22

@AnishSarkar22 AnishSarkar22 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Backend classifies generation failures by exception type (httpx status/timeout/network, JSON decode) instead of surfacing raw exception text, via a new modules/chat/errors.py module
  • Classification works identically for both providers (OpenAI-compatible connections and local Ollama), since both raise through the same httpx exception hierarchy
  • A turn that produced no content at all (e.g. a 401 before any reply streamed) is now rolled back and deleted instead of being persisted as a blank, unexplained assistant message
  • Thread auto-naming is deferred until the reply actually succeeds, so a fully failed first message no longer leaves a renamed-but-empty thread
  • The frontend now tracks errors per message instead of one global banner, and shows them inline below the reply that triggered them, matching the pattern used by chat UIs like Claude
  • Each error shows a friendly, backend-authored message plus a contextual action — "Model setup" for auth/not-found/bad-URL failures, "Retry" for rate limits/timeouts/unknown failures, and no action for an unreachable local Ollama (since there's no settings fix for that)
  • Retry resends the same message through the existing send pipeline
  • Fixed a pre-existing alignment bug in the shared Alert component where the icon only centered correctly when both AlertTitle and AlertDescription were present — it's now correct for single-row and multi-line content alike
  • Added backend test coverage for classification, turn rollback, and the deferred rename

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR improves error handling in the chat feature by introducing classified error types for LLM provider failures. On the backend, it adds an error classification system that maps HTTP failures to user-friendly messages with appropriate remediation actions (such as updating API keys or checking model availability). The frontend now displays contextual error notices with actionable buttons (Model setup or Retry) based on the error type. Additionally, the PR includes logic to discard incomplete chat turns when generation fails completely, preventing empty messages from persisting, and defers thread renaming until a successful reply is received. The changes include comprehensive test coverage for the new error handling behavior.

⏱️ Estimated Review Time: 15-30 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_local/backend/modules/chat/errors.py
2 surfsense_local/frontend/src/features/chat/sse.ts
3 surfsense_local/frontend/src/features/chat/use-chat-runtime.ts
4 surfsense_local/frontend/src/features/chat/chat-error-notice.tsx
5 surfsense_local/frontend/src/features/chat/message.tsx
6 surfsense_local/backend/modules/chat/router.py
7 surfsense_local/frontend/src/features/chat/thread-panel.tsx
8 surfsense_local/frontend/src/features/dashboard/dashboard-page.tsx
9 surfsense_local/frontend/src/components/ui/alert.tsx
10 surfsense_local/backend/tests/integration/chat/conftest.py
11 surfsense_local/backend/tests/integration/chat/test_chat.py

Need help? Join our Discord

@vercel

vercel Bot commented Sep 15, 2026

Copy link
Copy Markdown

@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 8049ea78-ffdc-4ae1-898a-399ddb80b858

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

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

@AnishSarkar22 AnishSarkar22 changed the title Fix/local app UI feat(chat): classify and surface generation errors inline Sep 15, 2026
@AnishSarkar22
AnishSarkar22 merged commit 719ed82 into MODSetter:dev Sep 15, 2026
4 of 8 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.

1 participant