fix(workflow): select nested workflow output by terminal node, not arrival order#1013
Open
wolo-lab wants to merge 1 commit into
Open
fix(workflow): select nested workflow output by terminal node, not arrival order#1013wolo-lab wants to merge 1 commit into
wolo-lab wants to merge 1 commit into
Conversation
…rival order WorkflowNode surfaced a nested workflow's result as "the last yielded event with non-nil Output", which is iteration-order dependent. This diverged from adk-python and was wrong for two shapes: a fan-out with multiple terminals picked a nondeterministic winner, and a silent terminal returned an earlier node's output as if it were the result. Select the output from the workflow's terminal node(s) (nodes with no outgoing edges) by graph topology, mirroring adk-python's _set_ctx_output_or_interrupts: exactly one terminal output is forwarded, more than one distinct terminal with output is ErrMultipleOutputs, and zero means no output. Outputs are keyed by terminal node name (last write wins, like adk-python's node_outputs dict) so re-activating one terminal is a single output. Terminal output is read via childEventOutput, so a MessageAsOutput terminal is handled too.
66a4db6 to
d14996c
Compare
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.
Problem
WorkflowNodesurfaced a nested workflow's result as "the last yieldedevent with non-nil
Output" — which is iteration-order dependent. Thisdiverged from adk-python and was wrong for two common shapes:
by wall-clock won, so the result was non-deterministic across runs.
earlier node did, the intermediate node's output was returned as if it
were the workflow's result.
The existing linear tests passed only because the single terminal happens
to emit last (
TestNestedWorkflow_MultipleOutputs, despite its name, isa linear
Chain).Solution
Select the output from the workflow's terminal node(s) — nodes with
no outgoing edges — computed from graph topology rather than event
arrival order, mirroring adk-python's
_set_ctx_output_or_interrupts:ErrMultipleOutputs(a workflow must have a single output identity; use a
JoinNodetomerge branches);
Outputs are keyed by terminal node name (last write wins), matching
adk-python's
node_outputsdict, so re-activating a single terminalcounts as one output rather than an error. Terminal output is read via
childEventOutput, so a terminal that carries its result as model text(
MessageAsOutput) is handled too.A new
graph.terminalNodeNames()helper computes the terminal set(mirrors adk-python's
graph._terminal_node_names).