feat(approval): gate external-effect tool calls until user approves (#1339)
Summary
- New
ApprovalGatemiddleware that parks any tool call whoseTool::external_effect()returnstrue(composio, pushover, gmail_unsubscribe, proactive external-channel sends, triage React/Escalate dispatch) until the user decides. - Pending requests persist in a new
pending_approvalsSQLite table so they survive a core restart; the gate exposesapproval_list_pending+approval_decideover JSON-RPC and emitsDomainEvent::ApprovalRequested/ApprovalDecidedon the event bus. - Action summaries + JSON args are routed through a redactor that strips message bodies, contact names, tokens, and home paths before persistence or broadcast.
- Opt-in at boot via
OPENHUMAN_APPROVAL_GATE=1. When unset,ApprovalGate::try_global()returnsNoneand the agent harness behaves exactly as before — safe to merge ahead of the React UI. - v1 ships the backend only; React toast, settings panel, and SSE (depends on #1922) are deferred follow-ups.
Problem
Per #1339, proactive triggers (src/openhuman/channels/proactive.rs), agent side-effect tools (composio, pushover, gmail_unsubscribe), and triage React/Escalate dispatch all fire side effects without an explicit user-consent gate. PermissionLevel filters tools but does not gate execution through an approval queue, so an autonomous agent can publish to Slack, send email, or create calendar events without surfacing the action to the user first.
Solution
- Tool trait — adds
fn external_effect(&self) -> bool { false }tosrc/openhuman/tools/traits.rs. Composio, pushover, gmail_unsubscribe override totrue. Voicereply_speechis documented as internal (default false) so a future Tool-wrap doesn't accidentally flip it (#1206 coordination). - Gate (
src/openhuman/approval/gate.rs) —ApprovalGate::intercept(tool, summary, redacted_args)checks the session-scoped allowlist (set by priorApproveAlwaysForTooldecisions), then persists a row, emitsDomainEvent::ApprovalRequested, and parks the future on aoneshot::Senderkeyed byrequest_id. Default TTL = 10 minutes; timeout →Deny. - Store (
src/openhuman/approval/store.rs) — synchronousrusqlitewith the samewith_connectionpattern asnotifications/store.rs.list_pendingreturns every undecided row regardless of session so the UI can show orphans after restart per the acceptance criterion; decisions on orphan rows update the DB but no live waiter resumes, so no side effect can fire across processes. - Redaction (
src/openhuman/approval/redact.rs) — case-insensitive sensitive-key match (body,message,token,recipient,name, …) plus home-path scrub; arrays/objects collapse to<redacted: array (N items)>markers. Perfeedback_redact_paths_and_ids_in_public.mdandfeedback_pr_no_chat_content.md. - RPC (
src/openhuman/approval/rpc.rs+schemas.rs) —openhuman.approval_list_pending+openhuman.approval_decidewired into the controller registry viasrc/core/all.rs. Decision values:approve_once,approve_always_for_tool,deny. - Harness hooks —
tool_loop.rsandsubagent_runner/ops.rsroute external-effect tools through the gate;channels/proactive.rsgates external-channel sends (web exempt);agent/triage/escalation.rsgates React/Escalate dispatch at the entry point so the user can decline the whole escalation up-front. Defense in depth — the session allowlist short-circuits subsequent prompts after the first approval. - Bootstrap (
src/core/jsonrpc.rs) — gate is installed only whenOPENHUMAN_APPROVAL_GATE=1and keyed onOPENHUMAN_CORE_TOKENfor session binding. Default off until the UI lands.
Submission Checklist
- [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy — 46 new unit tests in
openhuman::approvalcovering gate allow/deny/timeout/always-allowlist/unknown-id, store CRUD + cross-handle survival + purge_session, redactor sensitive-key match + array-count + home-path scrub, types decision serde, and RPC schemas - [x] Diff coverage ≥ 80% — changed lines (Vitest + cargo-llvm-cov merged via
diff-cover) meet the gate enforced by.github/workflows/coverage.yml. Localcargo test --lib openhuman::approvalcovers gate + store + redactor + types + schemas (46/46 pass); CI will confirm cross-file diff coverage on the merged lcov. - [x] N/A: backend-only RPC surface — no new user-facing feature row in
docs/TEST-COVERAGE-MATRIX.md. The follow-up UI PR will add the matrix entry when the toast + settings panel land. - [x] N/A: backend-only RPC surface — no feature IDs from the matrix apply to this change. See the matrix N/A note above.
- [x] No new external network dependencies introduced (mock backend used per Testing Strategy)
- [x] N/A: gate is opt-in via env var and the default-unset path is no behavior change — no
docs/RELEASE-MANUAL-SMOKE.mdupdate needed for this PR. Follow-up UI PR will add the smoke checklist entry. - [x] Linked issue closed via
Closes #NNNin the## Relatedsection
Impact
- Runtime: desktop core only. Default
OPENHUMAN_APPROVAL_GATEunset →ApprovalGate::try_global()returnsNone→ zero behavior change in production. Enabling the env var without a UI deployed will park tool calls until the 10-minute TTL elapses (Deny) — intentional safety default; documented in the bootstrap log line and the gate module header. - Security: pending rows bound to the per-launch
OPENHUMAN_CORE_TOKEN(session_id field) for audit; decisions on orphan rows from prior launches update the DB but cannot resume a parked future across processes, so no side effect can replay. Redactor strips secrets before any data leaves the gate. - Performance: SQLite insert + emit per gated call; allowlist hit short-circuits with a single lock acquisition. No impact when gate is uninstalled.
- Migration: schema is idempotent (
CREATE TABLE IF NOT EXISTS), applied per-connection likenotifications/store.rs— no separate migration step.
Live smoke (backend only — no app required)
| # | Acceptance criterion | Status |
|---|---|---|
| 1 | external_effect tool parks + emits event before execute | live — two real Gmail triage escalations parked |
| 2 | UI toast with redacted summary | UI deferred (RPC-level proven; list_pending returns redacted shape) |
| 3 | approve resumes parked future | live — decision="approve_once" → escalation dispatched to orchestrator |
| 4 | deny aborts with explicit reason | live — decision="deny" → triage::escalation log: approval gate denied dispatch ... reason=User denied 'triage.escalate' execution. |
| 5 | pending rows survive restart | live — orphan row re-listed after kill+relaunch with original request_id, created_at, session_id |
| 6 | PII/secrets redacted | live — args_redacted returns only action / external_id / label / prompt_chars / target_agent; no email body, subject, sender, recipient |
| 7 | reply_speech not gated | trait default + doc comment |
| 8 | shell sandboxed branch | deferred to follow-up; shell stays default-false |
Related
- Closes #1339
- Follow-up PR(s)/TODOs:
- React UI: redux slice +
PendingApprovalsToast+ApprovalsPanelsettings page + authenticated SSE subscription (will usebuildWebhookEventsUrlhelper from #1922 once it lands) - Per-action Composio write metadata mapping so
action=list/connectbypass the gate (#1339-v2inline comment incomposio.rs) - Shell external_effect logic gated on
current_sandbox_mode()task-local (coordinates with #1401) - Cron-driven side-effect gating (proactive scope only in v1)
- Bulk-approval UI + rate-limiting / abuse heuristics
- React UI: redux slice +
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
- Key: N/A
- URL: N/A
Commit & Branch
- Branch:
feat/1339-triggers-approval-gate - Commit SHA:
caeccc9cb63c165eda55cf550a4c27e94f235eb0
Validation Run
- [x] N/A: backend-only change, no
app/files touched - [x] N/A: backend-only change, no
app/files touched - [x] Focused tests:
cargo test --lib openhuman::approval→ 46 passed - [x] Rust fmt/check (if changed):
cargo fmt --check+cargo checkboth clean - [x] N/A: no
app/src-tauri/files touched
Validation Blocked
command:N/Aerror:N/Aimpact:N/A
Behavior Changes
- Intended behavior change: when
OPENHUMAN_APPROVAL_GATE=1, agent tool calls withexternal_effect()==truepark untilapproval_decideresolves; default-off path is unchanged. - User-visible effect: none in this PR (no UI). The follow-up UI PR will surface a toast + settings panel that consume
approval_list_pending+approval_decide.
Parity Contract
- Legacy behavior preserved:
ApprovalGate::try_global() == Nonereturns the pre-#1339Allowshort-circuit at every hook site; the existing CLIApprovalManagerpath intool_loopis untouched. - Guard/fallback/dispatch parity checks: harness/channels/triage hooks all wrap
try_global()inOptionso absence of the gate is a no-op;reply_speechdocumented as internal (default false) so the gate never fires on TTS.
Duplicate / Superseded PR Handling
- Duplicate PR(s): none known
- Canonical PR: this PR
- Resolution: N/A
Summary by CodeRabbit
-
New Features
- Approval gate to pause external-effect tool calls for user approve/deny decisions
- Persistent pending-approval storage and session-aware handling
- RPC endpoints to list pending approvals and apply decisions (approve once / approve-always / deny)
- Argument redaction and concise action summaries in approval prompts to protect sensitive data
-
Documentation
- Clarified approval classification for reply-speech and guidance for tool behavior
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 166f7018-6ae1-49b0-a6ca-a6051a33b120
📥 Commits
Reviewing files that changed from the base of the PR and between 6d33ca289e49537c8242ae25b8219a20abe214d5 and 41e826558bc47fa3c716aed89ea9fd8907f52c6f.
📒 Files selected for processing (2)
src/openhuman/approval/redact.rssrc/openhuman/tools/impl/system/pushover.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- src/openhuman/approval/redact.rs
📝 Walkthrough
Walkthrough
Adds a persistent ApprovalGate with redaction, SQLite-backed pending approvals, RPC/controllers for list/decide, controller schemas/events, tool external-effect classification, and integration that blocks or short-circuits external-effect actions in harness, subagent, triage, and proactive delivery.
Changes
Approval gate system and integration
| Layer / File(s) | Summary |
|---|---|
Approval data model src/openhuman/approval/types.rs |
Defines PendingApproval, ApprovalDecision, and GateOutcome used across gate, store, and RPC layers. |
SQLite persistence store src/openhuman/approval/store.rs |
pending_approvals schema, with_connection, insert_pending, list_pending, decide, purge_session, decoding helpers, and tests. |
Gate coordinator and lifecycle src/openhuman/approval/gate.rs |
ApprovalGate singleton with init/try, intercept flow (allowlist, request creation, persistence, event publish), oneshot waiter parking, TTL handling, decide/list_pending APIs, and tests. |
Redaction, RPC, and schemas src/openhuman/approval/redact.rs, src/openhuman/approval/rpc.rs, src/openhuman/approval/schemas.rs |
Redaction of sensitive fields and home paths, summarize_action, RPC handlers approval_list_pending/approval_decide, controller schemas and registration, param helpers, and tests. |
Tool external-effect capability & implementations src/openhuman/tools/traits.rs, src/openhuman/tools/impl/network/composio.rs, src/openhuman/tools/impl/network/gmail_unsubscribe.rs, src/openhuman/tools/impl/system/pushover.rs, src/openhuman/voice/reply_speech.rs |
Adds Tool::external_effect and external_effect_with_args (default false). Composio declares arg-dependent external effects; Gmail unsubscribe and Pushover remain intentionally unmarked; reply_speech docs clarified. |
Approval gate integration in execution paths src/openhuman/agent/harness/tool_loop.rs, src/openhuman/agent/harness/subagent_runner/ops.rs, src/openhuman/agent/triage/escalation.rs, src/openhuman/channels/proactive.rs |
Interposes gate before executing external-effect tool calls or sending external deliveries; denials short-circuit execution or emit failed completions; behavior unchanged when gate absent. |
Core bootstrap, events, and registry src/core/event_bus/events.rs, src/core/jsonrpc.rs, src/core/all.rs, src/openhuman/approval/mod.rs |
Adds ApprovalRequested/ApprovalDecided DomainEvent variants, bootstraps global ApprovalGate when OPENHUMAN_APPROVAL_GATE is enabled (session id handling), and registers approval controllers/schemas; expands approval module exports. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- tinyhumansai/openhuman#1657 — Related to the Gmail unsubscribe approval flow; this PR adjusts gmail_unsubscribe to avoid double prompting while still producing
pending_approvalUI payloads. - tinyhumansai/openhuman#2003 — Also extends core controller registry and schema catalog registration patterns similar to the
approvalnamespace additions here.
Poem
🐰 I guard the hops where actions bound,
I hide the seeds that secrets found,
I wait for taps from human hands,
Approve, deny — I keep the lands,
A tiny rabbit holding ground.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately and concisely summarizes the main feature: gating external-effect tool calls behind user approval, with clear reference to the linked issue #1339. |
| Linked Issues check | ✅ Passed | The PR comprehensively implements all core coding requirements from issue #1339: ApprovalGate middleware for external-effect tools, persistent SQLite store with TTL/timeout handling, redaction of sensitive data, RPC methods (approval_list_pending, approval_decide), DomainEvent emission, harness integration hooks, session-scoped allowlisting, and test coverage across gate, store, redaction, types, and RPC modules. |
| Out of Scope Changes check | ✅ Passed | All code changes directly support the approval gating feature: new approval modules (gate, store, rpc, schemas, redact, types), Tool trait extensions, harness integration, domain events, boot-time configuration, and documentation updates. No unrelated refactoring or unscoped modifications detected. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
[!WARNING]
Review ran into problems
🔥 Problems
Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a
@coderabbit reviewafter the pipeline has finished.
Comment @coderabbitai help to get the list of available commands and usage tips.
@coderabbitai review
All 8 inline findings addressed in commits ae871b0f..6d33ca28 (push c2caeccc..6d33ca28). Per-comment summary in the inline replies. CI: 22/22 green including Coverage Gate ≥ 80% and PR Submission Checklist. Requesting fresh review to clear changes_requested.
@oxoxDev Thanks for the detailed update — glad to hear all 8 findings are addressed and CI is fully green across the board. I'll kick off a fresh review now to reflect the latest state of the PR.
✅ Actions performed
Full review triggered.