Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CAPABILITIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ improvising or retrying when something is off.
| Stop before the effect instead of improvising (`HALTED_BEFORE_EFFECT`) | Released | Real app and synthetic | `runtime/replayer.py` |
| Never retry an uncertain save (`RECONCILIATION_REQUIRED`) | Released | Synthetic (fault server) | [VERIFICATION.md](packages/flow/docs/VERIFICATION.md) |
| One check-level scale, 0 to 5, from "unchecked" to "counterparty confirmed" | Released | Unit tests | `openadapt_flow/check_level.py` |
| Check a value where a careful person would look again: an effect location (`openadapt.effect-location/v1`) is pack data for one place an intended value shows (path and start condition, locator, expected value, codec, expected count, optional baseline). One summary row can cover two values ("Name (DOB)"), and a date can be split over three fields. Every planned value is `held`, `refuted` or `not_checked`; a place that can't be reached, found or read is `not_checked`. The check level follows the start condition (a new session is level 3), and the engine holds no application words | PR [#2500](https://github.com/OpenAdaptAI/OpenAdapt/pull/2500), not yet used by a runner | Unit tests and the fail-open harness (synthetic readings only) | `openadapt_flow/effect_location/`, [EFFECT_LOCATION.md](packages/flow/docs/EFFECT_LOCATION.md) |
| Judge any executor's write, including an agent's or a script's, from the system of record | Released | Synthetic | `openadapt-flow verify-run`, [VERIFY_RUN.md](packages/flow/docs/VERIFY_RUN.md) |
| Judge an "ensure the record exists" write (found, created once with every value, or needs review) through a FHIR server's read path only: searches, AuditEvent and `_history`, never the database; the coverage claim names that read path. An agent's own correction of the record it created counts as one write when the audit trail and history show only that agent, no other reader, and the same record in every version | Released ([#1640](https://github.com/OpenAdaptAI/OpenAdapt/pull/1640), corrections [#1655](https://github.com/OpenAdaptAI/OpenAdapt/pull/1655)) | Real app (Medplum 5.2.8; three blind fault suites: 17/18, 17/20, 19/20; no fault passed in the last two. Corrections, on 15 blind cases and the 37 public ones: false stops 8 to 2 and 9 to 4 for Claude, no harm passed that the old rule caught) | `openadapt_flow/ensure_record.py`, [ENSURE_RECORD.md](packages/flow/docs/ENSURE_RECORD.md) |
| Generate an ensure-record contract from three demonstrations, the server's CapabilityStatement and its SearchParameter definitions: field paths and `[system=…]` filters, comparison kinds, value maps, identity, search parameters, the closed record and the change feed. It refuses when unsure, asks a person to confirm an identity for a type with no reviewed template, and self-checks every demonstration plus a perturbation per field | Released ([#1653](https://github.com/OpenAdaptAI/OpenAdapt/pull/1653)) | Real app (Medplum 5.2.8: all 16 hand-written Patient lines regenerated; one blind write type, Immunization: 78 s of person time, 2 lines edited after the person declined the proposed identity; blind suite 23/24, no fault passed) | `openadapt_flow/generate/ensure_contract.py`, [RESULTS.md](packages/flow/benchmark/contract_autogen/results/RESULTS.md) |
Expand Down
1 change: 1 addition & 0 deletions llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ improvising or retrying when something is off.
| Stop before the effect instead of improvising (`HALTED_BEFORE_EFFECT`) | Released | Real app and synthetic | `runtime/replayer.py` |
| Never retry an uncertain save (`RECONCILIATION_REQUIRED`) | Released | Synthetic (fault server) | [VERIFICATION.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/docs/VERIFICATION.md) |
| One check-level scale, 0 to 5, from "unchecked" to "counterparty confirmed" | Released | Unit tests | `openadapt_flow/check_level.py` |
| Check a value where a careful person would look again: an effect location (`openadapt.effect-location/v1`) is pack data for one place an intended value shows (path and start condition, locator, expected value, codec, expected count, optional baseline). One summary row can cover two values ("Name (DOB)"), and a date can be split over three fields. Every planned value is `held`, `refuted` or `not_checked`; a place that can't be reached, found or read is `not_checked`. The check level follows the start condition (a new session is level 3), and the engine holds no application words | PR [#2500](https://github.com/OpenAdaptAI/OpenAdapt/pull/2500), not yet used by a runner | Unit tests and the fail-open harness (synthetic readings only) | `openadapt_flow/effect_location/`, [EFFECT_LOCATION.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/docs/EFFECT_LOCATION.md) |
| Judge any executor's write, including an agent's or a script's, from the system of record | Released | Synthetic | `openadapt-flow verify-run`, [VERIFY_RUN.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/docs/VERIFY_RUN.md) |
| Judge an "ensure the record exists" write (found, created once with every value, or needs review) through a FHIR server's read path only: searches, AuditEvent and `_history`, never the database; the coverage claim names that read path. An agent's own correction of the record it created counts as one write when the audit trail and history show only that agent, no other reader, and the same record in every version | Released ([#1640](https://github.com/OpenAdaptAI/OpenAdapt/pull/1640), corrections [#1655](https://github.com/OpenAdaptAI/OpenAdapt/pull/1655)) | Real app (Medplum 5.2.8; three blind fault suites: 17/18, 17/20, 19/20; no fault passed in the last two. Corrections, on 15 blind cases and the 37 public ones: false stops 8 to 2 and 9 to 4 for Claude, no harm passed that the old rule caught) | `openadapt_flow/ensure_record.py`, [ENSURE_RECORD.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/docs/ENSURE_RECORD.md) |
| Generate an ensure-record contract from three demonstrations, the server's CapabilityStatement and its SearchParameter definitions: field paths and `[system=…]` filters, comparison kinds, value maps, identity, search parameters, the closed record and the change feed. It refuses when unsure, asks a person to confirm an identity for a type with no reviewed template, and self-checks every demonstration plus a perturbation per field | Released ([#1653](https://github.com/OpenAdaptAI/OpenAdapt/pull/1653)) | Real app (Medplum 5.2.8: all 16 hand-written Patient lines regenerated; one blind write type, Immunization: 78 s of person time, 2 lines edited after the person declined the proposed identity; blind suite 23/24, no fault passed) | `openadapt_flow/generate/ensure_contract.py`, [RESULTS.md](https://github.com/OpenAdaptAI/OpenAdapt/blob/main/packages/flow/benchmark/contract_autogen/results/RESULTS.md) |
Expand Down
19 changes: 19 additions & 0 deletions packages/flow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@

<!-- version list -->

## Unreleased

### Features

- Effect locations (`openadapt.effect-location/v1`,
`openadapt_flow/effect_location/`): the place a careful person would look
again to see an intended value, stored as pack data. Each record holds the
demonstration path and start condition (`same_screen`, `fresh_navigation`,
`new_session`, `other_channel`), a locator (label, row key or region), the
expected value, a codec (including a `template` codec that reads one
summary row as two values and a `split_date` codec), the expected count
and an optional baseline. `evaluate_all` judges every planned value as
`held`, `refuted` or `not_checked`. A location that can't be reached,
found or read is `not_checked`, never a pass. The check level comes from
the start condition; the receipt word comes from
`check_level.outcome_word` when it is available. The engine holds no
application vocabulary: month names, yes and no words, currency signs and
tables come from the pack. See docs/EFFECT_LOCATION.md.

## v3.4.0 (2026-11-21)

### Features
Expand Down
98 changes: 98 additions & 0 deletions packages/flow/docs/EFFECT_LOCATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Effect locations

A careful person who has just entered a form checks their work. They read the
review page before they press submit, and afterwards they look again where the
value should now appear: the summary, the saved record, a list row, a second
session or an export. An effect location records one of those places as data,
so the engine can do the same check for any application without knowing which
application it is.

The record is `openadapt.effect-location/v1`
(`openadapt_flow/effect_location/record.py`). A pack stores one per place,
compiled from the demonstration. The evaluator
(`openadapt_flow/effect_location/evaluator.py`) judges it from a reading that
an adapter (a browser, an accessibility tree, a terminal screen, an export
reader) takes when it goes back.

## The record

| Field | What it holds |
| --- | --- |
| `keys` | The intended values the location shows. Usually one. A summary row such as "Name (DOB)" shows two. |
| `path` | The demonstration steps that reach the location. |
| `start` | Where the re-observation starts: `same_screen`, `fresh_navigation`, `new_session` or `other_channel`. |
| `locator` | How to find it: `label`, `row_key` (a row whose `column` cell equals `value`) or `region`. The adapter reads it; the evaluator does not. |
| `expected` | The value each key should show, in the codec's canonical form. The run's plan fills it in. |
| `codec` | How displayed text maps to the value (below). |
| `expected_count` | How many times the value shows. Required; usually 1. |
| `baseline` | Optional. What the location showed before the action. |

## Codecs

Every codec reads the whole displayed text. A prefix, a longer text or a value
with extra words never matches, so "Jane" is not "Jane Doe" and "250" is not
"$1,250.00".

| Kind | Reads | Canonical value |
| --- | --- | --- |
| `text`, `fold` | Text, whitespace collapsed (`fold` also ignores case) | string |
| `number`, `unit` | A decimal number, for `unit` followed by one of `units` | decimal |
| `money` | An amount with optional `affixes` (currency signs), `group_marks` and `decimal_mark` | integer minor units |
| `date` | ISO, or numeric in `date_order` (`YMD`, `MDY`, `DMY`), or with `month_names` | ISO date |
| `bool` | One of `true_tokens` or `false_tokens` | bool |
| `enum` | An entry of `table` (shown text to value) | string |
| `split_date` | Three displayed parts, `year`, `month` and `day` | ISO date |
| `template` | One text matched in full by `pattern`; each of `parts` reads one named group as one key with its own codec | one value per key |

The engine has no default words. A bool codec with no tokens, a date codec
with no month names or a money codec with no currency sign accepts only the
bare form. The pack supplies the rest from the demonstration.

## How a value is judged

The obligations are the run's intended values, fixed before any reading is
judged. Each one ends in one of the verdict kernel's three statuses.

- `not_checked`: no location shows the value, or the location was not read,
was not found, or was found a different number of times than expected. Also
when the read failed or came from another run, the start condition was not
met, a kind is unknown, the text can't be read, or the read was partial and
showed no conflict. Also when the expected value equals the baseline, so
the read can't tell the change from what was already there.
- `refuted`: the location shows a different value. A partial read can refute.
- `held`: every location for the value was read in full and showed exactly
the expected value the expected number of times.

The run passes only when every planned value held and no reading is left
over. When several locations show one value, a refutation at any of them
refutes it, and it holds only when all of them hold, at the weakest level.

## Check level and receipt word

The check level comes from the start condition the adapter achieved:

| Start | Check level |
| --- | --- |
| `same_screen` | 1, `same_screen` |
| `fresh_navigation` | 2, `reopened`; 3 with basis `fresh_reload` when the adapter proves the navigation fetched from the server (cache bypassed, the request kept) |
| `new_session` | 3, `separate_session`, basis `separate_session` |
| `other_channel` | 4, `system_of_record`, with the basis the adapter names (`system_api`, `activity_log`, `db_frame` or `owned_connection`) |

The receipt word comes from `openadapt_types.check_level.outcome_word`, so
this package never decides what `VERIFIED` means. A same-screen read or a
fresh navigation without the reload proof is `SHOWN`; a proven fresh reload
is `VERIFIED`. A new session is `VERIFIED`. Another channel is
`VERIFIED` only with a basis, otherwise `RECORDED`. Until `outcome_word` is on
main, the word is `None`.

The adapter states the start condition it achieved and binds the reading to
the run. The evaluator can't see whether a navigation really fetched from the
server; the adapter must prove it (a cache-bypassing request and its
response, kept as evidence) before it names the `fresh_reload` basis.

## Fail-open testing

`evaluate_all` is a registered verdict site (`effect_location.evaluate_all`).
Its spec, `tests/failopen/sites/effect_location.py`, runs the generic
mutations against a plan with a label, a summary row, a split date and an
amount.
53 changes: 53 additions & 0 deletions packages/flow/openadapt_flow/effect_location/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Effect locations: where a careful person would look again to see a value.

Echo before commit, re-observe after. For each intended value, a pack stores
an effect location compiled from the demonstration: how to get there (the path
and a start condition), what to look for (the locator), what it should show
(the expected value, read through a codec), how many times (usually once) and,
optionally, what it showed before. A review page is one effect location; a
summary row, a lookup-table row, a reopened record, a separate session and an
export are others.

:func:`evaluate` judges one location from one reading. :func:`evaluate_all`
judges every intended value of a run. A location that can't be reached, found
or read is ``not_checked``, never a silent pass. The engine holds no
vocabulary for any application or field: every word, pattern and token table
comes from the pack. See ``docs/EFFECT_LOCATION.md``.
"""

from __future__ import annotations

from openadapt_flow.effect_location.codecs import CodecError, decode
from openadapt_flow.effect_location.evaluator import (
KeyResult,
Report,
evaluate,
evaluate_all,
)
from openadapt_flow.effect_location.record import (
CODEC_KINDS,
LOCATOR_KINDS,
SCHEMA,
Codec,
EffectLocation,
Locator,
Reading,
Start,
)

__all__ = [
"CODEC_KINDS",
"LOCATOR_KINDS",
"SCHEMA",
"Codec",
"CodecError",
"EffectLocation",
"KeyResult",
"Locator",
"Reading",
"Report",
"Start",
"decode",
"evaluate",
"evaluate_all",
]
67 changes: 67 additions & 0 deletions packages/flow/openadapt_flow/effect_location/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""The two interfaces this package codes against before they reach main.

- ``openadapt_flow.verdict_sites.verdict_site`` (#2476) registers a verdict
site with the fail-open harness. Until it is on main, the decorator here
records the id on the function and changes nothing else.
- ``openadapt_types.check_level.outcome_word`` and ``level_for_basis``
(#2495) choose the receipt word and say which level a basis reaches. Until
they are on main, no word is chosen (``None``) and no basis is accepted
for another channel. Nothing here defines what ``VERIFIED`` means.

Delete this module once both are on main and import them directly.
"""

from __future__ import annotations

from collections.abc import Callable
from typing import Any, Optional, TypeVar

from openadapt_types import check_level as _check_level

F = TypeVar("F", bound=Callable[..., Any])

try: # pragma: no cover - which branch runs depends on what is merged
from openadapt_flow.verdict_sites import verdict_site as verdict_site
except ImportError: # pragma: no cover

def verdict_site(id: str, *, classes: str) -> Callable[[F], F]: # type: ignore[no-redef]
"""Record ``id`` on the function, as #2476's decorator does."""

def mark(fn: F) -> F:
setattr(fn, "__verdict_site__", id)
return fn

return mark


_level_for_basis: Optional[Callable[..., Any]] = getattr(
_check_level, "level_for_basis", None
)
_outcome_word: Optional[Callable[..., Any]] = getattr(
_check_level, "outcome_word", None
)


def has_ladder_words() -> bool:
"""True when ``check_level.outcome_word`` is available."""

return _outcome_word is not None


def reaches(basis: Optional[str], level: Any) -> bool:
"""True when ``basis`` is a known basis that reaches exactly ``level``."""

if basis is None or _level_for_basis is None:
return False
try:
return bool(_level_for_basis(basis) == level)
except ValueError:
return False


def word(level: Any, basis: Optional[str], *, confirmed: bool) -> Optional[str]:
"""The receipt word for ``level`` and ``basis``, or None before #2495."""

if _outcome_word is None:
return None
return str(_outcome_word(level, basis, confirmed=confirmed))
Loading
Loading