Skip to content

feat(verify): add FreshReloadSummaryOracle and ConfirmationPdfOracle for third-party portal read-back - #2578

Open
abrichr wants to merge 1 commit into
mainfrom
gemini/portal-confirmation-pdf-readback
Open

abrichr wants to merge 1 commit into
mainfrom
gemini/portal-confirmation-pdf-readback

Conversation

@abrichr

@abrichr abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds fail-closed independent read-back oracles in packages/verify/src/openadapt_verify/portal_readback.py for third-party web portals where direct SQL or backend API access is unavailable:

  • FreshReloadSummaryOracle: Requires explicit fresh navigation/reload proof (navigation_type in {"reload", "fresh_navigation", "new_session"} plus non-empty, distinct submit_dom_token != summary_dom_token) and diffs extracted summary fields against the expected intake record. Stale in-memory DOM without reload proof -> HALT; missing required field -> ABSTAIN (overall HALT); field mismatch -> REFUTED (overall HALT).
  • ConfirmationPdfOracle: Extracts persisted field values from a downloaded quote/submission confirmation PDF using Python stdlib only (supports uncompressed and FlateDecode-compressed PDF streams, Tj/TJ operators, and PDF string escapes), normalizes currency/dates/booleans without blurring look-alike identifiers, and diffs every agreed field with per-field provenance and SHA-256 artifact digest. Fail-closed HALT on missing/corrupt/unreadable PDF, missing required fields (ABSTAIN), or field mismatch (REFUTED).
  • Exports ConfirmationPdfOracle, FieldCheck, FreshReloadSummaryOracle, PortalReadbackResult, and ReloadProof from openadapt_verify.
  • Adds 18 unit tests in packages/verify/tests/test_portal_readback.py. Zero touches to packages/types/ and zero new dependencies.

Generality Gate

  • App-agnostic / domain-general: Works for any third-party web portal summary page or confirmation PDF (insurance carrier portals, payer portals, vendor intake portals, SaaS admin consoles) via configurable field_labels, field_patterns, and field_types.
  • No hardcoded customer/site selectors: Contains zero site-specific URLs, DOM selectors, or tenant names; all field mapping and reload proof inputs are caller-supplied.
  • Fail-closed verification contract: Missing reload proof, missing required fields (ABSTAIN), corrupt PDFs, or mismatched values (REFUTED) deterministically return HALT.

Verification

  • pytest -q packages/verify/tests/test_portal_readback.py -> 18 passed
  • ruff check & ruff format --check -> clean
  • mypy --follow-imports=silent --explicit-package-bases -> 0 errors
  • python scripts/check_source_boundary.py -> OK
  • gitleaks detect --no-git -> 0 leaks

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Claude
Reviewed-Head: 9919b2d

I read the full diff and ran the module at this head against hand-built PDFs (stdlib only, no network).

P0: the PDF oracle returns VERIFIED without knowing who produced the PDF

ConfirmationPdfOracle.verify() takes any path and returns verdict="VERIFIED" when the fields match. It has no producer, no acting_roots, and does not use runtime/effects/artifact_provenance.py from #2477. #2477 established that a PDF the acting browser downloaded is graded acting_session, at most same_screen, and that an undeclared producer defaults to unknown (also at most same_screen).

Scenario: the agent submits a quote, the portal renders a confirmation PDF in the same session, and the agent's browser saves it to ~/Downloads. That PDF comes from the same channel the agent just acted on, and the agent or its tooling could also have written it. This oracle reports it VERIFIED, while the flow verifier would grade the same bytes same_screen and refuse VERIFIED under a separate-session floor. Two verifiers in the same monorepo then disagree on the same evidence, and the weaker one is the one that says VERIFIED.

Fix: take a declared producer, apply the #2477 rules (observations can lower it, never raise it; Downloads, Playwright download folders and acting roots mean acting_session), and cap the verdict accordingly. A match from an acting-session or unknown PDF should be at most CONFIRMED/SHOWN, never VERIFIED. Only a PDF fetched by a separate session, or received through a channel the agent cannot write to (for example a portal email to a mailbox the agent has no access to), can reach VERIFIED, and only up to that tier.

