Repository navigation
fix(guardrails): close a blocked stream even when its refusal cannot be saved - #387
Merged
jddunn merged 3 commits intoOct 13, 2026
Merged
Conversation
…t be saved With conversational persistence on and a store that refuses the save recording the refusal, a block on the call a turn stops for must still close the stream: handleToolResult() on it must end in an error and never reach the GMI. The conversation in memory must still drop the pause and answer the call with the refused tool result.
Reviewer's GuideThis PR adds a real-path integration regression test covering the guardrail failure case where saving a refusal throws, ensuring the blocked stream is still finalized and cannot be continued while the in-memory refusal state remains correct. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…be saved When an output guard blocked the call a stream stopped for, the pause was dropped in memory and the conversation saved before the orchestrator removed the stream's context and closed the stream. A store that refused the save threw past both steps; AgentOS logged the error, and the stream stayed open with its context, so handleToolResult() continued it with a result for the blocked call. discardPendingExternalToolRequest() now removes the stream's context before the save and closes the stream whether or not the store takes it; a refused save rejects once the stream is closed. The warning AgentOS logs says the stored conversation keeps the pause until the conversation is saved again.
The Block bullet of the usage guide's Tool Calls section says the stream is closed even when the conversation store refuses the save, and when the stored conversation can still hold the pause after a restart.
jddunn
marked this pull request as ready for review
October 13, 2026 07:16
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. |
8 of 13 tasks
github-actions Bot
pushed a commit
that referenced
this pull request
Oct 13, 2026
## [0.13.88](v0.13.87...v0.13.88) (2026-10-13) ### fix * **guardrails:** close a blocked stream even when its refusal cannot be saved (#387) ([864941b](864941b)) * **meetings:** the follow-ups' forward fixes: the interlock's order on the worker's clock, the loop's two passes, handlers before destinations, the late notice first, finals during startCapture (#388) ([16dce24](16dce24))
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 follow-up to #384 from its review: the Codex thread on
ExternalToolResultHandler.tsL772, confirmed in the code at master df4f0b2, with a test on the real path that fails before the fix.A block whose refusal the store refused to save left the stream open
Evidence (df4f0b2). When an output guard blocks the call a stream stopped for,
discardPendingExternalToolRequest()records the refused tool result, clears the pending request in memory and then awaits the conversation's save with no catch (ExternalToolResultHandler.tsL765-773).discardBlockedToolCalls()deletes the stream's context and closes the stream only after that call returns (AgentOSOrchestrator.tsL724-737), and AgentOS'sonOutputVerdictlogs the error and goes on (AgentOS.tsL1515-1521). A store that refused the save left the stream open with its context:handleToolResults()registered on it (AgentOS.tsL2293), the orchestrator found the context, the one thing it checks (ExternalToolResultHandler.tsL208-219), and the GMI received a result for the blocked call.Fix.
discardPendingExternalToolRequest()now does the whole drop: once it has recorded the refusal and cleared the pending request, it removes the stream's context, saves the conversation, and closes the stream in afinally, so the stream is closed whether or not the store takes the save; a refused save rejects after that.discardBlockedToolCalls()returns what the handler reports. The warningonOutputVerdictlogs says what a refused save leaves: the stored conversation keeps the pause until the conversation is saved again.Test.
tests/api/AgentOS.processRequest.toolCallGuards.integration.spec.ts, "a block whose refusal the store fails to save still closes the stream, so the call cannot be continued on it": the real path throughprocessRequest()andhandleToolResult()with the GMI that stops for a host call, and a conversation manager whosesaveConversationrefuses the save that records the refusal, as a store does during an outage. The case asserts that the store refused that save, that the conversation in memory has no pause and answers the call with the refusal, and thathandleToolResult()on the blocked stream yields one error without reaching the GMI.What a refused save leaves in the store
The thread also notes that a restart may offer the stored pause again. The conversation in memory holds the refusal and no pause, and every later save of it stores both: the next turn's inbound save (
TurnExecutionPipeline.tsL418-450), the save before the conversation manager evicts it (ConversationManager.tsL466-468) and the save at shutdown (L812-822). A restart finds the pause stored only when the process stopped before any of those saves succeeded. A store that refuses writes cannot take a durable record of the refusal either, so this change does not try; the warning names the stream and the calls, and the Block bullet ofdocs/safety/GUARDRAILS_USAGE.md("Tool Calls") says when the stored pause can come back.Linked issues
Follows #384 (for #344).
Type of change
How this was verified
CI on this pull request.
expect(gmi.handleToolResult).not.toHaveBeenCalled(): the GMI received the blocked call's result (call-shell-1,{ exitCode: 0 }). The continuation then ended in an error only because the same store refused the continuation's own save, after the GMI had taken the result.Migration notes
None. A store that takes the save sees no change; with one that refuses it, the stream is closed as it is after a save that succeeds.
Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).Summary by CodeRabbit
Bug Fixes
Documentation