langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Error when attaching images to chat input with session_id parameter

Open robugpl opened this issue 1 year ago • 6 comments

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:

Image

This prevents maintaining chat histories for different users when file uploads are involved.

Reproduction

  1. Send a run request with session_id and files to a flow containing a chat input tweak.
  2. 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.

Image

Flow File

DBR77 Assistant Astra DB (1).json

robugpl avatar May 17 '25 20:05 robugpl

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:

  1. Error Handling for IndexError: The Langflow client has specific error handling mechanisms for IndexError exceptions. In some parts of the code, an IndexError is caught and a ValueError is 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 in custom_component.py and memory.py [1].

  2. Session Management: Ensure that the session data is being managed correctly. The session_id is crucial for maintaining separate conversational contexts. Verify that the session data is being loaded and utilized properly, especially when handling file uploads. The load_session method should be correctly retrieving and caching session data [2].

  3. File Upload Constraints: Check if there are any constraints or limitations in the run and stream methods 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].

  4. 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.

  5. 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

dosubot[bot] avatar May 17 '25 20:05 dosubot[bot]

created pull request #8142 . Please check it out, becaouse an error breaks a key functionality and the fix is super simple.

robugpl avatar May 21 '25 20:05 robugpl

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.

lice-reis avatar Sep 30 '25 21:09 lice-reis

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.

Image

wishescsnow avatar Oct 25 '25 18:10 wishescsnow

@lice-reis I will check in the latest version of langflow soon. I will let you know how was it.

robugpl avatar Dec 15 '25 20:12 robugpl

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

lice-reis avatar Feb 24 '26 17:02 lice-reis