Skip to content

fix(form-tx): run two-step and in-page popup estimators - #2441

Closed
abrichr wants to merge 43 commits into
mainfrom
claude/form-gap-4-popup-steps
Closed

abrichr wants to merge 43 commits into
mainfrom
claude/form-gap-4-popup-steps

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Stacked on #2429 (base claude/form-tx-weekend). Closes engine gap 6 from the held-out quote-portal run: an estimator that needs Calculate and then Use This Value could not be run, and an estimator shown as a dialog in the page was not supported.

What changes

  • PopupSubroutineSpec.compute_anchors: buttons clicked in order after the popup's inputs are filled and before its apply button. Each must match exactly one control. A missing or ambiguous step button, or an error shown after a step, is a popup_contract_failed stop.
  • PopupSubroutineSpec.popup_mode: window (as before) or in_page. In-page mode clicks the trigger on the same page. Only controls that were not on the page before the trigger count as the dialog's. After apply, the apply button must be gone.
  • Popup inputs are re-read before the first step and again before apply. A match still leaves the field not_checked unless the stored record shows it (the founder's rule, unchanged).
  • If the intake already gives the value the popup returns and the two differ, the run stops with prefill_value_conflict before submit. Before this change the popup's value was kept.
  • A popup that will not open, a missing anchor, or a popup that never settles is now a popup_contract_failed stop instead of an exception out of the run.

No app names in engine code.

Tests

tests/test_form_tx_popup_steps.py, headless Chromium, child window and in-page dialog each:

  • Calculate then Use submits the right value, and the estimator input stays not_checked, so the run ends readback_incomplete with no receipt.
  • An estimator result that differs from the intake stops before submit.
  • A missing Calculate button is a stop, not a crash.
  • A popup window that never opens is a stop, not a crash.

All tests/test_form_tx_*.py: 239 passed on the lab.

Follow-up (374563a): returned value checked against the popup's displayed result. PopupSubroutineSpec.result_anchor names the popup's own result. It is read before apply, and the value put back in the parent must equal it under return_codec. If it differs (for example 512,340 shown and 512,000 returned), the run stops with a prefill conflict before submit. If the declared result can't be read, the run stops with popup_contract_failed. A figure that came only from a popup with an unchecked input is now not_checked in the read-back too, unless it matched the displayed result. Three existing tests now expect that.

…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 popup routine can now list compute_anchors, buttons clicked in order
before its apply button (Calculate, then Use This Value), and can run as a
dialog in the same page (popup_mode: in_page). Popup inputs are re-read
before the first step and again before apply, and still stay not_checked
unless the stored record shows them.

An estimator result that differs from a value the intake already gives now
stops before submit instead of being kept. A popup that will not open, a
missing or ambiguous button, or a popup that never settles becomes a
POPUP_CONTRACT_FAILED stop instead of an exception out of the run.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: f42a998

First review of this PR, at the requested head, unique against #2429 124db5c9 (this branch does not include #2440). Author is GitHub abrichr, not Grok. Review only; I am not merging. The #2429 read-back hole remains in the base and is not unique to this change.

Several of the asked fail-closed rules hold. _check_popup_entries_before_apply re-reads popup inputs before a compute step and before apply, stops on a mismatch, and a match only sets checked_before_apply; the field stays not_checked because that re-read is not a record read-back (test_two_step_estimator_runs_calculate_then_use_and_keeps_its_input_unchecked). A missing or ambiguous compute or commit button, a new error after a step, a window that will not open, or an in-page dialog whose apply button is still present after click all become POPUP_CONTRACT_FAILED and do not submit. A popup return that disagrees with an intake fact for the same key becomes PREFILL_VALUE_CONFLICT before submit. On apply_human_resolution, ACCEPT_PORTAL_PREFILL stores the portal value as the fact, and PROVIDE_VALUE writes the operator value into the parent return control (this halt does not set in_popup_subroutine); run_until_halt_or_done then sees a matching fact and return field and does not re-run the subroutine. tests/test_form_tx_popup_steps.py drives real headless Chromium for both window and in_page.

Two fail-closed holes remain.

_run_popup_subroutine only turns PopupContractError, MissingAnchorError, AmbiguousAnchorError, and SurfaceSettleTimeoutError into a halt. SurfaceContextError (and other surface failures such as a keepalive mutation) can still raise out of the run. A popup or in-page dialog that closes or detaches while settling is one path.

_scope_to_new_controls keeps "new" controls only by exact dom_selector against the pre-trigger snapshot. A parent-form control that is re-rendered when the dialog opens (a new dynamic id, or a structural nth-of-type that shifts because the dialog inserted nodes) looks new. The in-page surface is the same page, so _reconcile_bindings_pass can then fill that parent control from a subroutine binding, or _collect_ungrounded_required_halts can raise a required-field halt from inside the dialog. Scoping needs a stable identity that survives a parent re-render, not only the selector string from the pre-trigger snapshot.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 374563a

Re-review of the unique delta since f42a9988 (prior REQUEST CHANGES). The new work is result_anchor (read the popup's displayed result before apply, and require the parent return to match it) and a judge downgrade so a popup-only figure cannot stay passed when the inputs that produced it are not checked.

That unique work is sound and fail-closed. A declared result_anchor that is missing, empty, ambiguous, or not a value under return_codec stops before submit. A mismatch between the displayed result and the value put back in the parent also stops, with the two figures in the halt. matched_popup_result is set only when that comparison actually ran (displayed_result is not None), which on this path also means the values were equal; otherwise the run has already halted. The judge then downgrades a passed summary read-back of a popup_return whose fact is subroutine:<id> when any write from that popup is not PASSED, unless matched_popup_result is true. Popup inputs themselves are not flipped to passed by a matched displayed result, so the founder rule stands: a popup input that was not re-read before apply stays not_checked. Lookup of those input verdicts is by field_key; if that misses a dossier_key verdict it treats the input as unchecked and downgrades, which is fail-closed.

The previous holes are still open. _run_popup_subroutine still catches only PopupContractError, MissingAnchorError, AmbiguousAnchorError, and SurfaceSettleTimeoutError. A SurfaceContextError from the popup surface can still escape the subroutine and fail the run instead of becoming a POPUP_CONTRACT_FAILED halt. _scope_to_new_controls is still a set difference on exact dom_selector, so an in-page popup control that reuses a parent selector is dropped from the scoped snapshot.

No merge from me.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: cdf3fdc

Re-review at the current head (moved since 374563a3, prior REQUEST CHANGES 7061370392). Commit cdf3fdc7 closes both holes from that review.

_run_popup_subroutine now catches Exception and turns a surface failure into a POPUP_CONTRACT_FAILED halt when _is_popup_surface_error matches, including SurfaceContextError, SurfaceStateError, KeepaliveMutationError, settle/anchor errors, and Playwright close/timeout errors, matched by class or by name so a backend this module does not import still stops the run. Anything else is re-raised. A popup halt is safe_to_retry only when the surface mutation count is readable and unchanged; an unreadable count is treated as a send.

In-page scope is no longer a raw dom_selector set difference. _InPageScope keeps controls whose modal_container is a dialog that was not open before the trigger, so a dialog control that reuses a parent selector is kept, and a parent that re-renders new ids does not steal the popup. Two new dialogs, or a non-dialog popup on a page whose parent selectors are no longer all present, raise PopupContractError rather than filling a parent control. Residual: a non-dialog in-page popup still falls back to selector difference when every parent selector is still present.

The earlier result_anchor / judge downgrade work is unchanged and still fail-closed.

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/form_tx/judge.py
#	packages/flow/openadapt_flow/form_tx/reconciler.py
…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: dc80070

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: dc80070

Delta check of the merge of claude/form-tx-weekend 0c61aaf and its follow-ups: OK. Conflicts in judge.py and reconciler.py were resolved keeping the popup-return not_checked downgrade and the weekend subject coverage, and the ledger record keeps both the popup fields and screen_id/keep_existing. Follow-up: the popup-steps fixture declares its commit endpoint and reads its submit reply.

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.
…ly again

The surface now takes a 2xx status as the save answer even when leaving
the page cuts the reply body off, so the fixtures go back to the common
`await fetch(); location = ...` pattern they were written with.
…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
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: 7a4300d

Delta since dc80070: the merges of 1067e97 and cfdb87b (both clean, with no conflict resolution) and 34c92e4. That commit is test only: the popup-step fixture goes back to await fetch(); location = ..., which the new save answer accepts.

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 cfdb87bf8 7a4300da4 --stat gives 9 files, +1115/-43, the same file set as before. Per file, the only line change is that fixture. The merge base is cfdb87b, not ef4f5cc, so this head does not yet include the main merges on #2429. That does not block.

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: REQUEST CHANGES

From: Grok
Reviewed-Head: 4c803ec

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

Logic: still sound

Since cdf3fdc7 the PR commits are tests only:

  • dc800702e declares the fixture commit endpoint /submit;
  • 34c92e444 adds back reading the submit reply before leaving the page.

I compared the engine diff at the old head and at this head, each against its own base. They are identical except for the indentation of the two new record_write keyword arguments (from_popup_subroutine, matched_popup_result), which follows a change in the base.

The popup rule still fails closed. A popup_return value whose subroutine had any input that is not PASSED is turned into not_checked, unless the value put back matched the popup's own displayed result. A popup or dialog that will not open, closes, detaches, has a missing or doubled button, or a keepalive that would write is a stop for a person.

Blocking: flow core lint (ruff, mypy) fails on this PR's code

openadapt_flow/form_tx/judge.py:552: error: Argument 2 to "setdefault" of "MutableMapping" has incompatible type "ReadbackStatus | None"; expected "ReadbackStatus"  [arg-type]
openadapt_flow/form_tx/judge.py:554: error: Incompatible types in assignment (... | None", target has type "ReadbackStatus")  [assignment]

status_by_key: dict[str, ReadbackStatus] is filled from v.status, which is Optional[ReadbackStatus] in the current base. At runtime a None status is treated as "not PASSED", so it fails closed: this is not a fail-open. But it is red CI on lines this PR adds. Fix: type the map as dict[str, Optional[ReadbackStatus]]. Or, better, normalise None to ReadbackStatus.NOT_CHECKED when filling it, so the "not PASSED means unchecked" rule is explicit. Then re-run lint.

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

test_form_tx_popup_steps.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: 68 passed. I did not run mypy locally. The error above is from CI's lint job at this head.

CI at review time

27 pass, 23 skipping, 1 pending (packages-gate), 3 failing: flow core lint (ruff, mypy) (above, blocking), plus protected-path evidence / protected-safety-review with "base must be main" (expected while stacked on #2429). I will re-approve once lint is green at a new head with no other logic change.

…popup rule

Fixes the mypy arg-type/assignment errors at judge.py:552/554. A verdict
with no status now maps to NOT_CHECKED explicitly, which is what the rule
already did at runtime (anything not PASSED is unchecked).
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 20547c6

Author declaration for the fix to the Grok review at 4c803ecf (#2441 (comment)).

  • Blocking: mypy at judge.py:552/554. Fixed in 20547c6fc. When status_by_key is filled, a verdict whose status is None now maps to ReadbackStatus.NOT_CHECKED, so the map stays dict[str, ReadbackStatus] and the "anything not PASSED is unchecked" rule is explicit. Runtime behavior is unchanged: a None status was already treated as not PASSED.
  • No other change.

Checks run locally (Python 3.12, in-tree flow and types):

  • mypy openadapt_flow/form_tx/judge.py with the flow mypy config: no issues.
  • ruff check and ruff format --check on judge.py: clean.
  • test_form_tx_popup_steps.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: 68 passed.

abrichr added a commit that referenced this pull request Nov 23, 2026
…popup rule

Same fix as 20547c6 on #2441: the mypy arg-type/assignment errors in the
status_by_key block. Runtime behavior is unchanged.
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 20547c6

Independent cross-vendor review of claude/form-gap-4-popup-steps.

What was verified

  • judge.py:552-556 mypy fix: Maps v.status is None explicitly to ReadbackStatus.NOT_CHECKED before populating status_by_key: dict[str, ReadbackStatus], resolving the mypy arg-type/assignment errors while preserving fail-closed runtime semantics (any missing status is treated as unchecked, never PASSED).
  • Generality / durability: Zero per-app engine code; fail-closed read-back accounting for popup-return writes. Approve for merge on green CI.

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 20547c6

Delta re-review of my REQUEST CHANGES at 4c803ecf474f7f29b2e27841559785a386c42740 (#2441 (comment)). The author's declaration for this head is #2441 (comment). The PR is open and its head matches this SHA. The base is still claude/form-tx-weekend (#2429). I will not merge this PR.

Delta

There is one commit, 20547c6fc, which changes only form_tx/judge.py (+5/−3). When status_by_key is filled, a verdict whose status is None is now mapped to ReadbackStatus.NOT_CHECKED, and then the existing "any non-PASSED wins" rule applies. This is the fix I asked for. It makes the existing fail-closed behaviour explicit: a None status was already "not PASSED", so a popup value is still turned into not_checked unless it matched the popup's own displayed result. No other engine or test file changed. Generality gate: unchanged. It keys on read-back status and the write ledger, with no app-specific code (scripts/check_engine_generality.py: OK).

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

  • test_form_tx_popup_steps.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: 68 passed.
  • ruff check openadapt_flow/form_tx: clean.
  • mypy (packages/flow config): the two judge.py:552/554 errors are gone. Three errors remain locally, in txplan/engine.py:708,1456 and rl_env/environment.py:363. This PR doesn't touch those files, and they look like local dependency-version differences (Playwright 1.65 here). CI's lint job is the gate.
  • Not run: the full flow suite, or the live popup portals.

CI at review time

5 pass, 6 pending, 1 skipping, 1 failing. Evaluate protected-path evidence fails because this PR is stacked on #2429 and its base is not main. The packages workflow, including flow core lint (ruff, mypy), had not reported at this head yet. This APPROVE is on the code. The merge gate still needs flow core lint and the flow unit shards green at this exact head, and the protected-path check resolved once the base is 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