Skip to content

Stabilize Windows UIA focus live gate - #391

Open
coneilen wants to merge 3 commits into
scgopi:mainfrom
coneilen:coneilen-microsoft-harden-uia-focus-gate
Open

coneilen wants to merge 3 commits into
scgopi:mainfrom
coneilen:coneilen-microsoft-harden-uia-focus-gate

Conversation

@coneilen

@coneilen coneilen commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Hardens the Windows native UI Automation worktree-row focus assertion against shared CI desktop-focus churn without weakening the assertion or changing product behavior.

Changes

  • Preserve the existing 30-second focus-retention polling loop and hard failure/diagnostics.
  • Reorder each polling iteration to settle briefly (40ms) after ActivateWindow before calling SetFocus, so the row's focus assertion is the last action before sampling FocusedElement.
  • Keep a final bounded nudge (300ms settle + short recheck) before the hard failure, using the same settle-then-focus-then-check ordering.

Notes on iteration

A first attempt (commit 7db72cd) only added a trailing final nudge without reordering; it still reproduced the failure on hosted windows-spikes (https://github.com/scgopi/GraphCode/actions/runs/35476483960/job/105986495560) with the identical symptom, showing the interfering refocus lands after SetFocus inside every loop iteration, not only at the loop boundary. Commit a3d6910 reorders each iteration accordingly.

Test plan

RED: Tools/windows/validate.ps1 -Task all -SkipTrayLive -SkipWslRemoteE2E on PR #387 commit 1ed41ca -> failed in windows-spikes with worktree row could not retain focus against concurrent desktop focus changes; focused=Text Area:Text Area (https://github.com/scgopi/GraphCode/actions/runs/35475073552/job/105985602192)
GREEN: PowerShell parser on Tools/windows/uia-live-gate.ps1 at commit a3d6910 -> passed with no parse errors; pwsh -NoProfile -File Tools/windows/Tests/ValidationRunner.Tests.ps1 -> PASS
REGRESSION: pwsh -NoProfile -File Tools/windows/validate.ps1 -Task windows-shell -SkipTrayLive -> reached the pre-UIA Swift release build and stopped on the known local SDK limitation missing required modules: '_complex', 'ucrt'; hosted windows-spikes runs the complete gate and is the authoritative pass/fail signal for this change

Checklist

  • I have read the Contributing Guidelines
  • I have signed off my commits (git commit -s) per the DCO
  • Tests pass locally (make test) — not applicable to this Windows-only test-infrastructure change; focused validation is documented above
  • Code follows the existing style (git diff --check)
  • I added the focused synchronization behavior after reproducing the intended RED failure in the linked same-source CI run, and iterated after the first fix attempt was disproven by hosted CI

coneilen and others added 3 commits September 19, 2026 16:33
Give the foreground transition one bounded settling interval before a final focus nudge and recheck. The assertion still fails with the last observed UIA focus data when the row never converges.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Colin Neilens <coneilen@microsoft.com>
The prior single trailing-nudge fix still failed on windows-spikes with the same symptom (focused=Text Area:Text Area), indicating a delayed activation-driven refocus of the terminal Text Area lands *after* our SetFocus call and before we sample FocusedElement, not merely before the loop starts. Reorder each polling iteration to settle briefly after ActivateWindow before calling SetFocus, so our focus assertion is the last action before sampling. Keep the loop's overall ~30s budget and hard failure/diagnostics unchanged; apply the same reordering to the final bounded nudge.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Colin Neilens <coneilen@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Colin Neilens <coneilen@microsoft.com>
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