Skip to content

Conversation

@HimavarshaVS
Copy link
Collaborator

@HimavarshaVS HimavarshaVS commented Dec 17, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved message handling reliability by adding defensive guards that prevent errors when messages lack identifiers.
    • Enhanced message deletion and processing to validate identifier presence before execution.
  • Refactor

    • Streamlined message identifier access patterns for consistency across the messaging pipeline.
    • Strengthened internal message validation and error handling for improved robustness.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

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

A refactoring to standardize message ID access patterns across the codebase. New public methods (get_id(), has_id(), require_id()) are added to the Message class to safely retrieve and validate message IDs. Multiple agent and component classes are updated to use these methods instead of direct attribute access, with added guard conditions to skip operations on messages without IDs.

Changes

Cohort / File(s) Change Summary
Message Schema Enhancement
src/lfx/src/lfx/schema/message.py
Added three public methods: get_id() returns ID or None, has_id() returns boolean, require_id() returns ID or raises ValueError. Includes docstrings on ID semantics and safe access patterns.
Agent ID Access Refactoring
src/lfx/src/lfx/base/agents/agent.py, src/lfx/src/lfx/base/agents/altk_base_agent.py, src/lfx/src/lfx/base/agents/events.py, src/lfx/src/lfx/components/datastax/astradb_assistant_manager.py
Updated exception handling in agent run methods to retrieve message ID via get_id() instead of direct attribute access. Added guard checks to only delete messages if ID is truthy; preserved subsequent event emission and logging.
Component Message Handling Expansion
src/lfx/src/lfx/custom/custom_component/component.py
Refactored message skipping logic with guards for Chat Output connectivity. Enforced ID validation for skip_db_update=True. Replaced direct ID access with get_id()/has_id() methods throughout. Updated streaming logic to require message IDs and use ID accessors. Added deletion guards for ID existence checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • src/lfx/src/lfx/custom/custom_component/component.py: Largest and most complex refactoring with multiple logic paths (message skipping, streaming, deletion guards, storage paths). Requires careful verification of ID validation enforcement and control flow changes.
  • Pattern consistency across agent files: Verify that all agent classes consistently apply the new guard pattern for message deletion.
  • Message class methods: Confirm that the new get_id(), has_id(), and require_id() methods are correctly implemented and handle all ID types (string/UUID/None).

Pre-merge checks and finishing touches

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 3 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error Pull request introduces three new public methods to Message class but includes no corresponding test coverage or regression tests for the bug fix. Add comprehensive unit tests to test_schema_message.py covering get_id(), has_id(), require_id() behavior and regression tests for modified files.
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test Quality And Coverage ⚠️ Warning Pull request introduces three critical public methods (get_id, has_id, require_id) for ID handling but test file lacks any coverage for these new methods. Add six test cases covering get_id, has_id, and require_id methods with both success and error scenarios to test_schema_message.py.
Test File Naming And Structure ⚠️ Warning Pull request introduces new public methods and refactors exception handling without corresponding test coverage for these critical changes. Add comprehensive test coverage for new methods (get_id(), has_id(), require_id()) and ID guard logic in all affected files.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Message ID and Output inconsistencies' directly aligns with the main changes, which involve refactoring ID access patterns across multiple files and adding safe ID accessor methods to the Message class.
Excessive Mock Usage Warning ✅ Passed Tests appropriately mock external dependencies without over-mocking core logic, include meaningful assertions verifying actual behavior, and integrate ID accessor methods correctly into production code.

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.

@github-actions github-actions bot added the bug Something isn't working label Dec 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 841a133 and 391eec5.

📒 Files selected for processing (6)
  • src/lfx/src/lfx/base/agents/agent.py (1 hunks)
  • src/lfx/src/lfx/base/agents/altk_base_agent.py (1 hunks)
  • src/lfx/src/lfx/base/agents/events.py (1 hunks)
  • src/lfx/src/lfx/components/datastax/astradb_assistant_manager.py (1 hunks)
  • src/lfx/src/lfx/custom/custom_component/component.py (6 hunks)
  • src/lfx/src/lfx/schema/message.py (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-24T19:47:28.997Z
Learnt from: CR
Repo: langflow-ai/langflow PR: 0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-11-24T19:47:28.997Z
Learning: Applies to src/backend/tests/**/*.py : Test Langflow's `Message` objects using `langflow.schema.message.Message` and validate text, sender, sender_name, session_id, files, and properties attributes

Applied to files:

  • src/lfx/src/lfx/schema/message.py
🧬 Code graph analysis (6)
src/lfx/src/lfx/base/agents/altk_base_agent.py (2)
src/lfx/src/lfx/custom/custom_component/component.py (1)
  • get_id (206-207)
src/lfx/src/lfx/schema/message.py (1)
  • get_id (335-345)
src/lfx/src/lfx/base/agents/agent.py (2)
src/lfx/src/lfx/custom/custom_component/component.py (1)
  • get_id (206-207)
src/lfx/src/lfx/schema/message.py (1)
  • get_id (335-345)
src/lfx/src/lfx/custom/custom_component/component.py (1)
src/lfx/src/lfx/schema/message.py (3)
  • has_id (347-358)
  • Message (34-377)
  • get_id (335-345)
src/lfx/src/lfx/schema/message.py (1)
src/lfx/src/lfx/custom/custom_component/component.py (1)
  • get_id (206-207)
src/lfx/src/lfx/base/agents/events.py (2)
src/lfx/src/lfx/custom/custom_component/component.py (1)
  • get_id (206-207)
src/lfx/src/lfx/schema/message.py (1)
  • get_id (335-345)
src/lfx/src/lfx/components/datastax/astradb_assistant_manager.py (2)
src/lfx/src/lfx/custom/custom_component/component.py (1)
  • get_id (206-207)
src/lfx/src/lfx/schema/message.py (1)
  • get_id (335-345)
🪛 GitHub Actions: Ruff Style Check
src/lfx/src/lfx/custom/custom_component/component.py

[error] 1569-1569: W293 Blank line contains whitespace. Ruff check failed during 'uv run --only-dev ruff check --output-format=github .'.

🪛 GitHub Check: Ruff Style Check (3.13)
src/lfx/src/lfx/custom/custom_component/component.py

[failure] 1582-1582: Ruff (W293)
src/lfx/src/lfx/custom/custom_component/component.py:1582:1: W293 Blank line contains whitespace


[failure] 1579-1579: Ruff (W293)
src/lfx/src/lfx/custom/custom_component/component.py:1579:1: W293 Blank line contains whitespace


[failure] 1574-1574: Ruff (W293)
src/lfx/src/lfx/custom/custom_component/component.py:1574:1: W293 Blank line contains whitespace


[failure] 1569-1569: Ruff (W293)
src/lfx/src/lfx/custom/custom_component/component.py:1569:1: W293 Blank line contains whitespace

src/lfx/src/lfx/schema/message.py

[failure] 47-47: Ruff (W293)
src/lfx/src/lfx/schema/message.py:47:1: W293 Blank line contains whitespace


[failure] 42-42: Ruff (W293)
src/lfx/src/lfx/schema/message.py:42:1: W293 Blank line contains whitespace


[failure] 36-36: Ruff (W293)
src/lfx/src/lfx/schema/message.py:36:1: W293 Blank line contains whitespace


[failure] 346-346: Ruff (W293)
src/lfx/src/lfx/schema/message.py:346:1: W293 Blank line contains whitespace


[failure] 340-340: Ruff (W293)
src/lfx/src/lfx/schema/message.py:340:1: W293 Blank line contains whitespace


[failure] 337-337: Ruff (W293)
src/lfx/src/lfx/schema/message.py:337:1: W293 Blank line contains whitespace

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Ruff Check and Format
  • GitHub Check: Update Component Index
  • GitHub Check: Update Starter Projects
🔇 Additional comments (9)
src/lfx/src/lfx/schema/message.py (1)

335-378: Well-designed ID accessor methods with minor whitespace issues.

The implementation provides a clean, safe API for ID access:

  • get_id() for optional access
  • has_id() for existence checks
  • require_id() for mandatory access with clear error messages

Fix the trailing whitespace on blank lines (337, 340, 346) to resolve pipeline failures.

     def get_id(self) -> str | UUID | None:
         """Safely get the message ID.
-        
+
         Returns:
             The message ID if it exists, None otherwise.
-            
+
         Note:
             A message only has an ID if it has been stored in the database.
             Messages that are skipped (via _should_skip_message) will not have an ID.
         """
         return getattr(self, "id", None)
-    
+
     def has_id(self) -> bool:
src/lfx/src/lfx/base/agents/events.py (1)

391-391: LGTM!

The change to use agent_message.get_id() aligns with the standardized ID access pattern introduced in the Message class. This safely returns None if the message hasn't been stored yet (e.g., when the Agent is not connected to a Chat Output).

src/lfx/src/lfx/components/datastax/astradb_assistant_manager.py (1)

302-306: LGTM!

The exception handling now safely:

  1. Retrieves the message ID via get_id() instead of direct attribute access
  2. Guards the delete_message call to only execute when an ID exists

This prevents errors when handling exceptions for messages that were never stored in the database.

src/lfx/src/lfx/base/agents/agent.py (1)

275-282: LGTM with a minor observation.

The exception handling now safely guards the delete_message call. However, the hasattr(e, "agent_message") check on line 276 may be redundant since ExceptionWithMessageError (defined in events.py) always initializes agent_message in its constructor.

That said, the defensive check doesn't hurt and provides safety if exception handling were to change in the future.

src/lfx/src/lfx/base/agents/altk_base_agent.py (1)

381-388: LGTM!

The exception handling mirrors the pattern in agent.py, ensuring consistent ID-safe deletion behavior across all agent implementations.

src/lfx/src/lfx/custom/custom_component/component.py (4)

1568-1591: Helpful documentation with whitespace issues.

The expanded docstring clearly explains when messages are skipped and the implications for ID availability. Fix the trailing whitespace on blank lines (1569, 1574, 1579, 1582) to resolve pipeline failures.

     def _should_skip_message(self, message: Message) -> bool:
         """Check if the message should be skipped based on vertex configuration and message type.
-        
+
         When a message is skipped:
         - It is NOT stored in the database
         - It will NOT have an ID (message.get_id() will return None)
         - It is still returned to the caller, but no events are sent to the frontend
-        
+
         Messages are skipped when:
         - The component is not an input or output vertex
         - The component is not connected to a Chat Output
         - The message is not an ErrorMessage
-        
+
         This prevents intermediate components from cluttering the database with messages
         that aren't meant to be displayed in the chat UI.
-        
+
         Returns:
             bool: True if the message should be skipped, False otherwise
         """

1660-1681: LGTM!

The send_message changes are well-designed:

  1. Validation for skip_db_update=True (lines 1662-1668): Correctly enforces that messages must already have an ID when skipping DB updates, since this path is for updating existing messages.

  2. Safe ID access (lines 1671, 1681): Uses get_id() for assigning _stored_message_id, consistent with the new safe access patterns.

The error message clearly explains the requirement, helping developers understand why their code might fail.


1747-1753: LGTM!

Using stored_message.has_id() is the correct pattern for the boolean check in the streaming eligibility condition.


1773-1798: LGTM!

The ID validation in _stream_message is appropriate:

  • Streaming requires a message ID to associate token events with the correct message
  • The validation fails early with a clear error message
  • The message_id variable is consistently passed to helper methods

Comment on lines 35 to 53
"""Message schema for Langflow.
Message ID Semantics:
- Messages only have an ID after being stored in the database
- Messages that are skipped (via Component._should_skip_message) will NOT have an ID
- Always use get_id(), has_id(), or require_id() methods to safely access the ID
- Never access message.id directly without checking if it exists first
Safe ID Access Patterns:
- Use get_id() when ID may or may not exist (returns None if missing)
- Use has_id() to check if ID exists before operations that require it
- Use require_id() when ID is required (raises ValueError if missing)
Example:
message_id = message.get_id() # Safe: returns None if no ID
if message.has_id():
# Safe to use message_id
do_something_with_id(message_id)
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix trailing whitespace in docstring.

The docstring is comprehensive and clearly documents the ID semantics. However, the static analysis tool flagged trailing whitespace on blank lines (lines 36, 42, 47) which is causing the pipeline to fail.

Apply this diff to fix the whitespace issues:

     """Message schema for Langflow.
-    
+
     Message ID Semantics:
     - Messages only have an ID after being stored in the database
     - Messages that are skipped (via Component._should_skip_message) will NOT have an ID
     - Always use get_id(), has_id(), or require_id() methods to safely access the ID
     - Never access message.id directly without checking if it exists first
-    
+
     Safe ID Access Patterns:
     - Use get_id() when ID may or may not exist (returns None if missing)
     - Use has_id() to check if ID exists before operations that require it
     - Use require_id() when ID is required (raises ValueError if missing)
-    
+
     Example:
         message_id = message.get_id()  # Safe: returns None if no ID
         if message.has_id():
             # Safe to use message_id
             do_something_with_id(message_id)
     """
🧰 Tools
🪛 GitHub Check: Ruff Style Check (3.13)

[failure] 47-47: Ruff (W293)
src/lfx/src/lfx/schema/message.py:47:1: W293 Blank line contains whitespace


[failure] 42-42: Ruff (W293)
src/lfx/src/lfx/schema/message.py:42:1: W293 Blank line contains whitespace


[failure] 36-36: Ruff (W293)
src/lfx/src/lfx/schema/message.py:36:1: W293 Blank line contains whitespace

🤖 Prompt for AI Agents
In src/lfx/src/lfx/schema/message.py around lines 35 to 53, there are trailing
spaces on blank lines in the module docstring (notably lines 36, 42, 47) causing
static analysis failures; remove the trailing whitespace on those blank lines so
they are truly empty (no spaces or tabs), leaving the rest of the docstring
content unchanged.

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Dec 18, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Dec 18, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Dec 18, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 18, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 17%
16.67% (4695/28164) 9.99% (2179/21794) 10.94% (677/6183)

Unit Test Results

Tests Skipped Failures Errors Time
1829 0 💤 0 ❌ 0 🔥 25.565s ⏱️

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Dec 18, 2025
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 26.47059% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.22%. Comparing base (841a133) to head (aaeec09).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...c/lfx/src/lfx/custom/custom_component/component.py 21.42% 9 Missing and 2 partials ⚠️
src/lfx/src/lfx/schema/message.py 54.54% 5 Missing ⚠️
src/lfx/src/lfx/base/agents/agent.py 0.00% 4 Missing ⚠️
src/lfx/src/lfx/base/agents/altk_base_agent.py 0.00% 4 Missing ⚠️
src/lfx/src/lfx/base/agents/events.py 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (26.47%) is below the target coverage (40.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (39.42%) 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   #11061      +/-   ##
==========================================
- Coverage   33.23%   33.22%   -0.01%     
==========================================
  Files        1391     1391              
  Lines       65848    65870      +22     
  Branches     9745     9751       +6     
==========================================
+ Hits        21884    21888       +4     
- Misses      42842    42859      +17     
- Partials     1122     1123       +1     
Flag Coverage Δ
backend 52.53% <ø> (-0.02%) ⬇️
frontend 15.36% <ø> (ø)
lfx 39.42% <26.47%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
src/lfx/src/lfx/base/agents/events.py 16.58% <0.00%> (ø)
src/lfx/src/lfx/base/agents/agent.py 27.84% <0.00%> (-0.16%) ⬇️
src/lfx/src/lfx/base/agents/altk_base_agent.py 0.00% <0.00%> (ø)
src/lfx/src/lfx/schema/message.py 58.48% <54.54%> (-0.14%) ⬇️
...c/lfx/src/lfx/custom/custom_component/component.py 58.93% <21.42%> (-0.45%) ⬇️

... and 3 files with indirect coverage changes

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

Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement.

LGTM

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants