Repository navigation
fix(agency): graph, review-loop and debate gate the input each agent receives, and a replaced final text meets the output check - #393
Conversation
… graph, review-loop or debate agent Under the graph, review-loop and debate strategies the beforeAgent gate reads the task prompt, while the agent is sent an input built after the gate from what other agents wrote: the dependencies' outputs, the draft and the reviewer's feedback, the debate transcript. Through agency() with real agents and only fetch stubbed, an earlier agent's output that code-safety blocks must turn the approval into a rejection, so it never reaches the gated agent's request, and the strategy must go on as it does after any rejection. An output the check passes must reach the agent as the approver was shown it, with the approval's instructions after it.
A beforeReturn approval's modifications.output replaced the final text after the agency's output guardrails and the post-approval check had read the strategy's text, so a replacement was never checked. Through agency() with a real agent and only fetch stubbed: a replacement code-safety blocks must reject generate() and end stream() with the override, as a blocked final text does; a replacement the check passes is returned once the agency's output guardrail has received it; an approval without modifications returns the strategy's text as before.
Reviewer's GuideThe PR fixes HITL input-gating inconsistencies in graph, review-loop, and debate strategies by checking the exact input delivered to each agent, and hardens beforeReturn approvals so replacement output passes the same output guardrails and post-approval checks as strategy output. End-to-end tests cover generate/stream paths, approval instructions, blocked inputs, refusal behavior, and blocked or accepted replacements. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…receives These strategies ran the beforeAgent gate over the task prompt, then sent the agent an input built after the gate from other agents' output: the dependencies' outputs under graph, the draft and the reviewer's feedback under review-loop, the transcript under debate. The approver was shown the task and the post-approval check read the task, while the text another agent wrote reached the agent unchecked. Each strategy now builds the agent's input first and gates it with checkBeforeAgentInput(), as sequential, parallel and hierarchical do. The approval request and the post-approval check read the input the agent is sent, the check reads it with and without the approver's instructions, and the strategy sends the input the check read. A refused or blocked agent ends the run the way a rejection did before.
…rails and the post-approval check
maybeApproveFinalResult() ran the post-approval check over the strategy's
text and then returned the approval's modifications.output in its place,
after finalizeExecutionResult() had run the agency's output guardrails over
the strategy's text. A handler or webhook that answered with a replacement
had it returned without code-safety, pii-redaction or the output
guardrails reading it.
The replacement now goes through the agency's output guardrails, and the
one post-approval check reads the strategy's text and the replacement
beside it ({ output, returned }), so a replacement the check blocks fires
guardrailHitlOverride and rejects as a blocked final text does. An approval
without modifications is checked as before.
…eforeReturn replacement is checked The guide and the HitlConfig and ApprovalDecision TSDoc said an approval's instructions reach the agent only under the sequential, parallel and hierarchical strategies, that a beforeReturn replacement is not checked, and that the LLM judge rewrites the final answer. Every strategy now gates and sends the input the agent receives, other agents' output included, and applies the instructions; a replacement goes through the output guardrails and the post-approval check; hitl.llmJudge() returns no modifications. The timer note names checkBeforeAgentInput(), the gate the strategies call.
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. |
## [0.13.91](v0.13.90...v0.13.91) (2026-10-13) ### fix * **agency:** graph, review-loop and debate gate the input each agent receives, and a replaced final text meets the output check (#393) ([c1e716a](c1e716a))
|
The automated reviews of CodeRabbit, Out of Scope Changes. The CodeRabbit, Docstring Coverage. Every exported function this diff touches carries JSDoc: Codex connector. Reviewed Sourcery. No review: its weekly budget was spent. Master CI (run 38371248369) passed on the squash commit |
… output on their own under graph, review-loop and debate Since #393 the gate under these strategies reads the input the agent receives, and that input puts the strategy's own text after the task and after other agents' output. The post-approval check reads its texts as JSON, where a line break inside a text is escaped, and two code-safety patterns match a statement only at the end of the text they read. So a task ending in `rm -rf .`, which the gate blocked while it read the task alone, reached the agent, and an earlier agent's output ending in an unconditional `DELETE FROM <table>` did too wherever the strategy wrote after it. checkBeforeAgentInput() takes the texts the strategy built the input from, and the check reads each of them on its own beside the input: graph passes the task and each dependency's output, review-loop the task, the draft and the feedback, debate the motion and each argument so far. The input the approver is shown and the agent is sent is unchanged.
Summary
Two defects, confirmed in the code at master
e58b14a1. I first read them atbcf37db3; the 0.13.89 release and #306 landed in between, and neither touches these files. Each defect gets a test commit and a fix commit, and a docs commit follows.1. Graph, review-loop and debate gate the input each agent receives (#345)
Evidence. These three strategies ran the
beforeAgentgate over the task prompt, then sent the agent an input they built after the gate from other agents' output:checkBeforeAgent(name, prompt, ...)(graph.tsL153, L226), then the dependencies' outputs (L163-172, L232-241) sent bygenerate(context)andstream(context)(L175, L253, L274);prompt(review-loop.tsL149, L189) and were sent the draft and the reviewer's feedback (L159-165, L196-202);prompt(debate.tsL110) and sent the transcript (L118-152).The approver saw the task (
details.input,shared.tsL434), and the post-approval check read the task too (L461-485). The agent received text another agent wrote, and nothing checked it.Fix. Each of the three strategies now builds the agent's input first and gates it with
checkBeforeAgentInput(), the gate sequential, parallel and hierarchical use since #340 and #360. The approval request and the post-approval check read the input the agent is sent, and the strategy sendsgate.input, which is the text the check read. An approval'smodifications.instructionsnow reach the agent under these three strategies too, and the check reads the input with and without them, as #360 set. A refused or blocked agent ends the way a rejection already did: graph skips it and records[skipped by HITL]as its output, a refused producer ends the loop with the previous draft, a refused reviewer leaves the current draft as the result, and a refused debater sits out that turn.agentCalls[].inputkeeps the strategy's input, as under sequential.Tests (
src/api/__tests__/agency-strategy-input-gate.e2e.test.ts). These run the realagency(),agent(),generateText,streamTextandOpenAIProvider, with onlyfetchstubbed.opsis the agentbeforeAgentlists, and the handler approves. The cases cover graphgenerate(), graphstream(), review-loop (the reviewer reading the draft, and the producer reading the reviewer's feedback in the next round) and debate:code-safetyblocks (... rm -rf / ...).guardrailHitlOverridefires once (code-safety,agent:ops), the approver was shown the input that carried it, and no request fromopscarries it. The run ends as after any rejection: graph keeps the last result standing, a refused reviewer leaves the current draft, a refused producer ends with its previous draft, and the debate's judge still rules withoutops.ops's request carries it, and that request is exactly the input the approver was shown, with the approval's instructions after it.2. A
beforeReturnreplacement goes through the agency's output guardrails and the post-approval check (#366)Evidence.
finalizeExecutionResult()runs the agency'sguardrails.outputover the strategy's text before it asks for the approval (agency.tsL273-275, L292-302).maybeApproveFinalResult()runs the post-approval check over that text (L1510-1531) and then returns the approval'smodifications.outputin its place (L1533-1535). When a handler, or ahitl.webhook()endpoint, whose JSON becomes the decision (hitl.tsL192), answered{ approved: true, modifications: { output: 'Run rm -rf / on the host to finish.' } }, that text came back andguardrailHitlOverridenever fired.Fix.
maybeApproveFinalResult()now runs the replacement through the agency'sguardrails.outputthe same wayfinalizeExecutionResult()runs the strategy's text. One post-approval check then reads{ output, returned }: the strategy's text and the replacement. Without a replacement it reads{ output }as before. A replacement the check blocks firesguardrailHitlOverride(return) and rejects with the sameAgencyConfigErroras a blocked final text.hitl.guardrailOverride: falsestill turns off only the post-approval check.Tests (
src/api/__tests__/agency-return-approval.e2e.test.ts). These run the realagency(),agent(),generateText,streamTextandOpenAIProvider, with onlyfetchstubbed. The agency setsguardrails.outputandbeforeReturn:code-safetyblocks:generate()rejects withGuardrail overrode HITL approval for final output, andguardrailHitlOverridefires once (code-safety,return).stream():fullStreamandtextend with that error, and no part carries the replacement.Docs.
docs/safety/HUMAN_IN_THE_LOOP.mdand theHitlConfig.guardrailOverrideandApprovalDecision.modificationsTSDoc insrc/api/types.tsnow say three things. An approval's instructions apply under every strategy. Under graph, review-loop and debate, the input the approver sees and the check reads carries other agents' output. A replacement goes through the output guardrails and the post-approval check. The guide no longer says the LLM judge rewrites the final answer, becausehitl.llmJudge()returns onlyapprovedandreason(hitl.tsL360-363). Its timer note now namescheckBeforeAgentInput(), the gate the strategies call.Linked issues
Closes #345
Part of #366: this PR does the check half, so the replacement goes through the agency's output guardrails and the post-approval check. The other half stays open on #366:
parsedis still read from the strategy's text when an approval replaces it.Type of change
How this was verified
CI only. The two test commits went up alone, at
3f4782db.3f4782db, the two test commits alone.Test & Lintfailed only in the two new files: 13 tests failed and 10909 passed (2 files failed, 833 passed). Lint and typecheck passed. Under each of the five strategy paths, the blocked case failed becauseguardrailHitlOverridewas called 0 times, and the passing case failed becauseopswas sent an input other than the one the approver was shown. In the return cases,generate()resolved instead of rejecting, thestream()drain resolved instead of rejecting, and the output guardrail reported once instead of twice. The case without modifications passed.436e0670. All four jobs passed: Test & Lint, Batch-1 gated tests, Browser tests and the release dry run.agency-strategy-input-gate.e2e.test.tspassed 10 tests andagency-return-approval.e2e.test.tspassed 4. The suite ran 10922 tests with none failing, across 835 test files.436e0670, and their threads are answered on this PR as they arrive.Migration notes
None. No signatures or options change. An approval without modifications is checked and sent as before, and the post-approval check still reads everything it read before.
Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).