Skip to content

fix(form-tx): type into type-aheads and stop on surface errors (partial-match-as-match fix) - #2448

Closed
abrichr wants to merge 45 commits into
mainfrom
claude/form-gap-2-typeahead
Closed

abrichr wants to merge 45 commits into
mainfrom
claude/form-gap-2-typeahead

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Stacked on #2429 (base claude/form-tx-weekend). This is the second of the PRs that close the engine gaps the held-out quote-portal run found.

What changes

  • Type-aheads. A portal_combobox binding whose control is a text input is now filled by typing. The surface clears the input, sends one key event per character, waits for the page to settle, then reads the one visible listbox (PlaywrightFormSurface.type_portal_combobox_query). The pack can set typeahead_query_chars on a binding to type only a prefix.
  • Choosing. A suggestion is chosen only when exactly one matches under the binding's codec. None or several matching stops for an operator, with the suggestions on the stop. It never takes the first. After the choice, the control must show the chosen suggestion or the intended value, or the run stops.
  • Stops instead of crashes. MissingAnchorError, AmbiguousAnchorError, PopupContractError, settle timeouts, surface-context errors and Playwright timeouts raised while acting on the form now end the run with an ambiguous_option_or_target stop instead of an exception. This applies in run_until_halt_or_done and apply_human_resolution. Before the submit click, safe_to_retry is true only if no request changed state. On or after the submit click, the run ends delivery_uncertain with safe_to_retry false, so a failed submit is never reported as safe.

Comboboxes that are not text inputs still open by click. The protocol change is optional: a backend without type_portal_combobox_query keeps the click path.

Tests

tests/test_form_tx_typeahead.py runs headless Chromium against a page served through context.route. Its suggestions load only after typed text. The tests cover:

  • one match chosen and submitted;
  • a prefix query;
  • two equal suggestions, which stop with both options and submit nothing;
  • no suggestion, which stops and submits nothing;
  • a click-only combobox whose list never opens, which stops and does not raise;
  • a submit button covered by an overlay, which ends delivery_uncertain with nothing submitted.

All form_tx tests pass on the zenbook lab: 238 passed, 28 skipped. ruff 0.17.0 check and format are clean.

This has not been measured on held-out portals yet. CAPABILITIES.md and docs/FORM_TX.md say 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.
A portal combobox that is a text input is now filled by typing, so
suggestions that load only after typed text appear. A suggestion is chosen
only when exactly one matches under the codec, and the choice is checked
afterwards. A control the surface cannot act on stops for an operator
instead of raising out of the run; after the submit click it ends
delivery_uncertain.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: cc8002c

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 typed type-ahead path uses resolve_unique_option on the suggestions: zero or several matches become AMBIGUOUS_OPTION_OR_TARGET with the options attached, and nothing is submitted (test_two_equal_suggestions_stop_with_the_options_and_submit_nothing, test_no_suggestion_is_a_stop_not_an_exception). After a unique choice, _verify_typeahead_choice stops unless the live control shows the chosen label or value (or the intended value). tests/test_form_tx_typeahead.py drives real headless Chromium through PlaywrightFormSurface, with no fake surface.

Delivery semantics hold. _commit_clicked is set when the submit control is clicked and is not cleared when _commit_in_progress is. _surface_error_result therefore ends DELIVERY_UNCERTAIN with safe_to_retry false after that click (test_error_on_the_submit_click_is_reported_as_delivery_uncertain). Before the click, safe_to_retry is true only if mutation_count did not move; a failure to read the count is treated as a move.

Residual only: _is_surface_action_error also matches builtin TimeoutError and any playwright class named Error or TimeoutError. That can report a driver or protocol failure as a person-facing halt. The named surface classes (MissingAnchorError, SurfaceSettleTimeoutError, and the rest of _SURFACE_ACTION_ERROR_NAMES) are the tighter set. I am not flipping this unique verdict on that residual.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: c9cbaa1

The form can submit without establishing which option the application selected.

  1. A prefilled combobox can bypass selection entirely. With a six-character query, a field already showing 2210 Juniper Loop matches the dossier’s longer address even if the existing selection refers to another apartment. The new prefix comparison returns true before this session has opened the list. The prefill conflict check, fill pass and required-field check all accept that result. Keep partial display text separate from proof of a particular choice. A fresh session with a shared-prefix prefill needs to establish the intended selection or halt before submit. Prefill predicate and call sites
  2. The default type-ahead query is the full intended label. If a click leaves the query untouched and fails to set the selected option, the first two comparisons in _verify_typeahead_choice still accept that text. The city fixture already distinguishes the displayed label from the selected code sent on submit. Its positive test sets both. The inert-click test uses a shortened query and misses this case. Add an inert full-query case and require evidence of the selected option or an operator stop before submit. Post-click check · Fixture submission

I traced the base-to-head change, the delta since the previous approval, and the synthetic Chromium test source. I did not run the suite. The implementation is application-independent. Both failures arise from treating text as evidence of a selected option. Held-out portal qualification remains open as declared in the PR.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: c9cbaa1

This review is from Gemini (gemini-3.1-pro-preview). It replaces Codex, which failed to start here. Gemini read the full diff against claude/form-tx-weekend (merge-base 124db5c9), the diff since the Grok-reviewed head cc8002c6, and the head versions of reconciler.py, playwright_surface.py and types.py. The review covers correctness and safety only.

Gemini checked these and found them sound:

  • The type-ahead never takes the first suggestion. When no suggestion matches, or several do, the run stops for an operator and the suggestions are attached to the stop.
  • After a pick, _verify_typeahead_choice stops the run unless the control shows the chosen suggestion.
  • A surface error before the submit click gives safe_to_retry true only when mutation_count did not move. If the count cannot be read, it is treated as moved.
  • A surface error on or after the submit click ends DELIVERY_UNCERTAIN with safe_to_retry false.
  • Comboboxes that are not text inputs still open by click.
  • The tests drive real headless Chromium, with no fake surface.

Gemini's first pass approved. A follow-up question asked how the new leading-part rule acts at the other call sites of _control_matches_fact. Gemini then changed its verdict to the blocker below.

Blockers

  1. The prefill conflict check now passes a value that is only the start of the intended one (packages/flow/openadapt_flow/form_tx/reconciler.py:283-296, added after cc8002c6).

    • What changed. _control_matches_fact now accepts any separator-bounded prefix of the intended value that is longer than formatted[:typeahead_query_chars]. That baseline is assumed, not what was actually typed.
    • Who uses it. The PREFILL_VALUE_CONFLICT check (about line 1130), the skip-actuation check (about 1179), the human-accepted path (about 1258 and 1266) and the popup readback (about 1648) all call _control_matches_fact.
    • Scenario. The binding is PORTAL_COMBOBOX with typeahead_query_chars=6, and the dossier holds "2210 Juniper Loop Apt 4, Brackenfield, OR". The page loads with the input already showing "2210 Juniper Loop". That text could come from the portal, a saved draft, or an earlier operator who typed and never picked. It could also be the start of a different address, such as Apt 5.
    • Result. At base this raised PREFILL_VALUE_CONFLICT. At this head the control counts as already correct, so the run neither stops nor acts. It goes on to submit a value that nobody chose, without opening the type-ahead or setting the page's hidden fields.
    • Suggested fix. Limit the leading-part rule to _verify_typeahead_choice, right after this session's own pick, and keep _control_matches_fact strict. Alternatively, accept a leading part only for a control this session filled.

    The PR body does not mention this loosening; it describes only the check after a pick. test_form_tx_partial_pick.py covers only the actuation flow and has no prefill case.

Earlier reviews

  • Grok (APPROVE at cc8002c6). Grok noted that _is_surface_action_error also matches builtin TimeoutError and generic Playwright Error. That match is still present. Gemini rates it non-blocking because the stop still fails closed, and safe_to_retry stays false whenever the mutation count moved or could not be read.
  • Commits after Grok's review (finding a redrawn type-ahead again by section, label and kind; accepting a leading-part pick). Gemini found the redraw matching safe, because it needs a unique, labelled match. The leading-part rule is safe inside _verify_typeahead_choice but not in _control_matches_fact (blocker 1).

The required checks at this head (ci, packages-gate, run-ci, gitleaks, protected-safety-review) were failing when this review ran. This review did not look into why.

…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.
…run's own pick

Gemini blocker on #2448: _control_matches_fact accepted a separator-bounded
leading part for any type-ahead, assuming the typed baseline, so a field the
portal prefilled with '2210 Juniper Loop' matched the intake's full address:
no stop, no action, submitted. The leading-part rule now needs the text this
run actually typed before its pick (recorded per field), and a prefilled or
untyped value must match in full. Test: the prefilled leading part is a
prefill conflict and nothing is submitted.
@abrichr abrichr changed the title fix(form-tx): type into type-aheads and stop on surface errors fix(form-tx): type into type-aheads and stop on surface errors (partial-match-as-match fix) Nov 21, 2026
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Head moved to c329c57dc to fix Gemini's blocker. The fix is a member of the partial-match-as-match class: _control_matches_fact accepted a leading part of a type-ahead value for any field. It now accepts one only after this run's own pick, using the text this run actually typed. A prefilled or untyped value must match in full. New headless test: test_prefilled_leading_part_is_a_prefill_conflict_not_a_match. All 154 tests/test_form_tx_*.py tests pass on the lab, and mypy is clean. When this PR is squash-merged, the commit message should name the class. I've put it in the title for that reason.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: c329c57

The fresh-prefill finding is resolved. A new session has no recorded typed query, so it cannot accept the shortened value before choosing. The new Chromium regression asserts PREFILL_VALUE_CONFLICT and zero submissions.

The full-label inert click still passes. In an offline synthetic check of this head's _actuate_control, typing the full label exposed one uniquely matching option. Its click left the selected value unset. The control still showed the query, and the reconciler returned no halt. The first two post-click comparisons accept that preexisting text. Recording the typed query after actuation does not establish which option was selected. Post-click check

When the query already equals the label, require observable evidence of the choice or stop before submit. Extend the existing full-label city case with an inert click that leaves its selected code empty, and assert zero submissions. This is the one remaining finding from the prior review. It applies across editable comboboxes. Held-out portal qualification is still pending. Existing full-label selection fixture

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: c329c57

Codex run on c329c57. Scope: the delta since c9cbaa1 (typed_query plumbing in reconciler.py, new prefill test). Relative links point into packages/flow/openadapt_flow/form_tx/ at this head.

Blockers

  1. An inert full-query click can submit. The default query is the full label. If the click leaves that text untouched, verification accepts it as the option label. Headless Chromium submitted the address with the city field still empty. reconciler.py:862, reconciler.py:1035
  2. A reload preserves stale pick evidence. After a valid pick and a halt on another field, I reloaded the page with 2210 Juniper at the same selector. Resolving the unrelated halt submitted that shorter address with zero picks on the reloaded page. The session reuses the cached query solely by selector. reconciler.py:1145, reconciler.py:1201
  3. Popup checks read the parent’s query. Writes use popup:<id>:<selector>, but both required-field and pre-Apply checks read the bare selector. I reproduced a valid popup pick being rejected. With a shorter parent query at the same selector, both checks also accepted a popup value equal to its own typed query. reconciler.py:1132, reconciler.py:1228, reconciler.py:1288, reconciler.py:1683
  4. A redraw loses a valid pick. Verification finds the replacement input by label, but the session records the old selector. A successful pick that changed the input ID and displayed 2210 Juniper Loop raised PREFILL_VALUE_CONFLICT on the next pass. reconciler.py:1025, reconciler.py:1228
  5. Operator resolution can click twice. PROVIDE_VALUE records the filled selector without recording its typed query. On resume, the valid partial display triggers another pick. Chromium recorded two option clicks for one resolution. reconciler.py:2818, reconciler.py:1200

Earlier blockers

All 10 existing tests in the two focused modules passed.

Out of scope (follow-up)

None.

…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.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 84e484a

Gemini run on 84e484a (gemini-3.1-pro-preview, cross-vendor; author is Claude). Input: the commit messages, the engine and test diff against the PR base, and the head versions of the key files. Posted by the form-tx agent on Gemini's behalf; output unedited below.

