fix: prevent crash when reloading conversations with Base64-encoded files#2799
fix: prevent crash when reloading conversations with Base64-encoded files#2799hztBUAA wants to merge 3 commits 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.
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.
|
Would love to merge this, please run |
|
|
||
| @pytest.mark.asyncio | ||
| async def test_get_element_not_found(self): | ||
| from unittest.mock import AsyncMock |
There was a problem hiding this comment.
This import might well be at the top! Same for other places.
| layer = self._make_layer() | ||
| layer.execute_query = AsyncMock(return_value=[]) | ||
| result = await layer.get_element("thread-1", "nonexistent") | ||
| assert result is None |
There was a problem hiding this comment.
I notice changes in two data layers but unit tests only for one, what's the reason?
|
Addressed the review comments in commit Updates:
I could not run tests in this environment because |
|
Follow-up after running full local verification in a project-specific environment. Updated branch head: Validation run (from
Results:
This PR is now validated end-to-end locally with no pending formatter/lint/test issues on the touched scope. |
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. Preserves bytes, fixes None handling, resolves element URLs on resume, and adds clear error reporting across the resume flow.
Written for commit ec951a0. Summary will update on new commits.