fix: prevent crash when reloading conversations with Base64-encoded files#2799
Open
hztBUAA wants to merge 1 commit intoChainlit:mainfrom
Open
fix: prevent crash when reloading conversations with Base64-encoded files#2799hztBUAA wants to merge 1 commit intoChainlit:mainfrom
hztBUAA wants to merge 1 commit intoChainlit:mainfrom
Conversation
…iles (Chainlit#2784) Multiple issues caused conversations with file attachments to crash on reload: 1. Element.from_dict() called str() on bytes content, producing repr like "b'\x89PNG...'" instead of preserving the raw bytes. 2. ChainlitDataLayer.get_element() converted None url/objectKey/mime to the string "None" via str(None). 3. The frontend resume_thread handler did not resolve element URLs from chainlitKey, unlike the element and set_sidebar_elements handlers. 4. Storage client failures during get_thread crashed the entire resume flow. Added try/except in ChainlitDataLayer and DynamoDB data layers. 5. The socket connection_successful handler had no error handling around thread resume. Added try/except with error messages to the frontend. 6. The HTTP get_thread endpoint had no error handling. Added try/except.
Contributor
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/chainlit/socket.py">
<violation number="1" location="backend/chainlit/socket.py:204">
P2: Exception handling for resume_thread emits an error but then falls through to the existing "Thread not found" branch, resulting in two error emissions for the same failure.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| await context.emitter.send_resume_thread_error( | ||
| "Failed to load conversation history." | ||
| ) | ||
| thread = None |
Contributor
There was a problem hiding this comment.
P2: Exception handling for resume_thread emits an error but then falls through to the existing "Thread not found" branch, resulting in two error emissions for the same failure.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/chainlit/socket.py, line 204:
<comment>Exception handling for resume_thread emits an error but then falls through to the existing "Thread not found" branch, resulting in two error emissions for the same failure.</comment>
<file context>
@@ -194,7 +194,15 @@ async def connection_successful(sid):
+ await context.emitter.send_resume_thread_error(
+ "Failed to load conversation history."
+ )
+ thread = None
+
if thread:
</file context>
Collaborator
|
Would love to merge this, please run |
dokterbob
reviewed
Feb 23, 2026
|
|
||
| @pytest.mark.asyncio | ||
| async def test_get_element_not_found(self): | ||
| from unittest.mock import AsyncMock |
Collaborator
There was a problem hiding this comment.
This import might well be at the top! Same for other places.
dokterbob
reviewed
Feb 23, 2026
| layer = self._make_layer() | ||
| layer.execute_query = AsyncMock(return_value=[]) | ||
| result = await layer.get_element("thread-1", "nonexistent") | ||
| assert result is None |
Collaborator
There was a problem hiding this comment.
I notice changes in two data layers but unit tests only for one, what's the reason?
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.
Summary
Fixes #2784 — Conversations with Base64-encoded file attachments crash on reload.
Root causes identified and fixed:
Element.from_dict()calledstr()on bytes content, producing"b'\x89PNG...'"instead of preserving raw bytesChainlitDataLayer.get_element()convertedNoneurl/objectKey/mime to the string"None"viastr(None)resume_threadhandler did not resolve element URLs fromchainlitKey, unlike theelementandset_sidebar_elementshandlersget_threadcrashed the entire resume flow — added try/except in both ChainlitDataLayer and DynamoDB data layersconnection_successfulhandler had no error handling around thread resume — added try/except with error message to the frontendget_threadendpoint had no error handling — added try/except with 500 responseChanges
backend/chainlit/element.pyfrom_dict()instead ofstr()conversionbackend/chainlit/data/chainlit_data_layer.pyget_element()None-to-string bug; add storage error handling inget_thread()backend/chainlit/data/dynamodb.pyget_thread()backend/chainlit/socket.pybackend/chainlit/server.pyget_threadendpointlibs/react-client/src/useChatSession.tschainlitKeyinresume_threadhandlerbackend/tests/data/test_chainlit_data_layer.pyTest plan
_convert_element_row_to_dictpreserves None url/objectKey valuesget_elementreturns None (not string "None") for missing url/objectKey/mime🤖 Generated with Claude Code
Summary by cubic
Prevents crashes when reloading conversations with Base64-encoded file attachments. Fixes bytes/None handling, resolves missing element URLs on resume, and adds error handling across the resume/get_thread path.
Written for commit c2c5722. Summary will update on new commits.