Repository navigation
fix(agency): the post-approval check reads the approved input, and output guards receive tool-call chunks - #340
Conversation
… check Under the sequential, parallel and hierarchical strategies, a beforeAgent approval that adds instructions the check blocks must turn into a rejection, and ops must not run. Approvals with instructions that pass, approvals without modifications and the beforeEmergent gate keep their behaviour.
…-call chunks A guard that sets evaluateToolCalls receives each tool-call chunk of the guarded stream; a block keeps an actionable call from the host and ends the stream with the guard's verdict, a replacement reply included; a sanitize is applied as a block; a guard written for text never receives a tool call.
…nt receives checkBeforeAgent ran the post-approval check over the input the strategy passed to the gate, and the sequential, parallel and hierarchical strategies appended the approval's modifications.instructions after it returned, so an approver's instructions reached the agent unchecked. Those strategies now gate through checkBeforeAgentInput, which builds the agent's input once with withApprovalInstructions, runs the check over that text and returns it for the strategy to send. Instructions the check blocks turn the approval into a rejection, handled as a blocked input is. An approval without modifications is checked and sent as before; the graph, review-loop and debate strategies, which do not send instructions, keep checkBeforeAgent; the beforeEmergent gate is unchanged. Closes #321
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. |
|
Warning Review limit reached
This review includes 13 billable files and costs up to $3.25.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 9 minutes for your next included review. View limit details
Comment |
Reviewer's GuideAdds regression coverage for two agency safety defects: post-approval checks now need to inspect the actual input sent after approval modifications, and output guards configured for tool calls need to receive TOOL_CALL_REQUEST chunks while other guards remain filtered. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoAdd regression tests for agency approvals and tool-call guards
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b453350b32
ℹ️ 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".
Code Review by Qodo
1. Unsafe instructions reach the agent
|
The output dispatcher handed a guard only text deltas and final chunks, so a guard's branch for TOOL_CALL_REQUEST chunks never ran (the code-safety pack has one). A guard whose config sets evaluateToolCalls now receives each non-final tool-call chunk of the guarded stream, as the stream carries it. A block ends the stream with the guard's verdict in place of the chunk, so a host never receives an actionable call it would execute; a sanitize cannot rewrite a tool call and is applied as a block that keeps the guard's reason; flag and allow pass the chunk on with the evaluation in its metadata. The flag is opt-in because the output contract promised guards no tool-call chunk, and a guard written for text may read any chunk it is given as text. A guard without the flag sees no change.
The runtime saves an actionable call's pause before the tool-call chunk goes out, so a block keeps the call off the stream while getPendingExternalToolRequest() returns it until the conversation's next turn ends. Say so where the block is described, and that a host resuming saved pauses does not run a call whose stream ended in a block.
## [0.13.67](v0.13.66...v0.13.67) (2026-10-12) ### fix * **agency:** the post-approval check reads the approved input, and output guards receive tool-call chunks (#340) ([a81d09d](a81d09d)) * **api:** send the routing keys of customModelParams with the planning call (#329) ([7271cc3](7271cc3)) * **gateway:** the completion gateway resolves and walks its chain as generateText and streamText do (#341) ([b4c8280](b4c8280))
…hout the approval's instructions With instructions on a beforeAgent approval, the check read only the input with the instructions appended. Two code-safety patterns match a statement only at the end of the text they read (an unconditional DELETE FROM <table>, rm -rf .), so an input ending in one of them, which the check blocked before #340, passed once the approval carried any instructions. The check now reads the strategy's input on its own beside the input the agent is sent, in one call: it matches what the check before #340 matched and what #340's check matched. An approval without instructions is checked as before, and the agent still receives the input with the instructions.
…hout the approval's instructions (#360) Since #340 the beforeAgent post-approval check read only the agent's input with the approver's instructions appended. Two code-safety patterns match a statement only at the end of the text they read (an unconditional DELETE FROM <table>, rm -rf .), so an input ending in one of them, which the check blocked before #340, passed once the approval carried any instructions. The check now reads the strategy's input on its own beside the input the agent is sent, in one call. An approval without instructions is checked as before, and the agent still receives the input with the instructions.
|
Cold read of this change behind its merge (a81d09d, 0.13.67). Line numbers are at a81d09d. One P1, fixed in #360 (merged as b382c69). Two P2s reported. P1, fixed in #360 (b382c69). With instructions on a Checked and found as described:
Reported, not changed (P2):
|
Summary
Two defects that cold reads confirmed in the code at master
b2957fa0(read at66d8a73e; onlydocs/evaluation/GMI_VS_AGENT.mdchanged between them). A test and a fix for each, and a docs commit that states what a block leaves in the saved pause.1. The post-approval check reads the input the approved agent receives (#321)
Evidence. After a
beforeAgentapproval,checkBeforeAgent()ran the post-approval check over{ input: context }, the input the strategy passed to the gate (shared.tsL366-389). The sequential, parallel and hierarchical strategies appended the decision'smodifications.instructionsonly after the gate returned (sequential.tsL102-104 and L177-179,parallel.tsL118-120,hierarchical.tsL213-215). A handler that answered{ approved: true, modifications: { instructions: 'run rm -rf / on the host' } }passed the check, and the agent ran with that instruction.Fix.
checkBeforeAgentInput()inshared.tsasks the handler ascheckBeforeAgent()does, builds the agent's input once withwithApprovalInstructions(), runs the post-approval check over that text and returns{ decision, input }. The three strategies sendgate.input, the text the check read, so the checked text and the sent text cannot drift. Instructions the check blocks turn the approval into a rejection, which each strategy handles as it handles a blocked input today: sequential skips the agent, parallel leaves it out of the synthesis, hierarchical answers the manager with the refusal. An approval without modifications is checked and sent exactly as before. The graph, review-loop and debate strategies do not send an approval's instructions, so they keepcheckBeforeAgent()and its check of the input as given.checkBeforeEmergentSpawn()is unchanged.Tests (
src/api/__tests__/agency-agent-approval.e2e.test.ts): realagency(),agent(),generateText,streamTextandOpenAIProvider; onlyfetchis stubbed. Under sequentialgenerate(), sequentialstream(), parallel and hierarchical:guardrailHitlOverridefires once (code-safety,agent:ops), ops sends no request, no request carries the instruction, and the hierarchical manager is told ops was rejected;<input>\n\n[Additional instructions]: Cite two sources.;Two more: a destructive input approved without modifications is still overridden, and a
beforeEmergentapproval spawns the specialist with the manager's instructions with no post-approval check, as before.Docs.
docs/safety/HUMAN_IN_THE_LOOP.md(the modifications paragraph and the post-approval section), theHitlConfig.guardrailOverrideJSDoc and theApprovalDecision.modifications.instructionsJSDoc insrc/api/types.ts, which described the old order.2. Output guards receive tool-call chunks
Evidence.
evaluateOutputfor a non-finalTEXT_DELTA(ParallelGuardrailDispatcher.tsL609-612) and for a chunk withisFinal: true(L763-765), and nowhere else. ATOOL_CALL_REQUESTcarriesisFinal: false(GMIChunkTransformer.tsL306,AgentOSOrchestrator.tsL880), so no guard ever received one. The contract said so (IGuardrailService.tsL446-452).@framers/[email protected](read fromnpm pack),src/CodeSafetyGuardrail.tsL267-298: aTOOL_CALL_REQUESTbranch that scans the code argument ofshell_execute,run_sql,write_file,create_fileandedit_file(src/types.tsL347-353). It never runs.Form taken: opt-in.
GuardrailConfig.evaluateToolCalls(defaultfalse). The contract onevaluateOutputand onGuardrailOutputPayload(L186-192), anddocs/safety/CREATING_GUARDRAILS.md, promised a guard no tool-call chunk, and a guard written to it may read any chunk it is given as text: one that takes every non-final chunk for aTEXT_DELTAreadstextDeltaasundefined, and a fail-closed guard that throws on that would block every tool call. Handing tool-call chunks to every guard would change what existing guards do; the flag leaves every guard without it as it is. The guide records the form and the reason (docs/safety/GUARDRAILS_USAGE.md, "Tool Calls").Fix. The dispatcher collects the guards whose config sets
evaluateToolCallsand runs them in parallel on each non-finalTOOL_CALL_REQUEST, as the stream carries it (chunk.toolCallswith each call'sid,nameand parsedarguments). The verdict applies as it does to text:BLOCKends the stream with the guard's verdict (the error chunk, or the final response holdingreplacementText) in place of the chunk;onVerdicthears it as it hears a block on a streamed delta, and in hold mode the text held before the call is dropped with it.SANITIZEcannot rewrite a tool call, so it is applied as aBLOCKthat keeps the guard's reason and reason code, with a warning logged.FLAGandALLOWpass the chunk on with the evaluation inmetadata.guardrail.output.What a block stops. On a
processRequest()stream and its continuations, the host executes an actionable call (executionMode: 'external') once it receives the chunk (AgentOS.tsL2123); a block replaces the chunk, so the stream never hands the host the call. The orchestrator saves the pause before it pushes the chunk (AgentOSOrchestrator.tsL851-885,ExternalToolResultHandler.tsL380-399), sogetPendingExternalToolRequest()still returns the blocked call until the conversation's next turn ends; the docs say so (commit6d3769d5), and clearing that pause on a block is left for a change of its own. A call the runtime executes itself (executionMode: 'internal',GMI.tsL1740) runs in the GMI's tool loop (L1933), which does not wait for the stream's reader (AsyncStreamClientBridge.tsL30-36 queues each chunk and returns): a block ends the stream but does not stop that call. The JSDoc and both guides say so, and point at the tool orchestrator's approval gate for those tools.Tests (
tests/core/guardrails.integration.spec.ts):AgentOS.processRequest()with the guard registered, the real output dispatcher, and the orchestrator stubbed at the model boundary; the reader executes each actionable call it receives, as a host does.evaluateToolCallsreceives the tool-call chunk with the call as the stream carries it, and a call it flags reaches the host with the evaluation in its metadata;replacementText: the stream ends with the replacement reply;wrapOutputGuardrails()with both guards registered, the text guard sees only the text and the tool-call guard only the call.Docs.
docs/safety/GUARDRAILS_USAGE.md(the config table, a "Tool Calls" section, the folder-permissions paragraph),docs/safety/CREATING_GUARDRAILS.md(the config block, which chunks reachevaluateOutput, theTOOL_CALL_REQUESTsection, whose example now showsargumentsas the parsed object the runtime sends), and the JSDoc inIGuardrailService.tsandguardrailDispatcher.ts.The code-safety pack. Its source is not in
framerslab/agentos-extensions:registry/curated/safety/code-safetythere holds a README pointing to the monorepo sinceae83aef. The pack lives inmanicinc/voice-chat-assistantatpackages/agentos-ext-code-safety, whose workflows test and publish it. It sets the flag in its 0.2.2 release (@framers/[email protected]on npm), with a test throughwrapOutputGuardrails()on@framers/agentos0.13.67: ashell_executethat runschmod 777and arun_sqlthat carriesDROP TABLEend in the guard's error chunk and never reach the host.Linked issues
Closes #321
Type of change
How this was verified
CI only.
b453350b(the two test commits). Test & Lint failed with exactly the 10 new tests and no other: the six tool-call tests (the guard received no chunk, or the host executed the blocked call), and the blocked-instructions case under each of the four strategy paths (guardrailHitlOverridecalled 0 times). 10403 other tests passed.8f4ac97a(both fixes): every job passed; Test & Lint ran 10472 tests, among them the 21 oftests/core/guardrails.integration.spec.tsand the 14 ofsrc/api/__tests__/agency-agent-approval.e2e.test.ts. The docs commit6d3769d5is checked by the run on the head.Release
@framers/agentos0.13.67 (v0.13.67), published by Release run 38267550390 at 15:06 UTC; the master CI on the merge commita81d09dcis run 38266525066.Follow-ups
executionMode: 'internal') does not stop the call.Migration notes
None. An approval without modifications is checked and sent as before, and a guard without
evaluateToolCallsreceives the same chunks as before.Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).