Skip to content

fix(runtime): a tool-result continuation pauses only on external calls that still need a result - #452

Merged
jddunn merged 7 commits into
masterfrom
fix/continuation-pause-on-ran-calls
Oct 14, 2026
Merged

jddunn merged 7 commits into
masterfrom
fix/continuation-pause-on-ran-calls

Conversation

@jddunn

@jddunn jddunn commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

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 reached FINAL_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 its toolCalls.length > 0 check (c11164d), so a final output that lists calls goes to the continuation's final branch: it records the reply, sends FINAL_RESPONSE with the calls in finalToolCalls as 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 === false and at least one entry in toolCalls (AgentOSOrchestrator.ts L924-962). The continuation did not read isFinal: any entry in toolCalls saved a pause and pushed an actionable TOOL_CALL_REQUEST, so the final branch below it was never reached (ExternalToolResultHandler.ts L394-417). The shipped GMI collects every call the model asks for (GMI.ts L1752-1761), runs it in its own tool round (L1962-1965), and returns those calls on an output with isFinal: 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 carried FINAL_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 for read_file on a GMI that leaves tools to the host, and the host resumes the saved pause with resumeExternalToolRequest() on a runtime whose session GMI is the shipped one, on a stub provider. The model calls lookup_notes, a tool registered with the runtime, then answers. The case checks that the tool ran once, that the stream ends with FINAL_RESPONSE listing the call in finalToolCalls, that no actionable call goes out, and that getPendingExternalToolRequest() returns null.

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.ts L1962-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.ts L908). 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_notes and shell_execute in one step, and the guard refuses shell_execute through the gate. The case checks that shell_execute never ran, that the model read the refusal, that lookup_notes ran once, and that the stream ends with FINAL_RESPONSE, hands the host no actionable call and leaves no pending request.

What does not change

  • "a continuation that asks the host for a new call stops for exactly that call": a GMI that leaves tools to the host returns a non-final output naming a new call after the host's result, and the continuation still stops with exactly that call, saved on the same stream.
  • "a turn with no continuation is unchanged": a user turn on the shipped GMI whose model calls a registered tool ends with FINAL_RESPONSE and no pause.
  • The tests that model a second pause on a continuation return 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

  • Bug fix
  • Feature
  • Performance
  • Documentation
  • Refactor
  • Tests
  • Build or CI

How this was verified

CI on this pull request.

  • Run 38560724921 on the test commits (c83052f): 3 failed, 11671 passed, all three in the new spec. The internal-tool case fails at expect(last.type).toBe(FINAL_RESPONSE) with tool_call_request: the continuation stopped for lookup_notes, which had run. The refused-call case fails at the same line with error for the guard that blocks on any chunk (it blocked the pause the continuation sent after the model had answered) and with tool_call_request for the guard that blocks only internal calls (the host was handed shell_execute). The checks above that line passed: in all three the model was called twice and lookup_notes ran once, and in the refused-call cases shell_execute never 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.
  • Run 38561388678 on the fix and the docs (d29b780): every job green. Test & Lint ran 907 test files (5 skipped); 11674 tests passed and none failed, the new spec's 5 cases among them.
  • Review: CodeRabbit reviewed d29b780 across all eight files with no actionable comments. Sourcery's review budget and the Codex connector's usage limit were used up, so neither reviewed this pull request; no review thread is open.

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": an IGMI stops a turn with a non-final output; GMI returns a final one whose toolCalls are a record), docs/safety/GUARDRAILS_USAGE.md ("Tool Calls", "Calls the runtime runs itself") and docs/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 stream processRequest() returns, and a continuation's stream carries no chunk for such a call. docs/safety/HUMAN_IN_THE_LOOP.md and docs/extensions/TOOL_CALLING_AND_LOADING.md say 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_RESPONSE where it used to stop again for calls that had run or been refused.

Checklist

  • Tests cover the changed behavior.
  • Docs are updated.
  • The title follows Conventional Commits, with ! before the colon for a change that breaks users (feat!: or feat(api)!:).
  • No secrets or private data are included.
  • Every automated review thread is settled (how).
  • I have read this change and can explain every line.

Summary by CodeRabbit

  • Bug Fixes
    • Tool calls that require host execution now pause the turn and can be resumed with their results. This also applies when a continuation requests another host-run tool.
    • Calls handled internally by the GMI no longer create a pending request or pause the turn; they’re reported with the final response.
    • Refused or blocked calls aren’t presented as actionable requests and are included in the final response’s tool-call details.
  • Documentation
    • Clarified how external and internally handled tool calls appear in streams and affect turn completion.

…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.
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: b8530c1a-84e0-42aa-8686-3ba1d42b6410
📥 Commits

Reviewing files that changed from the base of the PR and between 90f8c9c and d29b780.

📒 Files selected for processing: 8
  • docs/GMI.md
  • docs/TURN_LIFECYCLE.md
  • docs/safety/CREATING_GUARDRAILS.md
  • docs/safety/GUARDRAILS_USAGE.md
  • src/api/runtime/AgentOSOrchestrator.ts
  • src/api/runtime/ExternalToolResultHandler.ts
  • src/api/runtime/externalToolPause.ts
  • tests/api/AgentOS.toolResultContinuation.integration.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The runtime now uses a shared condition to decide whether GMI tool calls require host execution. Continuation handling no longer treats calls from final GMI output as pending external requests. Tests and documentation cover the distinction.

Changes: External Tool Pause Handling

Layer / File(s) Summary
Define and apply the pause condition
src/api/runtime/externalToolPause.ts, src/api/runtime/AgentOSOrchestrator.ts
Adds a helper that returns tool calls only when output is non-final and the call list is nonempty. The orchestrator uses those calls when saving and emitting an external tool request.
Apply pause classification to continuations
src/api/runtime/ExternalToolResultHandler.ts, tests/api/AgentOS.toolResultContinuation.integration.spec.ts, docs/GMI.md, docs/TURN_LIFECYCLE.md, docs/safety/*
The continuation handler saves and emits only calls selected by the helper. Integration tests cover resumed turns, further pauses, guardrail refusals, and internally executed calls. Documentation describes pause handling and final output calls.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to d29b7

The continuation pause change has no remaining actionable merge-blocking risk identified in the reviewed scope.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 4 files. (4 skipped: 4 …
Description check Passed The description follows the required template. It explains the fix, links issue #391, identifies the change types, reports verification, documents migration impact, and completes the checklist.
Linked Issues check Passed The description links issue #391 with Closes #391, and the issue objective matches the continuation pause behavior changed by this pull request.
Out of Scope Changes check Passed The runtime changes, integration tests, and documentation updates directly support the stated continuation pause fix. No unrelated changes are identified.
Title check Passed The title is concise, uses Conventional Commits syntax, and accurately describes the main runtime change: continuations pause only for external calls that still require results.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Reviewer's Guide

This 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

Change Details Files
Adds integration coverage for tool-result continuations so only unresolved external calls create pauses.
  • Exercises resumed turns where the shipped GMI executes registered tools internally and must finish with FINAL_RESPONSE.
  • Exercises gate-refused calls, including guards that inspect all chunks or only internal calls, ensuring refusals are consumed without host pauses.
  • Preserves coverage for legitimate second external pauses and unchanged non-continuation behavior.
  • Builds realistic AgentOS, GMI, provider, tool, guardrail, and pending-request test fixtures.
tests/api/AgentOS.toolResultContinuation.integration.spec.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#391 On a tool-result continuation, pause for tool calls only when the GMI output is non-final, so final outputs listing calls the GMI already ran reach FINAL_RESPONSE without creating a pending external request. ❌ The diff adds integration tests but no runtime code changes. The continuation handler therefore still pauses whenever toolCalls are present, regardless of isFinal.
#391 Preserve external pauses for non-final continuation outputs that request a new tool call. ❌ The diff adds a test for this behavior but does not change the handler that implements it.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

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
jddunn marked this pull request as ready for review October 14, 2026 12:07
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 14, 2026 12:07
@sourcery-ai

sourcery-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@jddunn
jddunn merged commit d044361 into master Oct 14, 2026
12 checks passed
@jddunn
jddunn deleted the fix/continuation-pause-on-ran-calls branch October 14, 2026 12:14
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A tool-result continuation pauses on the calls the GMI already ran itself

1 participant