Skip to content

refactor(form-tx): move the yes/no words to JSON word lists, with a codec override - #2511

Draft
abrichr wants to merge 3 commits into
claude/form-preset-role-qualifiersfrom
claude/form-preset-yes-no
Draft

abrichr wants to merge 3 commits into
claude/form-preset-role-qualifiersfrom
claude/form-preset-yes-no

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

What this does

Seventh form_tx preset move, stacked on the role-qualifier PR. The texts a yes/no field reads as yes (yes, y, true, 1) and as no (no, n, false, 0) are English vocabulary. They now ship as presets/words/true_tokens.json and false_tokens.json, and codecs._TRUTHY_TOKENS and codecs._FALSY_TOKENS load them.

The pack override. FieldCodecSpec gains optional true_tokens and false_tokens.

  • Reading: a codec that sets them reads only its own words, so a German codec reads "Ja" and refuses "yes".
  • Typing: when a codec sets both lists, typed entry uses the first word of each instead of "Yes" or "No".
  • A text that appears in both lists is refused as ambiguous.

Where the override doesn't reach. It applies wherever a codec is passed: normalize_with_codec, values_equivalent and format_for_text_entry. The calls in reconciler.py that pass no codec, such as checkbox state, keep the default words.

No behaviour change by default

  • Old values. The default sets equal the old literals; the test reads them from 2f506d6c4.
  • Pack digests. A model_serializer leaves an unset override out of the dump. A codec without overrides therefore dumps, and a pack hashes, exactly as before. A test checks the dump, and checks that the dump loads back to an equal codec.

Tests

  • test_form_tx_presets.py, test_form_tx_lease_and_compiler.py and test_form_tx_reconciler_and_receipts.py: 58 passed.
  • The differential now covers four word lists.
  • ruff check and ruff format are clean.

…can override them

The texts a yes/no field reads as yes or no (yes, y, true, 1 / no, n, false,
0) are English vocabulary. They now ship as presets/words/true_tokens.json
and false_tokens.json. FieldCodecSpec gains optional true_tokens and
false_tokens, which replace the defaults for that codec when reading and
supply the typed word when both are set; a text in both lists is refused as
ambiguous. An unset override is not written when a codec is dumped, so
existing packs dump and hash exactly as before. The default sets equal the
old literals (a test reads them from history).
…empty list

From review: with only true_tokens set, True was typed as "Yes", which
that codec then refused on read-back. Each side now types its own first word
when set. An empty override list is refused.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Gemini (gemini-3.1-pro-preview), round 1
Reviewed-Head: 901ad1d

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

This PR successfully extracts the hardcoded yes/no tokens into JSON presets and allows codecs to override them deterministically. The custom serializer correctly omits unset overrides to preserve pack digests, and the equivalence logic remains strictly fail-closed.

There is one correctness bug where the engine can type a value that it immediately rejects during read-back.

SHOULD-FIX

Independent overrides break text entry formatting
packages/flow/openadapt_flow/form_tx/codecs.py lines 364-366:

        if spec.true_tokens and spec.false_tokens:
            # A codec with its own words types its own first word.
            return spec.true_tokens[0] if yes else spec.false_tokens[0]
        return "Yes" if yes else "No"

If a user overrides only one side (e.g., true_tokens=("oui", "o") but leaves false_tokens=None), the and condition evaluates to False. The engine will type "Yes" for a True value. During read-back, normalize_with_codec("Yes", spec) will raise a CodecValueError because "yes" is not in the overridden true_tokens list. This causes a guaranteed fail-closed halt (readback refuted) on a valid input.

The formatting should evaluate the overrides independently:

        if yes:
            return spec.true_tokens[0] if spec.true_tokens else "Yes"
        return spec.false_tokens[0] if spec.false_tokens else "No"

NIT

Empty tuple overrides
packages/flow/openadapt_flow/form_tx/types.py lines 260-261:

    true_tokens: Optional[tuple[str, ...]] = None
    false_tokens: Optional[tuple[str, ...]] = None

Consider adding Field(min_length=1) to these fields. If a user explicitly passes an empty tuple (), it will clear the truthy/falsy sets entirely, making it impossible to type or read back any value for that boolean state.

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: d91be3d

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

Both earlier findings have been perfectly addressed.

The independent evaluation in format_for_text_entry now correctly handles cases where only one side of the boolean tokens is overridden, ensuring that the engine types a value it can successfully read back. The addition of min_length=1 to the tuple fields in FieldCodecSpec successfully prevents the edge case where an empty tuple could clear the truthy/falsy sets entirely.

The equivalence logic remains strictly fail-closed, and the custom serializer correctly preserves pack digests for older packs. The tests are comprehensive and verify the new behavior well.

APPROVE

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 2f3c62b

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

  • Gemini round 1 found a real typing bug: with only one side overridden, entry typed "Yes", which that codec's read-back then refused. Each side now types its own first word, and an empty list is refused. Gemini round 2 found nothing more.
  • test_form_tx_presets.py, test_form_tx_reconciler_and_receipts.py and test_form_tx_lease_and_compiler.py: 62 passed.
  • This head also merges refactor(form-tx): move the secondary role qualifiers to a JSON word list #2510's nit 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