Skip to content

feat(form-tx): check a lookup table's chosen row as an effect location - #2514

Draft
abrichr wants to merge 2 commits into
claude/effect-location-review-portfrom
claude/effect-location-lookup-row
Draft

abrichr wants to merge 2 commits into
claude/effect-location-review-portfrom
claude/effect-location-lookup-row

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What this does

Step 2c: the lookup-table row. It is stacked on #2508 and uses the effect-location record from #2500.

A lookup popup, such as a class finder, shows one row per result, each with its own Select button. Today the value it puts back (set4v2 hollowfen: class_code) stays not_checked. It came from a popup whose search term is not checked, and the popup has no single displayed result to compare it with.

PopupSubroutineSpec.result_row_pattern names the result cell in the chosen row. The pattern must match exactly one cell in full, such as a four-digit code. The check works in two steps (form_tx/lookup_location.py):

  1. Just before the commit click, the chosen row's cells are read. This is the echo before commit.
  2. After the popup closes, the shared evaluator checks the value now in the parent against that reading, as a row_key location with start same_screen.

The outcomes:

  • The row shows exactly that value. It becomes the popup's displayed result, so the summary read-back can pass it.
  • Anything else stops the run before submit. That covers a different value, no matching cell, more than one, and a return codec outside whitespace_collapse, casefold and iso_date. The stop is a POPUP_CONTRACT_FAILED.

Behaviour change (opt-in)

Only subroutines that set result_row_pattern change. Without it, the code path and verdicts are as before. An unset pattern is left out of the pack dump, so pack digests don't change.

The search term itself (class_keyword) stays not_checked. It is only re-read inside the popup, and the record never stores it.

Tests

tests/test_form_tx_lookup_row.py: 5 passed, headless Chromium against a local routed page, all synthetic. It covers:

  • no pattern: the code stays not_checked, as before;
  • with the pattern: the code passes and the search term stays not_checked;
  • a popup that puts back another code: stops before submit;
  • a row with no matching cell: stops before submit;
  • the unset pattern is left out of the dump, and a bad pattern is refused.

The form_tx suite: see the comment below.

Since opening

  • Fixed from Gemini round 1. With both result_anchor and result_row_pattern set, the anchor's displayed result is kept and still compared. Before, it was overwritten. A headless test covers this and fails without the fix.
  • Codec check at load. A row pattern now requires a whitespace_collapse, casefold or iso_date return codec, and a pack without one is refused when it loads.
  • Tests. tests/test_form_tx_lookup_row.py: 6 passed.

A lookup popup shows one row per result, each with its own commit button.
PopupSubroutineSpec.result_row_pattern names the cell of the chosen row
that holds the result (it must match exactly one cell in full). The row is
read just before the commit click; after the popup closes, the value in the
parent is judged against that reading by the shared effect-location
evaluator (row_key locator, start same_screen). If the row does not show
exactly that value the run stops before submit.

Behaviour change, opt-in: with the pattern set, the value the popup put back
is the popup's result, so a summary that shows it can pass it. Without the
pattern nothing changes and the value stays not_checked when the popup's
inputs are not checked. An unset pattern is left out of the pack dump.
…attern is set

From review: with both result_anchor and result_row_pattern, the row check
overwrote the anchor's displayed result, so a popup whose result field
disagreed with the value put back passed. The anchor's result now stays and
is still compared. A row pattern also now requires a whitespace_collapse,
casefold or iso_date return codec, refused when the pack loads rather than
at run time. A headless test covers the anchor case and fails without this
fix.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Gemini (gemini-3.1-pro-preview), round 1
Reviewed-Head: 77667a1

Sent the full diff of this PR's own files, those files in full, and any earlier findings.

Here is the review of PR #2514.

BLOCKER: Fail-open path when both result_anchor and result_row_pattern are set.
In packages/flow/openadapt_flow/form_tx/reconciler.py (line 2662), if a popup subroutine defines both a result_anchor and a result_row_pattern, the displayed_result obtained from the result_anchor is unconditionally overwritten by return_after.current_value after the row read is verified.
This causes the subsequent check on line 2666 (values_equivalent(displayed_result, return_after.current_value, ...)) to compare return_after.current_value with itself, silently bypassing the verification of the result_anchor value. If the popup showed one value in the result_anchor but put back a different value, this mismatch will be ignored, violating the fail-closed verification bar.
Failing input: A popup where result_anchor reads "$100", the chosen row matches "$50", and the value put back is "$50". The run will pass instead of halting on the mismatch between the anchor and the returned value.
Fix: Only set displayed_result if it is not already set:

            # The row showed exactly this value: it is the popup's result.
            if displayed_result is None:
                displayed_result = return_after.current_value

NIT: Default return_codec usability.
PopupSubroutineSpec.return_codec defaults to CURRENCY_CENTS. If a user adds result_row_pattern without explicitly changing return_codec to one of the supported codecs (WHITESPACE_COLLAPSE, CASEFOLD, ISO_DATE), the run will always halt with a POPUP_CONTRACT_FAILED because CURRENCY_CENTS is not mapped to a scalar codec in _codec (lookup_location.py). This is fail-closed and matches the PR description, but might be a usability gotcha worth documenting or catching earlier.

REQUEST CHANGES

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Gemini (gemini-3.1-pro-preview), round 2
Reviewed-Head: 1bab02f

Sent the full diff of this PR's own files, those files in full, and any earlier findings.

The blocker and nit from the previous review have been fully addressed.

The fix in reconciler.py correctly ensures that displayed_result is only populated from the row read if it wasn't already set by a result_anchor, preserving the fail-closed verification of both when both are present.

The addition of the _row_pattern_needs_a_text_codec model validator in types.py is a great usability improvement, catching the codec mismatch at pack validation time rather than failing opaquely at runtime.

The tests cover the new functionality well, including the specific edge case that caused the blocker.

APPROVE

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 1bab02f

Author declaration at the head above. Synthetic tests only; no real app was run.

  • Behaviour change, opt-in. It applies only to subroutines that set result_row_pattern.
  • Fix from Gemini round 1. When result_anchor was also set, the row check overwrote the anchor's result. It no longer does, and a test fails without the fix. A row pattern with a return codec it can't read is now refused when the pack loads.
  • Tests at this head:
    • test_form_tx_lookup_row.py: 6 passed, headless.
    • The whole form_tx suite (all tests/test_form_tx*.py): 415 passed in 8 min 20 s.
  • Gemini round 2 found nothing more to fix.

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.

1 participant