Skip to content

fix(agency): the post-approval check reads the approved input, and output guards receive tool-call chunks - #340

Merged
jddunn merged 5 commits into
masterfrom
fix/approval-instructions-and-tool-call-guards
Oct 12, 2026
Merged

jddunn merged 5 commits into
masterfrom
fix/approval-instructions-and-tool-call-guards

Conversation

@jddunn

@jddunn jddunn commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Two defects that cold reads confirmed in the code at master b2957fa0 (read at 66d8a73e; only docs/evaluation/GMI_VS_AGENT.md changed 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 beforeAgent approval, checkBeforeAgent() ran the post-approval check over { input: context }, the input the strategy passed to the gate (shared.ts L366-389). The sequential, parallel and hierarchical strategies appended the decision's modifications.instructions only after the gate returned (sequential.ts L102-104 and L177-179, parallel.ts L118-120, hierarchical.ts L213-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() in shared.ts asks the handler as checkBeforeAgent() does, builds the agent's input once with withApprovalInstructions(), runs the post-approval check over that text and returns { decision, input }. The three strategies send gate.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 keep checkBeforeAgent() and its check of the input as given. checkBeforeEmergentSpawn() is unchanged.

Tests (src/api/__tests__/agency-agent-approval.e2e.test.ts): real agency(), agent(), generateText, streamText and OpenAIProvider; only fetch is stubbed. Under sequential generate(), sequential stream(), parallel and hierarchical:

  • an approval whose instructions the check blocks: guardrailHitlOverride fires once (code-safety, agent:ops), ops sends no request, no request carries the instruction, and the hierarchical manager is told ops was rejected;
  • an approval whose instructions pass: ops's request carries <input>\n\n[Additional instructions]: Cite two sources.;
  • an approval without modifications: ops's input is unchanged.

Two more: a destructive input approved without modifications is still overridden, and a beforeEmergent approval 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), the HitlConfig.guardrailOverride JSDoc and the ApprovalDecision.modifications.instructions JSDoc in src/api/types.ts, which described the old order.

2. Output guards receive tool-call chunks

Evidence.

Form taken: opt-in. GuardrailConfig.evaluateToolCalls (default false). The contract on evaluateOutput and on GuardrailOutputPayload (L186-192), and docs/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 a TEXT_DELTA reads textDelta as undefined, 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 evaluateToolCalls and runs them in parallel on each non-final TOOL_CALL_REQUEST, as the stream carries it (chunk.toolCalls with each call's id, name and parsed arguments). The verdict applies as it does to text:

  • BLOCK ends the stream with the guard's verdict (the error chunk, or the final response holding replacementText) in place of the chunk; onVerdict hears it as it hears a block on a streamed delta, and in hold mode the text held before the call is dropped with it.
  • SANITIZE cannot rewrite a tool call, so it is applied as a BLOCK that keeps the guard's reason and reason code, with a warning logged.
  • FLAG and ALLOW pass the chunk on with the evaluation in metadata.guardrail.output.
  • The first block in registration order is the verdict; a guard's timeout and fail-closed posture apply as on text.

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.ts L2123); 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.ts L851-885, ExternalToolResultHandler.ts L380-399), so getPendingExternalToolRequest() still returns the blocked call until the conversation's next turn ends; the docs say so (commit 6d3769d5), and clearing that pause on a block is left for a change of its own. A call the runtime executes itself (executionMode: 'internal', GMI.ts L1740) runs in the GMI's tool loop (L1933), which does not wait for the stream's reader (AsyncStreamClientBridge.ts L30-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.

  • a guard that sets evaluateToolCalls receives 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;
  • a block: the host never executes the call, and the stream ends with the guard's error chunk (code, reason, guard id);
  • a block with replacementText: the stream ends with the replacement reply;
  • a sanitize: applied as a block that keeps the guard's reason and code;
  • an internal call reaches the guard, and a block ends the stream;
  • a guard written for text, without the flag, never receives the call, which reaches the host as before;
  • through 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 reach evaluateOutput, the TOOL_CALL_REQUEST section, whose example now shows arguments as the parsed object the runtime sends), and the JSDoc in IGuardrailService.ts and guardrailDispatcher.ts.

