Skip to content

feat(flow): repeating structures learned from the demo, added to match the intake and checked per instance - #2512

Merged
abrichr merged 29 commits into
mainfrom
claude/gui-repeating-groups
Nov 24, 2026
Merged

abrichr merged 29 commits into
mainfrom
claude/gui-repeating-groups

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

What this adds

Repeating rows caused most of the false stops in the Set 4 v2 held-out run (#2464). Each case had a control such as "add another traveller":

  • B0 stopped three clean cases on missing traveller facts.
  • B's pack stopped two more on a popup workaround that cannot exist.

This change makes repeating structures a general capability in the core engine.

  • learn_repeats finds a group in a demonstration. It looks for a click after which a new block of editable controls appeared in a new container of one kind (a fieldset, a table row, a list item), where the block repeats the fields of an instance already on the screen. A list that starts empty is learned from its second add.
    • It records the add control, the instance's container kind and its field slots.
    • The add control can be a button, a link or a toolbar item.
  • map_slots proposes the item key behind each slot from the values the demo typed, and reports slots that do not map. It is a proposal for the pack author.
  • find_instances reads each container of the declared kind that holds every slot exactly once, in document order. A slot control outside any instance, or an instance with a missing or repeated slot, makes the read unusable.
  • fill_instances fixes the obligations from the intake first, every item and every slot. It then adds instances until the count matches, fills them in document order and reads them back. It stops before writing on any of these:
    • an item that lacks a slot's key;
    • an instance already holding data the run did not enter (a prefilled row);
    • more instances on screen than the intake has items, since the run never deletes;
    • an add control that is missing or ambiguous;
    • an add that did not raise the count by exactly one, or that made a non-blank instance;
    • an add that wrote, or a backend that cannot count writes.
  • judge_instances (@verdict_site) settles item-by-slot obligations against a fresh read. Each item is checked in the instance it was written into, by its container handle bound at fill time, so two identical rows are never told apart by a guessed position.
    • A wrong value is refuted, and the value must match exactly: no prefix, and no whitespace or case leeway.
    • An instance nobody planned is refuted and unexpected. That includes a blank row an app adds on its own.
    • A missing instance is missing, and an empty intake never passes.
  • location_rows exports the per-instance checks as rows shaped like the effect-location record from feat(flow): effect-location record and evaluator #2500 (id, keys, start, locator, expected, expected_count). This PR doesn't import that package: feat(flow): effect-location record and evaluator #2500 is still open, and its files belong to another change. Once it merges, these rows can become EffectLocations, and evaluate_all can take over the read-back.

Tests

tests/gui/test_gui_repeating.py has 16 tests (10 functions, some parametrized):

App kind What is checked
Web form (group booking, "Add another attendee") The group, its fields and its item keys are learned from a two-person demo. Three people are added, filled and checked, and the booking that reaches the server holds all three. Each of these stops or is refuted: an add that adds nothing; an add that adds two; a prefilled first attendee; an add that posts a draft; more blank attendees on screen than the intake has; an app that rewrites names on blur; an app that adds a blank attendee on its own. An item missing a key stops before anything is added.
EMR-like medication table (starts empty, unlabeled rows) The group is learned from the second add. Three rows are filled and checked by row. When the app re-sorts the rows after filling, every value is still on screen, but the check by row refutes.
Spreadsheet-like grid (no browser) "Insert row" is learned, and three rows are filled and checked. A sheet that already holds data stops, and nothing is added. The rows exported for effect locations are checked.
SaaS invoice Line items are added through an "Add line item" link.

The fail-open harness runs its generic mutations on judge_instances. A hand-made fail-open copy that matches values by slot anywhere on the screen, ignoring the binding and extra instances, fails M3, M5, M7, M8, M10, M15 and P0. The fold ratchet is unchanged.

Everything is synthetic, headless Chromium on the Mac, single-process. No fixture copies a held-out portal.

Base and adoption

The base is #2502 (hub pages), which sits on #2501, #2499 and #2476. This PR doesn't wire up the form_tx reconciler. A pack would replace its traveller_N_* bindings and its popup workaround with one RepeatSpec, and the intake would carry the list.

Fail-open blockers kept coming back one PR at a time. This fixes the
classes once:

- openadapt_flow/verdict.py: obligations fixed from the plan, settle(),
  allow-list codes, run binding, trust labels. An empty set, a short read,
  a raised probe, another run's result or an unknown code never passes.
- tests/failopen: 13 generic mutations run against every @verdict_site.
  The self-test flags 14 historical bugs rebuilt from this repository's
  code and passes their fixes; three live sites on main are strict xfails
  owned by #2470, #2258 and the connector status follow-up.
- scripts/check_verdict_folds.py: fails CI when a file gains a
  hand-written fold; never on a drop.
- verify_run: an empty or unpaired effect list is INDETERMINATE, unknown
  and unchecked (latent behind min_length=1).

See packages/flow/docs/FAIL_CLOSED.md.
…rness

- settle matches on subject key and run binding; obligations dedupe on both
- a HELD token is bound to its subject, so replace() can't move it
- observe refuses to map an exception to Observed
- owned sites list their exact known failures (strict xfail per case)
- pre-fix controls are pinned copies, never live code; S3b shows the
  undo fix still passes an unlisted per-write code
- the ratchet compares per-kind totals, so moving code into a new module
  is not a new fold, judges each exit of an except, refuses a site id on
  two functions, and runs in the smoke job on every change
- HELD is minted only inside the kernel's constructors, so replace() can't
  copy or restore it; one result claimed by two obligations conflicts
- known failures carry the seed and lens, so a new case can't hide
- the ratchet checks every @verdict_site has a spec on every change, finds
  conditional sites, judges every branch of a returned value, and lowers
  the baseline per kind so a moved fold keeps its allowance
- M7 is out of P1; the S5 seeds plan 20 runs and a gate needing all 20
  passes
… lines on the kernel

- check_verdict_folds: count a broad handler that falls through, leaves by
  break, or names Exception in a tuple or by attribute (swallow_wide); add
  says_unchanged and empty_change_set for "nothing else changed" claims; a
  file that doesn't parse fails; a spec id is an id= or factory argument.
- verdict: count the obligations that claim a result, not repeats of it;
  add Result.nothing_else (any change refutes, zero holds only on a
  complete read).
- harness: three-level monotonicity (P6), M7 appends a separate equal
  copy, M3 says when the plan is kept, M15 partial "nothing else" read,
  M16 a result turned bad.
- hard_invariants and versions build verdicts with settle; versions no
  longer lets a duplicate or missing-history row hide another author.
- verify_run._aggregate/_observed settle against cfg.effects;
  receipt_record._line and _tally_lines move onto the kernel.
- wire_tap is a registered site now that #2470 merged.
- Baseline measured again after merging main; every kind is at or below
  a clean origin/main.
…ovenance boundary

A handler that only logs a not-checked word still swallows; only a call that
stores the value records it. M15 must not raise a refuted seed. Observed and
Result.held say the adapter establishes which run produced a read.
The empty-change test is read from either side, a [0:N] slice counts like
[:N], builtins.all/any count as folds, and an unplanned verdict beside a
refuted one makes _observed unknown.
…the step the demo saw writing

Adds openadapt_flow.gui, a neutral view of a screen (controls by role, name,
state and containers) with adapters for a browser page (links included), an
accessibility tree and a form_tx snapshot. gui.steps learns each clicked step's
role from what the backend counted in the demonstration (commit, navigate,
in place, unknown), never from its words, and judges a live step against it.
judge_step is a registered verdict site.
…ly on a person's grant

gui.attestations plans every checkbox and switch on a screen: a field
binding's, an attestation to tick, a box the pack leaves alone, or a stop.
An undeclared box, a changed statement, a missing grant, an attestation bound
to a field or a box ticked before the run touched it all stop the run before
anything is ticked. Grants are their own type, so no intake value or derived
fact can tick one. judge_attestations settles the planned boxes against a
fresh read and is a registered verdict site.
…ction from the hub

gui.hub classifies an open dialog by what is in it: one that holds an
editable control is a form, never a confirmation, and only a declared
section's dialog may be filled. run_section opens a section, fills and saves
it, and requires the dialog to close with the demonstrated writes and the
card to show done on a fresh read. learn_hub derives each section's opener,
dialog, save control and done tokens from a demonstration. judge_hub settles
the planned sections and is a registered verdict site.
…h the intake and checked per instance

gui.repeating learns an add-another group from a demonstration (the add
control, the instance's container kind and its fields), adds instances until
the count matches the intake, fills them in document order and reads each one
back by the container it was written into. It stops before writing on a
prefilled instance, more instances than items, an add that did not add exactly
one blank instance, or an add that wrote. judge_instances is a registered
verdict site; location_rows exports the checks in the effect-location shape.
… an in-place step that moves the screen

From Gemini's review of #2499. A navigation must be shown not to write, so
without a write count no step is judged and none is clicked. An in-place step
that moved the screen did something the demo did not.
…nting its own held result

From Gemini's review of #2502. Only judge_hub, a registered verdict site, can
say a section held; run_section now carries its status and verdict.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 1b628b0

Gemini run on 1b628b0 (model gemini-3.1-pro-preview, finish reason STOP). It was sent the full diff against the base branch, every changed Python file at head, the verdict kernel, the harness, the PR description and no earlier findings (first review).

Blockers

None.

Non-blocking

None.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 1b628b0

Author declaration: Claude wrote the changes on this branch up to and including 1b628b0. The Gemini review above is the cross-vendor review for this head.

…n every one

One grant covers one box. A loose spec naming two identical boxes used to
plan a tick for both on one grant; now each is a stop and nothing is ticked.
From Gemini's non-blocking note on #2501.
…lank nor a pass

From Gemini's review of #2512: an unread checkbox read as unticked, so an
item expecting unticked passed on missing evidence.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: f77fcdd

Gemini run on f77fcdd (model gemini-3.1-pro-preview, finish reason STOP), sent the full diff, changed files and the delta from the approved head 1b628b0.

Blockers

  1. packages/flow/openadapt_flow/gui/repeating.py:155: A checkbox whose state the backend could not read (ctrl.checked is None) defaults to "false". If the intake expected the checkbox to be unchecked (want == "false"), judge_instances will see "false" == "false" and report a pass. This is a false pass on missing evidence.
    Fix: Return a distinct string when the state is unknown so it cannot match a planned boolean.
    def _shown(ctrl: Control) -> str:
        if ctrl.role in ("checkbox", "switch", "radio"):
            if ctrl.checked is None:
                return "unknown"
            return "true" if ctrl.checked else "false"
        return ctrl.value.strip()
    
    (Note: This also correctly makes inst.blank() return False for an unknown checkbox, stopping the run instead of assuming it is safe to write over).

Non-blocking

None.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 5c43e62

Gemini run on 5c43e62 (model gemini-3.1-pro-preview, finish reason STOP). The only change since f77fcdd is 5c43e62, the fix for the finding above (an unread box is neither blank nor a pass), with a test. Gemini was sent the finding, the fix delta and the full PR diff.

Blockers

None.

Non-blocking

None.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 5c43e62

Author declaration: Claude wrote the changes on this branch up to and including 5c43e62. The Gemini review above is the cross-vendor review for this head.

# Conflicts:
#	.github/workflows/ci.yml
#	CAPABILITIES.md
#	packages/flow/CHANGELOG.md
#	packages/flow/docs/FAIL_CLOSED.md
#	packages/flow/openadapt_flow/gui/__init__.py
#	packages/flow/openadapt_flow/gui/dom.py
#	packages/flow/openadapt_flow/gui/model.py
#	packages/flow/openadapt_flow/gui/steps.py
#	packages/flow/openadapt_flow/receipt_record.py
#	packages/flow/scripts/verdict_folds_baseline.json
#	packages/flow/tests/failopen/sites/governed_safety.py
#	packages/flow/tests/failopen/sites/gui_steps.py
#	packages/flow/tests/gui/_apps.py
#	packages/flow/tests/gui/_grid.py
#	packages/flow/tests/gui/test_gui_steps.py
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 9e94da6

Verified delta (5c43e62f..9e94da63)

  • Pure origin/main merge (9e94da63e0) after #2502 merged, cleanly isolating the 7 #2512 files (capabilities/ row, CHANGELOG.md, FAIL_CLOSED.md, gui/__init__.py, gui/repeating.py, tests/failopen/sites/gui_repeating.py, tests/gui/test_gui_repeating.py).
  • All previously Gemini-approved repeating-group invariants at 5c43e62f remain intact: judge_instances() settles item-by-slot obligations at @verdict_site("gui.repeating.judge", classes="C1 C2 C5"), partial screen reads fail closed, and unread slot boxes are never treated as blank or matching. Zero per-app engine code.

@abrichr
abrichr enabled auto-merge (squash) November 24, 2026 14:17
# Conflicts:
#	packages/flow/docs/FAIL_CLOSED.md
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 7a6363e

Verified delta (9e94da63..7a6363e9)

  • Pure origin/main merge (7a6363e9b9) bringing in #2438 and cleanly preserving both verify_draft.judge_case and gui.repeating.judge_instances in packages/flow/docs/FAIL_CLOSED.md.
  • All 7 previously Gemini-approved files from 9e94da63 remain intact with zero behavioral changes.

@abrichr
abrichr merged commit b296bbb into main Nov 24, 2026
50 checks passed
@abrichr
abrichr deleted the claude/gui-repeating-groups branch November 24, 2026 16:19
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