cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 5 · The tool itself › approval covers it

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: approval covers it

approval covers it catches a payout without a matching, recorded approval.

Open: 11before loopopen ›Open: 22before modelopen ›Open: 33after modelopen ›Open: 44before toolopen ›Open: 55the toolopen ›Open: 66after toolopen ›Open: 77after loopopen ›Open: 88before replyopen ›It readsthe agent_state.approvals row forthis payoutapproval covers itrule · claims systempassCarries onfailIf it failsrefusedWHERE IN THE CODE: covers() · claims_system/server.py
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. Before paying above the limit, the claims system checks the approval itself: granted, not expired, same arguments, decided by someone other than the customer.
It readsthe agent_state.approvals row for this payout
Kindrule
Provided byclaims system
If it failsrefused
Where in the codecovers() · claims_system/server.py
Runs at5 · The tool itself
Real exampleFlow 8: paid only after Asha's decision was recorded.

More on this: Payout flow.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

def covers(
    approval: ApprovalRecord | None,
    *,
    holder: str,
    claim: Row,
    key: str | None,
    now: float,
    limit: Decimal = AOAS_LIMIT,
) -> str | None:
    """Why this approval record does not cover paying this claim now, or `None`.

    The call is rebuilt as this system received it — the claim, the amount this
    system holds for it, the policyholder it verified, the key on the call — and
    its digest must be the record's (`agent_harness.contracts.records.refusals`).
    `limit` is the automatic limit read for this payout."""
    if approval is None:
        return "issue_payout needs an approval, and none this system can read was named"
    amount = Decimal(str(claim.get("approved_amount", 0)))
    failed = refusals(
        approval,
        action="issue_payout",
        args={"claim_id": str(claim["id"]), "amount": str(amount)},
        requested_for=holder,
        idempotency_key=key or "",
        now=now,
    )
    if approval.decided_by in (None, holder):
        failed.append("nobody but the policyholder approved it")
    if amount > limit and approval.decided_by == AUTOMATIC_APPROVER:
        failed.append(f"{amount} is above the {limit} automatic limit, and no person decided it")
    if not failed:
        return None
    return f"approval {approval.id} does not cover this payout: {'; '.join(failed)}"