The code-safety pack. Its source is not in framerslab/agentos-extensions: registry/curated/safety/code-safety there holds a README pointing to the monorepo since ae83aef. The pack lives in manicinc/voice-chat-assistant at packages/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 through wrapOutputGuardrails() on @framers/agentos 0.13.67: a shell_execute that runs chmod 777 and a run_sql that carries DROP TABLE end in the guard's error chunk and never reach the host.

Linked issues

Closes #321

Type of change

  • Bug fix
  • Feature
  • Documentation
  • Tests

How this was verified

CI only.

  • Red: run 38264283712 on 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 (guardrailHitlOverride called 0 times). 10403 other tests passed.
  • Green: run 38264956876 on 8f4ac97a (both fixes): every job passed; Test & Lint ran 10472 tests, among them the 21 of tests/core/guardrails.integration.spec.ts and the 14 of src/api/__tests__/agency-agent-approval.e2e.test.ts. The docs commit 6d3769d5 is checked by the run on the head.

Release

@framers/agentos 0.13.67 (v0.13.67), published by Release run 38267550390 at 15:06 UTC; the master CI on the merge commit a81d09dc is run 38266525066.

Follow-ups

Migration notes

None. An approval without modifications is checked and sent as before, and a guard without evaluateToolCalls receives the same chunks as before.

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.

… 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
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 12, 2026 14:37
@sourcery-ai

sourcery-ai Bot commented Oct 12, 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 4 days and 16 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T14:39:24.891824Z b453350 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 13 billable files and costs up to $3.25.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 3e6712a0-2d9e-437d-8c1d-2ae8bbf2d60c

📥 Commits

Reviewing files that changed from the base of the PR and between b2957fa and 6d3769d.


📒 Files selected for processing (13)
  • docs/safety/CREATING_GUARDRAILS.md
  • docs/safety/GUARDRAILS_USAGE.md
  • docs/safety/HUMAN_IN_THE_LOOP.md
  • src/api/__tests__/agency-agent-approval.e2e.test.ts
  • src/api/runtime/strategies/hierarchical.ts
  • src/api/runtime/strategies/parallel.ts
  • src/api/runtime/strategies/sequential.ts
  • src/api/runtime/strategies/shared.ts
  • src/api/types.ts
  • src/safety/guardrails/IGuardrailService.ts
  • src/safety/guardrails/ParallelGuardrailDispatcher.ts
  • src/safety/guardrails/guardrailDispatcher.ts
  • tests/core/guardrails.integration.spec.ts

  • 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 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 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

Change Details Files
Ensures post-approval guardrails evaluate the complete agent input, including approver-supplied instructions, before execution.
  • Adds end-to-end coverage across sequential generate/stream, parallel, and hierarchical strategies.
  • Verifies destructive additions are rejected before the target agent runs, benign additions are appended and allowed, and unmodified approvals retain prior behavior.
  • Preserves the existing beforeEmergent approval path without applying the post-approval check.
src/api/__tests__/agency-agent-approval.e2e.test.ts
Extends output guard dispatching so tool-call request chunks are evaluated by guards configured for tool calls while preserving text-guard behavior.
  • Adds integration coverage for flagged, blocked, replacement, and sanitize tool-call verdicts.
  • Verifies both externally actionable and internally executed tool calls are guarded before execution.
  • Confirms non-tool-call guards receive only text/final chunks and allowed tool calls still reach the host.
tests/core/guardrails.integration.spec.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#321 Run the post-approval guardrail check on the effective agent input, including any instructions added by the approval, so blocked instructions prevent the agent from running. ❌ The diff adds tests for the expected behavior but contains no implementation changes to check the approval-modified input. The existing check therefore still reads the original input.
#321 Share the logic for appending approval instructions across the sequential, parallel, and hierarchical strategies so the checked input matches the input sent to the agent. ❌ No strategy or shared-helper implementation changes are present in the diff.

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

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add regression tests for agency approvals and tool-call guards

🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Test that post-approval checks include approver-added instructions across agency strategies.
• Test tool-call guard verdicts, host visibility, and text-only guard isolation.
• This diff adds tests only; it does not include the production fixes.
Diagram