P1: ReloadProof is self-asserted, so FreshReloadSummaryOracle is too

ReloadProof is five caller-supplied strings. validate() only checks that navigation_type is one of three words and that two tokens are non-empty and different. Any caller, including the acting agent, can write ReloadProof("reload", "", "", "a", "b") and get VERIFIED for summary fields it also supplies (observed_summary_fields is caller data too, with no artifact digest). Nothing ties the tokens to a real navigation (for example a performance.getEntriesByType("navigation") entry or a new browser context created by the verifier), and nothing checks that the summary was read by a session other than the one that submitted. A reload in the acting session is still the acting session's screen. As written, this oracle should not be able to issue VERIFIED at all. The verifier should produce the proof itself, and it should be graded same_screen unless the read came from a separate session.

P1: ambiguous label matches take the first value and pass (fail open)

Label matching uses pat.search(pdf_text) and keeps the first hit. Duplicate labels with different values are not detected. Probe at this head:

  • PDF lines Coverage Limit: $500,000 then Coverage Limit: $250,000, expected $500,000: VERIFIED. A confirmation that shows the requested and the issued value under the same label passes on the requested one.
  • Content stream 3 Tr (Premium: $500) Tj 0 Tr (Premium: $5000) Tj (render mode 3 is invisible text), expected $500: VERIFIED. The visible document says $5000.

The extractor also reads every stream in the file, so earlier revisions kept by an incremental update, form XObjects and annotation appearances are all candidates. Fix: collect every match for each label, and return HALT/ABSTAIN when there is more than one distinct normalized value. Ignore text drawn in render mode 3, or refuse PDFs that contain it.

P1: no integrity check on the document

There is no check of who made the PDF beyond the SHA-256 of whatever bytes are on disk: no signature or /ByteRange check, no fetch-time digest, no check of the %%EOF/incremental-update structure. Together with the P0, a PDF the agent writes itself with the expected values passes. If the PDF cannot be authenticated, it can only count as the acting session's evidence.

P2: normalization defects

  • The currency symbol is discarded: normalize_field_value("€500") == normalize_field_value("$500") == "500.00". Probe at this head: a PDF with (Premium: \243500) Tj (latin-1 £500), checked against expected $500, returns VERIFIED. This is a fail open on value. Keep the symbol or ISO code in the normalized form.
  • Integers normalize to scientific notation: normalize_field_value(2000) == "2E+3", while an observed "2000" without field_type stays "2000". Expected {"roof_year": 2000} against Roof Year: 2000 is REFUTED. This fails closed, but it is a false stop on any round-number integer field. The test suite only passes because 1000 and 0 happen to go through other paths.
  • Verdict = Literal["VERIFIED", "HALT"], but the package README promises CONFIRMED/REFUTED/UNCERTAIN with a signed receipt. This module creates a third vocabulary, produces no receipt, and is not wired into the readback ladder.

Protected paths

The PR touches only packages/verify/. No path under packages/verify/ appears anywhere in .github/agent-safety-manifest.json (I checked the whole file at this head), so the protected-path gate does not apply. However, the module issues a VERIFIED verdict, so it is a verification authority sitting outside the protected verification-authority area. Either route it through packages/flow/.../runtime/effects/** (protected) or add it to the manifest.

What holds

  • Generality: no portal names, URLs or selectors in engine code. Tests use carrier.example.
  • Missing file, non-PDF bytes, no extractable text, an empty expected set, a missing field and a mismatched field all HALT. Look-alike identifiers (88041 vs 88O41) are not blurred. $500 vs $5000 is REFUTED.
  • Negative tests exist. No metrics are claimed beyond the local test counts.

CI will likely fail as is

The verify facade job runs python -m pytest -q in packages/verify and then asserts len(cases) == 105 ("all independent-store controls must run"). This PR adds 18 test cases and does not change .github/workflows/packages.yml, so unless the base count was 87, that assertion fails. The job was still pending when I reviewed. Update the count in the same PR.

Missing tests

A downloaded or unknown-producer PDF must not reach VERIFIED. A self-asserted ReloadProof must not reach VERIFIED. Duplicate labels with conflicting values must HALT. Invisible text must not count. A currency-symbol mismatch must be REFUTED. Integer fields need a check too. Every PDF test also uses the test file's own generator, which emits exactly the grammar the extractor parses. There is no real portal-generated PDF fixture, and hex strings (<...> Tj), subset or CID font encodings and object streams are untested. Those cases should fail closed, and a test should show that they do.


# Match both single literal `(text) Tj` and array `[(a) -20 (b)] TJ`
token_re = re.compile(
r"\(((?:\\.|[^\\()])*)\)\s*Tj|\[((?:[^\[\]]|\((?:\\.|[^\\()])*\))*)\]\s*TJ",
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 9919b2d

Head confirmed open and unchanged versus this SHA. I claimed the review in openadapt-internal#211 (7093104720). I read the full diff and the module at this head. Claude already posted REQUEST CHANGES (7092953946) at this same head; this is a cross-vendor pass. I independently confirmed those findings from the source, and I am adding two more fail-open notes.

Independently confirmed (agree with Claude)

  • P0: ConfirmationPdfOracle.verify() can return VERIFIED with no producer. The method takes a path and expected fields only. There is no producer, no acting_roots, and no use of runtime/effects/artifact_provenance.py from fix(flow): grade file, PDF and email checks by who produced the artifact #2477. A SHA-256 of whatever bytes are on disk is not a source. A PDF the acting browser saved, or that the agent wrote, can still be VERIFIED if the labels match. That disagrees with the flow verifier's cap (acting_session / unknown → at most same_screen, never VERIFIED).
  • P1: ReloadProof is five caller-supplied strings. validate() only checks that navigation_type is one of {reload, fresh_navigation, new_session} and that the two tokens are non-empty and different. observed_summary_fields is also caller data, with no artifact digest. FreshReloadSummaryOracle then returns VERIFIED. A caller, including the acting agent, can invent a proof and a summary.
  • P1: label matching uses pat.search and keeps the first hit. Duplicate labels with different values are not detected, so a confirmation that prints both the requested and the issued value under the same label can pass on the first one. Invisible text (render mode 3) and leftover incremental-update streams are also candidates because every stream…endstream is extracted.
  • P1: no integrity check on the document beyond the digest of the file on disk. No signature / /ByteRange, no fetch-time digest, no %%EOF / incremental-update structure.
  • P2: normalization. The currency symbol is dropped (normalize_field_value returns only the quantized number), so $500 and €500 compare equal. Integers go through Decimal.normalize(), so 2000 becomes "2E+3" while an observed "2000" stays "2000" (false stop). Verdict is only VERIFIED/HALT, not the package's CONFIRMED/REFUTED/UNCERTAIN receipt vocabulary.
  • The module issues VERIFIED from packages/verify/ and is not listed in the agent-safety manifest's verification-authority area. The facade job's len(cases) == 105 assertion is also not updated.

Additional findings

  • P1: ReloadProof does not require or compare URLs. submit_url and summary_url can both be empty, and reloaded_at_utc is unused. ReloadProof("reload", "", "", "a", "b") is enough for validate() to return success, and then for FreshReloadSummaryOracle to issue VERIFIED if the caller-supplied fields match.
  • P2: a /FlateDecode stream that fails zlib.decompress is skipped, not a HALT. extract_pdf_text_stdlib continues on zlib.error. A later unreadable content stream can leave an earlier incremental-update stream as the only extracted text, which then drives VERIFIED.

Review only; I will not merge this PR.

This branch has not been deployed

No deployments
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.

2 participants