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
641cb3b
feat(receipts): the post-save screen check earns VERIFIED with basis …
abrichr Nov 30, 2026
caa81b9
test(receipts): signed vectors for a post-save-screen VERIFIED receip…
abrichr Nov 30, 2026
ddd42a1
style: ruff format and mypy fixes for the post-save screen basis
abrichr Nov 30, 2026
aaac197
docs(receipts): careful-operator baseline in THREAT_MODEL, receipt do…
abrichr Nov 30, 2026
6dc8258
fix(receipts): address review: per-save screen checks, strict ScreenC…
abrichr Nov 30, 2026
176533b
fix(receipts): review round 2: screen basis needs every line confirme…
abrichr Nov 30, 2026
7f08b90
fix(receipts): refuse a missing kernel proof at mint, keep the kernel…
abrichr Nov 30, 2026
3bd3266
feat(flow): record a post-save screen check per save and earn post_sa…
abrichr Dec 1, 2026
f4b5b48
feat(flow): read a same-screen check at the saved value's labelled fi…
abrichr Dec 1, 2026
b3827da
fix(flow): review round 4: one new labelled record per save, delivere…
abrichr Dec 1, 2026
5ce0be5
fix(flow): review round 5: results decide which saves need a check, l…
abrichr Dec 1, 2026
0190cf7
fix(flow): review round 6: weakest write level from the results, whol…
abrichr Dec 1, 2026
46b1c7d
docs(receipts): say exactly when a post-save screen check misses a dr…
abrichr Dec 1, 2026
81b5fa2
feat(flow): reopen the record after a save and read it again (reopene…
abrichr Dec 1, 2026
c5c06f0
Merge remote-tracking branch 'origin/main' into claude/post-save-scre…
abrichr Dec 1, 2026
9426725
fix(flow): keep the post-save check out of the budgeted files; CI fixes
abrichr Dec 1, 2026
a2bce07
Merge remote-tracking branch 'origin/main' into claude/post-save-scre…
abrichr Dec 1, 2026
471d445
test(golden): refresh mockmed_pass baselines for MockMed's labelled e…
abrichr Dec 1, 2026
f79c09e
fix(flow): a reopen earns reopened_record only when complete; unobser…
abrichr Dec 1, 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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| One receipt word per check, the same on every path: `VERIFIED` only at level 3 (a separate session) or 4 (the system of record), always with the basis that produced the evidence (`separate_session`, `system_api`, `activity_log`, `db_frame` or `owned_connection`); `SHOWN` for an acting-screen re-read, `CONFIRMED` for the counterparty, `ATTESTED` for an operator and `RECORDED` for the rest. `VERIFIED` means "as of the read-back time the read-back showed this value", not "persisted". Run receipts (`record/run/v1`, an additive optional field), `verify-run` receipts and `tx` receipts carry an evidence-scope block: level, basis, word, the wire channel watched, the read-back time, the recheck window, and what it did not cover (always server-side async and outbound effects; a run receipt says it has no per-read time). A run receipt never says `VERIFIED` below level 3. Receipts without the block still verify. A `verify-run` contract with `minimum_effect_strength: independent_session` now verifies on a separate-session read | On main | Unit tests (parity across the runtime report, `verify-run`, `tx` and Execute v1; fake verifiers) | `openadapt_types/check_level.py`, `openadapt_types/evidence_scope.py`, `openadapt_flow/evidence_basis.py` |
| One receipt word per check, the same on every path: `VERIFIED` always names the basis that earned it. The baseline is the check a careful person does after a save, basis `post_save_screen` (level 1): the form left edit mode, no error is shown, and every intended value was read on the screen, field by field, and matched; a banner or toast alone never earns it, and a value that was not read means `RECORDED`. The same check after reopening the record is `reopened_record` (level 2); stronger evidence is a stronger basis on the same word (`separate_session` or `fresh_reload` at level 3; `system_api`, `activity_log`, `db_frame` or `owned_connection` at level 4). A run or policy can require a stronger level: under `Regulated` a screen check is not `VERIFIED`. `CONFIRMED` is the counterparty, `ATTESTED` an operator and `RECORDED` the rest. `VERIFIED` means "as of the read-back time the read-back showed this value", not "persisted". Run receipts (`record/run/v1`, an additive optional field), `verify-run` receipts, `tx` receipts and the kernel's receipt bridge carry an evidence-scope block: level, basis, word, the wire channel watched, the read-back time, the recheck window, and what it did not cover (always server-side async and outbound effects). `openadapt.wrap` takes its word from the Contract's read-back receipt; a declared `checked_how` alone is `RECORDED`. In a browser the runtime records each save's post-save screen check (counts and flags only); on a backend that can't read the page, a run checked only on its screen gets a `RECORDED` receipt. When reloading can't repeat the save, the runtime then reopens the record on a fresh page load and reads every value again (`reopened_record`, level 2); a value the browser showed but the server didn't keep stops the run. Where it can't reopen safely, the check stays at level 1 and such a value can pass. Older receipts that say `SHOWN` still verify and are labelled as the older format. Receipts without the block still verify | On main | Unit tests (shared cases across the types ladder, the run receipt block, the kernel bridge and `openadapt.wrap`; signed `record/run/v1` vectors checked by the Python and JavaScript verifiers); real headless runs on MockMed, compiled without database access: a clean save's receipt is `VERIFIED` / `reopened_record`, and a save whose note the server dropped stops at the reopen (`packages/flow/benchmark/post_save_screen/`). Not yet shown on a held-out app | `openadapt_types/check_level.py`, `openadapt_types/evidence_scope.py`, `openadapt_flow/evidence_basis.py`, `openadapt_kernel/receipt_bridge.py`, `openadapt/wrap_sdk.py` |
22 changes: 22 additions & 0 deletions openadapt/receipt_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def _describe(result: Any, say: Say, indent: str = " ") -> None:
+ (f" ({reason})" if reason else "")
+ ", as the run recorded it. A receipt doesn't grade the run."
)
scope = predicate.get("evidence_scope")
if isinstance(scope, dict):
say(f"{indent}{_check_line(scope)}")
checks = predicate.get("checks", {})
lines = predicate.get("lines", [])
say(
Expand All @@ -81,6 +84,25 @@ def _describe(result: Any, say: Say, indent: str = " ") -> None:
say(f"{indent}{name}: {value}")


def _check_line(scope: dict[str, Any]) -> str:
"""One line naming how the run's writes were checked, from its
evidence-scope block. An older ``SHOWN`` block says it is the older
format."""

word = _one_line(scope.get("word"))
level = _one_line(scope.get("check_level"))
# The one older word, named here so the label works with any installed
# openadapt-types (``openadapt_types.evidence_scope.LEGACY_WORDS``).
if scope.get("word") == "SHOWN":
return (
f"Check: {word} ({OLDER}: the acting screen was read again; level {level})"
)
basis = scope.get("basis")
return f"Check: {word} (level {level}" + (
f", basis {_one_line(basis)})" if basis else ")"
)


def verify_record_file(
path: Path,
registry: Sequence[Any],
Expand Down
8 changes: 4 additions & 4 deletions openadapt/seal_view/viewer.html

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions openadapt/wrap_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"check_wrap_receipt",
"verify_wrap_receipt",
"wrap",
"wrap_receipt_word",
]

F = TypeVar("F", bound=Callable[..., Any])
Expand Down Expand Up @@ -627,6 +628,71 @@ def _receipt_names(data: Mapping[str, Any]) -> set[str]:
return names


def wrap_receipt_word(
receipt: WrapReceipt | Mapping[str, Any],
contract_receipt: Mapping[str, Any] | None = None,
) -> str:
"""The receipt word for a wrap receipt, the same word every path uses.

A wrap receipt carries no evidence of its own: ``checked_how`` is what the
caller declared for its check, not what was read. So only a Contract's
read-back can earn a word stronger than ``RECORDED``. Pass that read-back's
receipt (``contract_receipt``, a ``verify-run`` receipt whose digest is the
wrap receipt's ``contract_receipt_sha256``) and the word is the one its
evidence-scope block states, for example ``VERIFIED`` with basis
``system_api``. Anything else is ``RECORDED``: a wrap receipt whose own
digest does not match its fields, an outcome other than confirmed, no
contract receipt, a contract digest that does not match, a contract
receipt that fails ``verify-run``'s own checks or whose outcome is not
``verified``, or a block that does not validate. This checks integrity, not who signed: use
:func:`check_wrap_receipt` for that.

The word is derived, never signed, so receipts keep their exact bytes.
"""

data = receipt.to_dict() if isinstance(receipt, WrapReceipt) else receipt
if (
not isinstance(data, Mapping)
or data.get("schema") != RECEIPT_SCHEMA
or data.get("outcome") != WrapOutcome.CONFIRMED.value
):
return "RECORDED"
try:
if _sha256_hex(_digest_payload(data)) != data.get("sha256"):
return "RECORDED"
except (TypeError, ValueError):
return "RECORDED"
digest = data.get("contract_receipt_sha256")
if not isinstance(contract_receipt, Mapping) or not isinstance(digest, str):
return "RECORDED"
try:
from openadapt_flow.verifier import Outcome, classify
from openadapt_flow.verify_run import receipt_problem, receipt_sha256
from openadapt_types.evidence_scope import evidence_scope_problem
except ImportError: # pragma: no cover - the flow extra is not installed
return "RECORDED"
try:
if receipt_sha256(contract_receipt) != digest:
return "RECORDED"
if receipt_problem(contract_receipt) is not None:
return "RECORDED"
# Only an outcome verify-run classifies as confirmed supports the
# wrapper's "confirmed" (a verified rollback, for one, does not).
confirmed, _retry = classify(
str(contract_receipt.get("outcome")),
contract_receipt.get("checked") or {},
{},
)
if confirmed is not Outcome.CONFIRMED:
return "RECORDED"
except (TypeError, ValueError, KeyError, AttributeError):
return "RECORDED"
block = contract_receipt.get("evidence_scope")
if evidence_scope_problem(block) is not None:
return "RECORDED"
return str(block["word"]) # type: ignore[index]


def check_wrap_receipt(
receipt: WrapReceipt | Mapping[str, Any],
*,
Expand Down
64 changes: 64 additions & 0 deletions packages/flow/benchmark/post_save_screen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Post-save screen check: real-run evidence

The basis `post_save_screen` (level 1) means that, after the save, the form left edit mode, no error appeared, and every value the run typed was read on the screen under its label and matched. `reopened_record` (level 2) means the same check also held after the record was reopened on a fresh page load, the way a careful person reopens it.

This folder holds evidence from real headless runs on MockMed, the bundled synthetic clinic. It is in-house evidence: MockMed was changed for this work, so it is not a held-out app.

## What was run (2026-11-30 to 12-01)

`run_proof.py` records the quickstart's MockMed task in headless Chromium. It then compiles the recording as a customer without database access would get it: the system-of-record snapshots are removed, so the compiler mines an on-screen read-back for the save instead of a database check. It runs the program with the on-screen verifier only (no database or API), under the `standard` profile, and signs the run receipt.

Two choices are made by the script, standing in for the person who reviews the program:

- It keeps the read-back on the save step and removes the ones the compiler attached to four navigation clicks (#2858). Those are demonstrated read-backs that nobody admitted, and the runtime refuses to run with them.
- It uses the `permissive` policy. The strict packs (`clinical-write`, `record-write`) require a database effect and an idempotency key, which a customer without database access can't provide (#2859).

## Results

| Run | Outcome | Receipt |
| --- | --- | --- |
| Clean save, `standard` profile | `VERIFIED` | `VERIFIED`, basis `reopened_record`, level `reopened`. The post-save check read 1 of 1 fields and matched it; the form closed and no error appeared. The record, reopened on a fresh page load, showed the note again. Both the Python and JavaScript verifiers accept the receipt. |
| `?fault=partial` (the server stores the encounter without its note; the page still shows it) | Halted at the save | None: a halted durable run can still continue, so no receipt is signed. The reopened record showed 0 of 1 saved values (`run-partial-standard.txt`). |
| Clean save, `regulated` profile | Refused before running | The run gate requires a separate-session or system-of-record check (`gate-regulated.txt`). |
| `?fault=timeout` (MockMed shows "Save timed out" and the form stays open) | Halted | None. The save's expected screen never appeared. |

`probe-views.json` drives MockMed directly. For each fault mode, starting from an empty record store, it records the check right after the save and again after reopening the record:

| Fault | What the page shows after Save | After the save | After the reopen |
| --- | --- | --- | --- |
| `ok` | The encounter row `Type: Triage \| Note: <note>` | Complete | Complete |
| `timeout` | "Save timed out", form still open | Nothing read; error; form open | (not reached by the runtime) |
| `session` | The login page | Nothing read | Nothing read |
| `partial` | The note as saved; the server stored it without the note | Complete | Note missing |
| `optimistic` | The note as saved; the server refused the write | Complete | Note missing |

Right after the save, `partial` and `optimistic` look complete, because MockMed paints the saved encounter from the browser's own memory. Reopening the record loads it from the server, and the note is missing, so the runtime stops. A person who reopens the record would see the same thing.

## What a reopened check still can't see

- **Identical older records.** An older record with the same values that first appears after the save can't be told apart from the new one without record identity. The probe resets the store between faults for this reason.
- **Saves it can't reopen safely.** Reloading counts as safe when the save didn't load a new page, or when the new page's address has no query string. Otherwise, and on backends that can't reopen (desktop, Citrix, RDP), the check stays at level 1, and a value the server dropped while the page still shows it can pass.
- **Later and outbound effects.** Effects that happen on the server later, or are sent elsewhere, are outside any read-back. Every receipt lists them as not covered.

## What was changed to get here

- **MockMed record view: labelled fields.** The patient record view shows each saved encounter's fields with their labels (`Type: Triage | Note: <note>`), as a real EMR's record view does. Before, the note showed only inside the "Encounter saved" banner and an unlabelled `Triage — <note>` line, so no field-by-field read was possible.
- **MockMed record view: loaded from the server.** With the fault backend, a fresh page load reads the saved encounters from the server (`/api/db`). Before, MockMed kept them only in the page, so reopening a record showed nothing for any fault.
- **Compiler.** A same-screen read-back reads the saved value where the record shows it under its label (`effect_mining.mark_labelled_field`), not the banner the demonstration settled on.
- **Runtime.** After a complete post-save check, it reopens the record when that is safe and reads it again.

## Not shown yet

This hasn't been shown on an app that didn't motivate the work, a held-out app such as OpenEMR's encounter view.

## Files

| File | Contents |
| --- | --- |
| `receipt-ok-standard.json` | The clean save's signed receipt |
| `registry-public.json` | The public key that signed it |
| `receipt-verify-python.txt`, `receipt-verify-js.txt` | The two verifiers' output |
| `summary-ok-standard.json` | The receipt and report summary |
| `run-partial-standard.txt` | The `partial` run's halt |
| `gate-regulated.txt` | The regulated run's gate refusal |
| `probe-views.json` | The per-fault checks after the save and after the reopen |
82 changes: 82 additions & 0 deletions packages/flow/benchmark/post_save_screen/probe_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""The post-save screen check on MockMed's real pages, for each fault.

Drives MockMed in headless Chromium the way a person would (open the patient,
start a triage encounter, type the note, press Save), takes the page view the
runtime takes before and after the save, reopens the record on a fresh page
load, and prints the check
(:func:`openadapt_flow.runtime.post_save_screen.observe`) after the save and
after the reopen, for each fault mode.

Usage (from packages/flow)::

python benchmark/post_save_screen/probe_views.py [OUT.json]

Synthetic data only; needs a local Chromium for Playwright.
"""

from __future__ import annotations

import json
import sys
import time
from pathlib import Path

NOTE = "Follow-up in two weeks"
FAULTS = ("ok", "timeout", "session", "partial", "optimistic")


def probe(base_url: str, fault: str) -> dict:
import urllib.request

from openadapt_flow.backends.playwright_backend import PlaywrightBackend
from openadapt_flow.runtime.post_save_screen import observe

# Each fault starts from an empty record store, so an earlier probe's
# record (same note) can't stand in for this one.
urllib.request.urlopen(
urllib.request.Request(f"{base_url}/api/reset", data=b"{}", method="POST")
).read()

backend, close = PlaywrightBackend.launch(
f"{base_url}/?fault={fault}#tasks", headless=True
)
try:
page = backend.page
page.click("#open-p1")
page.click("#new-encounter")
page.click("#type-triage")
page.fill("#note", NOTE)
before = backend.post_save_view()
page.click("#save-encounter")
time.sleep(2.0) # past MockMed's 1.2 s client timeout
after = backend.post_save_view()
# Reopen the record the way a person would: a fresh load of the page.
reopened = backend.reopen_view()
finally:
close()
intended = [("Note", NOTE)]
check = observe(before, after, intended)
again = observe(before, reopened, intended)
return {
"after_save": check.model_dump(mode="json") if check is not None else {},
"after_reopen": again.model_dump(mode="json") if again is not None else {},
}


def main() -> int:
from openadapt_flow.mockmed.fault_server import serve

base_url, _db, stop = serve(port=0)
try:
results = {fault: probe(base_url.rstrip("/"), fault) for fault in FAULTS}
finally:
stop()
text = json.dumps(results, indent=2)
print(text)
if len(sys.argv) > 1:
Path(sys.argv[1]).write_text(text + "\n")
return 0


if __name__ == "__main__":
raise SystemExit(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"ok": {
"after_save": {
"fields_intended": 1,
"fields_read": 1,
"fields_matched": 1,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
},
"after_reopen": {
"fields_intended": 1,
"fields_read": 1,
"fields_matched": 1,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
}
},
"timeout": {
"after_save": {
"fields_intended": 1,
"fields_read": 0,
"fields_matched": 0,
"left_edit_mode": false,
"error_shown": true,
"banner_only": false,
"reopened": false
},
"after_reopen": {
"fields_intended": 1,
"fields_read": 0,
"fields_matched": 0,
"left_edit_mode": false,
"error_shown": false,
"banner_only": false,
"reopened": false
}
},
"session": {
"after_save": {
"fields_intended": 1,
"fields_read": 0,
"fields_matched": 0,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
},
"after_reopen": {
"fields_intended": 1,
"fields_read": 0,
"fields_matched": 0,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
}
},
"partial": {
"after_save": {
"fields_intended": 1,
"fields_read": 1,
"fields_matched": 1,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
},
"after_reopen": {
"fields_intended": 1,
"fields_read": 0,
"fields_matched": 0,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
}
},
"optimistic": {
"after_save": {
"fields_intended": 1,
"fields_read": 1,
"fields_matched": 1,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
},
"after_reopen": {
"fields_intended": 1,
"fields_read": 0,
"fields_matched": 0,
"left_edit_mode": true,
"error_shown": false,
"banner_only": false,
"reopened": false
}
}
}
Loading
Loading