Error when attaching images to chat input with session_id parameter
Description
I'm using @datastax/langflow-client with Node.js and Express API, running a self-hosted version of Langflow on Docker (latest version).
I've encountered an issue where attaching an image to a chat input tweak causes the entire flow to crash only when a session_id is provided. The problem occurs with both run() and stream() methods:
- With run(): Returns an error response
- With stream(): Connection terminates abruptly
Code example
app.post('/api/run/stream', async (req: Request, res: Response) => {
try {
const {flowId, message, session_id, files, chat_input_id} = req.body;
if (!flowId) {
return res.status(400).json({error: 'FlowId is required'});
}
if(!message && !files) {
return res.status(400).json({error: 'Message or files are required'});
}
if(!chat_input_id) {
return res.status(400).json({error: 'Chat input id is required'});
}
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Connection', 'keep-alive');
res.setHeader("Transfer-Encoding", "chunked");
res.setHeader("Cache-Control", "no-store");
// Execute flow asynchronously
try {
let flow = langflowClient.flow(flowId);
if(files) {
flow = flow.tweak(chat_input_id, {
files: files.map((file: { filePath: any; }) => file.filePath),
})
}
const response = await flow.stream(message, {session_id})
// @ts-ignore
for await (const chunk of response) {
try {
const response = 'event: ' + chunk.event +
'\ndata: ' + JSON.stringify(chunk.data) + '\n\n';
res.write(response);
} catch (e) {
console.error(e)
console.warn('Invalid response chunk. Skipping...');
}
}
res.end()
} catch (error) {
console.error('Error executing flow:', error);
res.end();
}
} catch (error) {
console.error('Error processing flow execution request:', error);
res.status(500).json({error: 'Failed to process flow execution request'});
res.end();
}
})
Next I was looking for errors in the Langflow IDE, and I found it in the playground, in my custom session_id conversation:
This prevents maintaining chat histories for different users when file uploads are involved.
Reproduction
- Send a run request with session_id and files to a flow containing a chat input tweak.
- Observe either:
- Error response (run())
- Connection closure (stream())
Expected behavior
The flow should process image attachments while maintaining session history when session_id is provided.
Who can help?
@italojohnny
Operating System
Ubuntu Linux 22.04 LTS
Langflow Version
1.4.1
Python Version
None
Screenshot
This request is handled by code I attached in description of the issue.
Flow File
Hello @robugpl! I'm Dosu, a bot here to help you resolve bugs, answer your questions, and guide you in becoming a contributor. While you're waiting for a human maintainer, feel free to let me know how I can assist you!
The issue you're encountering seems to be related to an IndexError occurring when attaching images to a chat input with a session_id in Langflow. This error is likely originating from the custom_component.py and memory.py files within the Langflow package, as indicated by the traceback in your error message.
Here are a few steps and considerations that might help you address this issue:
-
Error Handling for IndexError: The Langflow client has specific error handling mechanisms for
IndexErrorexceptions. In some parts of the code, anIndexErroris caught and aValueErroris raised with a descriptive message. It might be beneficial to check if similar error handling is implemented in the parts of the code where the error occurs, particularly incustom_component.pyandmemory.py[1]. -
Session Management: Ensure that the session data is being managed correctly. The
session_idis crucial for maintaining separate conversational contexts. Verify that the session data is being loaded and utilized properly, especially when handling file uploads. Theload_sessionmethod should be correctly retrieving and caching session data [2]. -
File Upload Constraints: Check if there are any constraints or limitations in the
runandstreammethods when handling file uploads. Ensure that the file size and type are within the allowed limits and that the file paths are correctly specified in the request payload [3]. -
Debugging and Logging: Add additional logging around the areas where the error occurs to capture more context about the state of the application when the error happens. This can help identify the specific conditions leading to the
IndexError. -
Review Flow Configuration: Double-check the configuration of your flow, especially the chat input tweak and how files are being attached. Ensure that all necessary parameters are correctly set and that the flow logic aligns with the expected behavior.
By addressing these areas, you may be able to pinpoint the cause of the error and implement a solution. If the issue persists, reviewing the specific logic in custom_component.py and memory.py related to session handling and file processing might be necessary.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
created pull request #8142 . Please check it out, becaouse an error breaks a key functionality and the fix is super simple.
Hi @robugpl Could you please test this again using Langflow version 1.6 and let me know if the issue persists? This feature may have been fixed or implemented in the latest release, so it would be great if you could validate it on your side.
Hi @lice-reis
I tested in version 1.6.5, the problem is still happening. My session_id is different from my flow_id as image shown. I confirmed that the file was uploaded successfully, and can be download using the langflow API.
@lice-reis I will check in the latest version of langflow soon. I will let you know how was it.
Hi, I tried to reproduce this issue on the current main branch (v1.8.0) and was unable to do so.
I tested the following scenarios via the /api/v1/run endpoint:
- With session_id + image file attached via tweaks → 200 OK, agent correctly interpreted the image
- Without session_id + image file attached → 200 OK