Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
db41968
wip: handoff ledger
abrichr Nov 21, 2026
aaf45e8
Merge remote-tracking branch 'origin/feat/receipt-counterparty-line' …
abrichr Nov 21, 2026
254f617
wip: handoffs mechanism, payer and read-back producers, handoff list
abrichr Nov 21, 2026
13c6e3f
wip: docs, receiver harness, live test
abrichr Nov 21, 2026
81f68aa
Merge remote-tracking branch 'origin/feat/receipt-counterparty-line' …
abrichr Nov 21, 2026
7a41ede
docs: rebuild llms-full
abrichr Nov 21, 2026
80fae99
feat(flow): counterparty confirmations: handoff ledger, payer and rea…
abrichr Nov 21, 2026
2753093
results: referral intake on the OpenEMR receiver at 80fae991
abrichr Nov 21, 2026
66a62da
fix(flow): handoff list joins the shared handoff group; observer fail…
abrichr Nov 21, 2026
e8c2682
Merge remote-tracking branch 'origin/feat/receipt-counterparty-line' …
abrichr Nov 21, 2026
1741f4d
refactor(cli): use the shared handoff_group helper when it is installed
abrichr Nov 21, 2026
6bf5c4a
docs: share the handoff command note with #2414
abrichr Nov 21, 2026
8b75dab
Merge remote-tracking branch 'origin/feat/receipt-counterparty-line' …
abrichr Nov 21, 2026
838b91d
feat: receipts carry the run's handoff lines; signed follow-up receip…
abrichr Nov 21, 2026
fb5cc35
Merge remote-tracking branch 'origin/feat/receipt-counterparty-line' …
abrichr Nov 21, 2026
42b354a
Merge origin/feat/receipt-counterparty-line into claude/counterparty-…
abrichr Nov 21, 2026
dc07e1f
fix(handoffs): fail closed on lines that can't hold every compared field
abrichr Nov 21, 2026
754add8
fix(handoffs): extend only a signed history that verifies
abrichr Nov 21, 2026
cdbc611
fix(handoffs): no update file is ever left out of a run's history
abrichr Nov 21, 2026
a8e2098
fix(handoffs): close the round-3 fail-opens in follow-ups and read-back
abrichr Nov 21, 2026
cd47e7c
Merge remote-tracking branch 'origin/feat/receipt-counterparty-line' …
abrichr Nov 21, 2026
e5646ed
fix(handoffs): one signer per run, recoverable publication, sidecar o…
abrichr Nov 21, 2026
01fe62f
Merge remote-tracking branch 'origin/feat/receipt-counterparty-line' …
abrichr Nov 21, 2026
5e03ec5
Merge origin/main into claude/counterparty-confirmations; pending han…
abrichr Nov 22, 2026
a45b39b
style: sort receipt_record.py imports
abrichr Nov 22, 2026
bbe9e7e
Merge remote-tracking branch 'origin/main' into claude/counterparty-c…
abrichr Nov 22, 2026
503dd3d
Merge origin/main into claude/counterparty-confirmations
abrichr Nov 22, 2026
2014301
Merge remote-tracking branch 'origin/main' into claude/counterparty-c…
abrichr Nov 22, 2026
94981d6
fix(ci): duplicate handoff task key, benchmark parser abbreviations, …
abrichr Nov 22, 2026
d88fe0d
fix(types): type the handoff send fields as text for mypy
abrichr Nov 22, 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
5 changes: 5 additions & 0 deletions CAPABILITIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ improvising or retrying when something is off.
| Learn the record check from the recording, when the person looks the record up after saving | Released ([#1290](https://github.com/OpenAdaptAI/OpenAdapt/pull/1290)) | Synthetic | `record --verify` |
| A record check's duplicate key can be several fields together, such as last name, first name and birth date: the check fails when more than one record carries all of them, counting records that were already there | Released ([#1393](https://github.com/OpenAdaptAI/OpenAdapt/issues/1393)) | Synthetic (OpenEMR-shaped patient rows) | verify.yaml `record.duplicate_key: [lname, fname, DOB]`, `confirm_params(idempotency_key=[...])`, `Effect.composite_key` |
| Checked later: a save confirmed by a later report or acknowledgment, never counted as done until then | Released ([#1297](https://github.com/OpenAdaptAI/OpenAdapt/pull/1297)) | Synthetic | `SAVED_AWAITING_CHECK` |
| Counterparty confirmations for payer claims: each claim with a deferred check is a handoff, and the payer's 999 or 277CA moves it to `acknowledged` (received or accepted, status only) or back to `sent` with a reason (rejected, no answer by the deadline, two claims on one key). The deferred check settles exactly as before | In a pull request | Synthetic (X12 999 and 277CA fixtures, unit tests) | `deferred settle`, `openadapt_flow/handoffs/payer.py`, [COUNTERPARTY_CONFIRMATIONS.md](packages/flow/docs/COUNTERPARTY_CONFIRMATIONS.md) |
| Counterparty confirmations by read-back: the sender records what it sent (as digests), then reads the other party's system by a profile (data) and reports `recorded_as_intended`, `recorded_differently` with the differing field ids, or `sent` with a reason (not found, matched twice, unreachable). One comparator for every producer | In a pull request | Real app: a second, synthetic OpenEMR 7.0.3 as the receiving clinic, written through its REST API and read back through FHIR with a read-only token; 180 of 180 runs as expected over 9 cases, 0 false alarms in 40 correctly recorded referrals, [results](packages/flow/benchmark/handoff_receiver/results/2026-11-21.json) | `openadapt_flow/handoffs/`, [COUNTERPARTY_CONFIRMATIONS.md](packages/flow/docs/COUNTERPARTY_CONFIRMATIONS.md) |
| Open handoffs by state, with who still needs to follow up | In a pull request | Unit tests | `openadapt handoff list` |
| Receipts carry the run's handoffs as counterparty confirmation lines (`predicate.confirmations[]` in `record/run/v1`), written by the after-run receipt hook | In a pull request | Unit tests, and a real replayer run whose receipt carries its claim's `sent` line and verifies | `openadapt_flow/handoffs/line.py`, `receipt_record.py` |
| Follow-up receipts: each later change in a handoff's state is a separately signed `record/run/v1` record naming the original receipt (`follows`), and the chain verifies in order (`verify_chain`) | In a pull request | Unit tests: a three-record chain verifies; wrong original, out of sequence, changed fields and empty updates are refused | `openadapt handoff list --run RUN --sign-updates`, `openadapt_flow/handoffs/followup.py` |
| Keep the server's own answer to a save as lower-level evidence on the receipt | Released ([#1298](https://github.com/OpenAdaptAI/OpenAdapt/pull/1298)) | Synthetic | receipts |
| A ledger of what changed before a stop, a write-ordering lint, and undo steps a person approves | Released ([#1263](https://github.com/OpenAdaptAI/OpenAdapt/pull/1263)) | Synthetic (MockMed) | change ledger |
| Propose an undo for each saving step (another recording, captured traffic, or the old value), keep it only if a test copy shows every record restored, and offer it after a stop once a person approves it | Released ([#1346](https://github.com/OpenAdaptAI/OpenAdapt/pull/1346)) | Synthetic (MockMed, MockLoan, live browser) | `openadapt-flow undo propose`, `undo accept`; [AFTER_A_STOP.md](packages/flow/docs/AFTER_A_STOP.md) |
Expand Down
5 changes: 5 additions & 0 deletions llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,11 @@ improvising or retrying when something is off.
| Learn the record check from the recording, when the person looks the record up after saving | Released ([#1290](https://github.com/OpenAdaptAI/OpenAdapt/pull/1290)) | Synthetic | `record --verify` |
| A record check's duplicate key can be several fields together, such as last name, first name and birth date: the check fails when more than one record carries all of them, counting records that were already there | Released ([#1393](https://github.com/OpenAdaptAI/OpenAdapt/issues/1393)) | Synthetic (OpenEMR-shaped patient rows) | verify.yaml `record.duplicate_key: [lname, fname, DOB]`, `confirm_params(idempotency_key=[...])`, `Effect.composite_key` |
| Checked later: a save confirmed by a later report or acknowledgment, never counted as done until then | Released ([#1297](https://github.com/OpenAdaptAI/OpenAdapt/pull/1297)) | Synthetic | `SAVED_AWAITING_CHECK` |
| Counterparty confirmations for payer claims: each claim with a deferred check is a handoff, and the payer's 999 or 277CA moves it to `acknowledged` (received or accepted, status only) or back to `sent` with a reason (rejected, no answer by the deadline, two claims on one key). The deferred check settles exactly as before | In a pull request | Synthetic (X12 999 and 277CA fixtures, unit tests) | `deferred settle`, `openadapt_flow/handoffs/payer.py`, [COUNTERPARTY_CONFIRMATIONS.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/docs/COUNTERPARTY_CONFIRMATIONS.md) |
| Counterparty confirmations by read-back: the sender records what it sent (as digests), then reads the other party's system by a profile (data) and reports `recorded_as_intended`, `recorded_differently` with the differing field ids, or `sent` with a reason (not found, matched twice, unreachable). One comparator for every producer | In a pull request | Real app: a second, synthetic OpenEMR 7.0.3 as the receiving clinic, written through its REST API and read back through FHIR with a read-only token; 180 of 180 runs as expected over 9 cases, 0 false alarms in 40 correctly recorded referrals, [results](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/benchmark/handoff_receiver/results/2026-11-21.json) | `openadapt_flow/handoffs/`, [COUNTERPARTY_CONFIRMATIONS.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/docs/COUNTERPARTY_CONFIRMATIONS.md) |
| Open handoffs by state, with who still needs to follow up | In a pull request | Unit tests | `openadapt handoff list` |
| Receipts carry the run's handoffs as counterparty confirmation lines (`predicate.confirmations[]` in `record/run/v1`), written by the after-run receipt hook | In a pull request | Unit tests, and a real replayer run whose receipt carries its claim's `sent` line and verifies | `openadapt_flow/handoffs/line.py`, `receipt_record.py` |
| Follow-up receipts: each later change in a handoff's state is a separately signed `record/run/v1` record naming the original receipt (`follows`), and the chain verifies in order (`verify_chain`) | In a pull request | Unit tests: a three-record chain verifies; wrong original, out of sequence, changed fields and empty updates are refused | `openadapt handoff list --run RUN --sign-updates`, `openadapt_flow/handoffs/followup.py` |
| Keep the server's own answer to a save as lower-level evidence on the receipt | Released ([#1298](https://github.com/OpenAdaptAI/OpenAdapt/pull/1298)) | Synthetic | receipts |
| A ledger of what changed before a stop, a write-ordering lint, and undo steps a person approves | Released ([#1263](https://github.com/OpenAdaptAI/OpenAdapt/pull/1263)) | Synthetic (MockMed) | change ledger |
| Propose an undo for each saving step (another recording, captured traffic, or the old value), keep it only if a test copy shows every record restored, and offer it after a stop once a person approves it | Released ([#1346](https://github.com/OpenAdaptAI/OpenAdapt/pull/1346)) | Synthetic (MockMed, MockLoan, live browser) | `openadapt-flow undo propose`, `undo accept`; [AFTER_A_STOP.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/docs/AFTER_A_STOP.md) |
Expand Down
4 changes: 4 additions & 0 deletions openadapt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,10 @@ def flow(command_ctx: click.Context) -> None:
("record", "Record a workflow. Uses the same options as flow record."),
("compile", "Compile a recording. Uses the same options as flow compile."),
("run", "Run a bundle with its checks. Uses the same options as flow run."),
(
"handoff",
"Handoffs to other parties: what they recorded, and who follows up.",
),
):
main.add_command(
_FlowAliasCommand(
Expand Down
2 changes: 2 additions & 0 deletions openadapt/receipt_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def _describe(result: Any, say: Say, indent: str = " ") -> None:
statement = result.statement or {}
predicate = statement.get("predicate", {})
reason = predicate.get("reason_code")
if reason == "awaiting_counterparty":
say(f"{indent}Awaiting counterparty confirmation: sent, not yet confirmed.")
say(
f"{indent}Outcome: {result.outcome}"
+ (f" ({reason})" if reason else "")
Expand Down
2 changes: 1 addition & 1 deletion openadapt/seal_view/viewer.html

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions packages/flow/benchmark/handoff_receiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Referral intake: a real, synthetic OpenEMR as the receiving clinic

These are the real-app cases for counterparty confirmations by read-back
(see [COUNTERPARTY_CONFIRMATIONS.md](../../docs/COUNTERPARTY_CONFIRMATIONS.md)). A synthetic referring clinic
sends referrals to a **second, separate OpenEMR 7.0.3** that plays the
receiving clinic. OpenAdapt reads the receiver back and says whether each
referral was recorded as intended, recorded differently, or never arrived.

- **Sender:** `referral_cases.Sender`, a SQLite outbox of generated synthetic
patients.
- **Delivery:** the receiving clinic's intake, written through OpenEMR's
standard REST API (`/apis/default/api/patient`), with the sender's
referral id as the patient's external id. It makes mistakes on purpose.
- **Read-back:** OpenEMR's FHIR R4 `Patient` search, with a separate
read-only token, by the profile in
[`tests/fixtures/handoffs/fhir-patient-intake.yaml`](../../tests/fixtures/handoffs/fhir-patient-intake.yaml).
It never reads the delivery call's answer.

## Bring-up (lab, WSL Docker)

```bash
docker compose -f docker-compose.yml up -d # project ho-openemr, loopback 9780/9781
# wait for "Starting apache!" in the logs (about 8 minutes on first boot), then:
OPENEMR_COMPOSE_FILE=$PWD/docker-compose.yml OPENEMR_BASE_HTTPS=https://127.0.0.1:9781 \
OPENEMR_SCOPES="openid api:oemr api:fhir user/patient.read user/patient.write user/Patient.read user/Patient.write" \
../openemr_live/setup.sh > write.env
OPENEMR_COMPOSE_FILE=$PWD/docker-compose.yml OPENEMR_BASE_HTTPS=https://127.0.0.1:9781 \
OPENEMR_SCOPES="openid api:fhir user/Patient.read" \
../openemr_live/setup.sh > read.env
```

Export these from the two tokens:

- `HANDOFF_RECEIVER_API_BASE=https://127.0.0.1:9781/apis/default/api`
- `HANDOFF_RECEIVER_WRITE_TOKEN` (from `write.env`)
- `HANDOFF_RECEIVER_FHIR_BASE=https://127.0.0.1:9781/apis/default/fhir`
- `HANDOFF_RECEIVER_READ_TOKEN` (from `read.env`; a POST with it gets 401)
- `HANDOFF_RECEIVER_VERIFY_TLS=0` (self-signed certificate)

Then run:

```bash
pytest tests/test_handoffs_live_openemr.py # or:
python -m benchmark.handoff_receiver.referral_cases --repeat 5 --out results.json
```

Tear down with `docker compose -f docker-compose.yml down -v`.

## Cases

Each case is repeated with a fresh synthetic patient. The table is in
`referral_cases.py`, and results are in [`results/`](results/).

| Case | What the intake does | Expected |
|---|---|---|
| intended | records it as sent | `recorded_as_intended` |
| benign_format | names in capitals with extra spaces | `recorded_as_intended` (no false alarm) |
| wrong_date | birth date one day later | `recorded_differently` [birth_date] |
| swapped_date | day and month swapped | `recorded_differently` [birth_date] |
| wrong_patient_field | another family name | `recorded_differently` [family_name] |
| wrong_sex | the other sex | `recorded_differently` [sex] |
| never_arrived | drops it | `sent`, `not_found` (follow-up due) |
| duplicate | records it twice | `sent`, `ambiguous_key` |
| unreachable | records it; the read goes to a closed port | `sent`, `receiver_unreachable` |

Synthetic data only.
60 changes: 60 additions & 0 deletions packages/flow/benchmark/handoff_receiver/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The receiving clinic for the referral-intake handoff tests: a second,
# separate, synthetic OpenEMR 7.0.3 with its own database. Nothing here is
# shared with any other OpenEMR stack. Ports are loopback only.
#
# docker compose -f docker-compose.yml up -d --wait
# OPENEMR_COMPOSE_FILE=$PWD/docker-compose.yml \
# OPENEMR_BASE_HTTPS=https://127.0.0.1:9781 \
# eval "$(../openemr_live/setup.sh)"
#
# See README.md.

name: ho-openemr

services:
mysql:
image: mariadb:11.4
command:
- mariadbd
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_general_ci
- --innodb-buffer-pool-size=96M
- --performance-schema=OFF
environment:
MYSQL_ROOT_PASSWORD: root
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 30
volumes:
- receiver_db:/var/lib/mysql

openemr:
image: openemr/openemr:7.0.3
ports:
- "127.0.0.1:9780:80"
- "127.0.0.1:9781:443"
environment:
MYSQL_HOST: mysql
MYSQL_ROOT_PASS: root
MYSQL_USER: openemr
MYSQL_PASS: openemr
OE_USER: admin
OE_PASS: pass
depends_on:
mysql:
condition: service_healthy
healthcheck:
test: ["CMD", "test", "-f", "/var/www/localhost/htdocs/openemr/sites/default/sqlconf.php"]
interval: 15s
timeout: 5s
retries: 80
volumes:
- receiver_sites:/var/www/localhost/htdocs/openemr/sites
- receiver_logs:/var/log

volumes:
receiver_db:
receiver_sites:
receiver_logs:
Loading
Loading