Skip to content

Receipts: counterparty confirmations in record/run/v1 - #2410

Merged
abrichr merged 19 commits into
mainfrom
feat/receipt-counterparty-line
Nov 21, 2026
Merged

abrichr merged 19 commits into
mainfrom
feat/receipt-counterparty-line

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

This PR adds counterparty confirmations to record/run/v1: evidence read from another party's system about a handoff. The founder approved the line type in openadapt-internal#211. It is stacked on #2394, so retarget it to main after #2394 merges.

Draft, not for merge.

Schema

predicate.confirmations[] is optional, and it is left out when empty. A receipt without confirmations is byte-identical to one written before this change, and a test checks that.

Each confirmation is closed:

Field Values
kind counterparty_confirmation
for_step null, or the step of one of the receipt's lines
system_kind ehr, payer_portal, bank, erp, crm, government_portal, email, other
read_method portal_read_back, api, acknowledgment_message
state sent, acknowledged, recorded_as_intended, recorded_differently
strength read_back, acknowledgment, none
differing_count the number of fields that differ
commitments salted commitments to the counterparty (<system_kind>:cp-<16 hex>), observed_at, the optional reason, and each observed field (<field_id>:<sha256>[:differs])

Rules

  • A sent confirmation has strength none, and an acknowledged one has strength acknowledgment.
  • Both recorded_* states need a portal or API read and strength read_back.
  • differing_count is at least 1 exactly when the state is recorded_differently.
  • A reason is checked against the state when the private openings are read:
    • sent takes any reason except conflicting_report.
    • acknowledged takes ambiguous_key, not_found or no_answer_by_deadline.
    • Both recorded_* states take only conflicting_report.

Verifier and public cards

  • Verifier output: the verifier prints each confirmation in a separate confirmation_lines list, for example "Confirmed in the other party's system at ". These lines never merge with or upgrade the signer_lines.
  • Independence: a confirmation counts as independent only for a portal or API read. Nothing in the handoff payload decides it.
  • Public cards: the allow-list is unchanged. A public card shows the state, strength, read method, system kind and differing count, and opens nothing else. It prints "Confirmed in the other party's system" with no time.

Vectors

9 new vectors:

  • one for each state;
  • a tampered confirmation;
  • a public redaction, and a card that opens a field it may not;
  • a valid reason (sent with no_answer_by_deadline), and an inconsistent one.

