Repository navigation
fix(runtime): a tool-result continuation pauses only on external calls that still need a result - #452
Merged
Merged
Conversation
…he final response The host resumes a saved pause on a runtime whose session GMI is the shipped one. The model calls lookup_notes, a tool registered with the runtime, and then answers. The GMI runs the call itself, so the continuation ends with FINAL_RESPONSE, lists the call in finalToolCalls, sends no actionable tool call and leaves no pending external tool request.
… for that call A GMI that leaves tools to the host returns a non-final output naming a new call after the host's tool result. The continuation stream ends with one actionable TOOL_CALL_REQUEST holding exactly that call, sends no FINAL_RESPONSE, and the conversation's pending request holds that call on the same stream.
… never paused on The resumed turn's model asks for lookup_notes and shell_execute in one step. An output guard that evaluates tool calls refuses shell_execute through the gate, so the tool never runs and the model reads the refusal; lookup_notes runs. The GMI's final output still lists both calls. The continuation must end with FINAL_RESPONSE, hand the host no actionable call and leave no pending request, both with a guard that blocks the call on any chunk and with one that blocks only the calls the runtime runs itself.
…esponse with no pause A user turn on the shipped GMI whose model calls lookup_notes and then answers: the stream carries the call as an internal TOOL_CALL_REQUEST, ends with FINAL_RESPONSE listing the call in finalToolCalls, and the conversation holds no pending external tool request. This pins the turn path's pause rule while the continuation is brought to the same rule.
Reviewer's GuideThis draft adds end-to-end regression tests for continuation handling, distinguishing internally executed or refused tool calls from genuinely unresolved external calls while preserving existing pause and final-response behavior; the provided diff contains tests only, with the implementation fix expected in a follow-up. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…d rule externalToolPauseCalls() holds the rule the turn path applied inline: a GMI output stops the turn for the host only when it is not final (isFinal: false) and names at least one call, and then the turn waits on those calls. A final output's toolCalls are the calls the GMI ran, or the tool-call gate refused, in its own tool rounds. The turn path now calls the function; its behavior does not change.
… non-final output A continuation saved a pause and sent an actionable TOOL_CALL_REQUEST for every call on the GMI's output, without reading isFinal. The shipped GMI lists on its final output the calls it ran itself and, since the tool-call gate, the calls the gate refused, so a resumed turn whose model used a registered tool stopped again for a call that had already run and never reached FINAL_RESPONSE, and a refused call was offered to the host after the model had read the refusal. The continuation now decides with externalToolPauseCalls(), the rule the turn path uses: it stops only for a non-final output that names calls, and a final output goes to the final branch, which records the reply and sends FINAL_RESPONSE with the calls in finalToolCalls. Fixes #391
The turn lifecycle and the GMI output stream pages state the pause rule: only a non-final GMI output that names calls stops a turn or a continuation for the host, and the calls a final output lists, run or refused by the tool-call gate in the GMI's own rounds, are reported in finalToolCalls with no pending request. The guardrail pages say that only the stream processRequest() returns carries a chunk for a call the runtime runs itself, and that a refused call never becomes an actionable request.
jddunn
marked this pull request as ready for review
October 14, 2026 12:07
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
github-actions Bot
pushed a commit
that referenced
this pull request
Oct 14, 2026
## [0.13.119](v0.13.118...v0.13.119) (2026-10-14) ### fix * **runtime:** a tool-result continuation pauses only on external calls that still need a result (#452) ([d044361](d044361))
This was referenced Oct 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.
Summary
A tool-result continuation (
handleToolResult(),handleToolResults(),resumeExternalToolRequest()) stopped the turn again for every call listed on the GMI's output, while the turn path stops only for an output that is not final. The shipped GMI lists, on its final output, the calls it ran itself and, since #384, the calls the tool-call gate refused, so a continuation on it saved a pause for calls that had already run or had been refused and never reachedFINAL_RESPONSE. Both defects were confirmed in the code at master 798ffa2 (the files involved are unchanged since 864941b).Fix
externalToolPauseCalls()holds the rule both paths share: an output stops the turn for the host only when it is not final (isFinal: false) and names at least one call, and the turn then waits on those calls. The turn path calls it where it held the same condition inline, with no change in behavior (760e1d9). The continuation calls it in place of itstoolCalls.length > 0check (c11164d), so a final output that lists calls goes to the continuation's final branch: it records the reply, sendsFINAL_RESPONSEwith the calls infinalToolCallsas the turn path does, and closes the stream. The one rule fixes both defects, since the shipped GMI lists a refused call only on a final output.1. A continuation paused on the calls the GMI already ran itself
Evidence (798ffa2). The turn path stops for the host only when the GMI's output is not final and names a call:
isFinal === falseand at least one entry intoolCalls(AgentOSOrchestrator.tsL924-962). The continuation did not readisFinal: any entry intoolCallssaved a pause and pushed an actionableTOOL_CALL_REQUEST, so the final branch below it was never reached (ExternalToolResultHandler.tsL394-417). The shipped GMI collects every call the model asks for (GMI.tsL1752-1761), runs it in its own tool round (L1962-1965), and returns those calls on an output withisFinal: true(L2030-2040);handleToolResults()hands that output to the handler (L2197-2242). A resumed turn whose model used a registered tool therefore ended with an actionable request for a call that had already run, the saved pause offered it to the host a second time, and the stream never carriedFINAL_RESPONSE.Test.
tests/api/AgentOS.toolResultContinuation.integration.spec.ts, "a resumed turn whose model uses a tool the GMI runs itself ends with FINAL_RESPONSE and leaves no pause": the user's turn stops forread_fileon a GMI that leaves tools to the host, and the host resumes the saved pause withresumeExternalToolRequest()on a runtime whose session GMI is the shipped one, on a stub provider. The model callslookup_notes, a tool registered with the runtime, then answers. The case checks that the tool ran once, that the stream ends withFINAL_RESPONSElisting the call infinalToolCalls, that no actionable call goes out, and thatgetPendingExternalToolRequest()returnsnull.2. A continuation paused on the calls the tool-call gate refused
Evidence (798ffa2). Since #384 (dcfe023) the GMI asks the output guards' tool-call gate before each call of its own round, and a refused call becomes a refused tool result without running (
GMI.tsL1962-1965). The call stays in the collected calls and on the final output (L2030-2033), so the continuation saved a pause for it and pushed it as an actionable request. The stream's tool-call guards judge that chunk again (ParallelGuardrailDispatcher.tsL908). A guard that blocks the call on any chunk ended the stream with its error after the model had already answered, and dropping that blocked pause (#384, #387) answered every call of it with a refused tool result in the conversation, a call that had run included. A guard that blocks only the calls the runtime runs itself passed the external chunk, so the host received the refused call after the model had read the refusal.Test. Same file, "a call the gate refused in a resumed turn is never paused on", once for each kind of guard: the resumed turn's model asks for
lookup_notesandshell_executein one step, and the guard refusesshell_executethrough the gate. The case checks thatshell_executenever ran, that the model read the refusal, thatlookup_notesran once, and that the stream ends withFINAL_RESPONSE, hands the host no actionable call and leaves no pending request.What does not change
FINAL_RESPONSEand no pause.isFinal: false(tests/api/AgentOS.processRequest.memory.integration.spec.ts,tests/api/AgentOS.processRequest.toolCallGuards.integration.spec.ts) and keep their meaning.Linked issues
Closes #391
Type of change
How this was verified
CI on this pull request.
expect(last.type).toBe(FINAL_RESPONSE)withtool_call_request: the continuation stopped forlookup_notes, which had run. The refused-call case fails at the same line witherrorfor the guard that blocks on any chunk (it blocked the pause the continuation sent after the model had answered) and withtool_call_requestfor the guard that blocks only internal calls (the host was handedshell_execute). The checks above that line passed: in all three the model was called twice andlookup_notesran once, and in the refused-call casesshell_executenever ran and the model read the refusal. The new-external-call case and the turn-only case passed, as they must before and after the fix.Docs
The pages that state when a turn waits on the host now say it for continuations too:
docs/TURN_LIFECYCLE.md(the turn's opening paragraph),docs/GMI.md("Output stream": anIGMIstops a turn with a non-final output;GMIreturns a final one whosetoolCallsare a record),docs/safety/GUARDRAILS_USAGE.md("Tool Calls", "Calls the runtime runs itself") anddocs/safety/CREATING_GUARDRAILS.md("TOOL_CALL_REQUEST"). The guardrail pages said a guard is asked twice about a call the runtime runs itself; that holds on the streamprocessRequest()returns, and a continuation's stream carries no chunk for such a call.docs/safety/HUMAN_IN_THE_LOOP.mdanddocs/extensions/TOOL_CALLING_AND_LOADING.mdsay nothing about external tool pauses.Migration notes
None. A host whose GMI stops for host tools with a non-final output sees no change. A continuation on the shipped GMI ends with
FINAL_RESPONSEwhere it used to stop again for calls that had run or been refused.Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).Summary by CodeRabbit