Repository navigation
fix(guardrails): a blocked tool call is refused before it runs, and a blocked external call leaves the saved pause - #384
Conversation
…s the tool A guard that sets evaluateToolCalls and blocks shell_execute, on the real path through processRequest() with a real GMI and the tool registered: the tool's execute must not run and the model's next call must carry the refusal. A call the guard allows still runs, and a guard without the flag is never asked about the call.
A guard that sets evaluateToolCalls and blocks shell_execute, on the real path through processRequest(), handleToolResult() and resumeExternalToolRequest() with a GMI that stops for host calls: after the block, getPendingExternalToolRequest() must return nothing, the conversation must answer the call with a refused tool result, and the stream the call was blocked on must be closed. A call the guard allows still pauses as before.
Reviewer's GuideAdds real-path integration tests covering guardrails configured with File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
… it runs A call with executionMode 'internal' ran in the GMI's tool loop while the output guard was still judging its chunk on the stream, so a block ended the stream but the tool ran anyway. AgentOS now builds a tool-call gate from the output guards that set evaluateToolCalls (createToolCallGate, over the same dispatcher evaluation the stream uses) and hands it to the orchestrator on processRequest(), handleToolResults() and resumeExternalToolRequest(). The orchestrator gives the GMI a gate that judges each call as the chunk the stream carries for it, and the GMI asks it before processToolCall: a BLOCK, or a SANITIZE applied as one, turns the call into a refused tool result with the permission-denied code, as a permission refusal is recorded, and the tool is not called. A gate that throws refuses the call. A continuation keeps the gate of the turn it continues when it is given none. Without an opted-in guard there is no gate and nothing changes.
The orchestrator saves an actionable call's pause (the pending request on the conversation and an assistant message with the tool_calls) before or, for a GMI that streams the call, just after the chunk goes out. When an output guard blocked that chunk, getPendingExternalToolRequest() kept returning the call until the conversation's next turn ended, so a host that resumes saved pauses after a restart ran the blocked call, and the history kept a tool_calls message no result answered. The verdict now lists the actionable calls a block withheld in toolCallIds, for a block on the tool-call chunk and for a hold-mode block on the text before it. AgentOS's onVerdict handler on processRequest(), handleToolResults() and resumeExternalToolRequest() hands them to the orchestrator, which waits for the stream's turn or resumed turn to end and, when the conversation's pending request is that stream's, records a refused tool result for each of its calls, clears the pending request and closes the stream. The handler never throws into the stream.
…locked pause The Tool Calls section of the usage guide and the TOOL_CALL_REQUEST section of the guide to writing guardrails described both old limits: a block did not stop a call the runtime runs itself, and a blocked call's pause stayed in getPendingExternalToolRequest() until the next turn ended.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70f3bd6f4b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…s a call A streaming GMI's turn saves its pause after the call's chunk goes out, so the docs no longer say the pause was saved before it. The refusal recorded for a withheld call names the blocked reply, which also covers a hold-mode block on the text before the call.
…tes tool calls A host without an output guard that sets evaluateToolCalls has no tool-call gate, so processRequest, handleToolResult and resumeExternalToolRequest hand the orchestrator the same arguments they did before, with no guards argument.
|
@coderabbitai review |
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e598c7cd8a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
## [0.13.86](v0.13.85...v0.13.86) (2026-10-13) ### fix * **guardrails:** a blocked tool call is refused before it runs, and a blocked external call leaves the saved pause (#384) ([dcfe023](dcfe023)) * **meetings:** the channel's follow-ups: lease, delivery, store and transport edge cases (#386) ([d925ceb](d925ceb)) ### docs * correct the GMI paper's T1 grading, preset moods and gate re-run cap (#385) ([4f649e6](4f649e6)) * fourteenth round of audit follow-ups (the P2 leftovers of the cold reads) (#377) ([0a7da7d](0a7da7d))
Summary
Two defects in how AgentOS applies an output guard that sets
config.evaluateToolCalls(#340, #360), each confirmed in the code at master 65802d3, each with a test on the real path that fails before its fix.#343: a blocked call the runtime runs itself still ran
Evidence (65802d3). The GMI yields the
TOOL_CALL_REQUESTchunk of its own tool round withexecutionMode: 'internal'(GMI.tsL1730-1740) and then runs the call in its tool loop (L1929,toolOrchestrator.processToolCall). Nothing between the two waits for the stream's reader:AsyncStreamClientBridge.sendChunkqueues the chunk and returns. The guard judged the chunk on the stream while the tool ran, and its block ended the stream after the tool had been called.Fix (the design recorded in #343).
createToolCallGate(services, context)inguardrailDispatcher.tsjudges aTOOL_CALL_REQUESTchunk with the guards that setevaluateToolCalls, throughParallelGuardrailDispatcher.evaluateToolCall, the evaluationwrapOutputruns on a stream's tool-call chunk (now shared by both); it is undefined when no guard sets the flag. AgentOS builds it from the same services and context as its output wrapper onprocessRequest(),handleToolResults()andresumeExternalToolRequest(), and hands it to the orchestrator (orchestrateTurn,orchestrateToolResultsandorchestrateResumedToolResultstake an optional{ toolCallGate }). The orchestrator gives the GMI a gate,GMITurnInput.metadata.toolCallGateon a turn andoptions.toolCallGateonhandleToolResult(s)for a continuation, that judges each call as the chunk the stream carries for it, holding that one call. The GMI asks it beforeprocessToolCall. A BLOCK, or a SANITIZE applied as one, records a refused tool result (isError, codeAUTH_PERMISSION_DENIED, the guard's reason as the message, its id and reason code in the details), as a permission refusal is recorded; the tool is not called, and the model reads the refusal on its next step. A gate that throws refuses the call. A continuation given no gate asks the gate of the turn it continues. The stream's evaluation of the chunk is unchanged, so a guard is asked about an internal call twice: by the gate before the call runs, and on the stream's chunk, where a block still ends the host's stream.Test.
tests/api/AgentOS.processRequest.toolCallGuards.integration.spec.ts, "on a call the runtime runs itself":AgentOS.initialize(), the orchestrator, the tool orchestrator and aGMI, withshell_executeregistered throughconfig.toolsand the model stubbed at the provider. A block, and a sanitize, leave the tool'sexecuteuncalled, and the model's next request carries the refusal. A call the guard flags runs; a guard without the flag is never asked about the call.#344: a blocked host call stayed in the saved pause
Evidence (65802d3). The orchestrator saves an actionable call's pause (
AgentOSOrchestrator.tsL857-866): after it pushed the chunk for a GMI that streams the call (L808), before it for one that does not (L868-885); a continuation saves and then pushes (ExternalToolResultHandler.tsL380-402). The save adds an assistant message carrying thetool_callsand the pending-request metadata (L677-688). The verdict on a blocked tool-call chunk named no calls (ParallelGuardrailDispatcher.tsL829-838; in hold mode a block on the text before the chunk withholds the chunk too, L842-868), theonVerdicthandler AgentOS passed rewrote a stored reply and nothing else (AgentOS.tsL2064, L2291, L2533), and the pause was cleared only when the conversation's next turn ended (AgentOSOrchestrator.tsL973-975). A host that resumes saved pauses after a restart got the blocked call back fromgetPendingExternalToolRequest(), and the history kept atool_callsmessage that no result answered.Fix (the design recorded in #344).
GuardrailOutputVerdict.toolCallIdslists the actionable calls a block withheld: on a block of the tool-call chunk, and on a hold-mode block of the text before an actionable chunk. AgentOS'sonVerdicthandler on all three entry points hands them toAgentOSOrchestrator.discardBlockedToolCalls(). It waits for the stream's turn or resumed turn to end, since a streaming GMI's turn saves its pause after the chunk, and, when the conversation's pending request is that stream's and holds one of the calls, records a refused tool result for each call of the pause (worded as the GMI words a refused result), clears the pending request and closes the stream. All of it completes before the verdict reaches the host. A failure is logged and the stream's verdict stands.Test. Same spec, "on a call the host executes": a GMI that stops for a host call, on the real path through
processRequest(),handleToolResult()andresumeExternalToolRequest(). After the block,getPendingExternalToolRequest()returns null, the conversation holds a tool message answering the call with the refusal, andhandleToolResult()on the blocked stream yields an error without reaching the GMI. A call the guard allows still pauses as before.Docs
docs/safety/GUARDRAILS_USAGE.md("Tool Calls"): the config table row, the Block bullet, which read as if a host that resumes saved pauses would not run a blocked call while the pause in fact stayed, and the bullet on calls the runtime runs itself.docs/safety/CREATING_GUARDRAILS.md(TOOL_CALL_REQUEST) and theevaluateToolCallsJSDoc stated the same two limits.docs/safety/HUMAN_IN_THE_LOOP.md(there is nodocs/HUMAN_IN_THE_LOOP.md) states neither limit: the usage guide linked to it as the way to stop an internal call, and the link stays as the way to have a person approve a tool before it runs.Found while reading, not changed here
The
GMI'shandleToolResults()returns, inGMIOutput.toolCalls, the calls its continuation already ran in its own tool loop, andExternalToolResultHandler.orchestrateToolResultstreats anytoolCallsas a new host pause (L380), so a resumedGMIthat used one of its own tools stops again for that call.Linked issues
Fixes #343
Fixes #344
Type of change
How this was verified
CI on this pull request.
expect(execute).not.toHaveBeenCalled()(executewas called once), and the turn, continuation and resume cases atgetPendingExternalToolRequest(...)toBeNull()(the saved pause came back). The three cases that pin the unchanged behavior passed.tests/api/AgentOS.spec.ts:597checks the argumentsresumeExternalToolRequest()hands the orchestrator, and the fixes added a fourth,{ toolCallGate: undefined }. e598c7c hands the orchestrator a guards argument only when a guard evaluates tool calls, so a host without one calls it exactly as before.Migration notes
None. Every new parameter and field is optional, and a host whose output guards do not set
evaluateToolCallssees no change.Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).Summary by Sourcery
Ensure output guardrails refuse blocked tool calls before execution and clean up any saved external-tool pause they reject.
Bug Fixes:
Enhancements:
Documentation:
Tests:
Summary by CodeRabbit