Expand description
Phase 3.4-3.6 human-in-the-loop (HITL) primitives.
This module houses the approval-request data model, the persistent
approval-store contract, the approval guard that decides when a call
needs human sign-off, and the async resume entry points used by the
HTTP surface after a human responds. The design follows
docs/protocols/HUMAN-IN-THE-LOOP-PROTOCOL.md.
Scope note (deviation documented in the phase report): the existing
crate::runtime::Verdict is Copy and threaded through 5,000+ lines
of kernel code. Rather than ripple a breaking change through every
call site, this module exposes a richer HitlVerdict that carries
the pending approval request when one is needed. The public
Verdict enum still gains a PendingApproval marker variant so
external callers can pattern-match on the three-way decision; the
payload is returned separately via ApprovalGuard::evaluate and
ChioKernel::evaluate_tool_call_with_hitl.
Structs§
- Approval
Context - Context passed into
ApprovalGuard::evaluate. - Approval
Decision - Decision packet delivered by an approver.
- Approval
Filter - Filter for
list_pending. - Approval
Guard - The built-in HITL guard. Runs before the generic guard pipeline and decides whether a call passes straight through, requires approval, or was already approved by an accompanying token.
- Approval
Request - A request for human approval, produced when the approval guard
returns
Verdict::PendingApproval. Designed to be serialized into the approval store and the webhook payload without further wrapping. - Approval
Token - Lightweight “approval token” representation used inside the kernel.
For HITL v1 this wraps the existing
GovernedApprovalTokentogether with the approval request it satisfies, so consumers do not have to re-plumb the full governance type through every surface. - Batch
Approval - Batch approvals let a human pre-approve a class of calls.
- Channel
Handle - Handle returned by
dispatch. Kernel records this alongside the request in the store socancelcan be called later. - InMemory
Approval Store - Thread-safe in-memory
ApprovalStore. Useful for tests and for ephemeral deployments where operators explicitly accept data loss on restart (the opposite of Phase 3.5’s durability contract; SQLite is the production path). - InMemory
Batch Approval Store - In-memory
BatchApprovalStoreused in tests. Production backends should persist viaSqliteBatchApprovalStore. - Resolved
Approval - Resolved-approval row retained for audit and replay protection.
Enums§
- Approval
Outcome - Minimal approval decision recorded after a human responds.
- Approval
Store Error - Errors emitted by approval stores.
- Channel
Error - Errors returned by approval channels.
- Hitl
Verdict - Outcome of running an approval guard against a tool call.
Constants§
- MAX_
APPROVAL_ TTL_ SECS - Maximum lifetime (in seconds) permitted on a single approval token.
Mirrors the
MAX_APPROVAL_TTL_SECSdocumented in the HITL protocol section 15: the single-use replay registry’s TTL is pinned to this value so no token can outlive its replay entry.
Traits§
- Approval
Channel - Contract a channel must satisfy to dispatch an approval request.
- Approval
Store - Persistent store for pending and resolved HITL approvals. The trait
is intentionally synchronous because every concrete implementation
in the kernel hot path today (in-memory, SQLite via
rusqlite) is synchronous, and the kernel itself does not run on an async executor. - Batch
Approval Store - Store for batch approvals. Counterpart to
ApprovalStore.
Functions§
- compute_
parameter_ hash - Compute the parameter hash that binds an
ApprovalRequestto a specific set of arguments. Input is canonicalized via the existingsha256_hex(chio_core::canonical::canonical_json_bytes(..))helper so independent kernels produce identical hashes. - resume_
with_ decision - Apply a resolved approval decision: verify the token, mark it consumed, persist the resolution, and return the final verdict that the kernel should treat as the outcome.