Skip to content
2 changes: 1 addition & 1 deletion CAPABILITIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ improvising or retrying when something is off.
| Read the saved record back from the system of record (API, database, FHIR, separate session) | Released | Real app (OpenEMR 12 of 12 fields) | [VERIFICATION.md](packages/flow/docs/VERIFICATION.md), `runtime/effects/` |
| Read values out of an app as a workflow step (READ), with a records format, a signed review queue and export to CSV or a database | Released ([#1229](https://github.com/OpenAdaptAI/OpenAdapt/pull/1229), [#1215](https://github.com/OpenAdaptAI/OpenAdapt/pull/1215), [#1218](https://github.com/OpenAdaptAI/OpenAdapt/pull/1218)–[#1224](https://github.com/OpenAdaptAI/OpenAdapt/pull/1224)) | Synthetic (mock desktop apps) | `openadapt_flow/interchange/` |
| Stop before the effect instead of improvising (`HALTED_BEFORE_EFFECT`) | Released | Real app and synthetic | `runtime/replayer.py` |
| Fill a multi-step browser form or quote wizard from an intake record, stop for an operator on a prefill that disagrees with the intake or a question the intake does not answer (decided in a Chrome side panel), submit once, and give every typed, selected or kept field a read-back verdict: `passed`, `failed` or `not_checked`. A field it cannot read back is `not_checked`, never passed; such a submit ends `readback_incomplete` with no receipt | On main, prototype; not on PyPI until Flow 3.4.0 ([#2308](https://github.com/OpenAdaptAI/OpenAdapt/pull/2308)) | Synthetic only. Four quote portals built separately from the layer, 32 scored cases, pre-registered: 6 correct submissions, 0 wrong values submitted, 0 verified (every field on the one workable portal is `not_checked`, because its summary is plain text). The surface cannot see iframe or shadow-DOM forms or fill type-aheads, so 3 of 4 portals submitted nothing. Estimator, session-timeout and type-ahead traps were never reached. Rule proposals from repeated operator answers (`form_tx/learning.py`) had no measured effect: none qualified ([RESULTS](packages/flow/benchmark/form_tx_heldout_run/RESULTS.md)) | `openadapt_flow/form_tx/`, [FORM_TX.md](packages/flow/docs/FORM_TX.md) |
| Fill a multi-step browser form or quote wizard from an intake record, stop for an operator on a prefill that disagrees with the intake or a question the intake does not answer (decided in a Chrome side panel), submit once, and give every typed, selected or kept field a read-back verdict: `passed`, `failed` or `not_checked`. A field it cannot read back is `not_checked`, never passed; such a submit ends `readback_incomplete` with no receipt. A summary shown as page text (definition list, table, "Label: value" lines, open shadow roots) is read back by label; a label shown twice is `not_checked` ([#2449](https://github.com/OpenAdaptAI/OpenAdapt/pull/2449)) | On main, prototype; not on PyPI until Flow 3.4.0 ([#2308](https://github.com/OpenAdaptAI/OpenAdapt/pull/2308)) | Synthetic only. Four quote portals built separately from the layer, 32 scored cases, pre-registered: 6 correct submissions, 0 wrong values submitted, 0 verified (every field on the one workable portal is `not_checked`, because its summary is plain text). The surface cannot see iframe or shadow-DOM forms or fill type-aheads, so 3 of 4 portals submitted nothing. Estimator, session-timeout and type-ahead traps were never reached. Rule proposals from repeated operator answers (`form_tx/learning.py`) had no measured effect: none qualified ([RESULTS](packages/flow/benchmark/form_tx_heldout_run/RESULTS.md)) | `openadapt_flow/form_tx/`, [FORM_TX.md](packages/flow/docs/FORM_TX.md) |
| 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) |
Expand Down
33 changes: 29 additions & 4 deletions packages/flow/docs/FORM_TX.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ re-read from their controls just before the popup's apply button. A mismatch
stops the run before apply. A match does not count as a read-back of the
record: unless the summary shows the field, it stays `not_checked`.

#### Summaries shown as page text

Many confirmation pages show the stored quote as text, not in form controls.
When a read-back anchor finds no control, the judge looks for the field in
label and value pairs read from the page text:

- definition lists (`dt` then `dd`);
- two-cell table rows (`th` or `td`, then `td`);
- tables with one header row and exactly one data row (each header names the
cell below it);
- "Label: value" text in a block element, and a block with two leaf
children whose first ends in a colon or is a `dt`, `th`, `label`,
`strong` or `b`.

Open shadow roots are read too; closed ones are not. Only an anchor's
`label_patterns`, narrowed by `section_patterns`, can match page text, because
text has no name, id or selector. The rules:

- a label shown more than once (even with the same value) makes the field
`not_checked`;
- an empty or placeholder value is `failed` when a value was expected;
- a different value under the field's codec is `failed`;
- the same value is `passed`, with a reason that says it was read from page
text.

A control always wins over page text. Outputs such as a quote number are read
from page text the same way. The pairs are kept apart from the form controls,
so the layer never fills or halts on them.

The summary must match its declared landmark when one is configured. This is
the configured browser read-back only. It does not prove server-side
isolation, the absence of changes in other records, or atomic rollback of a
Expand All @@ -69,10 +98,6 @@ Measured on four held-out synthetic portals

- It reads only the top document: a form inside an iframe shows no controls,
and controls inside shadow DOM are invisible.
- It reads values back only from form controls (`input`, `select`,
`textarea`, `output`, `[data-readonly-output]`). A summary or confirmation
page that shows values as plain text cannot be read, so every field ends
`not_checked`.
- A popup routine has one apply button; an estimator that needs Calculate and
then Use This Value stops for a person.
- A type-ahead that fetches suggestions only after typing cannot be filled:
Expand Down
4 changes: 4 additions & 0 deletions packages/flow/openadapt_flow/form_tx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
MissingAnchorError,
compute_field_signature,
match_anchor_in_snapshot,
match_text_pair_in_snapshot,
)
from openadapt_flow.form_tx.types import (
FORM_DOSSIER_SCHEMA,
Expand Down Expand Up @@ -100,6 +101,7 @@
ObservedEntityRow,
ObservedModal,
ObservedOption,
ObservedTextPair,
OutputExtractionSpec,
PackPatchCandidate,
PopupSubroutineSpec,
Expand Down Expand Up @@ -156,6 +158,7 @@
"MissingAnchorError",
"ModalRuleSpec",
"ObservedControl",
"ObservedTextPair",
"ObservedEntityRow",
"ObservedModal",
"ObservedOption",
Expand Down Expand Up @@ -202,6 +205,7 @@
"load_or_create_ed25519_key",
"load_ui_profile",
"match_anchor_in_snapshot",
"match_text_pair_in_snapshot",
"normalize_boolean_yes_no",
"normalize_currency_cents",
"normalize_phone_digits",
Expand Down
115 changes: 110 additions & 5 deletions packages/flow/openadapt_flow/form_tx/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
AmbiguousAnchorError,
FormSurfaceBackend,
match_anchor_in_snapshot,
match_text_pair_in_snapshot,
)
from openadapt_flow.form_tx.types import (
ControlKind,
DossierFact,
FieldBindingSpec,
FieldCodecSpec,
FieldWriteRecord,
FormCodecKind,
FormHaltKind,
Expand All @@ -39,6 +41,7 @@
HumanResolutionRecord,
InputDossier,
ObservedControl,
ObservedTextPair,
OutputExtractionSpec,
ProvenanceKind,
ReadbackFieldVerdict,
Expand Down Expand Up @@ -161,6 +164,25 @@ def _observed_control_matches(
return False


def _text_pair_matches(
expected_val: Any,
pair: ObservedTextPair,
binding: FieldBindingSpec,
) -> bool:
"""Compare an expected value with a value shown as page text."""
if _is_placeholder_or_empty(pair.value, binding.placeholder_values):
return False
if values_equivalent(expected_val, pair.value, binding.codec):
return True
if binding.control_kind in (ControlKind.CHECKBOX, ControlKind.RADIO_GROUP):
return values_equivalent(
expected_val,
pair.value,
FieldCodecSpec(kind=FormCodecKind.BOOLEAN_YES_NO),
)
return False


def _extract_present_outputs(
snapshot: FormSnapshot,
output_specs: Sequence[OutputExtractionSpec],
Expand All @@ -177,6 +199,21 @@ def _extract_present_outputs(
invalid_keys.add(spec.output_key)
continue
if ctrl is None:
# A read-only summary may show the output (a quote number, a
# premium) as page text rather than in a control.
try:
pair = match_text_pair_in_snapshot(spec.anchor, snapshot)
except AmbiguousAnchorError:
invalid_keys.add(spec.output_key)
continue
if pair is None or not pair.value.strip():
continue
try:
extracted[spec.output_key] = normalize_with_codec(
pair.value.strip(), spec.codec
)
except CodecValueError:
invalid_keys.add(spec.output_key)
continue
raw_val = ctrl.current_value.strip()
if not raw_val:
Expand Down Expand Up @@ -450,12 +487,34 @@ def _where(field_writes: Sequence[FieldWriteRecord]) -> str:
)
continue

if fact is None:
has_ungrounded_screen_val = (
observed_ctrl is not None
and not _is_placeholder_or_empty(
observed_ctrl.current_value, binding.placeholder_values
# With no control, the summary may show the value as page text.
observed_text: Optional[ObservedTextPair] = None
if observed_ctrl is None:
try:
observed_text = match_text_pair_in_snapshot(
binding.anchor, snapshot
)
except AmbiguousAnchorError as exc:
verdicts.append(
_not_checked(
binding.dossier_key,
prov,
f"Page text shows {binding.dossier_key!r} more than "
f"once, so it cannot be read back: {exc}",
)
)
continue

if fact is None:
shown_value = (
observed_ctrl.current_value
if observed_ctrl is not None
else observed_text.value
if observed_text is not None
else ""
)
has_ungrounded_screen_val = not _is_placeholder_or_empty(
shown_value, binding.placeholder_values
)
if has_ungrounded_screen_val:
verdicts.append(
Expand Down Expand Up @@ -490,6 +549,41 @@ def _where(field_writes: Sequence[FieldWriteRecord]) -> str:
)
continue

if observed_ctrl is None and observed_text is not None:
if _text_pair_matches(fact.value, observed_text, binding):
verdicts.append(
ReadbackFieldVerdict(
dossier_key=binding.dossier_key,
codec_kind=binding.codec.kind,
passed=True,
status=ReadbackStatus.PASSED,
provenance=prov,
reason=(
"Read from page text "
f"({observed_text.source}: {observed_text.label!r})"
),
)
)
else:
shown = (
"an empty value"
if _is_placeholder_or_empty(
observed_text.value, binding.placeholder_values
)
else "a different value"
)
verdicts.append(
_failed(
binding.dossier_key,
binding.codec.kind,
prov,
f"Page text shows {shown} for {binding.dossier_key!r} "
f"({observed_text.source}: {observed_text.label!r}) "
f"under codec {binding.codec.kind.value!r}",
)
)
continue

if observed_ctrl is None:
verdicts.append(
_not_checked(
Expand Down Expand Up @@ -532,6 +626,17 @@ def _where(field_writes: Sequence[FieldWriteRecord]) -> str:
continue
if oc is not None:
observations.setdefault(rb.dossier_key, set()).add(oc.dom_selector)
continue
# A value shown as page text, not in a control, is an observation
# too; two read-backs that land on the same shown pair are one.
try:
pair = match_text_pair_in_snapshot(rb.anchor, snapshot)
except AmbiguousAnchorError:
continue
if pair is not None:
observations.setdefault(rb.dossier_key, set()).add(
f"text|{pair.source}|{pair.section_text}|{pair.label}"
)
evaluated_subjects = read_subjects(writes, active_resolutions)
verdicts.extend(
uncovered_subject_verdicts(
Expand Down
Loading
Loading