Human Approval and Control Boundaries › The approval broker: pull model

Michael BrenndoerferDecember 1, 20267 min read
Language AI HandbookAll chapters
Part 49 of 67Long-Horizon Agents and Interoperability
Chapter 379Human Approval and Control Boundaries › The approval broker: pull model
Reading section 5 of 17 · The approval broker: pull model · 7 minSection 5 of 17 · 7 min

Section 5 of 17 · 7 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The caller submits its immutable intent and the decision identifier. The broker looks up its own record, checks the subject and exact scope, and compares the digest before it is allowed to create a release receipt. The decision identifier points to stored state. Possession of that identifier does not override policy or substitute for the requester's identity.

In the example both principal names stand for identities already resolved by trusted code. Outside a toy, the caller cannot set the “authenticated actor” field on its own. The owners map and the writers map model separate policy decisions. The owner can record a decision for the scope. The service may attempt dispatch for the scope. A person with approval rights is not automatically delegated execution rights.

We represent authorization as checks inside the same single-threaded broker method that performs the toy write. This avoids a gap between issuing a reusable permit and using it in the notebook. For a real queue or remote system, put the final check and key reservation as close to commit as the service contract permits. A short-lived permit checked only on dequeue may expire or be revoked while the job is still in flight.

PythonIn [7]
CollapseExpand
# The two maps are deliberately separate.
public_note = Scope("acorn", "public-board", "publish-note")
birch_note = Scope("birch", "public-board", "publish-note")
owner_policy = {"priya": {public_note}, "rei": {public_note, birch_note}}
writer_policy = {"publisher": {public_note, birch_note}}

The broker validates caller scope on issuance and again before dispatch. In the latter check it also verifies that the original approver is still authorized, so ownership changes can invalidate an otherwise exact approval. The order of checks chooses which status a caller sees when several conditions fail at once. An individual reason records the failure encountered in that call. It does not establish that the remaining conditions would pass.

Alongside each computed artifact digest, the next invariant checks which operation fields enter the combined digest. Holding the bytes fixed while changing the destination changes the intent fingerprint. The distinct artifact hash is the same because the file itself has not changed.

PythonIn [8]
CollapseExpand
def require_integer_seconds(*times):
    if any(type(time) is not int for time in times):
        raise TypeError("Use integer seconds for broker times.")


class ApprovalBroker:
    """Single-threaded synthetic publisher for release notes."""

    def __init__(self, owners, writers):
        self.owners = {
            actor: frozenset(scopes) for actor, scopes in owners.items()
        }
        self.writers = {
            actor: frozenset(scopes) for actor, scopes in writers.items()
        }
        self.approvals = {}
        self.latest_decision = {}
        self.paused = set()
        self.revoked = set()
        self.committed = {}
        self.audit = []

    def _record_event(self, now, event, approval_id, actor, outcome, intent):
        self.audit.append(
            AuditEntry(
                now,
                event,
                approval_id,
                actor,
                outcome,
                (intent.requester, intent.request_key),
                intent.digest(),
            )
        )

    def decide(
        self, intent, actor, now, expires_at, scope_expires_at, *, allow
    ):
        if not self._known_scope(intent):
            raise PermissionError("This operation is outside broker policy.")
        if intent.scope not in self.owners.get(actor, ()):
            raise PermissionError(
                "The approver lacks authority for this scope."
            )
        if type(allow) is not bool:
            raise TypeError("Record an explicit Boolean approval decision.")
        require_integer_seconds(now, expires_at, scope_expires_at)
        if min(expires_at, scope_expires_at) <= now:
            raise ValueError("An approval deadline must follow issuance.")
        approval_id = len(self.approvals) + 1
        decision = "allow" if allow else "deny"
        self.approvals[approval_id] = Approval(
            intent,
            intent.digest(),
            actor,
            now,
            expires_at,
            scope_expires_at,
            decision,
        )
        self.latest_decision[intent.digest()] = approval_id
        self._record_event(
            now, "decision", approval_id, actor, decision, intent
        )
        return approval_id

    def interrupt(self, approval_id, actor, now, *, permanent=False):
        require_integer_seconds(now)
        if type(permanent) is not bool:
            raise TypeError("Choose temporary or permanent explicitly.")
        approval = self.approvals[approval_id]
        if actor != approval.approver:
            raise PermissionError(
                "Only the recorded approver interrupts this demo."
            )
        if permanent:
            self.revoked.add(approval_id)
            outcome = "revoked"
        else:
            self.paused.add(approval_id)
            outcome = "paused"
        self._record_event(
            now, "interrupt", approval_id, actor, outcome, approval.intent
        )

    def release_pause(self, approval_id, actor, now):
        require_integer_seconds(now)
        approval = self.approvals[approval_id]
        if actor != approval.approver:
            raise PermissionError(
                "Only the recorded approver can release the pause."
            )
        self.paused.discard(approval_id)
        self._record_event(
            now,
            "release-pause",
            approval_id,
            actor,
            "released",
            approval.intent,
        )

    def _known_scope(self, intent):
        return (
            intent.scope.effect == "publish-note"
            and intent.scope in self.writers.get(intent.requester, ())
        )

    def _status(self, intent, actor, now, approval_id):
        if actor != intent.requester or not self._known_scope(intent):
            return "requester-outside-policy"
        approval = self.approvals.get(approval_id)
        if approval is None:
            return "approval-required"
        if approval.intent_digest != intent.digest():
            return "intent-changed"
        if self.latest_decision[approval.intent_digest] != approval_id:
            return "decision-replaced"
        if approval.decision == "deny":
            return "denied"
        if intent.scope not in self.owners.get(approval.approver, ()):
            return "authority-changed"
        if approval_id in self.revoked:
            return "revoked"
        if approval_id in self.paused:
            return "paused"
        if (
            not approval.issued_at
            <= now
            < min(approval.expires_at, approval.scope_expires_at)
        ):
            return "outside-time-window"
        return "eligible"

    def dispatch(self, intent, actor, now, approval_id, *, lose_ack=False):
        require_integer_seconds(now)
        status = self._status(intent, actor, now, approval_id)
        if status != "eligible":
            self._record_event(
                now, "dispatch", approval_id, actor, status, intent
            )
            return Result(status)
        key = (intent.requester, intent.request_key)
        record = self.committed.get(key)
        if record is not None:
            status = (
                "already-committed"
                if record.intent_digest == intent.digest()
                else "key-conflict"
            )
            self._record_event(
                now, "dispatch", approval_id, actor, status, intent
            )
            return Result(
                status, record if status == "already-committed" else None
            )
        approval = self.approvals[approval_id]
        record = Receipt(
            intent.digest(),
            intent.artifact_digest(),
            approval_id,
            approval.approver,
            now,
        )
        self.committed[key] = (
            record  # This insert is the only simulated effect.
        )
        self._record_event(
            now, "commit", approval_id, actor, "committed", intent
        )
        if lose_ack:
            return Result("ack-unknown")
        return Result("committed", record)

    def lookup_receipt(self, intent, actor):
        """Read a receipt under the toy's shared publication scope."""
        if actor != intent.requester or not self._known_scope(intent):
            return Result("requester-outside-policy")
        record = self.committed.get((intent.requester, intent.request_key))
        if record is None:
            return Result("no-receipt")
        if record.intent_digest != intent.digest():
            return Result("key-conflict")
        return Result("already-committed", record)