graph TD
  ApprovalTests["Agency approval tests"] --> Strategies["Agency strategies"] --> ApprovalGate["Before-agent gate"] --> PostCheck["Post-approval check"]
  GuardTests["Tool-call guard tests"] --> ProcessRequest["AgentOS processRequest"] --> Dispatcher["Output dispatcher"] --> Host["Host consumer"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use isolated unit tests
  • ➕ Faster execution and more targeted failures.
  • ➖ Would not verify strategy wiring, streamed responses, or host-visible tool calls.

Recommendation: Keep the integration-level regression tests because both defects concern behavior across component boundaries. The provided diff contains no production fixes, so the asserted behavior still needs implementation and verification before this can be described as a completed bug fix.

Files changed (2) +379 / -0

Tests (2) +379 / -0
agency-agent-approval.e2e.test.tsCover approver-added instructions across agency strategies +217/-0

Cover approver-added instructions across agency strategies

• Adds fetch-stubbed end-to-end tests for sequential generation and streaming, parallel execution, and hierarchical delegation. They assert that destructive added instructions prevent the ops agent from running, benign instructions reach its input, and approvals without modifications and beforeEmergent approvals retain their expected behavior.

src/api/tests/agency-agent-approval.e2e.test.ts

guardrails.integration.spec.tsCover output guard decisions on tool-call chunks +162/-0

Cover output guard decisions on tool-call chunks

• Adds processRequest and dispatcher integration scenarios for guards configured to evaluate tool calls. The tests assert flag metadata, blocking and replacement responses, sanitize-as-block behavior, internal-call coverage, and isolation of text-only guards from tool-call chunks.

tests/core/guardrails.integration.spec.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (1) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Unsafe instructions reach the agent 📎 Requirement gap ⛨ Security
Description
checkBeforeAgent() still receives the original strategy context, while
modifications.instructions is appended only when the strategy invokes the agent. With benign
PROMPT and TASK inputs plus destructive approved instructions, the new sequential, parallel, and
hierarchical cases cannot observe a post-approval block and the agent can receive the unchecked
text.
Code

src/api/tests/agency-agent-approval.e2e.test.ts[R134-143]

+  it('with instructions the post-approval check blocks: the approval is a rejection and ops never runs', async () => {
+    const handler = approve({ instructions: DESTRUCTIVE });
+    const guardrailHitlOverride = vi.fn();
+    await run(team(strategy, handler, { guardrailHitlOverride }));
+    expect(handler).toHaveBeenCalledTimes(1);
+    expect(handler.mock.calls[0][0]).toMatchObject({ type: 'agent', agent: 'ops' });
+    expect(guardrailHitlOverride).toHaveBeenCalledTimes(1);
+    expect(guardrailHitlOverride).toHaveBeenCalledWith(expect.objectContaining({ guardrailId: 'code-safety', toolName: 'agent:ops' }));
+    expect(opsRequests()).toHaveLength(0);
+    expect(chatBodies().filter((b) => said(b).includes('rm -rf'))).toHaveLength(0);
Evidence
The added tests approve destructive instructions and require a guardrail override with no operations
request, but the current shared check receives the original context and each affected strategy
appends approval instructions only after that check. This violates the requirements to check the
exact agent-bound input, share its construction across strategies, and confirm rejection of
destructive approved instructions.

Check approval-modified input before running the agent
Share input construction across agent strategies
Test rejection of destructive approved instructions
src/api/tests/agency-agent-approval.e2e.test.ts[134-143]
src/api/runtime/strategies/shared.ts[346-371]
src/api/runtime/strategies/sequential.ts[86-96]
src/api/runtime/strategies/parallel.ts[88-104]
src/api/runtime/strategies/hierarchical.ts[207-220]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new regression tests require approved `modifications.instructions` to be included in the text checked after `beforeAgent` approval, but the current strategies check the original context and append those instructions only afterward. This allows destructive approved instructions to reach the agent unchecked and causes the added rejection assertions to fail.
## Fix Focus Areas
- src/api/runtime/strategies/shared.ts[346-371]
- src/api/runtime/strategies/sequential.ts[86-96]
- src/api/runtime/strategies/sequential.ts[193-201]
- src/api/runtime/strategies/parallel.ts[88-104]
- src/api/runtime/strategies/hierarchical.ts[207-220]
## Recommended Fix
Create or use one helper that appends approved `modifications.instructions` to the strategy input before invoking the post-approval check, and use the same constructed value for the subsequent agent call in sequential, parallel, and hierarchical strategies. Preserve the existing behavior for approvals without modifications and for `beforeEmergent` approvals, then run the added regression tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can commit Qodo's fix in one click with committable suggestions (GitHub & GitLab)

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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.
@jddunn
jddunn merged commit a81d09d into master Oct 12, 2026
10 checks passed
@jddunn
jddunn deleted the fix/approval-instructions-and-tool-call-guards branch October 12, 2026 14:56
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
## [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))
jddunn added a commit that referenced this pull request Oct 12, 2026
…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.
jddunn added a commit that referenced this pull request Oct 12, 2026
…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.
@jddunn

jddunn commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

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 beforeAgent approval, the post-approval check read only the input with the instructions appended (src/api/runtime/strategies/shared.ts L449, L458). The built-in checks read it as JSON (src/api/agency.ts L1588), where the input is one line that ends in its closing quote, and two code-safety patterns match a statement only at that end: /rm\s+-rf\s+\.(?:["'\s/]|$)/i (L1685) and /DELETE\s+FROM\s+\S+\s*;?\s*$/im (L1693). An input that ends in DELETE FROM sessions; or rm -rf . (under the sequential strategy, a SQL or shell agent's whole output as the next agent's input) passed the check once the approval carried any instructions, where the check before this change blocked it. #360 has the check read the strategy's input on its own beside the input the agent is sent, in one call. Its two cases through agency() were red on the test commit alone, on top of master (run 38295776100, guardrailHitlOverride called 0 times), and pass with the fix (run 38296327784; master run 38315150689 on b382c69 is green).

Checked and found as described:

  • The strategies that apply instructions send exactly the gate's input: sequential generate() and stream() (sequential.ts L90, L171), parallel (parallel.ts L111) and the hierarchical delegate_to_<name> tool (hierarchical.ts L208), which a spawned specialist's delegate tool and the adaptive wrapper (compileAdaptiveWrapper() compiles the hierarchical strategy) share; the hierarchical stream() runs execute(). withApprovalInstructions() (shared.ts L302) is the only code that appends instructions. Debate, graph and review-loop do not apply them; their task-versus-input gap is graph, review-loop and debate: the beforeAgent check reads the task, not the input the agent receives #345.
  • No other modification reaches an agent: the tool gate refuses toolArgs (approval-gate.ts L244), and output applies only to beforeReturn (agency.ts L1533).
  • beforeAgent has no timer: the strategy awaits the handler itself, so no onTimeout policy produces an agent approval. The built-in handlers return no modifications (hitl.ts), and hitl.webhook() passes through what its server answers.
  • checkBeforeAgent() keeps its signature and result, and the strategies' module is not exported from the package root. GuardrailConfig only gains an optional field.
  • The dispatcher hands a TOOL_CALL_REQUEST only to guards whose config sets evaluateToolCalls (ParallelGuardrailDispatcher.ts L457, L829), so a guard written for text never receives one. callWithTimeout() (L93) turns a fail-closed guard's throw or timeout into a block, not a rejection, so failClosed holds, and a required guard keeps the flag through withRequiredPosture() (requiredGuardrails.ts L85). withGuardrailMetadata() merges with the input evaluations, isOutputGuardrailBlock() (AgentOS.ts L458) counts the blocked output for the meter, and the verdict record with originalText: null is a no-op (L1509). In hold mode the tool-call guards run before the held text is judged, and a block drops the held text.
  • A block does not stop a call the runtime runs itself (Output guards: a block on a tool call the runtime runs itself does not stop the call #343), and it leaves an actionable call's saved pause (A blocked actionable tool call stays in the saved pause #344), as the docs say.
  • Red run 38264283712 fails exactly the ten new red-before cases (six dispatcher, four blocked instructions); 38264956876 and the master run 38266525066 are green. The @framers/agentos-ext-code-safety 0.2.2 tarball sets evaluateToolCalls and reads object arguments (src/CodeSafetyGuardrail.ts L147-151, L273-298), and its README states the internal-call limit.

Reported, not changed (P2):

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.

beforeAgent: the post-approval check reads the input before the approval's instructions are appended

1 participant