Skip to content

fix(workflow): propagate delegated child output to parent context in use_as_output - #8185

Open
utkarshpatwa393-sys wants to merge 1 commit into
google:mainfrom
utkarshpatwa393-sys:fix/workflow-use-as-output-propagation-8183
Open

utkarshpatwa393-sys wants to merge 1 commit into
google:mainfrom
utkarshpatwa393-sys:fix/workflow-use-as-output-propagation-8183

Conversation

@utkarshpatwa393-sys

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
When a workflow node executes a child node dynamically with await ctx.run_node(child, use_as_output=True) without an explicit return statement (or returning None), the child node's output is properly emitted to the session event stream, but was never set on the calling parent's ctx.output.

As a result, subsequent workflow steps connected to that node receive None as node_input, and terminal workflow nodes fail to pass the delegated output to the workflow result.

Solution:

  1. In _dynamic_node_scheduler.py, after a dynamic step completes with use_as_output=True on a non-Workflow caller, set ctx.output = child_ctx.output if ctx.output is None.
  2. In Context.output.setter, allow idempotent assignment of equivalent values (self._output_value is value or self._output_value == value), preventing spurious ValueError: Output already set if a node also explicitly returns await ctx.run_node(...).
  3. Add a regression unit test in test_workflow_dynamic_nodes.py verifying that downstream nodes receive the delegated output.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

pytest tests/unittests/workflow/test_workflow_dynamic_nodes.py passes cleanly (27 passed, 1 xfailed):

======================== 27 passed, 1 xfailed in 1.20s =========================

Manual End-to-End (E2E) Tests:

Executed the minimal reproduction script from #8183:

@node(rerun_on_resume=True)
async def dispatch(ctx: Context, node_input: str):
    await ctx.run_node(child_node, node_input, use_as_output=True)

def receipt(node_input: str | None = None) -> str:
    return 'Packed: ' + (node_input or 'MISSING_ORDER')

wf = Workflow(name='purchasing', edges=[('START', dispatch, receipt)])
  • Before: Final Output: Packed: MISSING_ORDER
  • After: Final Output: Packed: 10 folders

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

…use_as_output

When a node runs a child with use_as_output=True without explicitly
returning its result (e.g. await ctx.run_node(child, use_as_output=True)),
the child's output was emitted to the event stream but never set on the
parent's ctx.output. Consequently, downstream workflow steps and graph
successors received None.

This patch:
- Sets ctx.output = child_ctx.output on the parent context when
  use_as_output=True finishes.
- Permits idempotent assignment of equivalent values in Context.output.setter
  so that explicit returns do not raise Output already set.
- Adds regression test covering downstream node input propagation in
  test_workflow_dynamic_nodes.py.

Closes google#8183

Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] A delegated order reaches the event stream but not the next workflow step

2 participants