Expand description
The server half of the approval extension: checking a person’s decision before the executor acts on it.
An executor asks with EventEmitter::request_approval, which parks the
task at input-required with an
ApprovalRequest on its
status message. A person answers by continuing the task with an
ApprovalDecision. With
an ApprovalGate installed
(RequestHandlerBuilder::with_approval_gate), that continuation is
admitted only if the decision answers the request pending on the task,
echoes its digest, and comes from an authenticated approver the gate
allows; the executor then finds it at
RequestContext::approval. Without a
gate, approval() is always None: a decision in a message’s metadata is
only a claim, and nothing here treats it as more.
§A quorum
ApprovalGate::with_quorum makes the gate wait for n distinct
approvers to approve the same pending request (same id, same digest)
before the decision reaches the executor; the EU AI Act’s Art. 14(5)
asks for two natural persons for the systems in its Annex III point 1(a).
Each approver sends their own decision, as one approver does without a
quorum, so nothing on the wire changes for them. Until the quorum is met
the gate records the approval on the task and answers the approver with
the task still input-required; the executor does not run. The record is
the QUORUM_METADATA_KEY entry in the metadata of the status message
that carries the request, so it is stored wherever the task is, and a
new request (a new status message) starts with none.
Who counts: approvers are told apart by their authenticated identity, the
one the four-eyes rule compares; an approver who approves twice counts
once; the requester counts only under
allowing_self_approval, as
without a quorum. A deny from any allowed approver is passed to the
executor at once: the action needs every one of the n, so one refusal
settles it, and waiting would let the others outvote it. A decision for
another digest is refused as it is without a quorum, and counts for
nothing.
What the record survives: on one handler, sends on one context are
serialized from the read the gate counts from to the save that records
the approval, so two approvals arriving together are both counted.
Replicas sharing a store do not share that lock; with turn claims (the
bundled PostgreSQL and SQLite stores take them by default) the count is
made under the task’s claim instead, so approvals arriving at two
replicas at once are counted one after the other, and the executor
resumes once. Without claims
(without_turn_claims,
or a shared store that provides none) two such approvals can each save
over the other: one is lost and its approver has to send it again, and
the last two can both meet the quorum and resume the executor twice. A
lost record can only leave the count short; it never adds an approval
nobody sent, since every name in it was written by the gate after that
approver’s check.
§Reviewing without sharing every task
With tasks isolated by caller, an approver cannot reach the requester’s
task; the alternative to share_tasks_across_callers is a gate that lets
the requester answer their own run. with_review_grants is the narrow
third way. A caller named by with_approvers who sends
REVIEW_FOR_HEADER with the requester’s identity is let into that
requester’s partition for two methods and one purpose: GetTask, for a
task that is waiting for a decision (any other task is TaskNotFound), and
SendMessage or SendStreamingMessage, for a message that is an
approval decision (any other message is refused, so a reviewer cannot
create, steer or continue a task). ListTasks, CancelTask,
SubscribeToTask and push configuration stay in the reviewer’s own
partition. How an approver learns that a task is waiting, and for whom, is
the application’s: it knows whom it asked.
Structs§
- Approval
Gate - Who may approve, checked before a decision reaches the executor.
- Verified
Approval - A decision the
ApprovalGateadmitted: the request it answers, the decision, and who made it.
Constants§
- QUORUM_
METADATA_ KEY - Where an
ApprovalGatewith a quorum records who has approved so far. - REVIEW_
FOR_ HEADER - The request header in which a reviewer names the requester whose task they
are answering; see
ApprovalGate::with_review_grants.