fix: use correct error handling for chat messages and ingestion#859
Merged
Conversation
2 tasks
Collaborator
|
@lucaseduoli can you fix the conflicts ? or is there an alternative PR? |
edwinjosechittilappilly
approved these changes
Mar 10, 2026
edwinjosechittilappilly
left a comment
Collaborator
There was a problem hiding this comment.
Code LGTM
Contributor
There was a problem hiding this comment.
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
errorflag 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
ErrorMessageUI 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_tokenis now optional, but the request headers are built with"X-Langflow-Global-Var-JWT": str(jwt_token). Whenjwt_tokenisNonethis 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_messageis only created whenfull_responseis truthy, but it is referenced unconditionally afterwards (usage assignment + append). If the stream yields only tool/function chunks or no text, this will raiseUnboundLocalErrorand prevent history persistence. Ensureassistant_messageis initialized (or the append is conditional) and keep theusage_datalogic 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 Bobdoesn'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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
ErrorMessageReact component for displaying styled error messages in chat, including support for animation and custom icons.ChatPageto renderErrorMessageinstead of the standard assistant message when a message has anerrorflag. [1] [2]errorproperty 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:
useChatStreaming) to detect error states from the backend, propagate them via theerrorflag, 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:
errorflag in messages, and store these error messages in the conversation history for persistence. [1] [2] [3] [4] [5]Error Message Extraction and Reporting:
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