Skip to content

fix: use correct error handling for chat messages and ingestion#859

Merged
lucaseduoli merged 6 commits into
mainfrom
fix/error_handling
Mar 10, 2026
Merged

fix: use correct error handling for chat messages and ingestion#859
lucaseduoli merged 6 commits into
mainfrom
fix/error_handling

Conversation

@lucaseduoli

Copy link
Copy Markdown
Collaborator

This pull request introduces comprehensive improvements to error handling and error message display across the chat frontend and backend. The main changes include a new, user-friendly error message component in the UI, consistent propagation and storage of error states in chat messages, and enhanced error detection and reporting throughout the backend and API layers. These updates result in clearer feedback for users when errors occur and ensure that error messages persist and are properly displayed in chat history.

Frontend Enhancements:

  • Error Message UI:

    • Added a new ErrorMessage React component for displaying styled error messages in chat, including support for animation and custom icons.
    • Updated ChatPage to render ErrorMessage instead of the standard assistant message when a message has an error flag. [1] [2]
    • Introduced an error property to the chat message type and ensured it is set and propagated when errors occur during chat interactions or streaming. [1] [2] [3] [4] [5] [6]
  • Streaming and Error Propagation:

    • Enhanced the chat streaming hook (useChatStreaming) to detect error states from the backend, propagate them via the error flag, and ensure error messages are immediately added to chat history and persist on refresh. [1] [2] [3] [4] [5] [6]

Backend and API Improvements:

  • Error Detection and Storage:

    • Updated the backend streaming endpoints to detect error conditions in Langflow responses, set an error flag in messages, and store these error messages in the conversation history for persistence. [1] [2] [3] [4] [5]
    • Improved conversion of Langflow messages to consistently detect and mark error messages, including heuristic detection based on content patterns.
  • Error Message Extraction and Reporting:

    • Enhanced the file ingestion service to extract and raise more informative error messages from Langflow responses, providing users with clearer feedback on failure. [1] [2] [3] [4]

These changes collectively provide a more robust and user-friendly experience when errors occur, ensuring that error states are clearly communicated, persist in chat history, and are handled consistently throughout the application.

Closes #810

Needs langflow-ai/langflow#11467

@lucaseduoli lucaseduoli self-assigned this Jan 27, 2026
@lucaseduoli lucaseduoli linked an issue Feb 18, 2026 that may be closed by this pull request
2 tasks
@edwinjosechittilappilly

Copy link
Copy Markdown
Collaborator

@lucaseduoli can you fix the conflicts ? or is there an alternative PR?

@github-actions github-actions Bot added bug 🔴 Something isn't working. frontend 🟨 Issues related to the UI/UX backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) labels Mar 10, 2026

@edwinjosechittilappilly edwinjosechittilappilly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves how errors are detected, propagated, persisted, and rendered across the chat/ingestion backend and the chat UI, so users can see meaningful failures in chat history (including after refresh).

Changes:

  • Add an error flag to chat messages and propagate it through backend history + frontend state.
  • Enhance Langflow ingestion error extraction to surface more informative failure reasons.
  • Introduce a dedicated ErrorMessage UI component and render it for error-marked assistant messages.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/services/langflow_history_service.py Adds error detection heuristics during Langflow → OpenRAG message conversion and stamps messages with source.
src/services/langflow_file_service.py Improves ingestion failure reporting by extracting Langflow error details; adjusts JWT token parameter.
src/services/chat_service.py Passes error through when building message payloads for Langflow history responses.
src/agent.py Detects error conditions during Langflow streaming and attempts to persist error states/messages.
frontend/hooks/useChatStreaming.ts Detects stream error status, marks final messages as errors, and propagates error messages to completion callbacks.
frontend/app/chat/page.tsx Plumbs error into local message state and conditionally renders ErrorMessage for error-marked assistant messages.
frontend/app/chat/_types/types.ts Extends the Message type with an optional error flag.
frontend/app/chat/_components/error-message.tsx Adds the new styled error message component.
Comments suppressed due to low confidence (3)

src/services/langflow_file_service.py:70

  • jwt_token is now optional, but the request headers are built with "X-Langflow-Global-Var-JWT": str(jwt_token). When jwt_token is None this will send the literal string "None" to Langflow, which can break auth or leak confusing values into the flow. Prefer omitting the header or using an empty string when the token is not set.
    async def run_ingestion_flow(
        self,
        file_paths: List[str],
        file_tuples: list[tuple[str, str, str]],
        jwt_token: Optional[str] = None,
        session_id: Optional[str] = None,
        tweaks: Optional[Dict[str, Any]] = None,
        owner: Optional[str] = None,
        owner_name: Optional[str] = None,

src/agent.py:752

  • assistant_message is only created when full_response is truthy, but it is referenced unconditionally afterwards (usage assignment + append). If the stream yields only tool/function chunks or no text, this will raise UnboundLocalError and prevent history persistence. Ensure assistant_message is initialized (or the append is conditional) and keep the usage_data logic inside the same block.
        # Add the complete assistant response to message history with response_id, timestamp, and function call data
        if full_response:
            assistant_message = {
                "role": "assistant",
                "content": full_response,
                "response_id": response_id,
                "timestamp": datetime.now(),
                "chunks": collected_chunks,  # Store complete chunk data for function calls
                "error": error_occurred,  # Mark if this was an error response
            }
            # Store usage data if available (from response.completed event)
        if usage_data:
            assistant_message["response_data"] = {"usage": usage_data}
        conversation_state["messages"].append(assistant_message)

frontend/app/chat/_components/error-message.tsx:52

  • Stray footer comment // Made with Bob doesn't add useful context and is likely to fail repo cleanliness standards. Please remove it (or replace with a meaningful rationale comment if needed).
}

// Made with Bob


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread frontend/app/chat/page.tsx Outdated
Comment thread src/services/langflow_file_service.py Outdated
Comment thread frontend/hooks/useChatStreaming.ts
Comment thread src/agent.py
Comment thread frontend/hooks/useChatStreaming.ts Outdated
Comment thread frontend/hooks/useChatStreaming.ts
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Mar 10, 2026
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Mar 10, 2026
@lucaseduoli lucaseduoli merged commit 3f02bb7 into main Mar 10, 2026
10 checks passed
@github-actions github-actions Bot deleted the fix/error_handling branch March 10, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. frontend 🟨 Issues related to the UI/UX lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: document ingestion fails with 500, error message not helpful [Feature]: UI Changes to display the Error Messaged from Responses API output

3 participants