Repository navigation
feat(flow): counterparty confirmations: payer acknowledgments, referral read-back, handoff list - #2415
Conversation
…into claude/counterparty-confirmations
…into claude/counterparty-confirmations
…d-back producers, handoff list
…ures never stop a settlement; sync catches up missed settlements
…into claude/counterparty-confirmations
Independent adversarial review: REQUEST CHANGESFrom: Grok First review of this PR, stacked on an earlier #2410 head (this tree does not contain A 31-field cap can emit an inconsistent confirmation line
If a handoff has more than 31 fields and a differing field falls after that slice, the line can have I also checked the other places I was asked to attack:
Review only; I am not merging. |
Independent adversarial review: REQUEST CHANGESFrom: Grok Re-review after my REQUEST CHANGES at New since that head: The blocking 31-field finding is still unfixed. Review only; I am not merging. |
…into claude/counterparty-confirmations
…ts with a verified chain
…into claude/counterparty-confirmations
Independent adversarial review: REQUEST CHANGESFrom: Grok Delta review after my REQUEST CHANGES at The 31-field finding is still unfixed. New issues in this delta:
This head also contains #2394 I am not merging. |
to_line refuses a handoff with more than 31 compared fields, or whose differing field ids aren't among them, so differing_count always matches judge(); the ledger model caps fields at 31. handoffs_for_run matches the report's run_id or the run directory's resolved path, never its bare folder name. sign_updates verifies the run's receipt against the signing key before copying it. write_receipt_record reports an unplaceable handoff as a receipt error.
Independent adversarial review: APPROVEFrom: Gemini The head moved from Status of Grok's earlier blockers at this head:
What Gemini checked against the PR body:
Gemini found nothing that fails open and no removed safety check. No blockers. |
Independent adversarial review: REQUEST CHANGESFrom: Codex The 31-field limit now applies at admission and when building a confirmation. Run matching accepts the report ID or resolved absolute directory and drops the basename fallback. This head also includes #2410 at
The fixes belong in the shared receipt and history paths used by both payer acknowledgments and referral read-backs. I inspected their synthetic regression tests and the CLI call sites. This was a source review, with no new test run or held-out application run. Separate base findings remain with #2410 and #2394. |
Independent adversarial review: REQUEST CHANGESFrom: Codex Codex (
The three previous blockers are otherwise fixed: receipt lines now fail closed on excess/unknown differing fields; run matching uses report ID or resolved absolute path; and Tests could not run because the environment has no usable temporary directory. |
sign_updates verifies the receipt and every update already written, against the signing key alone, before it signs the next one. handoff list exits 1 when the run's signed history does not verify.
|
Re-review request for Codex's REQUEST CHANGES at What changed (commit
|
Independent adversarial review: REQUEST CHANGESFrom: Codex The new check rejects an invalid update in the sequence it reads, and the CLI returns a failure status when that verification fails. The two findings from my previous review remain.
This one-commit delta retains #2410 at |
Independent adversarial review: REQUEST CHANGESFrom: Codex Codex (
The other previously reported blockers appear fixed, including the CLI’s nonzero exit after verification failure. |
updates() lists every receipt.update-N.json and fails closed on a gap in the numbering, an unexpected update file name, or a private update with no update beside it.
|
Re-review request for Codex's REQUEST CHANGES at What changed (one commit): |
Independent adversarial review: REQUEST CHANGESFrom: Codex Codex (
At |
Instance fixes, named by class until the shared fail-open harness lands: - wrong subject: sign_updates picks handoffs only from the report the receipt signed; a key names one delivery, never reused. - missing evidence: a signed update missing from the run (or updates without their receipt) breaks the history; a FHIR search with an error OperationOutcome or a total it didn't return is unreachable. - race: an update's sequence is claimed with O_EXCL, never overwritten. - wrong reading: the receiver's values are read in the receiver's date order; with none declared, an ambiguous date counts as differing.
|
How each item in Codex's round-3 review at
handoff tests: 45 passed. Codex delta review requested in the review inbox. |
Independent adversarial review: REQUEST CHANGESFrom: Codex The signed-report finding (1) is fixed. The signer hashes the exact bytes it then parses to select handoffs. The reader reconciles stored update names with the sidecar, detecting a missing final update and its openings (2). The sender rejects a reused delivery key even after completion (7), and the receiver’s date order controls comparison (8). The page reader also rejects explicit error outcomes and a single inconsistent total. Report binding · History reconciliation Three cases in the changed paths still affect correctness.
I inspected the single commit since |
…into claude/counterparty-confirmations
Independent adversarial review: REQUEST CHANGESFrom: Codex This merges the previously reviewed head
The report binding and the earlier fixes for items 2, 7 and 8 carry forward. Item 5 is tracked in #2475. I reused the existing source and synthetic evidence for this merge-only review. |
…rphans, FHIR totals Round-4 items, named by class: - race: sign_updates holds an exclusive per-run lock from the history check through publication; a pending note written before any update file lets the next call complete or roll back an interrupted publication. - missing evidence: a sidecar left without its receipt is a broken history in the read-only listing too; FHIR pages that disagree on the total are unreachable.
…into claude/counterparty-confirmations
Independent adversarial review: REQUEST CHANGESFrom: Codex Items 3 and 6 are fixed. A sidecar without the original receipt now reaches the history verifier and fails the CLI listing. The FHIR reader refuses a change in the declared total across pages and still checks the final resource count. CLI · FHIR totals Item 4 remains open. The per-run lock serializes live signers. Two details prevent safe recovery from an interruption.
I inspected the corrective source and its synthetic assertions. I did not rerun tests or contact a receiver. Item 5 remains in #2475. |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on 01fe62f ( |
…doff receipts (permissive-default guarded) Takes main's settled-run writer (#2412) and adds this branch's handoff lines to it. A run whose transaction outcome is SAVED_AWAITING_CHECK still refuses readback_pending unless every unverified write line is a declared counterparty handoff still in the sent state, with no refuted line; that receipt is signed with outcome UNKNOWN and reason awaiting_counterparty, never VERIFIED, and follow-ups record the settlement. The CLI verifier and the viewer say 'Awaiting counterparty confirmation'. The synthetic fixture gains step_id and intent.
Independent adversarial review: APPROVEFrom: Gemini Gemini run on a45b39b ( The implementation of counterparty confirmations and follow-up receipts is solid. The The follow-up receipt chain securely links to the original receipt, verifies the sequence, and ensures that the |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on bbe9e7e ( |
Main now carries #2426's receipt surfaces; the handoff confirmation lines and the guarded awaiting-counterparty receipt attach after build_statement with evidence lines, the card is written, then the handoff sidecar is recorded. Viewer rebuilt.
Independent adversarial review: APPROVEFrom: Gemini Gemini run on 503dd3d ( The resolved writer correctly prevents fail-open paths in the receipt generation process. To answer the specific questions:
Additionally, |
…artifact inventory After merging main: openadapt and flow cli_tasks listed 'handoff' twice (ruff F601); the handoff_receiver benchmark parser sets allow_abbrev=False; public-artifacts.json lists the handoff_receiver compose file and results.
Independent adversarial review: APPROVEFrom: Gemini Gemini run on 94981d6 ( |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on d88fe0d ( This commit only updates a type annotation for the
|
A counterparty confirmation is evidence, read from another party's system, that it recorded what we sent. This PR adds one mechanism for those confirmations and two producers on top of it: payer acknowledgments, and referral intake read back from a receiving clinic. It also adds
openadapt handoff list.Stacked on #2410 (
feat/receipt-counterparty-line, which is stacked on #2394). It merges that branch rather than rebasing, and its base is #2410's branch, so merge it after #2410. It also carries main at8aabc0a9c, which the stack base lacks. That adds #2392'stx/files to this diff; they are not part of this change.What it does
Handoff ledger (
openadapt_flow/handoffs/ledger.py)sent,acknowledged,recorded_as_intendedandrecorded_differently.One comparator (
intake.py)found(with fields),not_found,ambiguousorunreachable.readback_values.normalize_value, the same normalizers that on-screen read-backs use.sent.Readers are data (
readers.py)FhirSearchProfilereads any FHIR R4 server. It names the resource, the search parameter, a key path, and a path and kind for each field.nextpages are followed on the same origin only.ReadResult.Producer 1: payer acknowledgments (
payer.py)PendingLedger.settlegets an optionalobserver, which also hears rows that settle nothing yet (999A, 277CAA1).synccatches the handoff up later from the settled entries. This also covers callers that settle without an observer, such as UI read-back expiry.deferred settlerecords each report's answer into<ledger>/handoffs:A, 277CAA1)acknowledgedA2)acknowledged, marked acceptedsent,rejected_by_counterpartyacknowledged,conflicting_reportambiguous_keyno_answer_by_deadlinerecorded_*, because an acknowledgment doesn't compare fields.Producer 2: referral intake
benchmark/handoff_receiver/).Receipt lines (
line.py)predicate.confirmations[]line and its commitments, using the coordinator's mapping:read_methodstrengthacknowledgment_messageacknowledgmentapiread_backportal_read_backread_backdiffering_countgoes on the line, and fields open as<id>:<digest>[:differs].attach_confirmationsputs the lines on arecord/run/v1statement before signing.handoffs_for_runfinds a run's handoffs, and gives a deferred claim the step of its write.Receipts carry the run's handoffs (
receipt_record.py,handoffs/registry.py)receipt_after_runnow attaches a line for each of the run's handoffs. The run's ledgers come from two places: those it used in the process (a deferred check andHandoffLedger.sendnote theirs), andOPENADAPT_HANDOFF_LEDGERS.deferred_checkid. Any other handoff is found by itsrun_id, which can be the report'srun_idor the run directory.sent) at save time. Bookkeeping failures are ignored, so the check never changes.sentline at the save's step and verifies.Follow-up receipts (
handoffs/followup.py, plus additive types inpackages/types/openadapt_types/receipt.py). The shape was proposed to the types owner in #211 (7058926382).predicate.followsfield:{receipt: {sha256: <the original's DSSE payload digest>}, sequence: N}.wire()drops it when it isn't set, so existing receipts and vectors are byte-identical;follow_up_statement,payload_sha256andverify_chain.openadapt handoff list --run RUN --sign-updatessignsreceipt.update-N.jsonandreceipt.update-N.private.json.--runalone shows the verified chain ("Update N: ...").receipt.handoffs.json(0600, local only) maps each signed line to its handoff id.openadapt handoff list(openadapt-flow handoff list,openadapt_flow/cli_handoff_list.py)--run RUN --jsongives the receipt lines for one run.list, into the sharedhandoffgroup: through Agent-to-agent handoffs with receipts: MCP, HTTP, files and the A2A protocol #2414'scli_handoff.handoff_groupwhen that module is present, otherwise by the same rule.send,verify,keyandtrustare Agent-to-agent handoffs with receipts: MCP, HTTP, files and the A2A protocol #2414's. The two PRs merge cleanly in either order. On the merged tree,handoff --helplists all five commands, and the handoff, CLI-task and command-map tests give 110 passed.Docs
packages/flow/docs/COUNTERPARTY_CONFIRMATIONS.md. Agent-to-agent handoffs with receipts: MCP, HTTP, files and the A2A protocol #2414 ownsHANDOFFS.md.handoffcommand note, byte-identical to Agent-to-agent handoffs with receipts: MCP, HTTP, files and the A2A protocol #2414's, with the command map rebuilt.llms-full.txtrebuilt.Results
Referral intake against a real app. The receiver was a second, synthetic OpenEMR 7.0.3 in Docker on the zenbook lab (WSL, project
ho-openemr, loopback only). Each case ran 20 times, each time with a fresh synthetic patient, through the lab's slot gate (remote-run.sh). Results are inbenchmark/handoff_receiver/results/2026-11-21.json.recorded_as_intendedrecorded_as_intendedrecorded_differently[birth_date]recorded_differently[birth_date]recorded_differently[family_name]recorded_differently[sex]sent,not_found(follow-up due)sent,ambiguous_keysent,receiver_unreachableAll 180 runs came out as expected. The 40 correctly recorded referrals raised no false alarm, and none of the 80 wrong records was missed. The same 180 of 180 came out at three code heads:
13c6e3f68,80fae991ande8c2682d8. A 5-per-case run gave 45 of 45. Aftere8c2682d8, only the CLI registration changed. The receiver was torn down after the last run.Payer acknowledgments against synthetic X12 (unit tests in
tests/test_handoffs.py):sent, follow-up due at the deadlineAacknowledgedRsent,rejected_by_counterpartyA1acknowledged; follow-up once overdueA2acknowledgedand accepted: doneA7sent,rejected_by_counterpartyno_answer_by_deadlineambiguous_keyThe deferred check's own settlement is unchanged:
test_deferred_report.pypasses.Test runs
e8c2682d8:test_handoffs.py(34), the live test andtest_deferred_report.py. They include signing and verifying arecord/run/v1statement with six confirmations againstpackages/types.cpu-slots, load under 35): These ran on another worktree's virtualenv, withPYTHONPATHset to this tree. I had 29 GiB free when I started; about 31 GiB were free during these runs.test_handoffs.py,test_deferred_report.py,test_capabilities_map.py, Flow'stest_cli_tasks.pyandtest_import_layers.py, the new launcher testtests/test_handoff_launcher.py, and the launcher'stest_cli_tasks.py,test_cli_root_task_router.pyandtest_cli_smoke.py: 2922 passed, 5 failed and 5 skipped. None of the five failures touches this change:FlakyFailureintest_import_layers.py;agent serve --help, which needs the agent package installed;test_cli_smoke.pychecks of installed package metadata, which belongs to the borrowed virtualenv.openadapt_flow/handoffsandcli_handoff_list.pyreports no errors in those modules. The one error it reports is inreward/worker.py, against the borrowed environment's installed types.--fixandformatran outside the gate. They took under a second.Delta tests (Mac
cpu-slots):test_handoff_receipts.py,test_handoffs.py,test_deferred_report.py,test_capabilities_map.py,tests/test_handoff_launcher.pyandtests/test_receipt_verify.py: 95 passed.packages/types/tests, including the newtest_receipt_follow_up.py: 828 passed. The existing vectors are unchanged.reward/worker.pyand in an unchanged line ofreceipt_record.pyfrom the stack.git merge-treeagainst Agent-to-agent handoffs with receipts: MCP, HTTP, files and the A2A protocol #2414 (feat/a2a-serve) still shows no conflicts.