langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Fix: Generate new message ID when reusing existing Message instance …

Open keval718 opened this issue 1 year ago • 4 comments

This PR fixes an issue where User and AI messages were generated with the same message ID, causing one message to overwrite the other in the chat UI and in network payloads. The issue occurred because the ChatOutput component reused an existing Message instance without generating a new ID.

Root Cause When input_value is already a Message object, the component mutates it by updating the text but previously did not regenerate the message.id. As a result, both the User message and the AI message could share the same ID if the object was reused along the component chain.

This ID collision caused:

  • Messages appearing merged or overwritten
  • User and AI messages not rendering separately
  • Identical message IDs in network calls

What This Fix Does When reusing an existing Message instance, we now generate a fresh UUID: if isinstance(self.input_value, Message): message = self.input_value message.text = text message.id = uuid.uuid4() # Generate new unique ID

Why This Fix Matters With unique IDs:

  • User messages and AI messages are properly distinguished
  • No more overwriting in chat history
  • UI consistently renders separate bubbles
  • Network payloads reflect unique message entries
  • Downstream memory/session handling works as expected

Testing & Verification

  • Confirmed that reused messages now receive unique IDs
  • Verified in Playground UI that User and AI messages display independently
  • Checked network payloads to ensure IDs are no longer duplicated

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed message identity tracking across all starter projects and components to ensure processed messages receive unique identifiers for proper reference and tracking.

keval718 avatar Nov 13 '25 18:11 keval718

[!IMPORTANT]

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This PR updates the ChatOutput component across all starter projects and the corresponding Python module to assign a unique UUID to message.id when processing an existing Message input. The changes include adding import uuid and setting message.id = uuid.uuid4() in the message_response path, with corresponding code_hash updates.

Changes

Cohort / File(s) Summary
Starter Projects (ChatOutput UUID Assignment)
src/backend/base/langflow/initial_setup/starter_projects/Basic Prompt Chaining.json, Basic Prompting.json, Blog Writer.json, Custom Component Generator.json, Document Q&A.json, Financial Report Parser.json, Hybrid Search RAG.json, Image Sentiment Analysis.json, Instagram Copywriter.json, Invoice Summarizer.json, Knowledge Retrieval.json, Market Research.json, Meeting Summary.json, Memory Chatbot.json, News Aggregator.json, Nvidia Remix.json, Pokédex Agent.json, Portfolio Website Code Generator.json, Price Deal Finder.json, Research Agent.json, Research Translation Loop.json, SEO Keyword Generator.json, SaaS Pricing.json, Search agent.json, Sequential Tasks Agents.json, Simple Agent.json, Social Media Agent.json, Text Sentiment Analysis.json, Travel Planning Agents.json, Twitter Thread Generator.json, Vector Store RAG.json, Youtube Analysis.json
Added import uuid and assigned a new unique ID (message.id = uuid.uuid4()) to Message objects in ChatOutput.message_response when input_value is already a Message. Updated code_hash metadata from 4848ad3e35d5 to 76077de62755 to reflect these changes.
Python Implementation
src/lfx/src/lfx/components/input_output/chat_output.py
Added import uuid and implemented UUID assignment logic for existing Message inputs in ChatOutput component to match starter project updates.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Rationale: Although 32+ JSON starter project files are affected, the changes are highly homogeneous—identical UUID assignment logic repeated across all files with consistent code_hash updates. Review focuses on verifying consistency of the pattern rather than analyzing varied logic.
  • Areas requiring attention:
    • Verify code_hash values are consistently updated from 4848ad3e35d5 to 76077de62755 across all starter project files
    • Confirm uuid.uuid4() assignment is placed correctly within the message_response path for existing Message inputs
    • Ensure the Python implementation aligns with the starter project patterns

Possibly related PRs

  • langflow-ai/langflow#8529: Updates ChatOutput component implementation inside starter-project JSONs with code/metadata changes.
  • langflow-ai/langflow#8909: Filters/excludes messages by their id, which depends on the message.id field now being consistently assigned via UUID.

Suggested labels

bug, size:XS, lgtm

Suggested reviewers

  • ogabrielluiz
  • jordanrfrazier
  • edwinjosechittilappilly

Pre-merge checks and finishing touches

❌ Failed checks (1 error, 3 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR contains no new or modified test files despite implementing bug fixes for message ID generation in ChatOutput component. Add comprehensive unit and integration tests for ChatOutput message ID generation, including verification of UUID string casting and proper handling of reused Message instances.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test Quality And Coverage ⚠️ Warning PR lacks unit tests for critical UUID fix in ChatOutput component despite modifying 33 files and fixing message ID collision issues identified in review. Add pytest unit tests verifying UUID generation, string type casting, input immutability, and uniqueness across invocations; add integration tests validating fix prevents message overwrites.
Test File Naming And Structure ⚠️ Warning PR modifies ChatOutput implementation and starter project JSON files but adds no test files following pytest conventions or other testing patterns. Add test_chat_output.py with pytest tests covering UUID generation, message ID reuse scenarios, string casting, and instance mutation prevention.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Excessive Mock Usage Warning ✅ Passed PR contains no test files or mock-related code changes. Modifications are configuration JSON templates and production code for UUID generation.
Title check ✅ Passed The title accurately describes the main fix: preventing ChatOutput from overwriting message IDs when connected to ChatInput by generating new UUIDs for reused Message instances.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 13 '25 18:11 coderabbitai[bot]

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 15%
15.3% (4188/27372) 8.5% (1778/20915) 9.6% (579/6029)

Unit Test Results

Tests Skipped Failures Errors Time
1638 0 :zzz: 0 :x: 0 :fire: 20.872s :stopwatch:

github-actions[bot] avatar Nov 13 '25 20:11 github-actions[bot]

Codecov Report

:x: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 32.40%. Comparing base (a2aec42) to head (d03a34e). :warning: Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...c/lfx/src/lfx/custom/custom_component/component.py 57.14% 2 Missing and 1 partial :warning:

:x: Your project status has failed because the head coverage (40.22%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10586      +/-   ##
==========================================
+ Coverage   32.38%   32.40%   +0.01%     
==========================================
  Files        1366     1366              
  Lines       62943    62953      +10     
  Branches     9304     9305       +1     
==========================================
+ Hits        20387    20397      +10     
+ Misses      41532    41528       -4     
- Partials     1024     1028       +4     
Flag Coverage Δ
backend 51.05% <ø> (-0.03%) :arrow_down:
frontend 14.14% <ø> (ø)
lfx 40.22% <70.00%> (+0.04%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/lfx/src/lfx/graph/utils.py 35.71% <100.00%> (+1.76%) :arrow_up:
...c/lfx/src/lfx/custom/custom_component/component.py 58.57% <57.14%> (-0.02%) :arrow_down:

... and 5 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 13 '25 20:11 codecov[bot]

Hey @keval718

Could you give me some examples of this happening? This is actually a feature not a bug because the Agent creates a generic message and the ChatOutput component can update the message's params (sender name, etc.)

If an Agent sends a message, then the ChatOutput creates a new message, it would duplicate the message in the playground.

ogabrielluiz avatar Nov 14 '25 19:11 ogabrielluiz

Hey @keval718

Could you give me some examples of this happening? This is actually a feature not a bug because the Agent creates a generic message and the ChatOutput component can update the message's params (sender name, etc.)

If an Agent sends a message, then the ChatOutput creates a new message, it would duplicate the message in the playground.

Hey @ogabrielluiz Please review it again. Thanks

keval718 avatar Nov 17 '25 17:11 keval718

@keval718 Failing backend test and component_index conflict.

See jordan's comment on how to fix component_index: https://ibm-cloud.slack.com/archives/C094HC6JVUH/p1763996469073709?thread_ts=1763691056.550319&cid=C094HC6JVUH

Adam-Aghili avatar Nov 24 '25 21:11 Adam-Aghili