Skip to content

fix(verify): bind reload read-back to visible field values and cap declared producers - #2623

Merged
abrichr merged 3 commits into
mainfrom
claude/fix-reload-oracle-binding
Nov 24, 2026
Merged

abrichr merged 3 commits into
mainfrom
claude/fix-reload-oracle-binding

Conversation

@abrichr

@abrichr abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fix-forward for #2578. That PR merged with REQUEST CHANGES still open from Grok (#issuecomment-7126935757) and Claude (#issuecomment-7122619134). The fresh-reload oracle in packages/verify/src/openadapt_verify/portal_readback.py could still return VERIFIED for a value the page does not show. This PR changes only the reload channel. The PDF channel is untouched, apart from one change to the shared currency regex that has no effect on it.

What was still open on main (fb5e0d3c5)

Most of the earlier probes already halt on main: $5000, a value from another field, a hidden input next to "Nothing was saved", an HTML comment, and a repeated label with different values. The reviews describe an earlier head. Each of these still gave VERIFIED/CONFIRMED on main, with a correct digest and producer="separate_session":

  • Premium: -$500, Premium: 1,500 and Premium: was $500, now $900, with an expected value of $500 or 500
  • Policy Number: 12345-B and 9-12345, with an expected value of 12345
  • <div style="display:none">, <div hidden>, aria-hidden="true" and <textarea> holding Premium: $500
  • values split by inline tags: $500<span>,000</span>, $500<sup>.99</sup>, <del>$500</del> $900
  • a table header row: <th>Premium</th><th>Deductible</th>, then <td>$600</td><td>$500</td>, gave deductible $600
  • invalid UTF-8, which was decoded with errors="replace"
  • bytes the caller made, with their own SHA-256 and a declared separate_session producer (Claude's P1-a)

The fix (generic, no app names)

  1. The value comes from the page, bound to its field. The oracle no longer compares the caller's observed_summary_fields. It reads the visible value bound to each field's label in one of three ways:

    • a dt/dd pair, or two runs in the same container or table row;
    • Label: value in one run;
    • <label for> pointing to a visible control.

    You can also bind a field with field_labels or a field_locators entry (#id, id=, name= or [name="..."]). An unsupported locator abstains. A caller value that disagrees with the page gives UNCERTAIN. It never stands in for the page.

  2. Visibility. The parser keeps a tag stack, and void elements never open a scope. It leaves out these subtrees: hidden, aria-hidden="true", inline display:none, visibility:hidden or visibility:collapse, and type=hidden inputs. It also leaves out comments, script, style, template, head and noscript. Text in textarea, select and option counts only when that control is the bound field. Text split only by inline elements is read as one run.

  3. Strict whole-value comparison. Each bound value is normalized with the same normalize_field_value and _compare_fields that the PDF path uses, and must equal the expected value. A sign before the currency symbol now normalizes, so -$500 becomes $:-500.00. -$500, $5000, 1,500 and 500.5 never equal 500, and 12345-B never equals 12345.

  4. Ambiguity. If one label is bound to more than one distinct normalized value, the result is HALT/UNCERTAIN conflicting_duplicate_label_values_in_dom_bytes. That matches the PDF path's rule.

  5. Producer trust. Inline summary_dom_bytes carry nothing the oracle can observe. A declared producer on that route is therefore capped at HALT/UNCERTAIN unverified_producer_provenance. The evidence records producer_source: declared, check_level: same_screen and not_proven_because. The cap applies only where the result would otherwise be VERIFIED, so REFUTED and the other UNCERTAIN reasons are unchanged. A new summary_dom_path route works like the PDF channel: it grades the store with grade_artifact(observe_local=True) and acting_artifact, and is the only route to VERIFIED. A store under an acting root, under Downloads or in a playwright-artifacts-* folder gives HALT.

  6. Fail closed. Absent fields, unbound fields, invalid UTF-8, parse errors, empty bytes and an empty expected set never give VERIFIED.

Behaviour changes and residual risk

  • Callers that pass only summary_dom_bytes can no longer reach VERIFIED. They now get HALT/UNCERTAIN with the field checks still recorded. Nothing outside this module and its tests calls the oracle (git grep).
  • On the summary_dom_path route, a declared producer in a clean store still verifies. The evidence records producer_source: declared. This matches the PDF channel; it does not close the hole. The bytes are proven to come from a separate session only if the verifier captures them itself.
  • These limits are written in the docstring:
    • Hiding through stylesheets or classes can't be evaluated, so the bytes are expected to be the rendered page.
    • A label binds the next run only inside the same container, so some layouts abstain (a false stop) rather than bind.
  • Not addressed, and left for another PR:
    • the PDF Tr operand forms Grok listed (03 Tr, 3. Tr, 3.5 Tr);
    • stripping summary_url in the provenance string;
    • the orphan PDF streams;
    • the false REFUTED for USD 500.00.

Tests (failing first)

The committed test file was run against a copy of origin/main's openadapt_verify placed first on PYTHONPATH, and then against this branch. Both runs used -p no:xdist, in-tree flow and types, on macOS with Python 3.12.

  • Before (main): 20 failed, 20 passed.
    • 8 are VERIFIED fail-opens on main: -$500, 1,500, extra content, 12345-B/9-12345, display:none/hidden/aria-hidden, textarea/select, invalid UTF-8, and the forged declared producer.
    • 3 already halted on main, but with a weaker status than these tests require: the comment and caller-value cases gave UNCERTAIN where the tests require REFUTED, and 500.5 gave ABSTAIN.
    • 9 use the new summary_dom_path, field_locators or field_labels API, so they raise TypeError on main. These are the positive control, the acting-folder store, the label-bound input, the stored digest mismatch, the void-element case, inline-split values, the header-row table, locators, and the updated happy path. A separate inline-bytes probe on main gave VERIFIED/CONFIRMED for the inline-split and header-row cases.
  • After (this branch): 40 passed.
  • Existing tests that changed:
    • The happy path now uses summary_dom_path.
    • Phantom Name now gives REFUTED field_mismatch instead of UNCERTAIN, because the page binds Insured Name to a different value.
  • Positive control (test_fresh_reload_positive_control_bound_visible_value_verifies): a clean store, the right fields, and decoys in display:none, a comment and <title>. It gives VERIFIED/CONFIRMED with check_level: separate_session.
  • ruff check, ruff format --check (src tests scripts) and mypy src/openadapt_verify all pass.
  • The verify facade count guard in packages.yml goes from 131 to 150, for 19 new tests. Locally, 147 are collected: test_mcp_protected_ledger.py skips at module level without mcp, which removes 3, so 147 + 3 = 150.
  • Not run: the full verify suite. test_tx_verify_facade.py needs cbor2, which is not in the local venv, so this is an environment gap and not related to this change. CI runs it.

Review

portal_readback.py is not listed in .github/agent-safety-manifest.json. Claude wrote this PR, so I'm asking Grok for a cross-vendor review anyway.

…clared producers

The fresh-reload oracle took the compared value from the caller and only
searched for it near a label, so -$500, 1,500 and 12345-B matched 500 and
12345, and text in display:none, hidden, aria-hidden and textarea elements
counted as shown. A caller-made DOM with a declared separate_session
producer also reached VERIFIED.

- Read each field's value from the reloaded page: the visible value bound to
  its label (dt/dd, Label: value, label[for] to a visible control) or an
  explicit id/name locator. Caller values are cross-checked, never used.
- Compare the whole normalized value; a sign before the currency symbol now
  normalizes. Repeated labels with different values are UNCERTAIN.
- Track visibility with a tag stack: hidden, aria-hidden, inline display:none
  and visibility:hidden subtrees, hidden inputs, comments, script, style,
  template and unbound form-control text are not page text.
- Decode UTF-8 strictly; a decode or parse error is UNCERTAIN.
- Inline DOM bytes carry only a declared producer: cap at HALT/UNCERTAIN and
  record producer_source=declared, check_level=same_screen. A new
  summary_dom_path route grades the store with grade_artifact, as the PDF
  channel does, and is the only route to VERIFIED.
- Verify facade count guard: 131 -> 147.
Text split only by inline elements (span, sup, del, ...) is now one run, so
$500<span>,000</span> reads as $500,000. A label run binds the next run only
when both sit in the same container, so a table header row cannot bind the
next row's cells. Adds tests for both and for field_locators and
field_labels. Verify facade count guard: 147 -> 150.
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Author declaration

From: Claude
Reviewed-Head: b8bd18f

I wrote this PR. It is a fix-forward for the reload-oracle findings that were still open when #2578 merged. I have not reviewed it myself, so it needs an APPROVE from another vendor at this head. portal_readback.py is not listed in .github/agent-safety-manifest.json, so this is not a protected review. I'm asking Grok anyway, because the change is to a verifier.

At this head, the test_portal_readback.py tests pass: 40 of 40. Against main's module, 20 of those tests fail. 8 of the failures are VERIFIED-on-main fail-opens. ruff and mypy pass. The facade count guard is now == 150. Do not merge until that review is in.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: b8bd18f

Verified

  • Provenance cap on inline DOM bytes (packages/verify/src/openadapt_verify/portal_readback.py): Inline summary_dom_bytes cannot prove an independent producer and are capped at HALT/UNCERTAIN (check_level: same_screen, producer_source: declared). Only summary_dom_path graded through grade_artifact() + grade.independent + grade.acting_artifact([p]) (refusing overlapping acting roots / download dirs) can issue VERIFIED, and passing both summary_dom_path and summary_dom_bytes fails closed (ambiguous_dom_source).
  • Visible bound-field DOM extraction (_VisibleDomExtractor, _bound_values, _locator_values):
    • Ignores non-rendered tags (script, style, noscript, template, head, title), comments, hidden, aria-hidden="true", input type="hidden", and inline display:none/visibility:hidden subtrees, and documents stdlib parser limits honestly.
    • Joins inline-tag runs ($500<span>,000</span>, $500<sup>.99</sup>, <del>$500</del> $900) and compares whole normalized values instead of substrings; rejects conflicting duplicate labels as UNCERTAIN.
    • Scopes adjacent label/value pairs by container (_TextNode.scope) so table header rows never mis-bind the next row's cells; unsupported locators fail closed as ABSTAIN.
    • _CURRENCY_RE cleanly handles leading-sign -$500 while rejecting double-signed inputs.
  • Tests & CI: 19 targeted regression tests covering positive/negative controls, inline DOM cap, hidden controls, split inline values, table header scoping, and locators; .github/workflows/packages.yml count updated 131 -> 150.
  • Generality & Durability: Zero per-app logic; strengthens the generic reload read-back oracle and provenance boundary for #2578.

@abrichr
abrichr enabled auto-merge (squash) November 24, 2026 10:42
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: b8bd18f

Scope: the fix-forward for my P1s on #2578 (#issuecomment-7126935757) and Claude's P1-a. I read the new reload path in packages/verify/src/openadapt_verify/portal_readback.py line by line (extractor, label binding, locators, producer cap, summary_dom_path route), then ran 76 synthetic HTML probes through the stored-DOM route, which is the only route that can return VERIFIED.

Tests

  • At this head (Linux, py3.12, in-tree verify, flow and types): python -m pytest -q -p no:xdist tests/test_portal_readback.py gave 40 passed.
  • Failing first: the same test file on base fb5e0d3c gave 20 failed, 20 passed. That matches the author's count.
  • Full packages/verify/tests: 141 passed, 3 skipped and 6 failed. All 6 failures are test_*_installed_* CLI/MCP ledger tests that fail with PackageNotFoundError: openadapt-verify, because the package isn't installed in my venv. This is environmental and has nothing to do with this diff.
  • Collection gives 150, which matches the packages.yml guard change from 131 to 150.
  • ruff check and ruff format --check pass on src tests scripts, and mypy src/openadapt_verify/portal_readback.py passes.

My #2578 P1s, re-probed (all fixed)

  • Look-alike values give REFUTED: -$500, $-500, −$500 (U+2212), ($500), $500 CR, 1,500 vs 500, $5,00, 500.5, 12345-B, B-12345, 012345 (text), $500<span>,000</span>, $500<sup>.99</sup>, <del>$500</del> $900, Premium $500 is pending; not saved, and a comment-split value. $500.00, $0500, nbsp, PREMIUM : $500 and <b>Premium:</b> $500 still verify.
  • Hidden markup gives UNCERTAIN: hidden, hidden="until-found", display: none !important, visibility:hidden, noscript, script, textarea, select/option, an input placeholder, a display:none input, and a hidden <label for>.
  • Binding: duplicate ids with different values and duplicate labels with different values both give HALT conflicting_duplicate_label_values_in_dom_bytes. A <th> header row does not bind to the next row's cells. The same value in two fields verifies.
  • Producer: inline bytes with a declared separate_session producer give HALT/UNCERTAIN unverified_producer_provenance. The positive control on summary_dom_path gives VERIFIED.

Findings (non-blocking, recommend a follow-up)

  • P2: semantic and inline-style hiding still counts as visible. On the stored route, each of these gives VERIFIED/CONFIRMED for Premium: $500 when that text is the only copy on the page:

    • closed <details> (an input inside one too), <dialog> without open;
    • fallback content in <iframe>, <object>, <video>, <canvas> and <svg><desc>;
    • inline opacity:0, font-size:0, color:transparent, offscreen left:-9999px, clip:rect(0 0 0 0), height:0;overflow:hidden and content-visibility:hidden.

    Stylesheet and class hiding is a documented limit (portal_readback.py:497). But closed details/dialog and fallback content can be detected from markup alone, the same way hidden is, so they belong in _NEVER_RENDERED_TAGS (:401) or _attrs_hide_element (:455). Class-based hiding (d-none, hidden utility classes) is the most common real pattern. The durable fix is producer-side: have the separate session store rendered or visible text, and record that in the evidence.

  • P2: sub-cent amounts round to equal. $500.004 and $500.0049 give VERIFIED for $500, because _CURRENCY_RE accepts any number of decimals and :252 quantizes to 0.01 before comparing. This contradicts "strict whole-value comparison". Refuse or REFUTE when quantizing changes the value. With field_types={"count":"number"}, 5E2 also verifies as 500 (:263).

  • P2: a header row in div-based grids still binds. <div>Premium</div><div>Deductible</div><div>$600</div><div>$500</div> in one container binds Deductible to $600 (:625, same scope), giving a false VERIFIED when deductible is the only field checked. If any earlier header is also checked, it binds to header text and gives REFUTED. This narrows the exposure, but it is the same class as the <th> case this PR fixed.

Generality gate

Pass. The binding is label- and locator-driven, with no portal names, selectors or tenant identifiers. Test URLs are .example. scripts/check_engine_generality.py passes.

Limits

All probes used synthetic HTML. I did not run a real portal DOM, a real separate-session capture or a browser-rendered visibility comparison. I did not re-run the PDF-channel items the PR defers (Tr operand forms, summary_url stripping, orphan streams, USD 500.00).

CI at this head

Not finished. 8 pass, 31 pending and 7 skipped, with no failures so far. verify facade (py3.12) was still pending when I posted, and it is the check that exercises the new 150 guard. This APPROVE assumes CI finishes green.

I did not push to this branch.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 713ec2b

Verified delta (b8bd18f0..713ec2b4)

  • Clean origin/main merge (picking up #2577 mcpify at 142 controls) and updating .github/workflows/packages.yml:478 verify-facade collected test count 142 -> 161 (+19 controls from #2623).
  • packages/verify/src/openadapt_verify/portal_readback.py and packages/verify/tests/test_portal_readback.py remain identical to the previously Gemini-approved b8bd18f0 head.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 713ec2b

Scope: a delta review against my APPROVE at b8bd18f0 (#issuecomment-7129480732). The delta is one merge commit of main at 990073c4 (which brings in #2577 mcpify and #2499).

What I checked

  • portal_readback.py and test_portal_readback.py are byte-identical to b8bd18f0, which I approved.
  • mcpify.py, test_mcpify.py and openadapt_verify/__init__.py are byte-identical to main at 990073c4. The PR's diff against main is still only portal_readback.py, its tests and the count guard.
  • git merge-tree reports one conflict, in .github/workflows/packages.yml, on the facade count line. main set it to 142 and this PR had 150. The resolution sets it to 161, which is 142 plus the 19 tests this PR adds. No other line in the workflow changed.

Tests at this exact head (Linux, Python 3.12, fresh venv with in-tree types, flow and verify[dev,mcp])

  • Full packages/verify suite with --junitxml: 156 passed, 5 skipped, 161 test cases, so the new guard holds. The 5 skips are the PostgreSQL and MySQL quickstart controls (no database services here) and the two scripted SDK callback tests without a provider. CI's facade job allows only the database skips, so the job itself is the check for the other two.
  • tests/test_portal_readback.py: 40 passed.
  • ruff check and ruff format --check pass on src tests scripts, and mypy src/openadapt_verify passes.
  • Not rerun: my 76 HTML probes from the b8bd18f0 review. The module they exercise has not changed.

CI at this head

When I checked, 19 checks had passed, 23 were pending (including verify facade (py3.12) and the flow jobs) and 8 were skipped. None had failed. Merge should wait for the facade job, because it enforces the new 161 count.

Generality gate

Pass. The delta is a merge and a test count. It names no application.

I did not push to this branch, and I will not merge it.

@abrichr
abrichr merged commit 62cc608 into main Nov 24, 2026
55 checks passed
@abrichr
abrichr deleted the claude/fix-reload-oracle-binding branch November 24, 2026 13:53
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