Also: handoff payload and approval (openadapt-internal#270)

  • payload subject: a closed subject kind with a sha256 and a closed media_type, for the bytes handed to another party. verify_receipt(..., received=bytes) refuses payload_not_bound (the receipt names no payload) or payload_mismatch (a different digest), and reports payload_bound.
  • predicate.approval: optional. It carries mode (each_item, problems_only, not_gated), approver_kind (person, agent, none), and commitments to principal, scope and approved_at. It comes from Flow's item approval binding (APPROVAL_AND_VERIFICATION.md).
    • A public card shows only the mode and the approver kind.
    • With no block, the verifier prints "No approval recorded".
  • Vectors: 6 more: payload-bound, payload-mismatch, payload-missing, approval-public-card, approval-none and approval-not-gated. The existing vectors are byte-identical.
  • Not yet: Flow's emitter doesn't fill payload or approval yet. The handoff writer (feat/a2a-serve) fills payload, and filling approval from the report's item approvals is a follow-up.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 058851f

First review of this PR. Author is GitHub abrichr, not Grok. The PR is still a draft. I will not merge. Unique work versus current #2394 (99d3439f) is the record/run/v1 confirmation and payload subjects, the approval binding, vectors, Flow's _approval writer, and the merge commit that makes the weakest approver count. I am not re-litigating #2394's open safeHref finding here; this branch is stacked on that head.

A declined item can still be recorded as approved

packages/flow/openadapt_flow/receipt_record.py _approval looks only at block.mode and at entries whose decision is "approved". It never reads block.decision.

Flow's own model allows a declined item to keep earlier approved answers (ItemDecisionKind.DECLINED: "earlier saves of the same item, if any, stay as they are"; the last ref is the decline). I probed the writer's rule with that shape:

  • decision="declined" with one prior "approved" human answer and one "declined" answer produces approver_kind="person" and mode="each_item".
  • The verifier then prints "Approved by a person: each item".

The same overclaim applies to approval_required, problem, or stop_before_saving if any approved ref is already on the block. The mixed person-plus-delegate case in the merge is handled correctly (all(decided_by == "human"), otherwise "agent"), and the types verifier rightly does not try to reconstruct kind from private refs. The writer still has to take the block's overall decision so a declined (or not-yet-approved) item cannot be signed as approved.

What else I checked

  • Confirmation consistency is tight: sent/acknowledged/recorded_* strength and read-method rules, differing_count, required counterparty and observed_at commitments, and REASONS_FOR_STATE when a reason is opened. Confirmation lines are separate from signer lines and do not upgrade the outcome. Public-card openings cannot include confirmation paths (disclosure_not_allowed). Empty confirmations are omitted, so a receipt without one stays byte-identical.
  • A payload subject must have a media type; received bytes fail closed on payload_not_bound or payload_mismatch. SubjectName is report.json, bundle, evidence, payload with max_length=4. This head does not add report.canonical.json (commit 4f95a31e is not an ancestor). Flow's build_statement also still never emits confirmations or a payload subject; only the approval block is wired. Those are leftovers, not independent blockers for this review.

Review only; I am not merging.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 49da9cd

Re-review after my REQUEST CHANGES at 058851fb4aae8466c536d6e91d11fa5adf1538a7. Author is still GitHub abrichr, not Grok. The PR is still a draft. I will not merge.

Unique commits since that head: a merge of current #2394 (46b0630d, the encrypt renamed-leaf fix) and 49da9cddd, which adds a report.canonical subject (SHA-256 of RFC 8785 / JCS bytes) beside report.json, plus jcs(), report_canonical_sha256(), and report_subject_match(). Flow's build_statement now writes both subjects when the report can be expressed canonically. Verifiers compare file bytes only with report.json and a canonical digest only with report.canonical. I checked that neither digest is accepted in the other's place, that a whitespace-only rewrite of the same report still verifies via the canonical subject, and that a changed model_calls does not. That part is aimed correctly.

The blocking approval finding from 058851fb is still unfixed.

A declined item can still be recorded as approved

packages/flow/openadapt_flow/receipt_record.py _approval is unchanged. It still looks only at block.mode and at entries whose decision is "approved". It never reads block.decision.

Flow's own model still allows a declined item to keep earlier approved answers (ItemDecisionKind.DECLINED). The same probe still holds on this head: decision="declined" with one prior "approved" human answer and one "declined" answer produces approver_kind="person" and mode="each_item", so the verifier prints "Approved by a person: each item". The writer has to take the block's overall decision so a declined or not-yet-approved item cannot be signed as approved.

Secondary, not independently blocking

  • RunStatementV1.subject is still max_length=4 after a fifth name (report.canonical) was added. A receipt that names both report digests plus bundle, evidence, and payload cannot be said. A receipt may name only one of the two report subjects, which matches the new consistency rule, but the two-digest case plus the other three subjects does not fit.
  • Confirmation/payload schema, public-card redaction, and the weakest-approver rule from the previous head are unchanged and still look sound. Flow still does not emit confirmations or a payload subject.

Review only; I am not merging.

abrichr added a commit that referenced this pull request Nov 21, 2026
…ubject

handoff send, get_handoff and the A2A run artifact re-sign the run's receipt
with the payload subject (digest and media type) using the key that signed
the run; verify checks the bytes with verify_receipt(received=...), so a
swapped payload is payload_mismatch and a receipt naming none is
payload_not_bound. The two-party test now includes both, and the shared
payload vectors run through a handoff. Merges #2410 at 49da9cd.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: e19fe2b

Re-review after my REQUEST CHANGES at 49da9cddd35ca53fa8920092c8c3aca6cbc0065c. Author is still GitHub abrichr, not Grok. The PR is still a draft. I will not merge.

The unique change since that head is a merge of current #2394 (e3d8edfb: encrypt registration moved out of __main__, after_run_notes, receipt wording in the OpenEMR snapshot). _approval is unchanged: it still ignores block.decision, so a declined item with an earlier approved answer is still signed as "Approved by a person: each item". RunStatementV1.subject is still max_length=4 after a fifth name (report.canonical) was added. The JCS helpers from 49da9cdd are unchanged and still look sound.

Review only; I am not merging.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: f95f7c9

Re-review after my REQUEST CHANGES at e19fe2b6e8df65c179c90adaea9af426f1e974ac. Author is GitHub abrichr, not Grok. The PR is still a draft. Review only; I am not merging.

The only unique delta since that head is the merge of #2394 at 84a3c7ab3cb68d5cef69015b283aeed02821f678 (the safeFileHref extraction and the failed-copy / Raw-format viewer changes).

That does not clear the previous findings:

  1. safeHref still accepts https://openadapt.ai:@evil.example, https://openadapt.ai:.@evil.example, and https://openadapt.ai:443@evil.example. Browsers treat those as userinfo at host evil.example. See my review on Receipts: one signed record per run (replaces Seals) #2394 at this same safeFileHref commit. The older //evil.example and /\host cases are now rejected.

  2. _approval in packages/flow/openadapt_flow/receipt_record.py is unchanged. It still walks block.approvals for decision == "approved" and never consults block.decision. If the item's final decision is not approved, earlier approved answers can still produce approver_kind: "person" (or "agent") and approval commitments.

The subject list, JCS digest, and confirmation schema were already reviewed at the previous head and are unchanged here. Still draft; I am not merging.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 81ebfcb

Re-review after my REQUEST CHANGES at f95f7c98d06845d553b20b1359ee10de3c683757. Author is GitHub abrichr, not Grok. The PR is still a draft. Review only; I am not merging.

The two previous findings are still unfixed:

  1. safeHref still accepts the userinfo-after-colon forms (https://openadapt.ai:@evil.example and the same with :.@ or :443@). This head only merged Receipts: one signed record per run (replaces Seals) #2394 at 70bdde90, which did not change safeFileHref.
  2. _approval still ignores block.decision, so earlier decision == "approved" answers can still produce approver_kind: "person" or "agent" after the item's final decision is not approved.

New in this delta: predicate.follows, follow_up_statement, verify_chain, and the five shared chain vectors. The copied-field list, sequence 1, 2, 3, wrong_original, changed_original, and the new mixed_demo refusal (a demo-key update cannot extend a real chain, or the reverse) are right. wire() still drops follows when it is unset. verify_chain still accepts a follow-up signed by any key in the receiver's registry, not necessarily a key that already signed the original. Please require that.

I am not merging.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 15d87bd

Delta re-review of my REQUEST CHANGES at 81ebfcb2354598ea907e5a58535dbdf752a40c0d, after a merge of #2394's current head. Author is still GitHub abrichr, not Grok. Review only; I am not merging. Still a draft.

The unique delta is that same _write change from #2394 (open_binary and a short-write loop). No other unique files moved.

The inherited findings are unchanged: safeHref still accepts the userinfo-after-colon URLs, and _approval still ignores block.decision (it only filters item rows with decision == "approved"). Founder copy/visual approval still required.

…follows the final decision

verify_chain refuses a follow-up signed by any key that did not sign the
original (new refusal different_signer, with a shared vector). _approval
reads the item's final decision: earlier approved answers never make a
declined or unanswered item read as approved by a person or agent. Merges
#2394's safeHref fix.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Grok: re-review request for the REQUEST CHANGES at 15d87bde. New head: 941afc5ae9de106ac6733cdbdc0d16f392c3c9f3.

What changed, blockers only:

  • safeHref: merged Receipts: one signed record per run (replaces Seals) #2394's fix (only an optional numeric port may follow the host; userinfo forms such as https://openadapt.ai:443@evil.example return null).
  • _approval (packages/flow/openadapt_flow/receipt_record.py): approver kind person/agent and the principal/scope values now require block.decision == "approved". A declined, waiting or unanswered item yields approver_kind: "none" and no values, whatever earlier answers said. Test: test_earlier_approvals_never_make_a_declined_item_read_as_approved.
  • verify_chain (packages/types/openadapt_types/receipt.py): every signer of a follow-up must be a key that signed the original; otherwise the chain is refused with the new reason different_signer. That covers an update signed only by another registered key and one co-signed by the original key plus another. New shared vector chain-different-signer.json (other vectors byte-identical) and README item 12 updated.

Still a draft on feat/seal-page-app; it retargets to main once #2394 merges.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 941afc5

The final item decision now gates approval attribution. The verifier checks every follow-up signature against the trusted registry, then requires every follow-up signer to have signed the original. The normal three-record chain and the earlier-approval/final-decline regression both passed on this head (2 tests). The viewer link correction from #2394 is present.

The remaining blocker in this PR is the Flow approval writer. I reproduced both diagnostics directly on this head with the CI-pinned Mypy 2.3.0 and the package configuration.

  • At line 146, the commitment values are strings, while the return annotation requires an invariant dictionary that also permits null values. Give the returned dictionary its actual value type. Approval return type
  • At line 243, Mypy infers a collection for the nested predicate. Give the statement or predicate an explicit mutable dictionary type when constructing it so the approval assignment type-checks. Both corrections can preserve the signed bytes. Statement construction and assignment

The base’s receipt issuance, completeness and signer-label findings are tracked in the #2394 review. They are inherited here.

The approval and chain rules are application-independent. The new regression covers final decisions after earlier approvals, and the shared chain fixtures cover changes of signer across updates. No held-out external application was exercised in this review.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 4ab5ce0

One of the two Flow mypy findings remains. build_statement constructs statement without a type annotation at line 216. At line 250 it assigns approval through statement["predicate"], which mypy inferred as a Collection on the previously checked head. The statement construction and assignment are byte-for-byte identical across those heads. The return annotation of _approval, the imported receipt types and the Flow mypy configuration are also unchanged. Give statement its declared return type, dict[str, Any], at construction, then run the package type check. Statement and assignment · Prior mypy 2.3.0 findings

The other finding is resolved. _approval now types values as dict[str, Optional[str]], matching its return annotation. The final-decision and follow-up signer rules are unchanged. This check compared source. The current draft skipped package CI, and I did not rerun mypy locally. Approval values · CI

The annotations apply to every Flow report and introduce no application-specific behavior. The earlier synthetic approval-history and follow-up signer cases remain the scope of the runtime evidence. No held-out external application was exercised. The two inherited verification-route findings remain with #2394.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Codex
Reviewed-Head: f2a8be9

The last type-check finding is resolved in source. build_statement now constructs statement: dict[str, Any], which types the subsequent assignment to statement["predicate"]["approval"]. This annotation is the only change on top of the #2394 parent merge. The earlier values: dict[str, Optional[str]] correction is present. Statement and assignment

The final-decision check still requires an approved decision, and each follow-up still requires a nonempty signer set drawn from the original receipt’s signers. The signer validator and its regression tests are byte-identical to the previous reviewed head. Decision check · Signer check

I verified the immutable source delta. The author reports that the statement diagnostic cleared in Flow mypy, with a separate Playwright import diagnostic in their environment. The exact-head hosted CI run was pending at review. This PR remains a draft stacked on #2394. Hosted CI

Base automatically changed from feat/seal-page-app to main November 21, 2026 21:44
@abrichr
abrichr marked this pull request as ready for review November 21, 2026 21:44
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

From: Gemini
Reviewed-Head: 3691eec

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Codex
Reviewed-Head: 3691eec

The sole change since the approved parent reorders the six import groups identified by the failed Flow lint job. All imports and aliases stay in their original scopes. The approval-decision check and the explicit values and statement types are intact. One-file diff

I compared all six corrected groups and the Flow Ruff configuration with the previously checked stack commit. They match byte for byte. This source-only change adds no application rules or runtime evidence. Current-head CI is still pending.

@abrichr
abrichr merged commit e7dd2ec into main Nov 21, 2026
52 of 53 checks passed
@abrichr
abrichr deleted the feat/receipt-counterparty-line branch November 21, 2026 23:10
abrichr added a commit that referenced this pull request Nov 22, 2026
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 3691eec

abrichr added a commit that referenced this pull request Nov 22, 2026
fix(hooks): emit #2410-compliant StepResult fields in hooks receipt reports
yunusarda-sudo pushed a commit to yunusarda-sudo/OpenAdapt that referenced this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant