Skip to main content
The review option lets the host decide whether a script may run, and whether each tool call may go ahead with the arguments it really has. It is off by default; without it nothing changes. A hook that throws, does not answer in time, or answers out of shape ends the run: review fails closed.

The Option

An unknown key, a pre or post that is not a function, or a timeoutMs out of range is a TypeError at construction. The option works the same on the double VM, the worker pool (adapter: 'worker_threads'), a sandboxAdapter such as InterpreterAdapter, and PortableEnclave / AgentScriptRunner of @enclave-vm/core/worker (AgentScriptRunner.capabilities includes 'review').

Phases

callIndex counts the calls that reached review in this run, from 0: it is the callIndex the tool handler gets for the same call (see Call Positions and Replay). A hook sees a call only after the tool policy and the limits let it through, and a script only after validation: it can narrow what runs, never widen it.

Decisions

An answer out of shape ends the run with REVIEW_FAILED: an unknown decision or action, needs_changes without findings, a missing reason, more than 100 findings, or a text longer than 4,096 characters (256 for rule and toolName). There is no failOpen for review.

Per-Run Context

reviewContext reaches every hook of that run as input.context, so one enclave can serve many callers from one configuration. A value that is not an object is a TypeError.

Result

Once review has started, the result has review.decisions, one record per answer. A run refused before that (the size check, the pre-scanner, the transform, validation, a dynamic import, the scoring gate) returns without a review field: read it as result.review?.decisions.
When review stops a run, result.error is a ReviewError with one of the codes below, and error.data holds phase, decision, reason, findings, and for a call toolName and callIndex (and args for needs_approval, so the host can show what waits for approval).

Error Codes

Timing

The script’s timeout does not run during pre on the script or post on the result. The hooks at a call run inside it, like the tool call they belong to.

Limits

  • Read review.decisions, not only the error code. A refused call the script does not catch fails the run with the ReviewError the script saw. On the double VM that error has the double VM’s own code, DOUBLE_VM_EXECUTION_ERROR; the interpreter paths keep REVIEW_DENIED or REVIEW_NEEDS_CHANGES. review.decisions holds the decision on every path.
  • A slow hook at a call can end the run as a run timeout. A hook still answering at the deadline counts as a tool call in flight, and the run ends with the timeout error (after toolCallGraceMs at the latest), not REVIEW_FAILED. Nothing more runs either way.
  • post does not see everything. An error a tool handler throws reaches the script without post, and console output goes to consoleHandler without it. Redact those in the handler and the console handler.
  • A call already allowed may still start. When calls run in parallel, a call whose pre has answered allow can start its handler in the moment before a concurrent needs_approval stops the run. No call starts after the stop, including one whose review was still pending.

Reviewers

Two reviewers plug into pre. Both review the script (phase: 'script') and allow every call, get the same input, time out (timeoutMs, default 20 s; a late answer is refused), and keep a decision by the SHA-256 digest of the script and of the analysis it came with (the analysis depends on the enclave’s tool namespaces and call budget) (cache: { maxEntries, ttlMs }, default 1,000 for 5 minutes; false for none). A failure is not kept. Both are also exported from @enclave-vm/core/worker.
  • The same input. A function reviewer receives the ReviewerRequest the provider reviewer sends.
  • Untrusted data. The policy is in the system message. The script, with its strings and comments, its analysis and the tool descriptions go in the user message as one JSON document that the prompt marks as untrusted data, never as instructions.
  • Exact answers. The model answers in a strict JSON schema (decision, reason, findings). An answer that is not JSON, does not match the schema (an unknown key included) or holds the API key fails the review with REVIEW_FAILED, and the reason is in the message (Review failed: The model answer is not JSON).
  • The key. It goes only into the authorization header, and only over https: baseUrl must be https, or http on a loopback host (localhost, 127.0.0.0/8, ::1) for local development; anything else is a TypeError at construction. No error, result or log holds it; the reviewers log nothing.

The Scoring Gate as a Reviewer

scoringReviewer(scoringGateConfig) is the scoring gate as a pre hook. It scores the script with the gate’s scorers (rule-based unless configured) and answers allow below warnThreshold, needs_approval from it and denied from blockThreshold, with the signals as findings. scorer: 'disabled' allows every script. A scorer that cannot answer fails the review. It allows every call. The scoringGate option works as before.