Skip to content

[Python] Preserve data and timer payloads in the final Fn API block - #41447

Open
wozhenbang2004 wants to merge 4 commits into
apache:masterfrom
wozhenbang2004:fix/python-final-data-payload-21164
Open

wozhenbang2004 wants to merge 4 commits into
apache:masterfrom
wozhenbang2004:fix/python-final-data-payload-21164

Conversation

@wozhenbang2004

Copy link
Copy Markdown

Fixes #21164.

The Python gRPC data channel drops payloads in blocks marked with is_last=True; the in-memory channel does the same for timers. Preserve those payloads while keeping the end-of-stream bookkeeping and empty end markers unchanged.

Added regressions for both channels. The data-plane tests and the gRPC runner tests for ordinary input, timer firing and timer clearing pass. A localhost BeamFnData RPC also preserves encoded data and timers in the final block.

@github-actions github-actions Bot added python runners size/s S: 10-49 lines changed labels Nov 18, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This PR resolves #21164 for the Python SDK by ensuring InMemoryDataChannel and _GrpcDataChannel yield Elements.Data and Elements.Timers messages containing payloads even when marked with is_last=True, while still recording stream completion and ignoring empty end-of-stream markers. The changes are minimal, accurate, and accompanied by unit tests covering both data and timer final payloads.

🔍 General Feedback

  • The condition if element.<payload> or not element.is_last: in _GrpcDataChannel.input_elements and InMemoryDataChannel.input_elements cleanly preserves final block payloads while suppressing empty end-of-stream markers.
  • Note for InMemoryDataChannel.input_elements: line 399 still checks if element.data or element.is_last: (though InMemoryDataChannel.output_stream never sets is_last=True). In a future cleanup or if desired here, aligning it to if element.data or not element.is_last: would make both channels completely consistent if an external caller ever appends an empty Data(is_last=True) marker.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.
Backup reviewer: tvalentyn (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@wozhenbang2004

Copy link
Copy Markdown
Author

InMemoryDataChannel already yields non-empty Data(is_last=True) payloads. Its output_stream leaves is_last unset and can append empty buffers; changing this condition would start yielding those empty non-final blocks. I’m keeping the current data-path behavior here so this fix does not change that separately.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.37%. Comparing base (8616d1f) to head (b07e5ab).
⚠️ Report is 261 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41447      +/-   ##
============================================
- Coverage     59.47%   59.37%   -0.11%     
  Complexity     5123     5123              
============================================
  Files          1468     1468              
  Lines        187422   187424       +2     
  Branches       3807     3807              
============================================
- Hits         111478   111279     -199     
- Misses        72545    72746     +201     
  Partials       3399     3399              
Flag Coverage Δ
python 80.62% <100.00%> (-0.24%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @jrmccluskey

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @damccorm for label python.
Backup reviewer: shunping (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This PR fixes Fn API data channels (_GrpcDataChannel and InMemoryDataChannel) so that non-empty data and timer payloads attached to final messages (is_last=True) are yielded to consumers while still recording stream completion and suppressing empty end-of-stream markers. The changes are minimal, preserve existing behavior for non-final and empty final blocks, and include unit test coverage for both channels.

🔍 General Feedback

  • No code issues found.
  • Note: the PR currently has a merge conflict (mergeable_state: "dirty", likely in CHANGES.md) and will need a rebase onto master.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@damccorm damccorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks - I'll merge once checks pass

@damccorm

damccorm commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Could you please pull in the latest changes from master? We'll need #41870 for CI to go green

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure that the payload is consumed on Elements.Data and Elements.Timers when is_last = true

2 participants