Repository navigation
Check cancellation in more Windows desktop-driver helper waits - #4483
Merged
Jason Morse (JasonVMo) merged 16 commits intoNov 11, 2026
Merged
Conversation
Contributor
Bundle size reportTree-shaken, minified production esbuild bundles with React and React Native runtimes externalized.
The job is advisory: size changes are reported but do not fail the pull request. Bundle or analysis errors still fail. |
5 of 10 tasks
Jason Morse (JasonVMo)
marked this pull request as ready for review
November 10, 2026 15:29
Jason Morse (JasonVMo)
enabled auto-merge (squash)
November 10, 2026 23:18
A cancelled command could not be acknowledged while the helper waited up to 5 s on a bounded provider call, a whole-subtree cache, or the 2 s wait after terminating a packaged application. Node then killed the helper, which since the kill-on-close Job Object also ends the application under test. Bounded provider calls now read the command's token through a thread-local CancellationScope and wait in 50 ms slices. A cancelled read throws CancelledError; a cancelled mutation is abandoned and quarantined like a timed out one, so the command reports effect `unknown`. Whole-subtree and probe caches run on the bounded worker, and closeApplication's post-terminate wait observes the token and keeps the lease for a retry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ShowWindow, SetWindowPos, and activation wait on the thread that owns the window, so a hung target held the helper, and the physical input lock, until it recovered. Activation also granted every process foreground rights. The helper now probes the window with SendMessageTimeoutW(WM_NULL, SMTO_ABORTIFHUNG) in 200 ms tries for up to 2 s and fails with automation-failed and reason `target-non-response`. setWindowRect posts its restore (ShowWindowAsync) and move (SWP_ASYNCWINDOWPOS) and polls for them with the cancellation token, recording each as dispatching until it settles. Activation skips attaching to a hung holder's input queue and grants AllowSetForegroundWindow only to the target process. A self-test stalls a window thread and checks the probe, restore, activation, and cancellation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The cross-process physical input mutex was released after every command even when keys or buttons stayed down, so another helper could inject while our modifiers were held. The worker's exit paths skipped ReleaseInput, and queued commands ran under a token re-armed after the transport ended. A command that leaves input depressed now moves its scope into the driver, which releases it once ReleaseInput leaves nothing down. The worker releases input on every exit and drops queued commands once stopping. Because the lock is already held while input is down, the cancel path's cleanup no longer waits for the mutex. A self-test checks that a held key keeps the lock from another thread. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
performActions did not check where a pointer press or scroll landed, so either could reach a window of an application the helper never launched or attached to. Before pointerDown and before a scroll moves the pointer, the driver now hit tests the point and fails with element-not-interactable when the window there, or its root, belongs to no leased application. A test hit tester lets the self-test cover a foreign press and scroll. Naming the target window in performActions is a cross-platform protocol change and is left for later. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A failed GetCurrentPatternAs was reported as unsupported-operation and a failed focus read as an unfocused element, hiding stale elements and provider failures behind the wrong error. QueryPattern now returns available, absent, stale, or failed. Pattern actions, accessibility clicks, and value clears report stale-element for a stale element and automation-failed for a failed query, and keep their existing results for an absent pattern. HasKeyboardFocus fails a stale element and returns any other failure to FocusForKeyboard, which reports automation-failed. A self-test clicks an element of a destroyed window. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A successful launch posted WM_CLOSE to and terminated a still-running launch root even when the Job Object owned it, a packaged root was trusted by process id alone, and an unreadable start time serialized as 1601-01-01, which the incarnation probe reads as exited. Under a containment job the launch root is now left to the job. A packaged root must report the requested AUMID before it is tracked or terminated, and ActivateApplication uses AO_NOERRORUI. Lease creation fails when the start time cannot be read, and a zero FILETIME serializes as an empty string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When the known-window table overflowed, every tracked window was re-added with the process id of the window being remembered, mislabeling later destroy events. Tracked windows now keep the process they were recorded for. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The protocol says invalid JSON fails the transport, but the helper logged and skipped the frame. A skipped frame may have been a request or a cancel, so Node could wait on an id the helper never saw. The host now writes a diagnostic and exits with code 1 without reading further frames. A self-test sends a malformed frame between two requests and checks the exit code and that the later request never runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The README now describes the posted window management, the target-non-response probe, the input lock held while input is down, pointer hit checks, launch cleanup under a job, and cancellation, and corrects the close sequence and the build-warnings claim. PROTOCOL.md widens target-non-response to window messages, and remaining-work.md records what is still unbounded. Adds the patch changeset. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PROTOCOL.md defines every JSON message as an object with a `type`, and the macOS helper now fails the transport on a frame that is not one. The Windows host logged and skipped such a frame, so the two helpers disagreed. It now writes a diagnostic and exits with code 1, and the malformed-frame self-test also runs with a JSON array. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The changeset and the README verification paragraph now say that a non-object JSON frame fails the transport, as the host and its self-test do. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Windows native contract sent a malformed frame and expected the helper to keep answering. The helper now follows PROTOCOL.md and exits with code 1, so the contract writes the malformed frame and a probe, expects exit code 1 within 10 s, and expects no response to the probe. The 1,024-byte identifier request and cancel that followed the bad frame could no longer be read, so they are dropped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The README, remaining-work notes, and changeset implied that every Windows activation and provider path now acknowledges a cancel promptly. Only the newly wrapped waits check cancellation between polls; direct UI Automation calls and the activation calls themselves can still block, and none of it has run on Windows. Describe the polling intervals as implementation bounds on those waits and name the paths that remain unbounded. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 53a0c7cf-1330-4677-8700-d249b508c6ee
Keep a posted restore pending through the responsiveness check and verify its possible late effect. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 53a0c7cf-1330-4677-8700-d249b508c6ee
Keep unreleased strokes and buttons under the physical-input lock, preserve uncertain host recovery, and refuse unsafe fallback or disposal. Fix Windows portability of desktop-test lifecycle and reporting contracts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 53a0c7cf-1330-4677-8700-d249b508c6ee
Jason Morse (JasonVMo)
force-pushed
the
user/jasonvmo/desktop-driver-windows-helper
branch
from
November 11, 2026 11:58
999438c to
bdeb0b2
Compare
Vladimir Morozov (vmoroz)
approved these changes
Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Platforms Impacted
Description of changes
Related to #4435.
Addresses the Windows helper findings WIN-5, WIN-7, WIN-8, WIN-9, WIN-10, and WIN-13, and partly addresses WIN-1, WIN-2, WIN-3, WIN-4, and WIN-6, in
@fluentui-react-native/desktop-driver(native/windows). WIN-11 and WIN-12 are deferred. Since #4469, killing the helper also ends every application its kill-on-close Job Object contains, so the goal is for the helper to acknowledge a cancel well inside Node's 10 s Windows deadline on every path. This PR moves several waits toward that goal but does not reach it: the paths listed under Not in this PR can still block past a cancel.RunBoundedProviderCallwaited up to 5 s without a token. Whole-subtreeBuildUpdatedCachecalls, and their retries, ran directly under the 5 s UI Automation transaction timeout.closeApplicationwaited 2 s after terminating a packaged app.CancellationScope, set inDriver::Execute, gives bounded calls the command's token, and they check it between 50 ms wait slices. A cancelled read throwsCancelledError. A cancelled mutation is abandoned and quarantined like a timed-out one, so the cancel reports effectunknown, notnone. Subtree and probe caches run on the bounded worker. The wait after terminating sleeps through the token's cancellable wait and keeps the lease so the close can be retried. Direct UI Automation calls and packagedActivateApplicationare still not token-aware (see Not in this PR).ShowWindow(SW_RESTORE),SetWindowPos, and activation wait on the target's thread, so a hung target held the helper and the input mutex.SendMessageTimeoutW(WM_NULL, SMTO_ABORTIFHUNG)probes the target in 200 ms tries for up to 2 s and checks the token between tries. A hung target fails withautomation-failedand reasontarget-non-response.setWindowRectposts its restore (ShowWindowAsync) and move (SWP_ASYNCWINDOWPOS), polls for both with the token, skips a move to the current frame, and records each change as dispatching until it settles. A restore that stalls after its initial probe remainsunknown; it can still take effect after the failure. Activation probes before and during its loop and does not attach to a hung foreground holder's input queue. A target that hangs after a passed probe can still blockSetForegroundWindow,SetActiveWindow, orBringWindowToTop.AllowSetForegroundWindow(ASFW_ANY).ReleaseInput(), and queued commands ran under a token re-armed after EOF.PhysicalInputScopeinto the driver (heldInput_), which is released onceReleaseInputleaves nothing down. The worker releases input on every exit and drops queued commands once stopping. The cancel path's cleanup scope is therefore nested and immediate, which removes the 5 s mutex wait beforecancelledis written.desktop-testcontracts inherited from main assumed POSIX paths or process behavior.pointerDownand wheel scrolls did not check what window was under the pointer.element-not-interactableover a window, or root window, that belongs to no leased application.unsupported-operation, and a failed focus read became "not focused".QueryPatternreturns available, absent, stale, or failed. Pattern actions, accessibility clicks, and value clears reportstale-elementorautomation-failedand keep their previous results only for an absent pattern. A failed focus read is reported asautomation-failedand a stale element asstale-element.WM_CLOSEto, and terminated, a still-running launch root even when the job owned it, and a packaged root was trusted by process id alone.ActivateApplicationusesAO_NOERRORUI.1601-01-01…, which the incarnation probe reads asexited.launch-failedorattach-failed, and a zeroFILETIMEserializes as an empty string.src/native/nativeDriver.test.tsnow expects this: after a malformed frame and a probe request, the helper exits with code 1 within 10 s and never answers the probe. It replaces the old recovery expectation, and the 1,024-byte identifier request and cancel that followed the bad frame are dropped because they can no longer be read. The README now gives the actual close sequence and the actual build settings: warning level 4, without/WX, CFG, or/sdl, and no longer claims to be warning-clean. It also covers posted window management,target-non-response, the held input lock, the pointer hit check, launch cleanup under a job, and cancellation.PROTOCOL.mdwidenstarget-non-responseto window messages, andremaining-work.mdrecords what is still unbounded. The docs and changeset state the polling intervals as implementation bounds on the wrapped waits, not as measured cancellation times.target-non-responsefailure, cancellation, and recovery;unknownand the posted restore takes effect after the failure;FILETIME;target-non-responsefor move and activation preflight..changeset/win-helper-cancellation.md(desktop-driver, patch).Not in this PR
--release-inputor--sweep.performActionswindow (WIN-4): naming the target window is a cross-platform protocol change, so the hit check accepts any leased application.Disposewith job leases, and an unreadable attach identity.ElementFromHandle,observepaging, the tree walker), which are bounded only by the 2 s connection and 5 s transaction timeouts;SetForegroundWindow,SetActiveWindow, andBringWindowToTopon a target that hangs after its probe;ActivateApplication, which is synchronous.src/native/windows/protectedService.contract.test.ts:233is being updated by theopschange, for SRV-11.Verification
Rebased follow-up, Windows 11 x64, November 11, 2026:
bdeb0b291contains the review fix and desktop-test corrections. Commands below run in the named package unless otherwise stated.$env:FURN_NATIVE_DRIVER_TEST = '1'; yarn test --runInBand(desktop-driver)$env:FURN_NATIVE_DRIVER_TEST = '1'; yarn test nativeDriver --runInBand(desktop-driver)yarn format,yarn lint,yarn build(desktop-driver)yarn format,yarn lint,yarn build,yarn test(desktop-test)yarn storybook smoke --win32 --mode stories-and-tests --input physical(apps/storybook)yarn clean-lage-cache; yarn lage buildci --concurrency 4(root)desktop-testfailures. After the fixes, the aggregate passed; the final rerun had 7 successful and 171 skipped/cached tasks, 0 failed.Hosted on
bdeb0b291, Windows PR, Windows Storybook, Win32 PR, and both Win32 Storybook lanes passed. The macOS Paper Storybook job failed duringcomponents-listitem--overviewnavigation withStorybook context did not settle; an unchanged-head retry passed. The original failure's cause is not established.Windows 11 x64, Node 26.13.0, November 10, 2026, head
999438c5e: the native-enabled suite built the C++ helper, ran its self-test and real Windows contracts, and exercised physical input and capture. The Storybook smokes used the same fixed production helper.$env:FURN_NATIVE_DRIVER_TEST = '1'; yarn workspace @fluentui-react-native/desktop-driver test --runInBand$env:FURN_NATIVE_DRIVER_TEST = '1'; yarn workspace @fluentui-react-native/desktop-driver test --runInBand nativeDriveryarn workspace @fluentui-react-native/agentic-components-storybook storybook build-driver --windows --reporter json, then the returnedexecutablePath --self-testpartialbefore the fix andunknownafter it; the restore took effect after the failure.yarn workspace @fluentui-react-native/desktop-driver format --checkyarn workspace @fluentui-react-native/desktop-driver lintyarn workspace @fluentui-react-native/desktop-driver build$env:STORYBOOK_SMOKE_STORY = 'components-card--native-structure'; yarn workspace @fluentui-react-native/agentic-components-storybook storybook smoke --windows --mode stories-and-tests --input accessible$env:STORYBOOK_SMOKE_STORY = 'components-card--native-structure'; yarn workspace @fluentui-react-native/agentic-components-storybook storybook smoke --win32 --mode stories-and-tests --input accessible$env:STORYBOOK_SMOKE_STORY = $null; yarn workspace @fluentui-react-native/agentic-components-storybook storybook smoke --win32 --mode stories-and-tests --input accessible$env:STORYBOOK_SMOKE_STORY = $null; yarn workspace @fluentui-react-native/agentic-components-storybook storybook smoke --win32 --mode stories-and-tests --input physicalyarn test-links -c .github\markdown-link-check-config.json packages\agentic\desktop-driver\native\windows\README.mdyarn clean-lage-cache; yarn lage buildci --concurrency 4The focused
win32Fixturerun selected the hung-window and in-flight cancellation cases: 2 passed and 10 were filtered out. Cancellation was acknowledged in 31 ms in that run and 38–47 ms in earlier full runs. These observations are not general timing guarantees. The full Win32 physical lane exercised real pointer and keyboard input; the accessible smokes alone do not qualify physical input. Owned services stopped and their recorded ports had no listeners afterward.Hosted CI: On
114c2f605, Win32 Storybook accessible ran all 214 selected tests successfully, but the job failed during owned-service/reporting shutdown. The matching local 214-test run passed including cleanup. The failure resembles the independently addressed shutdown-deadline issue in #4476, but the nested failure's cause is not established. On999438c5e, Win32 PR and Win32 Storybook accessible passed, but the physical job failed while navigatingcomponents-tab--overviewwithStorybook context did not settle; all 52 attempted hosted navigations passed in the full local physical run. An unchanged-head retry later passed 258 tests with one quarantined/unsupported. The original failure's cause remains unconfirmed.Earlier macOS verification: Run in
packages/agentic/desktop-driverunless noted. The Windows-only contracts skipped in these runs.msbuild,--self-test), and the Windows contracts.clang-formatfor this codeBefore the contract and wording commits (tree
998278dfa):yarn formatyarn lintyarn buildyarn testyarn oxfmt --checkon the README,PROTOCOL.md,remaining-work.md, and the changeset (root)native-lock.sh win-buildci bash -c 'yarn clean-lage-cache && yarn lage buildci --concurrency 4'(root)After the
nativeDriver.test.tscontract update (a1653720a) and the wording correction (b16d0349c):yarn build(type-check)yarn lintyarn formatyarn test nativeDriveryarn oxfmt --checkon the README,remaining-work.md, and the changeset (root)buildcinone.SetForegroundWindow,SetActiveWindow, andBringWindowToTopafter a passed probe, and packagedActivateApplicationcan still block past a cancel. A cancelled mutation reportsunknown, a window that fails its probe fails withtarget-non-response, held input keeps the lock, and malformed or non-object frames fail the transport.Pull request checklist
This PR has considered (when applicable):