adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Workflow skips graph validation and drops its output when given a graph directly

Open hyeonsang010716 opened this issue 2 weeks ago • 2 comments

🔴 Required Information

Describe the Bug: Workflow.model_post_init only builds and validates a graph when edges is set and graph is not:

if self.edges and self.graph is None:
  self.graph = self._build_graph()

A graph passed in directly with Workflow(graph=Graph(...)) therefore never goes through Graph.validate_graph(). Two things follow:

  • None of the graph checks run, so a node that START cannot reach (or an unconditional cycle) is accepted.
  • Graph._terminal_node_names is never computed and stays empty. The terminal node's output is never used as the workflow's output (use_as_output is always false), so a node after the nested workflow receives None.

The same graph built with edges= validates and hands its output on.

Steps to Reproduce:

  1. Install google-adk.
  2. Run the code below.

Expected Behavior: Both workflows hand on their output, and the graph with a node START cannot reach is rejected, as it is with edges=.

-- edges=
consume got 'inner result'
-- graph=
consume got 'inner result'
-- graph= with a node START cannot reach
rejected

Observed Behavior:

-- edges=
consume got 'inner result'
-- graph=
consume got None
-- graph= with a node START cannot reach
accepted

Environment Details:

  • ADK Library Version (pip show google-adk): main at 0795861 (2.14.0)
  • Desktop OS: macOS
  • Python Version (python -V): 3.14.7

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: N/A (no model call is needed to reproduce)

🟡 Optional Information

Additional Context: Graph is not exported from google.adk.workflow, but graph is a public field of Workflow, and the unit tests build workflows with Workflow(graph=Graph(...)).

Minimal Reproduction Code:

import asyncio

from google.adk.runners import InMemoryRunner
from google.adk.workflow import START
from google.adk.workflow import Workflow
from google.adk.workflow._graph import Graph
from google.genai import types


def produce():
  return "inner result"


def consume(node_input):
  print("consume got", repr(node_input))


def orphan():
  return "never runs"


async def run(inner):
  outer = Workflow(name="outer", edges=[(START, inner, consume)])
  runner = InMemoryRunner(app_name="repro", agent=outer)
  session = await runner.session_service.create_session(
      app_name="repro", user_id="u"
  )
  async for _ in runner.run_async(
      user_id="u",
      session_id=session.id,
      new_message=types.Content(role="user", parts=[types.Part(text="hi")]),
  ):
    pass


async def main():
  print("-- edges=")
  await run(Workflow(name="inner", edges=[(START, produce)]))
  print("-- graph=")
  await run(
      Workflow(name="inner", graph=Graph.from_edge_items([(START, produce)]))
  )

  print("-- graph= with a node START cannot reach")
  try:
    Workflow(
        name="broken",
        graph=Graph.from_edge_items([(START, produce), (orphan, produce)]),
    )
    print("accepted")
  except ValueError:
    print("rejected")


asyncio.run(main())

How often has this issue occurred?:

  • Always (100%)

hyeonsang010716 avatar Nov 11 '26 00:11 hyeonsang010716

Taking this.

Workflow.model_post_init validates a graph only when it builds one from edges. Workflow(graph=...) skips that, so _terminal_node_names stays empty and the parent gets None. A node START cannot reach is accepted.

I validate a graph that is passed in. The parent test fails while the input is None, and the unreachable graph does not raise until the check runs.

claxman avatar Nov 13 '26 07:11 claxman

Hi @hyeonsang010716, thanks for the detailed report and the minimal repro.

I have reproduced the issue on main. When Workflow(graph=...) is used, Graph.validate_graph() never runs, so:

  • a node that START cannot reach is accepted, and
  • _terminal_node_names stays empty, so the nested workflow passes None to the next node instead of its output.

Your PR #8091 addresses both. I checked it locally:

  • the repro now prints consume got 'inner result', and the unreachable-node graph is rejected
  • the new tests fail on main and pass with the fix

The PR is now being reviewed by our team and will be merged once it's approved.

sanketpatil06 avatar Nov 17 '26 07:11 sanketpatil06