🐛 Bug Report: Workflow runs cut off at the 50-step limit are reported as completed
📜 Description
WorkflowEngine._run_graph stops a run after MAX_EXECUTION_STEPS (50) node executions. When the cap is what ends the run, the engine only writes a log line. No error event is yielded, and WorkflowAgent._determine_run_status only looks for failed node logs, so the run is saved as completed.
A looping workflow that never converges (for example a review/revise loop where an If / Else sends the run back to an AI Agent node until the output is approved) runs 50 nodes, which for agent nodes means up to 50 LLM calls, and then looks like it finished. In chat the user sees whatever was streamed so far, often nothing. A scheduled or webhook-triggered run is recorded as successful, so nothing tells the owner it was cut off.
docs/content/Agents/nodes.mdx says "A run stops after 50 node steps, so a loop needs an exit condition", which reads as if the stop is reported. It isn't.
The existing tests (test_max_steps_limit, test_max_steps_exactly_reached) only check that the loop terminates, so this was never covered.
👟 Reproduction steps
- Create a workflow: Start → Set State (
tries = 1) → If / Else → back to the Set State node, with the Else branch going to an End node. Give the If / Else one case with the expressiontries >= 0, which is always true. - Run the workflow from chat, or from a schedule/webhook.
- Look at the stream and at the run in the workflow runs list.
The same thing without the UI:
repro.py
from unittest.mock import MagicMock
from docsgpt.agents.workflow_agent import WorkflowAgent
from docsgpt.agents.workflows.schemas import NodeType, Workflow, WorkflowEdge, WorkflowGraph, WorkflowNode
from docsgpt.agents.workflows.workflow_engine import WorkflowEngine
def node(i, t, config=None):
return WorkflowNode(id=i, workflow_id="wf", type=t, title=i, config=config or {})
def edge(i, s, t, handle=None):
return WorkflowEdge(id=i, workflow_id="wf", source=s, target=t, sourceHandle=handle)
cond = {"cases": [{"name": "again", "expression": "tries >= 0", "sourceHandle": "case_0"}]}
graph = WorkflowGraph(
workflow=Workflow(name="loop"),
nodes=[
node("start", NodeType.START),
node("bump", NodeType.STATE, {"operations": [{"expression": "1", "target_variable": "tries"}]}),
node("check", NodeType.CONDITION, cond),
node("end", NodeType.END, {"output_template": "done"}),
],
edges=[
edge("e1", "start", "bump"),
edge("e2", "bump", "check"),
edge("e3", "check", "bump", "case_0"),
edge("e4", "check", "end", "else"),
],
)
engine = WorkflowEngine(graph, MagicMock(chat_history=[]))
events = list(engine.execute({}, "q"))
print("completed steps:", len([e for e in events if e.get("status") == "completed"]))
print("error events:", [e for e in events if e.get("type") == "error"])
agent = WorkflowAgent.__new__(WorkflowAgent)
agent._engine = engine
agent._bridge_error = None
print("run status:", agent._determine_run_status().value)
👍 Expected behavior
The run ends with an error naming the step limit, and the run row is stored as failed. A schedule or webhook that hits the cap shows up as a failed run.
👎 Actual Behavior with Screenshots
On main the script prints:
completed steps: 50
error events: []
run status: completed
No error reaches the client and the run is saved as completed.
💻 Operating system
MacOS
🤖 What development environment are you experiencing this bug on?
Local dev server
📃 Provide any additional context for the Bug.
The warning at the end of _run_graph is also written when a path ends exactly on step 50 (the last node has no outgoing edge), so the check has to look at whether a node is still queued, not only at the step count.
🔗 Are you willing to submit PR?
Yes, a PR is coming.
Assigned to @cr-sbarbouche.
- Open a PR or post progress within 14 days; otherwise the issue will be made available to others.
- Read
CONTRIBUTING.mdand include a screenshot or short recording showing the workflow error and failed run. - Add regression tests for a loop cut off at the limit and for a path that finishes exactly at step 50; check both error events and the stored run status.
Automated triage. A maintainer will follow up.