Skip to content

fix(transducer): confirm saved values where they reappear, bound to the pinned record - #2867

Merged
abrichr merged 2 commits into
mainfrom
fix/obligations-across-saved-screens
Dec 1, 2026
Merged

abrichr merged 2 commits into
mainfrom
fix/obligations-across-saved-screens

Conversation

@abrichr

@abrichr abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member

Problem

openadapt.wrap verified a save only when every compiled value showed on one screen, as non-editable text, under a label its vocabulary accepts. Real apps break that in three ways:

  • they spread a record over several screens;
  • summary views cut long values short;
  • the full saved value shows only when the record is reopened in its own form, which wrap treated as an editable draft.

Labels such as From:, To: and DOB: also never matched the date vocabulary. On a prior-authorization benchmark on a real EMR (OpenEMR 8.0.0.3, synthetic patients), every correct save the wrapped agent made ended unverified: 6 of 6 dev episodes that a screen-only judge scored correct. HOLD_DONE kept sending the agent back to look until it ran out of steps.

Change

wrap now remembers which field each typed or selected value went into before a commit. After the commit, a write is confirmed on a screen whose saved text shows every pinned identity value, in one of two ways:

  • its full value appears verbatim in that saved text (6 characters or more); or
  • the same field shows the same value in a form the read-back provider marks reopened (loaded again after the save, untouched), and the agent has not typed into that field since the save.

At done, an obligation that is still missing from the current screen is met by a confirmed write that contains it as a whole token (units 1 is not met by units 12), or by a pinned identity value already seen on a saved screen. With no pinned identity, nothing changes.

Evidence

  • Unit tests. One positive path and four negatives: a reopened form on another record, a form without reload evidence (failed save), a longer saved value, and a value typed after the save.
  • Live negative controls on real OpenEMR. A scripted agent drove six end states through the wrapped read-back path. The two correct saves verify. A save on the look-alike chart, a valid-to date off by one day, units 12 for units 1, and a refused save all end unverified.
  • Benchmark. Wrapped dev VCR went from 5/20 to 18/20 with this PR and fix(transducer): let a fill that does not save clear a field #2853, equal to the unwrapped agent, with 0 silent wrong saves.

Limits

  • Values shorter than 6 characters confirm only in their own reopened field.
  • A freshly opened blank form also counts as reopened. Its untouched fields hold defaults, which do not match earlier writes.

…he pinned record

wrap verified a save only when every compiled value showed on one screen
as non-editable text that its label vocabulary accepts. Real apps spread
a record over screens, cut long values in summary views, and show the
full saved value only when the record is reopened in its form. Labels
such as From:, To: and DOB: never matched. On the OpenEMR
prior-authorization dev split, every correct save the wrapped agent made
ended unverified.

wrap now remembers which field each typed value went into before a
commit. After the commit, a write is confirmed on a screen whose saved
text shows every pinned identity value, when either its full value
appears verbatim in that saved text (six characters or more), or the
same field shows the same value in a form the read-back provider marks
reopened (loaded again after the save, untouched) and the agent has not
typed into it since. At done, an obligation still missing from the
current screen is met by a confirmed write that contains it as a whole
token, or by a pinned identity value seen on a saved screen. Without
pinned identity nothing changes.
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: f8e4065

A write can be confirmed, and the run can be stamped VERIFIED, when the saved screen shows a longer value that only contains the typed text as a substring. The official "longer value" test does not catch this because its read-back is the identity header alone.

What holds

The reopened-field path compares the field value exactly, and _met_by_saved_writes uses a token boundary so units 1 is not met by a confirmed write whose own text is units 12. A form that is not marked reopened does not confirm from editable echo. A reopened form on a different pinned identity does not confirm. I ran the five new tests in tests/test_transducer_v3_runtime.py at this head; all five passed.

Blocker: verbatim confirmation is an unanchored substring, and it outranks a failed field match

observe_saved confirms a write when len(value) >= 6 and value in saved. There is no token boundary. After normalizing, the typed comment cpt 29881; units 1 is a prefix of a screen that shows cpt 29881; units 12. Once that write is marked confirmed, _met_by_saved_writes searches the write's own typed text, not the screen, so the compiled obligation is treated as met.

I ran the PR's own _fb_run helper at this head:

  • After the save, a non-reopened summary whose read-back was Ada Quill DOB: 1959-08-03\nComments: CPT 29881; units 12\nFrom: 2026-12-16 returned VERIFIED with reason "Every compiled field obligation is the pinned identity or a write confirmed on a saved screen of the pinned record."
  • The same longer comments on a form marked reopened=True also returned VERIFIED. The exact field comparison correctly refuses units 12 versus units 1, but the elif value in saved branch still confirms the write from the page text.

test_longer_saved_value_does_not_meet_a_shorter_one passes _HEADER only as readback_text, so saved never contains the longer comments and the substring path is not exercised.

Please confirm a verbatim write only as a whole token (the same boundary _met_by_saved_writes already uses), and do not fall through to page-text confirmation after a reopened field for that key is present and disagrees. Add a regression whose read-back actually displays CPT 29881; units 12 while the typed value was CPT 29881; units 1, for both a summary screen and a reopened form.

Generality

The new confirmation logic is field-key and pinned-identity based, not application-specific. No application name was added to engine code. I did not run the Flow generality script because these files are outside packages/flow/openadapt_flow.

CI and release

CI at this head is otherwise green; Evaluate review verdict is still red from before a matching verdict. I am not merging or approving a release.

…r over a disagreeing reopened field

Review (Grok) found that verbatim confirmation used an unanchored
substring: a typed "CPT 29881; units 1" was confirmed by a screen showing
"CPT 29881; units 12", and the run went VERIFIED. It also fell through to
page text when the reopened form showed the field with a different value.

A write now confirms from saved text only as a whole token (the boundary
the obligation check already uses), and a reopened field that is on
screen decides alone: a different value there is never overruled by page
text elsewhere. Regression: the screen shows units 12 where units 1 was
typed, on a summary and on a reopened form; the run ends unverified.
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Response to the Grok review at f8e4065. Fixed at ca4b84a.

Blocker: verbatim confirmation was an unanchored substring, and it outranked a failed field match. Both parts are fixed.

  • A write now confirms from saved text only as a whole token. This is the same boundary _met_by_saved_writes uses, so units 1 is not found inside units 12.
  • When the reopened form shows that field, the field decides alone. A different value there is never overruled by page text elsewhere.

Regression: test_longer_saved_value_on_screen_does_not_confirm_a_shorter_typed_one, parametrized for a summary screen and for a reopened form. In both, the read-back actually shows CPT 29881; units 12 where CPT 29881; units 1 was typed. The test requires the run to finish unverified. It fails at f8e4065 and passes now.

The fix is merged up into #2871, #2872 and #2873. Re-review requested at ca4b84a.

@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: ca4b84a

I re-reviewed this exact head (R2 after my REQUEST CHANGES at f8e40657b18a). Both blockers from that review are fixed. I am not merging.

Previous blockers at this head

  1. A shorter typed value is no longer confirmed by a longer saved string. Confirmation from saved page text now uses _whole_token, the same boundary _met_by_saved_writes already used ((?<![\w.-])...(?![\w-]|\.\w)). Typed CPT 29881; units 1 is not a whole-token match in text that shows units 12, and PA1468922 is not a match inside PA14689226. I probed those cases against _norm_text input; _whole_token and the obligation regex agree.
  2. A reopened field that is on screen decides alone. If reopened.get(field_key) is not None, only an exact match on that field confirms the write (and only when the agent has not typed into it since the save). A different value there is not overruled by page text elsewhere. This is the elif that used to fall through to the substring check.

Tests I ran at this exact head

  • tests/test_transducer_v3_runtime.py: 25 passed, including the new test_longer_saved_value_on_screen_does_not_confirm_a_shorter_typed_one (summary screen and reopened form) and the existing positive case test_save_confirmed_in_reopened_untouched_form_verifies (still VERIFIED on an exact reopened match).
  • ruff check on the two changed files: clean.

Generality: no per-app engine code. The rule is token-boundary and field-key generic. Fixtures are synthetic.

CI at this head

Smoke, packages, and launcher are green except review-verdict, which is red because the newest posted review was still my REQUEST CHANGES at f8e40657b18a, not this head.

No release decision from me.

@abrichr
abrichr added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit ad29841 Dec 1, 2026
43 of 44 checks passed
@abrichr
abrichr deleted the fix/obligations-across-saved-screens branch December 1, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant