[Bug]: astream ignores Command.goto when the node also returns an update
What happened?
A node returns Command(update="ready", goto="chosen") and has a static edge to fallback. I expect both APIs to execute router -> chosen. On the source checkout below, ainvoke does that, while astream executes router -> fallback.
The destination is a literal string; the trace is recorded at node entry. Reproduced at 4cd96e5.
AI assistance was used to prepare and verify this report. This is an offline local-graph reproduction with no LLM/provider or external service. A local patch is held pending the repository's full PR checks.
Minimal reproduction
"""Compare literal Command.goto routing through real local graph APIs."""
import asyncio
from tenxgraph.core.graph import StateGraph
from tenxgraph.core.state import Message
from tenxgraph.utils import Command
from tenxgraph.utils.constants import END
async def run(mode):
entered = []
def router(state):
entered.append("router")
return Command(update="ready", goto="chosen")
def chosen(state):
entered.append("chosen")
return "chosen result"
def fallback(state):
entered.append("fallback")
return "fallback result"
graph = StateGraph()
for name, node in [("router", router), ("chosen", chosen), ("fallback", fallback)]:
graph.add_node(name, node)
graph.set_entry_point("router")
graph.add_edge("router", "fallback")
graph.add_edge("chosen", END)
graph.add_edge("fallback", END)
app = graph.compile()
data = {"messages": [Message.text_message("hello")]}
try:
if mode == "ainvoke":
await app.ainvoke(data, config={"thread_id": mode})
else:
async for _ in app.astream(data, config={"thread_id": mode}):
pass
finally:
await app.aclose()
return entered
async def main():
for mode in ("ainvoke", "astream"):
print(f"{mode}: {await run(mode)}")
if __name__ == "__main__":
asyncio.run(main())
10xgraph version
0.10.3 (editable source checkout at 4cd96e5c69b7ae36cae486442770903c3aa334bd)
Python version
3.12.13
LLM provider
Not relevant
Relevant logs / traceback
ainvoke: ['router', 'chosen']
astream: ['router', 'fallback']
Thanks for the detailed report and clean minimal reproduction!
We've verified this behavior on main at 4cd96e5 — astream indeed drops Command.goto when an update payload is present, falling back to static edges instead.
We’ve acknowledged the bug and will look into getting a fix prioritized. Appreciate the contribution!
Thanks for confirming. I have retained a small local fix that preserves the explicit destination while normalizing the update, plus regression tests for a named destination, END, and static fallback. In the October 23 local run on 4cd96e5, those regressions changed from 20 passed / 6 failed to 26 passed. The full pre-commit run and unfiltered test suite remain unverified, so the patch is still local.
Is someone already taking this on, or would a focused patch and these tests be useful? I can align with your preferred approach.
AI assistance was used for the local investigation and this follow-up.
@March-7
Thanks for following up, and for writing the regression tests already.
Nobody is working on this yet, so if you're interested, feel free to assign it to yourself and open a PR.
Your approach sounds right: keep the explicit goto destination, normalize the update payload, and fall back to static edges only when no destination is given.
A few things for the PR:
- Branch from the latest
main. - Include the three regression cases you listed: a named destination,
END, and the static fallback. If you can, also check thatinvokeandastreamroute the same way for the sameCommand, so the two paths can't drift apart again. - Run
pre-commit run --all-filesand the fullpytestsuite before you open it. If something unrelated fails, mention it in the PR description and we'll sort it out.
Thanks for saying AI was used, too. We'll review it once it's up.
Thanks — I'll take the focused fix. I've prepared the candidate on aa4e9d3, with named-destination, END, and static-fallback regressions across invoke, ainvoke, and astream; all 39 routing cases pass with the fix.
One validation constraint to align before opening the PR: my local execution scope excludes Bandit, detect-private-key, and security-focused tests. The reviewed ordinary selection passes 3,604 tests, with 80 existing skips and 118 cases not executed, at 86.44% coverage using the original 80% threshold. This is not an unfiltered pytest run, and I cannot report a complete pre-commit pass. Would a PR explicitly documenting these unrun checks, with full validation run upstream, be acceptable?
AI assistance was used for the implementation and validation.
@March-7 Sorry for the slow reply, your question got lost on our side.
Yes, please open the PR as it is. Just list the checks you couldn't run (Bandit, detect-private-key, the security tests) in the description, and our CI will run the full pre-commit and pytest suite.
We'd like this fix in the next release.