Skip to content

a route source that returns None or a single model instead of a list leaves the run running forever with no error row #767

Done

Description

@XBeg9

A route(...) forks over the list its source step returns. When the source body returns something that is not a list, _route_fork returns None (_runner.py:2671-2672), called from the body path at _runner.py:1602-1607. The finalize only attaches a route fork when that value is not None (_runner.py:2250-2254), so the source finalizes succeeded with no fork. No <source>.join row is created, and the consumer that was created waiting on that join keeps deps_pending=1. The _route_fork docstring keeps None for a non-list on purpose. The same paragraph describes this exact state as the wedge the empty-list fix removed: the join row never existed and the consumers' reserved deps were never released (_runner.py:2643-2653).

The build only checks the annotation, get_origin(returned) is list (_graph.py:1679), and encode_result wraps whatever the body returned, with None staying None (_runner_codec.py:190-197). The guide says a non-list source is refused at build (workflows.md:1441-1449), and that refusal looks at the declaration only; the returned value is never checked. A body declared -> list[Image | Audio] that misses a return on one branch, or returns one element without the brackets, passes the build. The map sibling turns a non-list into an empty item list (_runner.py:2483-2485), so its join fires with zero children and the run ends.

Reproduced on ffcb61f against a real Postgres. The source tree there is identical to main at 9b9fa72; nothing under src/ changed in between. The shape:

class Image(BaseModel):
    doc_id: str

class Audio(BaseModel):
    doc_id: str

class Done(BaseModel):
    doc_id: str

async def media(ctx: StepContext) -> list[Image | Audio]:
    return None  # e.g. a branch that forgot its return

async def on_image(ctx: StepContext, item: Image) -> Done:
    return Done(doc_id=item.doc_id)

async def on_audio(ctx: StepContext, item: Audio) -> Done:
    return Done(doc_id=item.doc_id)

async def summarize(ctx: StepContext, items: list[Done]) -> dict[str, int]:
    return {"n": len(items)}

@app.workflow("route_non_list")
def route_non_list() -> Promise[object]:
    routed = route(
        step(media, key="media"),
        {Image: RouteArm(body=on_image), Audio: RouteArm(body=on_audio)},
    )
    return build(step(summarize, routed, key="summary"))

With media returning None, and again with it returning a bare Image(doc_id="a"), FlowRunner.drive hit its tick limit and returned "max_ticks". Both cases left the same rows: __flow__ running, media succeeded, summary pending with deps_pending=1. The flow has no media.join row and no edge rows, and no row is failed or carries an error. Fifty more ticks, which run the sweeps and the outbox drain, changed nothing. On the same graph, a source returning [Image, Audio] and one returning [] both end succeeded. A map_source whose source returns None reaches a terminal state with no rows left pending.

The run stays running for good with no failed row and no error class. Nothing alerts, and an operator sees a flow whose only finished step succeeded. The trigger needs a body that breaks its own declared return type, which a type checker would flag in a body like the one above. When such a body does reach the runner, the run should end with a named failure.

PR 750 and PR 751 both change this part of the runner (the fork source in _finalize_success and the route fork's join wiring). The non-list guard is unchanged on both.

Probably wants: _route_fork raising for a non-list return so the body path fails the source with the error on the record, as it already does for an element with no arm via RouterNotTotal (_runner.py:1608-1634). If None should keep meaning "route over nothing" as the docstring says, it needs the empty-list fork. Coercing every non-list to [] the way _map_fork does would end the run, but it would silently drop the element when a body returns a single model.

Activity

  1. added
    bug
    medium
    on Nov 24, 2026
  2. XBeg9 commented on Nov 24, 2026

    @XBeg9
    ContributorAuthor

    This one shipped with the route feature itself. The return None for a non-list return in _route_fork (_runner.py:1732-1733) and the annotation-only list[...] check in the build (_graph.py:1042) both blame to 5b383f295, the squash of PR 681 that added taskq.workflows, and searching the history for that guard turns up no other commit touching it since. I ran the reproduction at that commit and it hangs the same way it does on main: the None and bare-model cases both hit the tick limit with __flow__ running and summary pending at deps_pending=1, and the map control passes. At its parent taskq.workflows doesn't exist yet, so there was never a working version of this path to regress from. The docstring from that same PR already calls the empty-list version of this wedge fixed, so [] got the born-zero join and a non-list return kept the None.

    Related:

    • issue 745 and PR 751: PR 751 changes the join wiring in _route_fork and _map_fork for a leftover join row, and leaves the non-list guard alone.
    • PR 750: edits _finalize_success right next to the prebuilt_route_fork is not None check that lets this source finish with no fork.
    • issue 768: another graph that passes the build and then hangs with no error row.
    • issue 749 and PR 754: a runtime value that doesn't match its declared type, fixed there by refusing it before any row is written, which is probably the shape this one wants too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmedium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions