feat: human-in-the-loop approval gate (step 7) - #3
Merged
Conversation
A side-effecting tool call that policy gates pauses until a human approves or
denies it. Deterministic — no LLM decides what needs approval.
- internal/approval: Policy (exact-tool or side-effect-glob match, plus a
fail-closed default-safe mode) and a Gate that persists a pending approval,
notifies push channels, and BLOCKS the calling goroutine until resolved or
the run's context is cancelled. Webhook notifier (user-configured egress).
- internal/storage: approvals table (forward migration 00003) + CRUD; resolve
is idempotent (double-resolve -> ErrNotFound). Auditable record of who
allowed which side effect, when, why.
- API: POST /v1/runs/{id}/approve (resolves the named or single pending
approval, returns the run), GET /v1/approvals, and GET /v1/runs/{id} now
surfaces pendingApproval + waiting_approval status.
- Three channels: CLI (`approvals list/approve/deny`, via the daemon API so it
wakes the blocked waiter), a local embedded admin page (/admin/approvals),
and the optional webhook.
- config: RISKKERNEL_APPROVAL_DEFAULT_SAFE (default true) + _WEBHOOK.
- SECURITY.md: document the webhook as the third user-configured egress point.
- api/v1: additive GET /v1/approvals; ApprovalRequest gains resolution fields.
- Tests: policy match/glob/default-safe; gate block->approve/deny, ctx-cancel,
resolve-unknown; storage CRUD + double-resolve; HTTP approve flow unblocks a
blocked call, no-pending 409. Verified live: v3 migration, endpoints, admin
page, CLI. Full suite green with -race.
This was referenced May 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Implements the human-in-the-loop approval gate (§8 step 7). A side-effecting tool call that policy gates pauses until a human approves or denies it — the LLM proposes, deterministic code disposes. No LLM is in the approval decision.
Highlights
internal/approval— deterministicPolicy(exact-tool match or side-effect glob like*write*, plus a fail-closed default-safe mode) and aGatethat persists a pending approval, notifies push channels, and blocks the calling goroutine until resolved or the run's context is cancelled.approvalstable (forward migration00003) as an auditable trail; idempotent resolve.POST /v1/runs/{id}/approve,GET /v1/approvals, andGET /v1/runs/{id}(surfacespendingApproval+waiting_approval).riskkernel approvals list/approve/deny), a local embedded admin page (/admin/approvals), and an optional webhook.RISKKERNEL_APPROVAL_DEFAULT_SAFE(defaulttrue),RISKKERNEL_APPROVAL_WEBHOOK.The gate's live producers are the MCP gateway (step 9) and the Python SDK (step 8); this PR lands the mechanism + channels + contract, fully tested.
Verification
go test -race ./...green;vet+gofmtclean./admin/approvalsserves, CLI reaches the daemon.Notes
SECURITY.mdupdated: the approval webhook is the third user-configured egress point (carries approval metadata, never secrets).api/v1: additiveGET /v1/approvals;ApprovalRequestgains resolution fields.