Skip to content

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.

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 31.64%. Comparing base (5497f93) to head (3b618a9).

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

❌ Your project check has failed because the head coverage (42.66%) is below the target coverage (55.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   34.23%   31.64%   -2.60%     
==========================================
  Files        1409     1414       +5     
  Lines       66923    67202     +279     
  Branches     9877     9910      +33     
==========================================
- Hits        22914    21267    -1647     
- Misses      42808    44719    +1911     
- Partials     1201     1216      +15     
Flag Coverage Δ
backend 42.66% <ø> (-10.88%) ⬇️
frontend 16.03% <ø> (ø)
lfx 41.60% <0.00%> (+0.79%) ⬆️

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 112 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

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