Repository navigation
fix(workflow): make JoinNode in a loop wait for each iteration's predecessors - #7499
Closed
AkshayShah03 wants to merge 1 commit into
Closed
AkshayShah03 wants to merge 1 commit into
AkshayShah03 wants to merge 1 commit into
Conversation
…ecessors _buffer_barrier_trigger treated a wait-for-all node as ready when every predecessor's status was COMPLETED. That status is never consumed when the join fires, so in a loop the join fired as soon as the first predecessor of the next iteration completed, using the other predecessors' outputs from the previous iteration, and then fired again when they arrived. Track the predecessors that completed since each wait-for-all node last fired and clear them when it fires. Resume replays recorded completions through the same path, so the tracking is rebuilt without persisting anything new. Fixes google#7498
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 17, 2026
Merge #7499 - A predecessor that routes away from the JoinNode no longer counts as arrived; the join waits until every incoming edge has fired for the current iteration. Previously this was order-dependent (the join fired if the routed-away predecessor happened to complete first), so some existing graphs with conditional edges into a JoinNode will see the join stop firing. - A node that completes without an output no longer leaves its previous iteration's output in node_outputs; downstream nodes (and the workflow's terminal output) now observe None for that run. - Known limitation: if an iteration restarts before the JoinNode fires (for example, when one predecessor arrives at the join while another routes back to restart the loop), the partial arrival carries over and a later firing can combine outputs from different iterations. Fixes #7498 Fixes #7515 PiperOrigin-RevId: 1001343757
Collaborator
|
Thank you @AkshayShah03 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit a6ed859. Closing this PR as the changes are now in the main branch. |
9 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
Workflow._buffer_barrier_triggerconsidered a wait-for-all node (JoinNode) ready when every predecessor'sNodeState.statuswasCOMPLETED. That status is never consumed when the join fires, so inside a loop a predecessor that has not re-run yet still counts as done. The join fires as soon as the first predecessor of the next iteration completes, with the others' outputs from the previous iteration, and then fires again when they arrive, so everything downstream runs an extra time. With human-in-the-loop, the join even fires while the slower branch is still waiting for user input.Solution:
Add
_LoopState.join_arrivals: for each wait-for-all node, the set of predecessors that completed since it last fired._handle_completionrecords the arrival (_record_join_arrivals), and_buffer_barrier_triggerfires only when every predecessor (other than START, which stays always-satisfied as before) is in the set, then clears it.Notes:
COMPLETEDcheck. Only the "since last fire" scoping changes._LoopStateis rebuilt on resume by replaying recorded completions through_handle_completion, which rebuildsjoin_arrivalstoo. The resume test below covers this for both resumable and non-resumable apps.Testing Plan
Unit Tests:
Added to
tests/unittests/workflow/test_join_node.py:test_join_node_in_loop_waits_for_each_iteration: two-iteration loop where one branch is a hop longer. Expects join inputs[{A1, B1}, {A2, B2}];maingives[{A1, B1}, {A2, B1}, {A2, B2}].test_join_node_in_loop_waits_for_predecessor_paused_for_input[False|True]: same loop, but the slower branch pauses forRequestInputon iteration 2. Expects no join firing while it waits, then exactly{A2, B2}after resume. Onmainthe join fires with{A2, B1}before the user answers.All three fail on
mainand pass with this change.pyinkandisortreport no changes.Manual End-to-End (E2E) Tests:
Ran the reproduction script from #7498 through a real
RunnerwithInMemorySessionService:main: the join fires 3 times, the second time with{'a': 'A2', 'b': 'B1'}{'a': 'A1', 'b': 'B1'}then{'a': 'A2', 'b': 'B2'}Also checked an existing non-loop join +
RequestInputresume scenario (resumable and non-resumable): output unchanged.Checklist
Additional context
A related, separate issue in the same area:
_handle_completiononly overwritesnode_outputs[name]when the output is notNone, so a predecessor that returnsNoneon a later iteration passes its previous output to the join. I left that out to keep this PR to one concern and can follow up separately.