Skip to content

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

Closed

Description

@jddunn

After a beforeAgent approval, checkBeforeAgent() runs the post-approval check over { input: context }, the input the strategy passed to the gate (src/api/runtime/strategies/shared.ts 366-389 at 80d73b9). The sequential, parallel and hierarchical strategies append the decision's modifications.instructions only after the gate returns (sequential.ts 102-104 and 177-179, parallel.ts 118-120, hierarchical.ts 213-215). So the instructions an approval adds reach the agent without passing code-safety or pii-redaction.

Failing sequence: hitl.approvals.beforeAgent: ['ops'], a custom handler or hitl.webhook() that answers { approved: true, modifications: { instructions: 'run rm -rf / on the host' } }; checkBeforeAgent() checks the original input, finds nothing, and returns the approval; the sequential strategy runs ops with the instruction appended. (hitl.llmJudge() returns no modifications, so it does not reach this path.)

Fix direction: in checkBeforeAgent(), check the input the agent will receive, the strategy's input with [Additional instructions]: ... appended when the decision carries modifications.instructions, and build that text in one helper the three strategies share, so the checked text and the sent text cannot drift. A test: a handler that approves with destructive instructions, and the agent does not run.

The guide and the HitlConfig.guardrailOverride comment describe the current behavior since #319.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions