Fix lost state updates in Set state#39175
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a race condition in Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Assigning reviewers: R: @jrmccluskey for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
There was a problem hiding this comment.
Code Review
This pull request introduces tracking of outstanding asynchronous state requests in bundle_processor.py to ensure they are properly awaited and committed during the commit phase, and adds a corresponding unit test to verify stateful set state compaction under race conditions. The reviewer suggested a critical improvement to the commit logic: using a while loop to repeatedly drain self._futures rather than a single snapshot, ensuring that any new futures appended while awaiting previous ones are also fully resolved before the commit returns.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
When elements are added to
SynchronousSetRuntimeState, it occasionally triggers data compaction (_compact_data) which launches asynchronousclearandextendrequests to the State Handler. However, these futures were not tracked. Thecommit()method only blocked on the last futures generated during the commit phase, causing outstanding compaction futures to complete out of order or after the bundle processor finished, resulting in lost state updates.An example failed test:
https://github.com/apache/beam/actions/runs/28001498086/job/82874623596
Traceback:
This PR fixes a race condition in
SynchronousSetRuntimeStatewhere asynchronous state requests triggered by state compaction or early clears were not being awaited.self._futuresto record all asynchronous state requests initiated by compaction and early clears.commit()to combineself._futureswith current commit-time futures and await all of them before completing.