Skip to content

fix(flow): let the strict UIA census pass a password field it cannot match - #2767

Merged
abrichr merged 1 commit into
mainfrom
fix/windows-uia-census-not-unique
Nov 29, 2026
Merged

abrichr merged 1 commit into
mainfrom
fix/windows-uia-census-not-unique

Conversation

@abrichr

@abrichr abrichr commented Nov 29, 2026

Copy link
Copy Markdown
Member

Problem

windows replay (Patient Notes, WindowsBackend) fails
test_native_editable_values_and_runtime_type_retry with

UIA census refused (match=ambiguous, candidate_count=1, reason=not_unique)

(for example run 46214956282, attempt 2, which failed after 8 s on the first
structural read, _wait_label("patientHeader")).

Root cause

Two things combine:

  1. The census stops at any password field. Since fix(verification): require complete native values for approvals and read-back #2291 the strict walk in
    _find_candidates calls require_non_sensitive_structure on every node of
    the desktop. A control with IsPassword=True raises (PROVIDER_REFUSAL),
    so the whole census returns truncated=True, whatever the locator is. The
    test's OBSERVATION_HOOK adds a UseSystemPasswordChar text box
    (leasePassword) to the same window, so every read stopped there, even a
    read of the unrelated patientHeader label. The same would happen on any
    login form or other screen that has a password field.
  2. A census cut short was labelled as a duplicate. /uia/read set
    match = "ambiguous" if found or truncated and always used
    reason = "not_unique". One candidate found before the stop therefore came
    back as ambiguous / 1 / not_unique, which is the contradictory message.

#2291's own Windows job never reached this test (the lease test timed out
first), so this got through.

Fix

  • When a control is affirmatively protected (IsPassword is True, or the
    native edit has a password style, EditEvidence.PROTECTED), the census reads
    only its AutomationId and control type. Neither is field content. The
    control is skipped only when the locator's automation id or role provably
    cannot match it and it has no subtree. Its Name and value are never read.
  • Everything else stops the census exactly as before:
    • a locator that could still name the control (matching id and role, or
      role+name only)
    • an unreadable selector or any subtree
    • every unknown sensitivity status (missing, unrecognized, query error, other
      native-edit outcomes)
    • an older helper without these enum members
    • a second real match
  • A census cut short now reports reason="census_incomplete". match stays
    "ambiguous", so the wire vocabulary and the client's refusal are unchanged.
    The e2e helper now shows that reason.

Tests (tests/test_structural_value_completeness.py)

  • The bug condition: one target next to a password field (both
    IsPassword=True and the native-protected path) returns unique / 1 with a
    complete value, and the password control's Name and value are never read. A
    password field of a different role is also skipped.

  • Still refuses:

    • a password field the locator could name (by id, by id+role, by role+name)
    • a password field with a subtree
    • the native-protected match case

    Each returns ambiguous / 1 / census_incomplete with the original
    sensitivity trace stage, and never reads Name or value.

  • Real ambiguity: two matching controls next to a password field still
    return ambiguous / 2 / not_unique, with no point, preview or value.

  • Against the unfixed server, the new bug-condition tests fail.

Checks run

  • pytest over every non-e2e flow test that touches the Windows agent,
    backend or native value code: 1637 passed, 11 skipped. Two modules failed to
    import because optional deps are missing locally (benchmark.choice_widgets,
    openenv.core), unrelated to this change.
  • ruff check and ruff format --check on the modified files: clean.
  • mypy --follow-imports=silent on server.py: clean.
  • check_engine_generality.py OK, check_verdict_folds.py OK.

Not fixed here

In the most recent runs on #2758, #2759 and #2761, the job fails earlier:
test_native_keyboard_lease_actual_delivery_and_refusal hangs on an agent HTTP
read until pytest's 600 s timeout (at a different line each run: 519, 530,
543, 572, 598). That is a separate problem, so the editable test never ran in
those runs. The Windows job may stay red on that timeout until it is fixed
separately.

…match

Since #2291 the strict census stopped at any control whose IsPassword was
True, wherever it sat on the desktop. The read endpoint then reported the
cut-short census as match=ambiguous, reason=not_unique with whatever it had
found so far. In the hosted Patient Notes test the window holds one
patientHeader and a planted password box, so every structural read refused
as "ambiguous, candidate_count=1, not_unique".

An affirmatively protected control (IsPassword True, or a native password
edit) is now ruled out from AutomationId and control type alone when the
locator's id or role cannot match it and it has no subtree. Its Name and
value are never read. A locator that could still name it, an unreadable
selector, any unknown sensitivity status, or a second real match still
refuses as before.

A census cut short now reports reason=census_incomplete instead of
not_unique, so a single candidate no longer reads as a duplicate.
@abrichr
abrichr enabled auto-merge November 29, 2026 14:30
@abrichr
abrichr added this pull request to the merge queue Nov 29, 2026
@abrichr

abrichr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 740fceb

The change is narrow. A node is skipped only when two conditions both hold. First, the helper gives an affirmative password verdict: PROVIDER_REFUSAL, which is set only when IsPassword returns exactly True, or NATIVE_EDIT with EditEvidence.PROTECTED. Second, the locator provably cannot match the node, using the same id and role normalisation as the existing possible check (AutomationId or None, SplitButtonControl → button), and the node has no children through the same GetChildren call the walk uses. Every other stop is unchanged. Name and value are never read on the skip path. I found no way to weaken the strict census or the uniqueness checks beyond password fields.

Adversarial probes (temporary local pytest file, synthetic controls, exact head): 22 passed

In every case below, the census still stops with ambiguous / census_incomplete, with no text, point or preview. The password control's Name and value are never read.

  • Unknown status on a control that cannot match: IsPassword is None, "yes" or 1, or GetPropertyValueEx raises.
  • Native-edit evidence other than PROTECTED: UNAVAILABLE, MASK_QUERY_UNAVAILABLE, STYLE_UNAVAILABLE, CLASS_UNAVAILABLE, OWNER_UNAVAILABLE and NO_HANDLE.
  • Unreadable selector or children on the password control: AutomationId or ControlTypeName raises, AutomationId is not a string, GetChildren raises, or GetChildren is missing.
  • Older helper: the same functions with no SensitivityStage/EditEvidence.
  • Locators that could still name the field: a matching automation_id, or role+name for textbox. A SplitButtonControl password with a matching id and role button is not skipped. Name-only and role-only locators are rejected earlier with invalid_locator.
  • Real duplicates are still refused (ambiguous / 2 / not_unique). This holds for a duplicate after three password fields and for a duplicate nested in a pane beside one.
  • A password target itself is never returned as unique.

Tests and checks (Linux, py3.12, exact head)

  • tests/test_structural_value_completeness.py: 76 passed. Against the base server.py (d749779c), 26 of these fail. The two bug-condition tests and the other-role test fail on behaviour. The rest fail on the new census_incomplete reason string or on the base census stopping at the password field.
  • All 44 non-e2e flow test modules that touch the Windows agent, backend or native value code: 1649 passed, 26 skipped.
  • With the flow core lint job's own commands, ruff check, ruff format --check, the py3.11 E9 syntax check and mypy (Success: no issues found in 945 source files) are all clean. check_engine_generality.py, check_verdict_folds.py, check_file_size_ratchet.py and check_source_boundary.py all exit 0.
  • The client contract is unchanged: match stays ambiguous and WindowsBackend refuses on match/truncated. value_protocol accepts any bounded reason string, and the only other not_unique match in tests is an unrelated qualification error.

Generality gate: The repository has no section named "Generality gate", so I applied the flow CONTRIBUTING rule "App knowledge lives in data" and whole-class testing. Point 1 passes: there are no app names, the rule is keyed on UIA sensitivity evidence and locator fields, and check_engine_generality.py is OK. Point 2 passes: the fix covers both affirmative password paths, any password field on any screen, and every locator shape the schema accepts.

CI at this head (15:10 UTC): 26 passed, 22 skipped, 1 failed. In windows replay (Patient Notes, WindowsBackend), the target step Exact editable values and bounded runtime TYPE retry now passes. It failed on every recent run that reached it (for example 46214956282, 46208980479, 46184284625, 46172017422 and 46081544907). The keyboard-lease step also passed in this run. The job now fails one step later, in test_native_approval_completeness_refuses_a_provider_prefix: record_verified_window(...) returns False. That path is /window/root-at, which runs user32 foreground and root-window checks and does not use the census. It is a separate failure that the earlier failure used to hide. Auto-merge was enabled at 14:30 UTC but is not enabled now, and merge state is UNSTABLE.

Limits, and what I could not run on Windows: I have no Windows host. I did not run the e2e Windows tests locally, real UI Automation providers, real IsPassword or native password-style detection, or real uiautomation child enumeration. The Windows evidence above is the CI job only. The probes use the repo's synthetic _Control fixtures. I did not push to this branch, and I will not merge it.

Merged via the queue into main with commit 96e91fe Nov 29, 2026
48 of 49 checks passed
@abrichr
abrichr deleted the fix/windows-uia-census-not-unique branch November 29, 2026 18:15
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