fix(agent): close open steps before the step-limit reply finishes the run - #74
Merged
Merged
Conversation
… run When the graph hit its recursion limit, the adapter had already started a step for the interrupted node and dropped its run state on the exception, so the recovery path sent RUN_FINISHED with that step still open. @ag-ui/client's verifier rejects that, and Slack showed "Cannot send 'RUN_FINISHED' while steps are still active" instead of the step-limit reply. Track the steps, text messages, and tool calls the stream opens, and close whatever is left innermost-first before the snapshots and the reply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
guidovizoso
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a Slack turn hits the graph step limit, the person sees
instead of the "I hit the step limit… ask me again" reply.
The adapter opens a step for every graph node. When the graph raises
GraphRecursionErrorit drops its run state without closing that step, soiter_agent_eventsinagent/agui.pysentRUN_FINISHEDwhile the step was still open.@ag-ui/client's event verifier rejects that. A raw SSE read of the agent looks fine, because nothing on that side checks the event order.Fix
iter_agent_eventsnow tracks the steps, text messages, and tool calls the stream opens. On a step-limit crash it closes whatever is still open, innermost first, before the snapshots, the reply, andRUN_FINISHED.Verification
verifyEventsfrom@ag-ui/client@0.0.59. Before the fix:Cannot send 'RUN_FINISHED' while steps are still active: step. After: accepted (30 events).agent/tests/test_agui_recursion.py, both failing before the fix:RUN_FINISHED;uv run pytest(536 passed, 1 skipped),pnpm check-types,pnpm test(436 passed), Railway IaC (no diagnostics).support, together with feat(arcade): Arcade as a second connected-app provider #73): the step-limit turn now ends with the polite reply instead of the error.Not in this PR
The step budget itself is unchanged. A limit of 25 graph steps is about five tool calls, because each tool call costs four nodes (
model, twoafter_modelmiddlewares,tools). That's a separate decision.🤖 Generated with Claude Code