Repository navigation
fix(verify): one strict evidence matcher and an adversarial corpus - #2784
Conversation
Several verifiers decided whether text on a screen proves a write with their own matcher. Most were bare substring or loose token checks, so "250" was found in "Total $1,250.00", "John Smith" in "John Smith-Jones", and "Note will be signed by Dr A" counted as signed. openadapt_types.evidence is one stdlib-only matcher, based on Flow's readback_values.compare_value. match_field returns MATCH, MISMATCH or AMBIGUOUS, and only MATCH may pass. A value bound to its label is tried first; otherwise the whole text must equal the value. A value merely found in longer text is AMBIGUOUS. Tokens never end at joining punctuation, numbers compare as whole numeric tokens by value, and a label with two values is AMBIGUOUS. phrase_affirmed checks a commit phrase across two frames. - packages/types/tests/evidence_corpus.json: adversarial cases with pinned verdicts, plus true positives. - The launcher (openadapt/_evidence.py) and the kernel (openadapt_kernel/_evidence.py) carry byte-identical copies, checked by tests, so neither needs openadapt-types from PyPI or pydantic. - Migrated: transducer obligation read-back and SOP tokens, and the kernel's token_boundary_check with every oracle built on it. - Flow parity test: compare_value never passes a corpus case the shared module refuses, except one listed Flow follow-up. Hypothesis properties cover the shared module. - Callers not migrated yet have strict expected-failure tests and are listed in packages/types/docs/evidence-migration.md.
…labels - A code bound to its label with a second code after it (Diagnosis: E11.9 I10) is ambiguous, not a match. - phrase_affirmed treats must, can, may, need, if, once, when, required and similar forms as not done, and error, missing and invalid as negations. - Transducer page labels that say Error, Not, Missing, Required, Previous, Worklist and the like no longer verify a prompt obligation. - The launcher checks its own copy of the matcher for drift. - xfail reasons say which caller has no fix yet; the guard branch fixes 15 of its 21 loose cases.
…read-backs stay unverified
A prefix-labelled ID obligation (CLM) verifies only as the value of the one
page field holding an ID with that prefix. Two such fields, as on a
worklist, or the same ID in two fields, don't verify. New tests pin that
the old sentence read-backs ("Saved CLM-3 and REF-20.", "CLM-1234 saved,
total $1,250.00") now end unverified.
Independent adversarial review: REQUEST CHANGESFrom: Grok This is a real improvement. On main, all 30 of my transducer probes below verify. At this head, the sentence read-backs, Blocking
Non-blocking
Tests at this head (Linux, Python 3.12, clean venv from the locks)
Generality gate:
Not run: the Flow CI at this head (when I checked):
I didn't push to this branch, and I won't merge it. |
…lue refuse it - A label binds only at the start of its field. "Previous Patient ID:", "Former Name:" and "Error: Claim ID:" no longer bind. - A bound value may hold only unit words beside a number. A status, a comparator, a trailing sign, CR/DR or an aside gives AMBIGUOUS. - Kernel binding keys must start with the key's words. An input's name, id, test id and label are scored apart. - Transducer page labels must name the obligation's kind, or for an ID its prefix, on a line with no negation, failure or modal word. This replaces the refusing-word list. - phrase_affirmed also refuses a negation on the line below, a failure word on any new line, and nothing/none/rolled back/draft/0 records. - Folds are set comparisons, so check_verdict_folds passes without a baseline change. - The corpus grows to 112 cases. The Flow parity and pending-caller lists are remeasured; the guard list now names #2786.
…er-corpus-f04cf8 # Conflicts: # packages/kernel/CHANGELOG.md
Independent adversarial review: REQUEST CHANGESFrom: Grok Big progress. All 30 transducer read-backs and all 47 matcher cases from my last review now give the answer the corpus pins, and Prior blockers
BlockingA. A modifier still binds a label after an earlier field, or after a column gap.
B. The prefix-letter and initials rules accept labels that name another record.
Non-blocking
Tests at this head (Linux, Python 3.12, editable venv from the locks)
Generality gate:
Not run: macOS-only tests, Playwright and OCR callers, a benchmark rerun, and kernel CI at this head (when I checked):
I didn't push to this branch, and I won't merge it. |
…isted words
- A label binds only at the start of a line or after |, ; or a tab, with
only punctuation between. "Name: Jane Doe Previous MRN:", "Status:
superseded Claim ID:" and "Previous MRN:" no longer bind. A bare word or
a value-less heading in the cell before ("Previous | MRN:", "Previous: |
MRN:") refuses too. A single-line "Patient: X DOB: Y" no longer binds DOB.
- Kernel: a binding key scores 2.0 only when its words are the key's words,
and the share rule needs every word to be one of the key's.
member_id_old, "Member ID (previous)" and "Member Previous ID" are not
member_id.
- Transducer: an ID's page label must use its prefix, a listed name for it,
or the generic ID words. The letter-order and initials tests are gone, so
"Maternal MRN:", "Mother Record Number:" and "Claimant ID:" refuse.
- phrase_affirmed also refuses undo, previously, before, outbox and queued.
- Two kernel fixtures put their single-line fields behind | and ; separators.
- The corpus grows to 129 cases. The Flow lists are remeasured against
#2786 at 1ee554d.
Independent adversarial review: APPROVEFrom: Grok Both blocking items from my last review are fixed, and the replacement rules are strict rather than tuned to my examples. I could not make a modifier-before-label or a loose ID label verify with any new phrasing I tried. Prior blockers
Verification at this head (Linux, Python 3.12)
New adversarial probes (throwaway, not committed)
Limitations I found (non-blocking; none is a regression and each is the nature of text matching)
Generality gate
CI at this headWhen checked: 12 pass, 18 skipped by the path filter, 18 pending (the Not runmacOS-only tests, Playwright and OCR callers, a benchmark rerun. The 13 launcher failures the author reports (CLI surface, metadata, PATH) were not re-run here; I ran only the evidence- and transducer-related launcher tests listed above. I did not push to this branch and will not merge it. |
#2786 merged after this branch was written, so the 21 cases it refuses now pass and their strict xfail markers failed the merge queue. The 36 cases check_identity still verifies keep their markers.
Independent adversarial review: APPROVEFrom: Grok This is a test-only follow-up to my APPROVE at What changed since
|
Behavior change: what earns VERIFIED
Saved CLM-3 and REF-20.orCLM-1234 saved, total $1,250.00used to giveVERIFIED. It now ends unverified, with a hold orCOMPLETED_UNVERIFIED. Such text reports that a save was claimed, not the saved record. A read-back needs each value as a field's value (Claim ID: CLM-1234).Claim ID: CLM-1234 not found,Dose: 5 mg (rejected),Balance: 250.00 CR,Previous Patient ID: MRN-104,Error: Claim ID: CLM-1234andName: Jane Doe Previous MRN: MRN-1no longer verify.|,;or a tab. A single-linePatient: John Smith DOB: 1990-01-01bindsPatientbut notDOB, so the date stays unverified. This fails closed: the text can't tell the end of one value from a modifier on the next label.Charge: $250.00verifies a$250.00charge;Copay:,Balance due:,Requested:andUnable to post:don't. A true label the list doesn't hold (Supporting reference,Submitted) leaves the value unverified.VERIFIEDin the wrapped benchmark arms, so the published HealthAdminBench wrapped-arm numbers will change when they're rerun.What this changes
Several verifiers decided whether text on a screen proves a write, each with its own matcher. Most were substring or loose token checks. This adds one strict matcher, moves the callers nobody else is editing onto it, and lists the rest with tests that fail when they're fixed.
openadapt_types.evidenceis stdlib only and based on Flow'sreadback_values.compare_value. It doesn't import Flow.match_field(expected, observed_text, *, label=None, kind="auto")returnsMATCH,MISMATCHorAMBIGUOUS. OnlyMATCHpasses.|,;or a tab (or a JSON key's{or",), with only punctuation between. Any word before it (Previous,Former,Error:, an earlier field's value) may name another record. The cell before a|,;or tab must be empty or a whole field (Name: Jane | MRN:); a bare word or a value-less heading (Previous | MRN:,Previous: | MRN:) refuses.5 mg,5 mmol/L,250.00 USD). A status, a comparator (<,>,~,≤,≥, a+suffix), a trailing sign,CR/DR, or an aside givesAMBIGUOUS.AMBIGUOUS.-,,,.,/or@before a letter or digit), so2026-11is not in2026-11-29andJohn Smithis not inJohn Smith-Jones.250never matches$1,250.00, and5never matches50 mg.AMBIGUOUS.phrase_affirmed(before, after, phrase)checks a commit confirmation. The phrase must be absent before and present after. A question, a modal, future or conditional form, or a negation or failure word on its line or the lines next to it, a control label (Confirm,Cancel,OK,Sign) next to it, or a failure word (Error,rolled back,draft,0 records,by another user,undo,previously,before,outbox,queued) on any line new since the first frame givesAMBIGUOUS.has_negation_or_modal(text)exposes the word check.No.meaning number doesn't count.Corpus.
packages/types/tests/evidence_corpus.jsonhas 129 cases with pinned verdicts: every repro from three review rounds, more adversarial cases, and 29 true positives. Two of those are deliberate: a code matches with or without its separators when one side has none (E119andE11.9).Copies, not a new dependency. The launcher installs openadapt-types from PyPI, and only below Python 3.13. The kernel depends only on
cryptography. So both carry byte-identical copies (openadapt/_evidence.py,openadapt_kernel/_evidence.py) instead of depending on openadapt-types, which would add pydantic to the kernel. Drift fails tests in all three packages.Verdict folds. The module and the transducer fold verdicts as set comparisons (
{verdict} == {MATCH}), which an empty list can't pass, socheck_verdict_folds.pypasses without a baseline change. A@verdict_siteisn't possible here: the launcher copy can't importopenadapt_flow.verdicton Python 3.13 and newer, where Flow isn't installed.Migrated
openadapt/transducer_obligations.py)._value_in_textneedsMATCH.date,CPT code, an ID's own prefix) must be the whole value of aLabel: valuefield on the page.Charge,Total,Amount;Visit date,Date of service;Diagnosis,ICD-10 code), or for an ID be its prefix, a listed name for it, or a generic ID word (Claim IDandClaim No.forCLM-…,Medical Record NumberforMRN-…). Shared letters or initials don't count:Claimant ID:,Maternal MRN:andMother Record Number:refuse. This replaces the refusing-word list.CLM) verifies only as the value of the one field on the page that holds an ID with that prefix. A worklist with two CLM IDs doesn't verify. An ID next to another ID with the same prefix never verifies.transducer_form_batch._rule_satisfied) match whole tokens, sosignedno longer matchesunsigned.token_boundary_check, and through it every read-back oracle and the non-DOM adapter, cites a value only onMATCH.Previous Member ID,member_id_oldandMember ID (previous)are notmember_id, whileStatestill namesstate_code. An input's name, id, test id and label are scored apart.Parity with Flow
packages/flow/tests/test_evidence_parity.pyruns the corpus throughcompare_valueand fails when Flow passes a case the shared module refuses, unless the case is listed.5inDose: 5 mg then 10 mg,Dose: 5 mg was not savedandDose: 5 mg (rejected). Its label extraction binds after other words in the field or the cell before (Previous Patient ID:,Error: Claim ID:,Name: Jane Doe Previous MRN:,Previous | MRN:). These need a Flow follow-up.The file also holds Hypothesis properties of the shared module.
Not migrated (listed for later)
packages/types/docs/evidence-migration.mdlists each remaining caller, with file, line and the corpus cases it gets wrong.packages/flow/tests/test_evidence_pending_callers.pyandtests/test_evidence_pending_callers.pyrun those cases asxfail(strict=True), so a fix turns them into failures until the marker is removed.guard.check_identitypasses 57 of the 68 field refusals. fix(flow): identity gate refuses lookalike values before a guarded write #2786 (measured at1ee554d86) fixes 21; 36 have no fix yet, mostly words beside the value and labels after a modifier or an earlier field.worklist_copilot._contains_affirmed_phrasepasses 23 of the 31 phrase refusals, with no fix yet. fix(flow): pixel commit observer reads only new text in the changed region #2778 changes the observer around it.SimplexTransducer._evaluate_verification_framepasses all 31 phrase refusals, with no fix yet. fix(transducer): route re-prompts through the gates and stop four false VERIFIED paths #2776 leaves it as it is.visible_text_present, the OCRtext_presentpredicate and_normalize_anchor_for_matchare documented only.Tests changed because they relied on loose matching
tests/test_transducer_v3_runtime.pyandtests/test_simplex_transducer.pyexpectedVERIFIEDfrom sentence read-backs (Saved CLM-3 and REF-20.). They now use labelled record views. A new test per old sentence asserts that it no longer verifies. No transducer runtime file is changed.Supporting reference:toReference:,Submitted:toEncounter date:).Member: MEM-442,POSTAL_CODE=,data-field).Approvedbefore the record instead of in theCode:field, and separates its fields with|. The portal fixture separatesREF=,POLICY=andPOSTAL_CODE=with;.Previous Member ID,member_id_old,Member ID (previous)andMember Previous IDare refused.Release
There is no version bump. Merging a bumped
pyproject.tomlwith a dated CHANGELOG heading publishes the package to PyPI, so the entry sits under## Unreleased. When it ships, 0.24.3 fits within the<0.25.0range that Flow and the launcher accept.Tests
packages/types: 1078 passed.packages/kernel: 363 passed. ruff and mypy are clean.origin/mainin this environment.check_verdict_folds.py: "Verdict folds OK", baseline unchanged.ruff format --check openadapt/are clean.Left for later (non-blocking from review)
Claim ID: CLM-1234thenStatus: rejected) isn't checked. The transducer checks only the label's own line, because a neighbouring field'sNo(Smoker: No) would refuse true record views.Total:and a bareDate:still name an amount and a date.