Each new decision replaces the prior decision for the same exact intent. A deny decision therefore blocks use of an older approval ID for that intent. Replacement leaves the prior decision in the audit history. The in-memory commit dictionary is the only simulated publication. The key is (requester, request_key). An eligible repeat with the same intent digest reads its existing receipt. If the caller reuses the key for a different, separately authorized intent, the broker reports a conflict without a second write. One key per intended operation allows people to repeat a genuine operation with a new decision and a distinct key when policy permits it.

PythonIn [9]
CollapseExpand
def make_broker():
    return ApprovalBroker(owner_policy, writer_policy)


first_intent = Intent(
    "publisher",
    "release-acorn-1.4",
    public_note,
    b"Acorn 1.4 is available now.",
)
birch_intent = Intent(
    "publisher",
    "release-birch-2.0",
    birch_note,
    b"Birch 2.0 is available now.",
)
PythonIn [10]
CollapseExpand
moved_intent = replace(
    first_intent, scope=replace(public_note, destination="private-board")
)
print(
    "same artifact:",
    first_intent.artifact_digest() == moved_intent.artifact_digest(),
)
print("same action:", first_intent.digest() == moved_intent.digest())
ConsoleOut [10]
CollapseExpand
same artifact: True
same action: False

The distinct roles can be tested separately. Priya owns only Acorn’s public board. Rei owns both the Acorn and Birch boards. The same publisher identity may dispatch to both, provided an appropriate human approves the exact action. A proposal for one project cannot inherit the authority granted for the other. Treat authorization for a shared tool as narrower than authorization for every possible use of that tool.

PythonIn [11]
CollapseExpand
scope_checks = [
    ("Priya · Acorn", "priya", public_note, public_note),
    ("Priya · Birch request", "priya", public_note, birch_note),
    ("Priya · Birch scope", "priya", birch_note, birch_note),
    ("Rei · Birch", "rei", birch_note, birch_note),
]
array_scope = np.array(
    [
        [scoped in owner_policy[actor], requested == scoped]
        for _, actor, scoped, requested in scope_checks
    ],
    dtype=int,
)
VisualizationOut [12]
CollapseExpand
A four-row grid marks matches for approver authority and request scope.
The first column checks whether the human owns the offered scope. The second checks whether the request matches that scope. Priya's Birch request under an Acorn scope fails the second check. A Birch scope offered by Priya fails the first check. The checks shown concern the scope and ownership only.

The two columns answer different questions. An Acorn owner can put forward Acorn as a scope, but that decision cannot authorize a Birch publication. A request that matches a Birch scope cannot rely on a decision by a person who lacks authority there. The chart holds the other worker checks out of view so these two comparisons are visible.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy