Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7339faa
feat(types): counterparty confirmations in record/run/v1, with a comm…
abrichr Nov 21, 2026
956df69
feat(types): bind a handoff payload and record the approval binding i…
abrichr Nov 21, 2026
c2edb9d
feat(flow): record the run's item-approval binding in its receipt
abrichr Nov 21, 2026
273509d
style: ruff
abrichr Nov 21, 2026
058851f
Merge feat/seal-page-app into feat/receipt-counterparty-line; the wea…
abrichr Nov 21, 2026
3e2a87e
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
49da9cd
feat(types): report.canonical, the RFC 8785 digest of the report, bes…
abrichr Nov 21, 2026
e19fe2b
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
f95f7c9
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
f9e8953
feat(types): follow-up receipts (predicate.follows) and chain verific…
abrichr Nov 21, 2026
81ebfcb
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
15d87bd
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
eb0c4a7
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
941afc5
fix(receipts): follow-ups only from the original's signers; approval …
abrichr Nov 21, 2026
e50373e
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
4ab5ce0
fix(flow): type the approval values for mypy
abrichr Nov 21, 2026
91908d1
Merge remote-tracking branch 'origin/feat/seal-page-app' into feat/re…
abrichr Nov 21, 2026
f2a8be9
fix(flow): type the run statement for mypy
abrichr Nov 21, 2026
3691eec
style(flow): sort imports in receipt_record.py (ruff I001)
abrichr Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openadapt/receipt_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def _registry(keys: Optional[Path]) -> list[Any]:
def _describe(result: Any, say: Say, indent: str = " ") -> None:
for line in result.signer_lines:
say(f"{indent}{line}")
if result.ok:
# Separate lines: they never merge with or upgrade the signer line.
for line in getattr(result, "confirmation_lines", ()):
say(f"{indent}{line}")
if getattr(result, "approval_line", ""):
say(f"{indent}{result.approval_line}")
if not result.ok:
if result.detail:
say(f"{indent}({result.detail})")
Expand Down
23 changes: 23 additions & 0 deletions packages/flow/docs/RECEIPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ URLs or page text.** Evidence files, screenshots included, appear only by
SHA-256 digest. A verifier refuses a receipt or card that carries an image,
a base64 blob, a URL or long text (`embedded_content`).

A receipt may also carry **counterparty confirmations**: evidence read from
another party's system about a handoff, such as a referral a portal later
shows as recorded. Each confirmation states the kind of system, how it was
read (a portal read-back, an API, or an acknowledgment message), its state
(`sent`, `acknowledged`, `recorded_as_intended` or `recorded_differently`) and
its own strength. Who the other party is, when it was observed, which fields
it showed and any reason are salted commitments, never shown on a public card.
The verifier prints each one on its own line, for example "Confirmed in the
other party's system at 2026-11-20T23:41:07Z". That line never merges with or
upgrades the signer line: "Signed by this computer" still means only that this
computer signed the statement.

A receipt handed to another party can also be **bound to the bytes it hands
over**: a `payload` subject names the SHA-256 and media type of the MCP tool
result, HTTP body or file. The receiver checks the bytes it got against it.
And it says **how its writes were approved**, from Flow's item approval
binding ([APPROVAL_AND_VERIFICATION.md](APPROVAL_AND_VERIFICATION.md)): the
approval mode (`each_item`, `problems_only` or `not_gated`) and the kind of
approver (a person or an agent delegate) are visible; who approved, the
scope and the time are commitments. A receipt with no approval block says
"No approval recorded", so a receipt never implies authority it doesn't
record.

## Who signed it

Each signature names a key id. The verifier's pinned key registry maps that
Expand Down
83 changes: 77 additions & 6 deletions packages/flow/openadapt_flow/receipt_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,53 @@ def _line(index: int, result: Mapping[str, Any]) -> dict[str, Any]:
}


