Skip to content

fix: improve condition check for streaming token callback in handle_on_chain_stream#11362

Merged
ricofurtado merged 5 commits intomainfrom
lfoss-3036-streaming-output-bug
Feb 17, 2026
Merged

fix: improve condition check for streaming token callback in handle_on_chain_stream#11362
ricofurtado merged 5 commits intomainfrom
lfoss-3036-streaming-output-bug

Conversation

@ricofurtado
Copy link
Contributor

@ricofurtado ricofurtado commented Jan 20, 2026

This pull request makes a minor update to the logic for streaming token events in the handle_on_chain_stream function. The change improves the condition that checks whether to send a token event, ensuring it is more explicit and reliable.

Summary by CodeRabbit

  • Bug Fixes
    • Refined token callback emission logic for more consistent handling of output validation.

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

@github-actions github-actions bot added the community Pull Request from an external contributor label Jan 20, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

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.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

A condition check in the handle_on_chain_stream function was modified to explicitly validate that output_text is not None and not an empty string, replacing a truthiness-based check with explicit equality comparisons.

Changes

Cohort / File(s) Summary
Token callback guard condition
src/lfx/src/lfx/base/agents/events.py
Updated the condition for emitting a token callback from output_text and output_text.strip() to output_text is not None and output_text != "", changing from implicit truthiness checks to explicit None and empty string validation

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


Important

Pre-merge checks failed

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

❌ Failed checks (1 error, 2 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR implements a bug fix to condition check for streaming token callbacks but includes no new tests to validate the fix or prevent regressions. Add regression tests for whitespace-only strings, None values, empty strings, and a test case reproducing the original bug to validate the condition change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Quality And Coverage ⚠️ Warning PR changes token emission condition from filtering whitespace-only strings to allowing them, but existing test expects whitespace-only strings to be skipped. Update test_agent_streaming_skips_empty_chunks() to reflect new behavior or add new test explicitly validating the condition change with clear assertions.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: improving condition checks for streaming token callbacks in a specific function.
Test File Naming And Structure ✅ Passed The test file follows correct patterns with 45 fully implemented test functions using proper pytest structure and comprehensive coverage.
Excessive Mock Usage Warning ✅ Passed Test file demonstrates appropriate use of mocks for external dependencies while using real objects to test actual behavior, with 30+ tests validating improved condition logic.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lfoss-3036-streaming-output-bug

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 Jan 20, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 20, 2026
@github-actions
Copy link
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 17%
17.49% (4997/28566) 10.83% (2388/22036) 11.58% (724/6248)

Unit Test Results

Tests Skipped Failures Errors Time
1998 0 💤 0 ❌ 0 🔥 26.269s ⏱️

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 35.23%. Comparing base (9d2a666) to head (93231eb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/lfx/src/lfx/base/agents/events.py 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (40.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (42.10%) 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   #11362      +/-   ##
==========================================
- Coverage   35.26%   35.23%   -0.03%     
==========================================
  Files        1521     1521              
  Lines       72960    72941      -19     
  Branches    10938    10932       -6     
==========================================
- Hits        25729    25704      -25     
- Misses      45835    45842       +7     
+ Partials     1396     1395       -1     
Flag Coverage Δ
backend 55.73% <ø> (-0.14%) ⬇️
lfx 42.10% <0.00%> (+<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%> (ø)

... and 11 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
Collaborator

@Adam-Aghili Adam-Aghili left a comment

Choose a reason for hiding this comment

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

Do we want to allow whitespace only stings, such as " "?

@ricofurtado
Copy link
Contributor Author

ricofurtado commented Jan 20, 2026

Yes, we want. That was the original issue; the chunks outputs were different from the text outputs. e.g. "PISA 2022" was becoming "PISA2022" when accumulating the chunks.

# Note: we should expect the callback, but we keep it optional for backwards compatibility
# as of v1.6.5
if output_text and output_text.strip() and send_token_callback and message_id:
if output_text is not None and output_text != "" and send_token_callback and message_id:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if output_text is not None and output_text != "" and send_token_callback and message_id:
if output_text is not None and output_text.lstrip() and output_text.rstrip() and output_text != "" and send_token_callback and message_id:

Based on the tests failing I think it would be safe to use either lstrip or rstrip to preserve the previous intent of ignoring " " but allowing "PISA 2022".

We could use both but that seems unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to allow " " spaces. So using lstrip() or rstrip() will return falsy, defeating the purpose.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if you want to allow " " that is fine but the UTs need to be updated.

Choose a reason for hiding this comment

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

What happened to this PR? Was it abandoned? I find the issue I resported pretty serious: #10970

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 17, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 17, 2026
@ricofurtado ricofurtado disabled auto-merge February 17, 2026 22:00
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Feb 17, 2026
@ricofurtado ricofurtado disabled auto-merge February 17, 2026 22:06
@ricofurtado ricofurtado added this pull request to the merge queue Feb 17, 2026
Merged via the queue into main with commit ac0c451 Feb 17, 2026
37 of 39 checks passed
@ricofurtado ricofurtado deleted the lfoss-3036-streaming-output-bug branch February 17, 2026 22:58
dpguthrie pushed a commit to dpguthrie/langflow-1 that referenced this pull request Feb 18, 2026
…n_chain_stream (langflow-ai#11362)

* fix: improve condition check for streaming token callback in handle_on_chain_stream

* [autofix.ci] apply automated fixes

* bug: fixed test for streaming skip empty chunks

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working community Pull Request from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants