Skip to content

fix(form-tx): see forms in iframes and open shadow roots - #2440

Closed
abrichr wants to merge 42 commits into
mainfrom
claude/form-gap-3-frames-shadow
Closed

abrichr wants to merge 42 commits into
mainfrom
claude/form-gap-3-frames-shadow

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Stacked on #2429 (base claude/form-tx-weekend). Third of a short stack that closes the engine gaps the held-out quote-portal run found.

What changes

  • iframes. Builds on Codex's unmerged codex/frame-form-surface branch. Its two commits are cherry-picked here with -x, unchanged: a surface bound to a Frame, or routed to exactly one same-origin frame by URL path, refusing unknown, cross-origin and ambiguous frames. This PR makes the routing pack data. UIProfileSpec.frame_path_patterns is used when the surface gets no explicit patterns, and invalid patterns are refused when the profile loads.
  • Open shadow roots. All three in-page scripts (snapshot, settle check, listbox reader) now share one set of composed-tree helpers. Controls, labels (for, aria-labelledby), sections, banners, sign-in walls, modals, busy markers, listboxes and options inside open shadow roots are observed. Visibility is checked across host boundaries, and shadow-root edits change the settle signature.
  • Selector format. A control inside a shadow root gets <host selector> >> <selector inside the root>, nested as needed (for example #panel >> #inner >> #year). Playwright locators accept that form, and the in-page resolveSel resolves it the same way.
  • Closed shadow roots can't be read and stay invisible, so the layer never acts there.
  • Popup fix. With the frame commits on this branch, a child popup that closed itself after its apply button made the settle wait raise. Three e2e portal tests failed on that. The settle wait now ends cleanly for that case only. A main page or frame that closes still raises.

No app names in engine code.

Tests

tests/test_form_tx_shadow_dom.py runs real headless Chromium against synthetic loopback pages. It covers:

  • nested open shadow roots: labels, required, section, select options;
  • fill, select, check and text entry through >> selectors;
  • a portal combobox and its listbox inside a shadow root;
  • a banner and a sign-in wall inside a shadow root;
  • shadow edits changing the settle signature;
  • routing into an iframe from the UI profile, including a shadow root inside it, without seeing the shell page;
  • an invalid pattern refused.

All 272 tests/test_form_tx_*.py tests pass on the lab (WSL, headless Chromium), and ruff passes.

Not shown

None of this has been measured on a held-out run yet. CAPABILITIES.md says so.

…rest as not_checked

The judge covered pack bindings and facts, not what the run wrote. Fields
typed inside a popup estimator had no verdict at all, so a run could end
verified with a signed receipt while those fields were never checked.

- Record every write (auto fill, operator value, kept prefill, fixed on
  screen, popup return) in a per-session ledger; the judge gives each one a
  verdict.
- Add a third verdict status, not_checked, for a field with no declared
  read-back, a missing or ambiguous summary control, or a failed lookup. It
  is never passed.
- Add the readback_incomplete outcome: submitted, nothing contradicted, but
  at least one field unchecked. No receipt; receipts and verdict models
  refuse to pass with an unchecked field.
- Re-read popup inputs just before the popup's apply button, since the
  summary usually does not show them; a mismatch stops before apply.
- Side panel shows refuted and incomplete runs as needing action.
…apply

A re-read of the popup before its apply button guards the apply, but it is
not a read-back of what the application recorded. Report those fields as
not_checked. Key the write ledger by field, selector and popup so a popup
input never hides a main-form write of the same key. The historical
underwriting fixture now ends readback_incomplete: its estimator inputs are
never shown.
Frame routing (Codex's codex/frame-form-surface commits, cherry-picked
above) becomes pack data: UIProfileSpec.frame_path_patterns, used when the
surface gets no explicit patterns.

Every in-page script now walks open shadow roots: controls, labels,
sections, banners, sign-in walls, modals, busy markers and listboxes.
A control inside a shadow root gets the selector
'<host selector> >> <selector inside the root>', which Playwright
locators accept. Closed shadow roots stay invisible.

A child popup that closes itself after its apply button ends its settle
wait instead of raising, as before the frame commits.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 4add178

First review of this PR, at the requested head, unique against #2429 124db5c9. Author is GitHub abrichr, not Grok. Review only; I am not merging. The #2429 read-back hole (an optional declared field_readbacks key with no expected fact and an empty/placeholder control can skip a verdict) is still in the base and is not unique to this change.

Fail-closed on frame routing is tight: frame_path_patterns come from the explicit argument when that argument is non-empty, otherwise from the UI profile; empty or invalid patterns are refused when the profile loads; unknown, ambiguous, and cross-origin matches raise and do not fall back to a shell. I found no application names in the engine diff. Visibility, auth walls, banners, and the settle signature do walk open shadow roots; test_banners_and_auth_walls_inside_shadow_roots_are_seen and test_shadow_root_changes_count_as_dom_activity pin that. The popup self-close path in wait_for_quiescence is limited to _scoped_to_page_only, which is set only on the child surface created by open_popup_surface, and is refused when the surface is a frame.

The blocking issue is the host >> inner selector. computeDomSelector only requires the inner selector to be unique inside the element's own root (isUniqueMatch / safeQueryAll(rootOf(target), …)). Live actuation uses Playwright's page.locator(dom_selector), and _resolve_live_locator will act when exactly one of the matches is visible. Playwright's >> also sees the host's light-DOM descendants, including slotted nodes. So a light-DOM or slotted child that shares the inner selector (duplicate id, name, or structural path) can be the unique visible match, and the fill or click goes to a different element than the snapshot observed. There is no test for slotted light-DOM children or for a duplicate inner selector across the host's light tree and shadow tree. Uniqueness should be required across that whole composed subtree, or the live resolver should refuse when light-DOM and shadow matches coexist, even if only one is visible.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 5baf94a

Re-review at the current head (moved since 4add17832, prior REQUEST CHANGES 7060617288). The unique work closes the host >> inner hole.

isUniqueMatch now scopes a shadow-root element to its host's whole composed subtree (shadow tree plus light-DOM descendants, slotted nodes included), not only the shadow root, which is what a Playwright host >> inner locator searches. If no inner selector is unique there, the emitted host >> … selector is still refused at _resolve_live_locator whenever that locator matches more than once, visible or not: it raises AmbiguousAnchorError rather than acting on the unique visible light-DOM or slotted node. The new Chromium tests cover a slotted duplicate, a hidden light-DOM duplicate, and a short #host >> #amount when the inner selector is actually unique.

Two other unique fixes are sound: selector building uses a local cssEscape instead of the page's CSS global, and a child window gets a fresh surface with empty frame_path_patterns so it does not inherit the parent's frame routing.

No merge from me.

…as key material

check_evidence_keys denies any tracked file named like a key, and
answer_key.json matched. The file is now answers.json and the manifest field
answers_sha256; contents and sha256 are unchanged. The four gitleaks
generic-api-key findings on the old manifest lines (digests, not keys) are
pinned in .gitleaksignore by commit, file and line.
…mary is not_checked

Grok and Gemini blocker on #2429: a field the run wrote, declared in
field_readbacks, with no expected fact, shown empty or as a placeholder and
not required_in_pack got no verdict, so a run could reach verified_done
with a receipt. It is now not_checked. Headless test included. RESULTS.md
points at the arm A rows in arm_A_full.log.
…by class

Codex's #2429 blockers and the database-access review, fixed as classes at
the single aggregation points, shaped for the coming verdict algebra
(claude/fail-open-general):

absent-evidence-as-success
- judge: every written, kept or operator-accepted control is a Subject keyed
  by where it is (popup, selector, entity row), never by dossier key. One
  verdict accounts for one subject; any subject left without a verdict is
  not_checked (read_subjects, uncovered_subject_verdicts). Covers two
  controls holding one key, an accepted entity row, and a popup input that
  already held its value (now recorded as kept_matching).
- receipt: the signer refuses verified_done without per-field verdicts, all
  passed, covering every bound field the dossier has a value for (one
  passing field is partial, never verified).
- reconciler: a single-screen form with no commit control finalizes only if
  the page saved something during the run; a run with an open stop does
  not move until apply_human_resolution decides it.
- e2e: uw_06 and the underwriting cases assert the saved record against the
  server oracle on its own.

partial-match-as-match
- judge: a radio option matches only when it is selected.

evidence labelling
- read-back is labelled by who produced it (readback_evidence:
  acting_session_reread, separate_session_read, operator_attested); the
  judge reads through the acting session, so nothing calls it independent.

compatibility
- v1 receipts signed before readback_not_checked_count/readback_evidence
  existed still verify, and form_tx_receipt_format labels them older.

docs
- RESULTS.md pins the engine-freeze diff to the measured commit 124db5c.
…-evidence-as-success, partial-match-as-match)

Codex's delta review at dd78df9:

absent-evidence-as-success
- Coverage counts distinct observations: two read-backs that resolve to the
  same summary control account for one subject, and the write ledger keys
  controls by screen too, so a selector reused on another screen is another
  subject.
- One subject per accepted entity row, not per table.
- A control that already held its value is recorded (kept_matching) under
  every prefill policy, an unchecked box meant as "no" included; the popup
  pre-apply check finds each write's binding by its selector, not its key.
- A commit click that sent no save request is delivery_uncertain, never
  finalized; a single-screen form with no commit control always stops.
- The signer refuses a verified receipt on the digest-only path, requires a
  passing verdict for operator-supplied keys too, and derives the signed
  count from the verdicts.
- A repeated call on an open stop is never more retryable than that stop.
- Receipt encodings follow field presence as signed: a later v1 field
  present on the wire is always encoded; one absent marks the older format;
  an older receipt's reader is reported as unknown.

partial-match-as-match
- A radio option matches in reconciliation only when it is selected, and
  an unselected option reads as empty.

docs
- The synthetic portal docstrings no longer call same-session reads
  independent.
…t-evidence-as-success)

Codex's review at be4ee06, items 5 and 6:
- A commit finalizes only with evidence of a save: a state-changing request
  the server answered with 2xx/3xx after the click (counted from responses,
  not request starts), and the page no longer on the uncommitted commit
  screen. Otherwise delivery_uncertain, never verified.
- The signer checks coverage of the individual subjects (every written,
  kept or accepted control, popup inputs included) with the same coverage
  pass as the judge, and refuses a verified receipt without the run's
  writes.
Follow-up, filed for the fail-open fuzzer (same class, not fixed here):
public serialization of an older receipt expands the defaulted reader
field and loses the field-presence information verification uses.
…and bind signer to auto-fill subjects and judge ledger
…subject source with exact auto-fill equality
# Conflicts:
#	.gitleaksignore
#	llms-full.txt
#	packages/flow/CHANGELOG.md
#	packages/flow/public-artifacts.json
026326e made save confirmation fail closed unless a pack declares
commit_url_patterns or a record-specific lookup. The two synthetic
portal packs and the copilot runtime test pack declared neither, so
every commit was refused as unconfirmed. Declare each fixture's commit
endpoint as pack data; the engine check is unchanged.
# Conflicts:
#	packages/flow/openadapt_flow/backends/_page_quiescence.py
#	packages/flow/openadapt_flow/form_tx/playwright_surface.py
The frame-routing surface reads the owner page's url at construction.
…ped settle

Main's TOP_TICKS_JS returns {ticks, stalled}. The root-frame check still
indexed it as a list (KeyError: 0). A stalled top window now falls back
to the screenshot settle, as _per_frame does.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: cdd7802

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: cdd7802

Delta check of the merge of claude/form-tx-weekend 0c61aaf and its follow-ups: OK. Conflicts in _page_quiescence.py and playwright_surface.py were resolved keeping both sides (top-window paint check with main's stall fallback; frame-scoped request ownership). Follow-up: the root-frame settle reads main's new {ticks, stalled} probe shape (it raised KeyError: 0).

Local single-process runs (load under 15) passed on this head.

…e reply body

The surface marked a save as failed when the request failed after its
status arrived. That happens whenever a page does `await fetch(); location
= ...`: leaving cuts off the reply body. No save decision reads the body,
so the status and headers are the answer; a request that never got a
status still fails.
…nt fills from the ledger; a signer refusal is a stop

- Every control the reconciler actuates is noted apart from the write
  ledger. Before signing, each must be in the ledger (a radio option may
  be named by its group); otherwise the run ends readback_incomplete with
  no receipt.
- The receipt's fields_filled_auto is the number of distinct auto-filled
  controls in the ledger, so a control filled again after a sign-in or a
  re-render is one field.
- A signer refusal (ValueError) ends the run readback_incomplete instead
  of raising, including from apply_human_resolution.

Tests pin the await-fetch-then-leave pattern with a reply that is still
streaming, a save with no status, an actuation missing from the ledger,
a planted signer refusal after a human decision, and a re-filled control.
…a client abort; actuations keyed by popup and screen

Review follow-ups:
- The answered flag is keyed by the request's sequence number and cleared
  with the counter, so a reused object id cannot turn a later failed save
  into a cut-off reply. A request that failed after its status counts as a
  cut-off reply only when the browser reports a client abort; any other
  failure still vetoes the save.
- An actuation is covered only by a ledger entry in the same popup and on
  the same screen, as the ledger keys its subjects.

Tests: a later save with no status vetoes an earlier 2xx; a ledger entry
for the same selector in another popup does not cover an actuation.
# Conflicts:
#	packages/flow/CHANGELOG.md
# Conflicts:
#	packages/flow/openadapt_flow/form_tx/playwright_surface.py
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: b2e2529

This head is b2e2529, a further merge of ef4f5cc on top of d7e4850. Delta since cdd7802: two merges of claude/form-tx-weekend, with no new commits of this branch's own.

Conflicts:

Since the last approval, this head carries the #2429 engine commits (the 2xx save answer, the ledger check before signing, a signer refusal as a stop, and keying by sequence, popup and screen). Every _actuate_control call site in this head passes session and in_popup_subroutine, there is one signing site, and it is guarded by _unrecorded_actuations and the ValueError stop. I checked the call sites statically.

Own changes preserved: git diff ef4f5cc88 b2e252988 --stat gives 9 files, +1336/-225. The file set and line changes are the same as before, except that the CAPABILITIES.md row now lives in the row file and one blank line differs.

Tests: none were reported for this head, and I did not run any.

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: b2e2529

Independent cross-vendor review of claude/form-gap-3-frames-shadow (stacked on claude/form-tx-weekend).

What was verified

  • Same-origin & fail-closed frame routing: UIProfileSpec.frame_path_patterns validates non-empty regexes as pack data; PlaywrightFormSurface restricts frame routing to base_origin, refuses cross-origin/ambiguous/detached contexts (SurfaceContextError), and walks only open shadow roots (closed shadow roots remain invisible).
  • Decision context binding: FormSnapshot.context_id is bound into ReconcilerSession._halt_contexts so a human decision cannot replay across a navigated or swapped iframe document.
  • Quiescence: _page_quiescence.py scopes paint-stall checks to window === window.top while tracking frame-scoped network activity.
  • Tests & generality: test_form_tx_frames.py and test_form_tx_shadow_dom.py pass in CI; zero per-app engine code; honestly notes synthetic headless-Chromium coverage (no held-out portal run yet).
  • CI note (merge blockers outside this PR's logic): launcher / run-ci fails test_build_capabilities.py (stale CAPABILITIES.md.sha256 after editing 0115-*.md) and flow core unit (shard 2/4) fails test_cli_surface.py on exceptions answer (fixed by #2573 on main). Sync with main + refresh capabilities stamp before merging.

Base automatically changed from claude/form-tx-weekend to main November 23, 2026 22:25
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Architectural pivot (founder Option 1, 2026-11-23): freezing the hand-written form-tx DOM heuristic and word-list stack to focus on openadapt wrap + demonstration-derived CheckpointSpec + Cross-Tab Entity Ledger + GUI-to-API/MCP promotion. Branch preserved for reference.

@abrichr abrichr closed this Nov 24, 2026
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