def _approval(
report: Mapping[str, Any],
) -> tuple[Optional[dict[str, Any]], dict[str, Optional[str]]]:
"""``predicate.approval`` from the report's item-approval block, and its values.

The source is Flow's approval binding (``report.approval``,
``openadapt.approval-mode-item/v1``): its mode, and each approved
``ItemApprovalRef``. The approver's id is committed, never shown.
"""
block = report.get("approval")
if not isinstance(block, Mapping):
return None, {}
mode = block.get("mode")
if mode not in ("each_item", "problems_only", "not_gated"):
return None, {}
approved = [
a
for a in block.get("approvals") or []
if isinstance(a, Mapping) and a.get("decision") == "approved"
]
# The item's final decision decides: earlier "approved" answers never
# make a declined, waiting or unanswered item read as approved.
if mode == "not_gated" or block.get("decision") != "approved" or not approved:
return {"mode": mode, "approver_kind": "none", "commitments": {}}, {}
# The weakest approver counts: one delegate's answer among people's makes
# the whole run "approved by an agent delegate", never "by a person".
kind = (
"person" if all(a.get("decided_by") == "human" for a in approved) else "agent"
)
ids = sorted(
str(
a.get("approver_id")
or (a.get("approver") or {}).get("id")
or a.get("approver_kind")
or "unknown"
)
for a in approved
)
scope = sorted(str(a.get("request_sha256", "")) for a in approved)
values: dict[str, Optional[str]] = {
"approval.principal": f"{kind}:pr-"
+ hashlib.sha256("\n".join(ids).encode("utf-8")).hexdigest()[:16],
"approval.scope": hashlib.sha256("\n".join(scope).encode("utf-8")).hexdigest(),
}
return {"mode": mode, "approver_kind": kind, "commitments": {}}, values


def build_statement(
report: Mapping[str, Any],
report_sha256: str,
Expand Down Expand Up @@ -137,6 +184,15 @@ def build_statement(
bundle = bundle if isinstance(bundle, str) and _SHA256.fullmatch(bundle) else None
version = bundle or report_sha256
subject = [{"name": "report.json", "digest": {"sha256": report_sha256}}]
try:
subject.append(
{
"name": "report.canonical",
"digest": {"sha256": r.report_canonical_sha256(report)},
}
)
except ValueError: # a report JSON can't express canonically: file digest only
pass
if bundle:
subject.append({"name": "bundle", "digest": {"sha256": bundle}})
name = report.get("workflow_name")
Expand All @@ -152,9 +208,14 @@ def build_statement(
run_id = report.get("run_id")
if isinstance(run_id, str) and r.DISCLOSURE_FIELDS["run_id"].fullmatch(run_id):
values["run_id"] = run_id
commitments, openings = r.make_openings(values, salt=salt)
approval, approval_values = _approval(report)
commitments, openings = r.make_openings({**values, **approval_values}, salt=salt)
if approval is not None:
approval["commitments"] = {
path.split(".", 1)[1]: commitments.pop(path) for path in approval_values
}
checks = _checks(report)
statement = {
statement: dict[str, Any] = {
"_type": r.STATEMENT_TYPE,
"subject": subject,
"predicateType": r.PREDICATE_TYPE,
Expand Down Expand Up @@ -187,6 +248,8 @@ def build_statement(
},
},
}
if approval is not None:
statement["predicate"]["approval"] = approval
return statement, openings


Expand Down Expand Up @@ -411,12 +474,20 @@ def verify_run_receipt(
result = r.verify_receipt(envelope, registry, openings=openings)
if not result.ok or result.statement is None:
return result
subjects = {s["name"]: s["digest"]["sha256"] for s in result.statement["subject"]}
# ``attach-seal`` keeps the signed bytes as report.pre-seal.json.
# ``attach-seal`` keeps the signed bytes as report.pre-seal.json. The
# file digest is checked against ``report.json`` and the canonical digest
# against ``report.canonical``, never one against the other.
for name in ("report.json", "report.pre-seal.json"):
path = run_dir / name
if path.is_file() and (
hashlib.sha256(path.read_bytes()).hexdigest() == subjects.get("report.json")
if not path.is_file():
continue
data = path.read_bytes()
try:
canonical = r.report_canonical_sha256(loads_strict(data.decode("utf-8")))
except (UnicodeDecodeError, ValueError):
canonical = None
if r.report_subject_match(
result.statement, file_bytes=data, canonical_sha256=canonical
):
if name != "report.json" and (run_dir / "report.json").is_file():
# Say which bytes it covers: never a silent pass for a
Expand Down
Loading
Loading