Skip to content

Governance

Every tool call the loop is about to run passes through the run’s execution gate, beforeTool, first (see Concepts). Calls the loop refuses itself never reach it: arguments it cannot use, an unknown or not-yet-loaded tool, invalid input, or an exhausted tool-call budget. Inside the API’s gate, plan mode and the check on GitHub writes to repositories not listed with write refuse a call before anyone is asked to approve it. The gate belongs to the application, never to a caller: an HTTP request cannot supply one, choose tools, or switch approvals off. The terminal client uses it to ask before each write. The API uses it for approvals, described here.

Approval rules name tools, by exact name or with * and ? globs. An exact name beats a glob, and among equal matches the last rule wins. A rule can apply only when certain arguments are present and non-empty, can make a grant last for a number of seconds (ttl_seconds), or can allow exactly one call (one_shot).

The checks a tool call passes, in order, and where each can refuse itThe model's reply, with its tool calls, is checkpointed to the session before any of them runs. Each call is then prepared in order. The loop first refuses a call whose arguments the provider could not use, whose tool is unknown, or whose tool is held back until tool_search loads it. Next the tool's own parse validates the arguments against its schema. Then the run's budgets are checked: when the tool-call budget, token budgets or deadline is used up, the call is not executed. Each of these refusals becomes an error result the model reads, and the tool does not run. Only then does the loop await the application's execution gate, beforeTool. On the hosted API that gate is composed in a fixed order: plan mode refuses any tool not marked read-only; a GitHub write to a repository not listed with write access is refused before anyone is asked; the approval gate applies deployment rules first and a named agent's rules only for calls no deployment rule decides, reusing a grant or waiting on an approval row in thread storage, and refusing on a denial, a timeout or an already-used one-shot grant; last, the injected policy, ChatConfig.beforeTool when one is configured, sees only calls a person allowed, with any edited arguments. If the approval store fails or the run is stopped while the gate waits, the gate throws and the run stops without running the call. A rewrite, such as arguments an approver edited, is parsed again by the tool, and invalid replacement input is refused. The tool then executes, the optional afterTool hook may rewrite its output, and the result is checkpointed to the session. Refusals are checkpointed the same way, as the call's result.beforeTool, as the API composes iteach call, in orderallowed, maybe with editedargumentsgrant, request, wait for adecisionrewriteallowresultunknown, held back, orunusableinvalid inputexhaustednot read-onlynot writabledenied, timeout, already usedblockinvalid replacementrecorded as the call's resultstore fails or run stoppedSession: the replyand its tool callsKnown and loadedtool,usable argumentstool.parseschema validationRun budgetstool calls, tokens,deadlinePlan moderead-only toolsonlyGitHub writeprecheckrepository listedwith writeApproval gatedeployment rules,then agent rulesInjected policyChatConfig.beforeToolApproval rowsthread storagetool.parse againreplacement inputtool.executethen afterTool,when setSession: toolresultError result themodel readsthe tool does notrunRun stopsthe call does notrunWhat a tool call passes through
What does a tool call pass through, in what order, and where can it be refused?Drawn from docs/diagrams/governance-stack.mmd, which follows packages/agent/src/run.ts:runAgent (prepare, execute, settle), apps/api/src/routes/chat.ts:chatResponse (the composed beforeTool), apps/api/src/approvals/gate.ts:approvalGate.

On a deployment, the rules come from MCP, where every tool of a hosted MCP server needs approval unless the server sets "approval": false, and from the built-in github-writes rule, which allows each GitHub change once. A named agent’s rules apply only to a call no deployment rule matches. A thread in bypass mode skips the MCP and agent rules but keeps the GitHub rule. Approvals are recorded in thread storage, so a deployment without it does not offer tools that need one at all.

A waiting call stays inside the gate, so the run pauses without ending and nothing else in the loop changes.

States a tool call moves through while it waits for a person's decisionWhen an approval rule matches a tool call, the gate first asks the store for a grant: a live approved row for the same tool and call signature, a hash of its canonical arguments. A grant is reused without any frame, and a one-shot grant is spent in the same transaction. With no grant, the call opens a pending row, or joins a live pending row for the same tool and signature, and the stream sends an approval_required frame naming the approval id and its expiry. The call waits inside the gate, polling the row about once a second. A person decides with POST /v1/approvals//decide, approving, optionally with edited arguments, or denying; deciding a row that is no longer pending, or has lapsed, is refused with 409. When the waiter's deadline passes, ttl_seconds or five minutes by default, the row is closed as denied by felix with the note timeout, unless a decision landed first. If the run is stopped while waiting, the row is closed with the note aborted and the run stops without running the call. After a decision the stream sends approval_resolved, with the outcome approved, denied or timeout, before the call's result. An approved one-shot row is consumed once; if an identical call consumed it first, the call is refused with the note already used. Approved calls run, with the edited arguments when an approver gave them; refused calls give the model the text [approval ] tool= rule=. An approved row stays a grant for identical calls until its expires_at, or for good when the rule sets no ttl_seconds.an approval rule matches thecallgrant() finds a live grant, noframes sentrequest() opens or joins a row,approval_required sentdecide approved, edited_argsoptionaldecide denieddeadline passes, felix closes itwith note timeoutrun stopped, closed with noteabortedapproval_resolved approvedone-shot already consumed,approval_resolved deniedapproval_resolved denied ortimeoutthe tool runs, with edited_argswhen giventhe model reads [approvalnote] tool and rulethe run stops, the call doesnot runMatchedRunsPendingApprovedDeniedStoppedRefusedThe run waitshere, inside thegate.A second decide,or one after thedeadline, isrefused with 409.The row stays agrant for identicalcalls untilexpires_at, or forgoodwith nottl_seconds.Tool approval lifecycle
What happens to a tool call that needs a person's decision?Drawn from docs/diagrams/approval-lifecycle.mmd, which follows apps/api/src/approvals/gate.ts:approvalGate, packages/storage/src/approval-store.ts:approvalRepository (grant, request, decide, close, consume), apps/api/src/routes/approvals.ts:approvalsResponse.
  1. Reuse a grant. An approval for the same tool and the same arguments that has not expired is used again. A one-shot grant is used up atomically, or not at all.
  2. Ask. Otherwise the call joins a pending request for the same tool and arguments, or opens one, and the stream sends an approval_required frame.
  3. Wait. The gate waits until someone decides with POST /v1/approvals/<id>/decide, or until the rule’s deadline passes (five minutes by default).
Outcome What happens
Approved The tool runs.
Approved with edited arguments The tool runs with the new arguments, validated like the originals.
Denied The call does not run. The model reads [approval <note or "denied">] tool=<name> rule=<id>.
The deadline passes The request is closed as denied, with the note timeout. A decision that arrived first still stands.
A one-shot grant was already used by an identical call The model reads [approval already used] ….
The run is stopped while waiting The request is closed with the note aborted, and the call is recorded as not run (“Not run: the run was stopped before this call started.”).
Approval storage fails The run stops, and no tool runs.

Child agents started through delegate are never given a tool that needs approval, so delegation cannot get around a decision. That includes a tool a named agent’s own approval rules gate.

A named agent’s approval rules only add approvals: one decides a call only when no deployment rule does, so it can never loosen or replace one, and the built-in rule on GitHub writes always applies.