VERDICT: APPROVE
BLOCKERS: none
NON-BLOCKING: none
CHECKED: Verified that the removal of _is_leading_part_of_choice correctly enforces full matches for comboboxes, fixing the partial-match-as-match fail-open. Checked that surface errors are safely caught and converted to halts, and that any surface error after a commit click results in a terminal DELIVERY_UNCERTAIN outcome. Verified that typeahead picks are strictly checked against the pre-click baseline to ensure the click actually changed the field, safely halting if the pick is inert.

# 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.
…s read their reply

The weekend branch requires a pack to declare commit_url_patterns (or a
record lookup) before a save counts as confirmed. Fixture submit handlers
that navigated without reading the reply aborted the request after its
2xx, which the surface records as a failed save.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: f034812

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: f034812

Delta check of the merge of claude/form-tx-weekend 0c61aaf and its follow-ups: OK. The merge had no conflicts. Follow-up: the typeahead and partial-pick fixtures declare their commit endpoints.

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
…wrapper

The actuation note added on claude/form-tx-weekend wraps _actuate_control;
the type-ahead pick's typeahead_query_chars argument must reach the inner
actuation.
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: 27220ed

Delta since f034812: the merges of 1067e97 and cfdb87b (both clean) and 27220ed. That commit adds typeahead_query_chars to the new _actuate_control wrapper and passes it through to _actuate_control_once. Without it, the type-ahead pick would hit a TypeError or lose its query length.

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. The surface-error halt in _actuate_control_once returns before the actuation is noted. Resolving that halt records a ledger entry for the same selector, so I see no fail-open.

Own changes preserved: git diff cfdb87bf8 27220ed2c --stat gives 7 files, +1025/-7, the same file set. Per file, the only line change is the two-line pass-through. The merge base is cfdb87b, not ef4f5cc.

Tests: 82 passed on the targeted form_tx files. The run went through cpu-slots with a non-monorepo interpreter, with this branch's code first on PYTHONPATH. I did not run them myself.

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 29c61f0

Cross-vendor re-review at the current head. My last verdict was APPROVE at cc8002c6b73107eb23919c3a2736503635d376ca (#2448 (comment)). The PR is open and its head matches this SHA. The base is claude/form-tx-weekend (#2429). Against it the diff is 7 files, +1025/−7. I will not merge this PR.

What changed since cc8002c

There are nine PR commits. The ones that matter for safety:

  • Partial matches are gone (a055c4a3c). The earlier "leading part of the label" acceptance (dfcd7c5bf, c329c57dc) and its typed-query bookkeeping are removed. _control_matches_fact accepts only values_equivalent(intended, current, codec): a field that shows a leading part of the value does not match, whoever put it there.
  • _verify_typeahead_choice. After a pick, the live control must show the chosen option's label or value, or the intended value under its codec. The click must also be what changed the field: if the value was already there before the click (typed text, an inline completion), it halts. If the input was redrawn, it is found again only as a new control, unique by section, label and kind. An existing look-alike never counts. If the control is gone, that halts.
  • Surface errors become a person stop. _actuate_control turns MissingAnchorError, AmbiguousAnchorError, PopupContractError, SurfaceSettleTimeoutError, SurfaceContextError, TimeoutError and Playwright Error/TimeoutError into a FormHaltItem, with PROVIDE_VALUE / FIXED_ON_SCREEN / ESCALATE / ABORT. Any other exception still propagates.
  • 27220ed2c passes typeahead_query_chars through the actuation wrapper. By default the typed query leaves the last character to the pick, so a successful pick shows up as a change.

A pick is still not the final verdict. The summary read-back judges every written subject. I found no path where a type-ahead with typed-but-unpicked text, or a prefix, ends passed. Everything here keys on control kind, anchors and codecs, not on any portal. It passes the generality gate.

Tests at this head (Python 3.12, in-tree flow and types)

test_form_tx_partial_pick.py, test_form_tx_typeahead.py, test_form_tx_fail_open_classes.py, test_form_tx_reconciler_and_receipts.py, test_form_tx_written_field_no_fact.py, test_form_tx_save_answer.py: 62 passed.

CI at review time

27 pass, 22 skipping, 1 pending (flow core unit (shard 3/4)), 2 failing: protected-path evidence / protected-safety-review with "pull request base must be main". Expected while stacked on #2429. This approval assumes shard 3/4 finishes green, and that the protected checks pass once the PR is retargeted to main.

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