From fec94cec4995c7372b798877c5412ddcb156523b Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Sun, 8 Nov 2026 13:59:59 -0800 Subject: [PATCH 1/2] Qualify Windows desktop application ownership Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 19ee4435-64e4-4799-b8fc-f3b7742f2c92 --- .changeset/windows-application-containment.md | 5 + .changeset/windows-qualification-records.md | 7 + .../references/current-status.md | 46 +- .../fixtures/win32/src/fixture.cpp | 69 +++ .../agentic/desktop-driver/native/PROTOCOL.md | 11 + .../desktop-driver/native/windows/README.md | 54 ++- .../native/windows/src/application.cpp | 458 ++++++++++++++++-- .../native/windows/src/application.h | 49 +- .../native/windows/src/selftest.cpp | 114 +++++ .../references/current-status.md | 31 +- .../references/remaining-work.md | 20 +- .../agentic/desktop-driver/src/host/types.ts | 6 + .../windows/win32Fixture.contract.test.ts | 102 +++- .../desktop-test/references/current-status.md | 119 +++-- .../references/native-qualification.md | 9 + .../references/platforms/win32.md | 13 + .../references/troubleshooting.md | 16 +- 17 files changed, 1026 insertions(+), 103 deletions(-) create mode 100644 .changeset/windows-application-containment.md create mode 100644 .changeset/windows-qualification-records.md diff --git a/.changeset/windows-application-containment.md b/.changeset/windows-application-containment.md new file mode 100644 index 0000000000..87c3bc6b2f --- /dev/null +++ b/.changeset/windows-application-containment.md @@ -0,0 +1,5 @@ +--- +'@fluentui-react-native/desktop-driver': patch +--- + +Contain unpackaged Windows launches in a helper-owned Job Object so the application and its descendants end with the lease or the helper, report each lease's `containment` (`job-object`, `uncontained`, or `external`), and fail attach closed on unreadable or cross-session identity. A refused foreground activation now re-attaches to a changed foreground holder and names the holder and its cause. diff --git a/.changeset/windows-qualification-records.md b/.changeset/windows-qualification-records.md new file mode 100644 index 0000000000..fe68a66f47 --- /dev/null +++ b/.changeset/windows-qualification-records.md @@ -0,0 +1,7 @@ +--- +'@fluentui-react-native/desktop-driver-mcp': patch +'@fluentui-react-native/desktop-test': patch +'@fluentui-react-native/storybook-desktop': patch +--- + +Record Windows Fabric and Win32 Paper launch, containment, and MCP measurement evidence, and document the Win32 agent-mode bundle, the Windows foreground refusal, and the `serve --agent` interrupt behavior. diff --git a/packages/agentic/desktop-driver-mcp/references/current-status.md b/packages/agentic/desktop-driver-mcp/references/current-status.md index 93a9a68c27..e9081330a3 100644 --- a/packages/agentic/desktop-driver-mcp/references/current-status.md +++ b/packages/agentic/desktop-driver-mcp/references/current-status.md @@ -73,7 +73,51 @@ tokenizer/version, serialized UTF-8 bytes and characters, text tokens, instructions overhead, projection/budgets, sample count, cold/warm timing, success/retry/cancellation/cleanup counts, and approved artifact locator. Do not claim token reductions from reducing information scope or omitting -discovery. Windows and Paper measurements are currently **not recorded here**. +discovery. macOS Paper measurements are currently **not recorded here**. + +### Windows Fabric and Win32 Paper - 2026-11-08 UTC + +Revision `9d3e11516` plus the uncommitted Windows ownership and foreground +helper changes, which do not alter tool text. MCP SDK 1.32.2 stdio client +through the default descriptor; `gpt-tokenizer` 4.1.0 with `o200k_base` over +every text block. Windows 11 build 26300, AMD64; Storybook served by +`yarn desktop-test --target windows|win32 --reporter json serve --agent`. The +console session was disconnected, so `click` was not measured; the toggle +row uses `activate`. Each endpoint made 139 calls with no errors or retries, +then closed its session. Runs `caba9e12-d9da-42a0-8b06-7300940e8318` +(Windows) and `5f75aac2-d74c-4969-aba3-bd8c925d5725` (Win32), each with its +`run.json` under `apps/storybook/artifacts/desktop//`. + +| Measurement | Windows Fabric | Win32 Paper | +| ------------------------------------------------------- | ----------------------------------- | ----------------------------------- | +| Six-tool `tools/list` | 4,691 tokens; 20,277 bytes (chars) | Same | +| Server instructions | 120 tokens; 591 bytes | Same | +| `open` (attach) | 45 ms | 31-40 ms | +| Checkbox `activate` + `checked` check + default observe | 1,923 tokens; 5,346 bytes; 2,288 ms | 1,645 tokens; 5,187 bytes; 2,302 ms | +| Of which `activate` | 2,190 ms | 2,196 ms | +| Observe default (100 of about 113 nodes, 20 calls) | 66.7-73.7 ms median, max 93.1 ms | 81.1-85.8 ms median, max 97.3 ms | +| Observe text per call | 1,801-1,843 tokens | 1,594-1,633 tokens | +| Delta (20 calls, idle) | 72.7-77.5 ms median, max 98.4 ms | 83.3-88.3 ms median, max 106.4 ms | +| Delta text per call | 368 tokens | 220 tokens | + +Ranges span the Button, Checkbox, and Menu stories (`components-button--appearance`, +`components-checkbox--constrained-text`, `components-menu--default`); the +toggle row used `components-checkbox--default`. Observe used the default +budget, which emitted 100 nodes. On Windows an idle delta is never empty: +the React Native Test App's React, Debug, and System menu-bar items get new +references on every read (three removed, three added). The helper reuses a +reference only when the UI Automation runtime identity matches; whether these +items lack stable runtime identities is unconfirmed. Without those changes +the envelope is about 151 tokens. The Win32 +idle delta was not decomposed. The first Win32 toggle attempt chose the +wrapping-label checkbox in `constrained-text` and returned a `stopped` +sequence; it is retained here, not diagnosed, and the default story was used +instead. + +Discovery grew by 3 tokens and 8 bytes since `41fc7473f` from tool-text +changes. The Windows toggle rows are not comparable with the 386-token macOS +row: they target a different story and their closing observe is an unscoped +default observe, which accounts for most of their text. ## Before full submission diff --git a/packages/agentic/desktop-driver/fixtures/win32/src/fixture.cpp b/packages/agentic/desktop-driver/fixtures/win32/src/fixture.cpp index be8f1eb9e7..1ba00c6cb8 100644 --- a/packages/agentic/desktop-driver/fixtures/win32/src/fixture.cpp +++ b/packages/agentic/desktop-driver/fixtures/win32/src/fixture.cpp @@ -10,6 +10,9 @@ // --offscreen <0|1> place the main window off every monitor (default 0) // --lifetime-ms exit the process after this long even when the UI thread is // blocked, so an abandoned run cannot linger (default 600000, 0: never) +// --child-pid-file start one offscreen descendant copy of this fixture and +// write " " to this file, so a +// contract can prove which processes an owned launch reaches #define NOMINMAX #define WIN32_LEAN_AND_MEAN #include @@ -19,6 +22,7 @@ #include #include +#include #include #include @@ -57,6 +61,7 @@ struct Options { DWORD stuckMilliseconds = 0; DWORD lifetimeMilliseconds = 600000; bool offscreen = false; + std::wstring childPidFile; }; Options options; @@ -89,6 +94,8 @@ Options ParseOptions() { parsed.lifetimeMilliseconds = static_cast(std::max(0, _wtoi(value))); } else if (name == L"--offscreen") { parsed.offscreen = _wtoi(value) != 0; + } else if (name == L"--child-pid-file") { + parsed.childPidFile = value; } } LocalFree(arguments); @@ -397,6 +404,65 @@ void StartWatchdog() { }).detach(); } +DWORD ReadParentProcessId() { + const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (snapshot == INVALID_HANDLE_VALUE) { + return 0; + } + DWORD parent = 0; + PROCESSENTRY32W entry{}; + entry.dwSize = sizeof(entry); + for (BOOL more = Process32FirstW(snapshot, &entry); more != FALSE; more = Process32NextW(snapshot, &entry)) { + if (entry.th32ProcessID == GetCurrentProcessId()) { + parent = entry.th32ParentProcessID; + break; + } + } + CloseHandle(snapshot); + return parent; +} + +// Starts one offscreen copy of this fixture with the default title, then +// publishes its process id and this process's parent id through a rename, so a +// reader never sees a partial file. Returns false when either step fails. +bool StartDescendant() { + if (options.childPidFile.empty()) { + return true; + } + wchar_t modulePath[MAX_PATH * 4] = {}; + const DWORD length = GetModuleFileNameW(nullptr, modulePath, static_cast(std::size(modulePath))); + if (length == 0 || length >= std::size(modulePath)) { + return false; + } + std::wstring commandLine = L"\"" + std::wstring(modulePath, length) + + L"\" --offscreen 1 --lifetime-ms " + std::to_wstring(options.lifetimeMilliseconds); + STARTUPINFOW startup{}; + startup.cb = sizeof(startup); + PROCESS_INFORMATION information{}; + if (CreateProcessW(modulePath, commandLine.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &startup, + &information) == FALSE) { + return false; + } + CloseHandle(information.hThread); + CloseHandle(information.hProcess); + + const std::string contents = + std::to_string(information.dwProcessId) + " " + std::to_string(ReadParentProcessId()) + "\n"; + const std::wstring temporary = options.childPidFile + L".tmp"; + const HANDLE file = CreateFileW(temporary.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, nullptr); + if (file == INVALID_HANDLE_VALUE) { + return false; + } + DWORD written = 0; + const bool complete = WriteFile(file, contents.data(), static_cast(contents.size()), &written, nullptr) != + FALSE && + written == contents.size(); + CloseHandle(file); + return complete && + MoveFileExW(temporary.c_str(), options.childPidFile.c_str(), MOVEFILE_REPLACE_EXISTING) != FALSE; +} + } // namespace int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int) { @@ -417,6 +483,9 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int) { return 1; } ShowWindow(window, SW_SHOWNOACTIVATE); + if (!StartDescendant()) { + return 3; + } MSG message{}; while (GetMessageW(&message, nullptr, 0, 0) > 0) { diff --git a/packages/agentic/desktop-driver/native/PROTOCOL.md b/packages/agentic/desktop-driver/native/PROTOCOL.md index 5848f2a3d1..04c88fddc0 100644 --- a/packages/agentic/desktop-driver/native/PROTOCOL.md +++ b/packages/agentic/desktop-driver/native/PROTOCOL.md @@ -114,6 +114,17 @@ application descriptors may include an existing absolute `workingDirectory` for unpackaged process launch; packaged activation rejects that override. These fields are trusted supervisor configuration, not WebDriver capabilities. +A `launch` or `attach` result is the application lease `{ id, ownership, +processId, processStartedAt }`. The Windows provider adds `containment`, which +states how far its ownership reaches: `job-object` for an unpackaged launch it +started suspended inside a Job Object of its own, so closing the lease or the +helper exiting ends the application and every descendant; `uncontained` for a +packaged activation, where it owns only the identity-verified process whose +window it leased (the activated process or a verified descendant) and no job; +and `external` for an attached application it never ends. A provider that omits +`containment` makes no containment claim. The field is additive and does not +change the wire version. + Element snapshots can additionally include `required` as a supported Boolean or an unsupported value with its reason. Older or non-supporting providers may omit it; the Node boundary treats absence as unsupported. This is additive diff --git a/packages/agentic/desktop-driver/native/windows/README.md b/packages/agentic/desktop-driver/native/windows/README.md index e130e6fdbe..c955b7b003 100644 --- a/packages/agentic/desktop-driver/native/windows/README.md +++ b/packages/agentic/desktop-driver/native/windows/README.md @@ -86,18 +86,41 @@ remain unsupported. Attach accepts an owner-generated nonce-bound lease, or an exact title qualified by the canonical executable or AUMID. Title-only attach, zero -matches, and multiple qualified matches fail. -Leases record ownership, PID, process start, executable, and the primary window. -Attached apps survive WebDriver deletion; launched apps are closed only by -their exact recorded process identity. +matches, and multiple qualified matches fail. Attach fails closed: a lease's +process must be in the helper's session and match the lease's executable or +AUMID, and an unleased attach fails as ambiguous when any titled candidate's +identity cannot be read rather than skipping it. +Leases record ownership, PID, process start, executable, the primary window, +and `containment`. Attached apps survive WebDriver deletion and helper +disposal (`external`); launched apps are closed only by their exact recorded +process identity. Unpackaged arguments use the standard `CommandLineToArgvW` quoting rules. Launch ownership requires a non-preexisting window from the exact created process or a verified descendant, plus a matching canonical executable or AUMID and a process start after the launch request. Reused packaged processes fail with guidance to use attach mode. Cancellation, launch failure, session -cleanup, and helper disposal close only causally owned processes and retain -the lease when forced termination cannot be proven. +cleanup, and helper disposal close only owned processes and retain the lease +when forced termination cannot be proven. + +Launch and attach require the helper's window station to be interactive. An +unpackaged launch is containment `job-object`: the helper creates the process +suspended, assigns it to a Job Object of its own with +`JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE` and no breakaway, and only then resumes +it, so every descendant starts inside the job. A failed assignment ends the +suspended process and fails the launch as unsupported instead of running it +uncontained. Window discovery then accepts only windows of job members in the +helper's session. Closing the lease asks the root window to close, then ends +the job and waits up to 3 seconds for it to drain; an undrained job fails +`cleanup-failed` and keeps the lease so the close can be retried. If the helper +exits without closing, the operating system ends the job. Descendants are ended +by the job, not asked to close, and an application that starts children with +`CREATE_BREAKAWAY_FROM_JOB` fails inside the job. A packaged activation is +containment `uncontained`: the Application Activation Manager starts it outside +any job the helper owns, so closing the lease ends only the identity-verified +process whose window the helper leased (the activated process or a verified +descendant); other processes the application starts are not ended. +The helper never places an attached application in a job. ## Automation behavior @@ -144,6 +167,14 @@ already active, as macOS does for application activation. Reactivating the owner would light-dismiss an open popup with input that no user produced. A physical press on the owner still activates it. +Activation shares the input queue of whichever thread holds the foreground, +moving to the new holder when the foreground changes during the attempt. When +Windows still keeps the foreground away, `window-activation-failed` names the +holder by opaque window handle and process id, never by title or class, and the +first matching cause: no foreground window, another window of the target +application, an elevated or unreadable holder, a holder that is not responding, +a refused input-queue attachment, or a holder that took the foreground back. + A subtree walk retries while its root remains available if a descendant becomes unavailable, or if a closing popup island's provider reports a UI Automation timeout or an unspecified failure. Only an unavailable root is a @@ -483,7 +514,9 @@ handshakes, runs the native self-test, exercises malformed-frame recovery, and verifies shared Windows/Win32 selection. A second suite builds the test-only Win32 fixture (`fixtures/win32` in the repository, not published) and drives it through the helper: window events, owned popups, hung and stuck providers, large -trees, and bounded retention. `yarn test --runInBand win32Fixture` runs only +trees, bounded retention, and application containment (a contained launch whose +descendant ends on close and when the helper is killed, and an external fixture +that survives attach, close, and disposal). `yarn test --runInBand win32Fixture` runs only that suite. A third suite serves the same fixture through a grant-protected Desktop Driver service with the helper behind it: unauthenticated requests reach no helper call, sessions keep their owner, a revoked grant closes its @@ -564,6 +597,13 @@ attached app survived. Shutdown used the CLI's stop handler through a test-only IPC bridge, not a physical console Ctrl+C. These fixture results do not qualify either React Native renderer's new agent-operation path. +Application containment passed the fixture contract and two launch probes +through `desktop-test serve --agent`: when the helper was killed, a REX +FluentTester launch on Win32 Paper (`job-object`) ended with it, and the +packaged Storybook app on Windows Fabric (`uncontained`) survived. The +foreground-refusal causes are self-tested only; a live Windows Fabric +physical click has not been rerun. + CI must build this helper explicitly into a job-local cache, run the opt-in native contract once for the shared Windows/Win32 provider, verify each endpoint with `desktop-driver doctor`, and set diff --git a/packages/agentic/desktop-driver/native/windows/src/application.cpp b/packages/agentic/desktop-driver/native/windows/src/application.cpp index a3ecd52ea0..8a7dbe7b47 100644 --- a/packages/agentic/desktop-driver/native/windows/src/application.cpp +++ b/packages/agentic/desktop-driver/native/windows/src/application.cpp @@ -54,6 +54,9 @@ constexpr DWORD kLaunchCleanupForcedMs = 1000; constexpr unsigned int kDisposeGraceMs = 3000; constexpr unsigned int kDisposeForcedMs = 3000; constexpr DWORD kOwnedProcessAccess = PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE; +// Bounds how long closing an owned launch waits for its contained descendants +// to exit after the helper ends its Job Object. +constexpr unsigned int kJobDrainMs = 3000; // PowerShell writes the lease with 100-nanosecond precision; allow a small // tolerance so rounding never rejects the correct process. constexpr std::uint64_t kStartTimeToleranceTicks = 100000; // 10 milliseconds @@ -233,6 +236,34 @@ bool ProcessMatchesLaunchIdentity(HANDLE process, const std::wstring& aumid, return !actualPath.empty() && _wcsicmp(actualPath.c_str(), executablePath.c_str()) == 0; } +enum class IdentityEvidence { Matches, Differs, Unreadable }; + +// Like ProcessMatchesLaunchIdentity, but tells a process that is provably some +// other application apart from one whose identity could not be read. +IdentityEvidence ReadIdentityEvidence(HANDLE process, const std::wstring& aumid, + const std::wstring& executablePath) { + if (!aumid.empty()) { + UINT32 length = 0; + const LONG measured = GetApplicationUserModelId(process, &length, nullptr); + if (measured == APPMODEL_ERROR_NO_APPLICATION) { + return IdentityEvidence::Differs; + } + const std::wstring actualAumid = + measured == ERROR_INSUFFICIENT_BUFFER ? ReadProcessApplicationUserModelId(process) : std::wstring(); + if (actualAumid.empty()) { + return IdentityEvidence::Unreadable; + } + return _wcsicmp(actualAumid.c_str(), aumid.c_str()) == 0 ? IdentityEvidence::Matches + : IdentityEvidence::Differs; + } + const std::wstring actualPath = NormalizeExecutablePath(ReadProcessImagePath(process)); + if (actualPath.empty()) { + return IdentityEvidence::Unreadable; + } + return _wcsicmp(actualPath.c_str(), executablePath.c_str()) == 0 ? IdentityEvidence::Matches + : IdentityEvidence::Differs; +} + winrt::handle DuplicateProcessHandle(HANDLE process) { HANDLE duplicated = nullptr; if (DuplicateHandle(GetCurrentProcess(), process, GetCurrentProcess(), &duplicated, 0, @@ -244,6 +275,91 @@ winrt::handle DuplicateProcessHandle(HANDLE process) { return result; } +bool ProcessInHelperSession(DWORD processId) { + DWORD helperSession = 0; + DWORD processSession = 0; + return ProcessIdToSessionId(GetCurrentProcessId(), &helperSession) != FALSE && + ProcessIdToSessionId(processId, &processSession) != FALSE && + processSession == helperSession; +} + +// A helper on a service or other non-interactive window station cannot see or +// drive desktop windows, so owning or attaching to an application there fails. +void RequireInteractiveWindowStation(std::string_view failureCode) { + const HWINSTA station = GetProcessWindowStation(); + USEROBJECTFLAGS flags{}; + if (station == nullptr || + GetUserObjectInformationW(station, UOI_FLAGS, &flags, sizeof(flags), nullptr) == FALSE) { + FailLastError(std::string(failureCode), "Reading the helper's window station", GetLastError()); + } + if ((flags.dwFlags & WSF_VISIBLE) == 0) { + Fail(std::string(failureCode), + "The helper does not run on an interactive window station, so it cannot own or drive " + "desktop applications."); + } +} + +// The Job Object that contains an unpackaged launch. It grants no breakaway, so +// every descendant stays inside, and it ends its processes when its last handle +// closes, so an owned launch cannot outlive a helper that exits or crashes. +winrt::handle CreateContainmentJob() { + winrt::handle job{CreateJobObjectW(nullptr, nullptr)}; + if (!job) { + FailLastError(kErrorLaunchFailed, "Creating the launch containment Job Object", GetLastError()); + } + JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits{}; + limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + if (SetInformationJobObject(job.get(), JobObjectExtendedLimitInformation, &limits, + sizeof(limits)) == FALSE) { + FailLastError(kErrorLaunchFailed, "Configuring the launch containment Job Object", GetLastError()); + } + return job; +} + +std::optional ReadActiveJobProcesses(HANDLE job) { + JOBOBJECT_BASIC_ACCOUNTING_INFORMATION accounting{}; + if (QueryInformationJobObject(job, JobObjectBasicAccountingInformation, &accounting, + sizeof(accounting), nullptr) == FALSE) { + return std::nullopt; + } + return accounting.ActiveProcesses; +} + +bool ProcessIsInJob(HANDLE process, HANDLE job) { + BOOL member = FALSE; + return IsProcessInJob(process, job, &member) != FALSE && member != FALSE; +} + +// Ends every process in a containment job and waits, bounded, until the job +// reports none still active. Returns why that could not be verified, or empty. +std::string EndContainedProcesses(HANDLE job, unsigned int timeoutMs, const CancellationToken& token) { + token.ThrowIfCancelled(); + if (TerminateJobObject(job, 1) == FALSE) { + const DWORD error = GetLastError(); + const std::optional active = ReadActiveJobProcesses(job); + if (!active || *active != 0) { + return "Ending the containment Job Object failed: " + DescribeHresult(HRESULT_FROM_WIN32(error)); + } + return {}; + } + const Deadline deadline(timeoutMs); + for (;;) { + token.ThrowIfCancelled(); + const std::optional active = ReadActiveJobProcesses(job); + if (!active) { + return "The containment Job Object could not report its remaining processes: " + + DescribeHresult(HRESULT_FROM_WIN32(GetLastError())); + } + if (*active == 0) { + return {}; + } + if (deadline.Expired()) { + return std::to_string(*active) + " contained process(es) did not exit after the containment Job Object ended."; + } + token.Wait(25); + } +} + void PostCloseToExactProcessWindows(DWORD processId, const FILETIME& expectedStartTime) { if (processId == 0 || FileTimeTicks(expectedStartTime) == 0) { return; @@ -505,34 +621,48 @@ void TrackRelatedLaunchProcesses(const LaunchRootIdentity& root, struct ActivationOutcome { bool activated{false}; bool sawForeground{false}; + // The Windows error of the latest refused input-queue attachment, or 0. + DWORD attachError{0}; }; class ForegroundInputAttachment { public: explicit ForegroundInputAttachment(DWORD selfThread) noexcept : selfThread_(selfThread) {} - ~ForegroundInputAttachment() { - if (otherThread_ != 0) { - AttachThreadInput(selfThread_, otherThread_, FALSE); - } - } + ~ForegroundInputAttachment() { Detach(); } - bool Attach(DWORD otherThread) { - if (otherThread_ != 0 || otherThread == 0 || otherThread == selfThread_) { - return otherThread_ != 0; + // Shares the input queue of `otherThread`, first releasing a queue shared with + // a thread that no longer owns the foreground. + void AttachTo(DWORD otherThread) { + if (otherThread == otherThread_) { + return; + } + Detach(); + if (otherThread == 0 || otherThread == selfThread_) { + return; } if (AttachThreadInput(selfThread_, otherThread, TRUE) == FALSE) { - return false; + error_ = GetLastError(); + return; } + error_ = 0; otherThread_ = otherThread; - return true; } - bool attached() const noexcept { return otherThread_ != 0; } + DWORD thread() const noexcept { return otherThread_; } + DWORD error() const noexcept { return error_; } private: + void Detach() noexcept { + if (otherThread_ != 0) { + AttachThreadInput(selfThread_, otherThread_, FALSE); + otherThread_ = 0; + } + } + DWORD selfThread_{0}; DWORD otherThread_{0}; + DWORD error_{0}; }; // Like application activation on macOS, a foreground popup that the window owns keeps the window's activation @@ -570,20 +700,37 @@ ActivationOutcome ActivateWindowInternal(HWND window, const CancellationToken& t if (deadline.Expired()) { break; } - if (!inputAttachment.attached()) { - // Foreground ownership only transfers between threads that share an - // input queue, so borrow the current foreground thread's queue. - const DWORD candidate = GetWindowThreadProcessId(foreground != nullptr ? foreground : window, nullptr); - inputAttachment.Attach(candidate); - } + // Foreground ownership only transfers between threads that share an input + // queue, so borrow the queue of whichever thread holds the foreground now. + inputAttachment.AttachTo(GetWindowThreadProcessId(foreground != nullptr ? foreground : window, nullptr)); BringWindowToTop(window); SetForegroundWindow(window); SetActiveWindow(window); token.Wait(50); } + outcome.attachError = inputAttachment.thread() == 0 ? inputAttachment.error() : 0; return outcome; } +ActivationRefusal ReadActivationRefusal(HWND window, const ActivationOutcome& outcome) { + ActivationRefusal refusal; + refusal.sawForeground = outcome.sawForeground; + refusal.attachError = outcome.attachError; + refusal.helperIntegrity = HelperIntegrity(); + const HWND foreground = GetForegroundWindow(); + if (foreground == nullptr) { + return refusal; + } + refusal.foreground = DescribeWindowHandle(foreground); + GetWindowThreadProcessId(foreground, &refusal.foregroundProcess); + DWORD windowProcess = 0; + GetWindowThreadProcessId(window, &windowProcess); + refusal.foregroundInTargetProcess = windowProcess != 0 && windowProcess == refusal.foregroundProcess; + refusal.foregroundHung = IsHungAppWindow(foreground) != FALSE; + refusal.foregroundIntegrity = ReadProcessIntegrity(refusal.foregroundProcess); + return refusal; +} + } // namespace std::vector EnumerateTopLevelWindows(DWORD processId) { @@ -640,16 +787,58 @@ bool TryActivateWindow(HWND window, const CancellationToken& token) { return ActivateWindowInternal(window, token).activated; } +std::string DescribeActivationRefusal(const ActivationRefusal& refusal) { + if (!refusal.sawForeground) { + return "The session has no interactive foreground desktop, so the window could not be activated."; + } + const std::string prefix = "The target window did not become the foreground window: "; + if (refusal.foreground.empty()) { + return prefix + + "no window held the foreground when activation stopped, so the session may have been locked, " + "disconnected, or switched to a secure desktop."; + } + const std::string holder = "window " + refusal.foreground + " of process " + std::to_string(refusal.foregroundProcess); + if (refusal.foregroundInTargetProcess) { + return prefix + "the foreground stayed with " + holder + + ", another window of the target application that the target window does not own. Address that window, " + "then retry."; + } + const ProcessIntegrity& holderIntegrity = refusal.foregroundIntegrity; + if (holderIntegrity.known && refusal.helperIntegrity.known && holderIntegrity.level > refusal.helperIntegrity.level) { + return prefix + holder + " runs at " + DescribeIntegrityLevel(holderIntegrity.level) + + " integrity and this helper at " + DescribeIntegrityLevel(refusal.helperIntegrity.level) + + ", so Windows does not let the helper take the foreground from it. Bring a window that is not elevated " + "forward, then retry."; + } + if (!holderIntegrity.known && holderIntegrity.error == ERROR_ACCESS_DENIED) { + return prefix + "Windows denied reading the security token of " + holder + + ", so it is probably elevated, protected, or owned by another account, and Windows does not let the helper " + "take the foreground from it. Bring a window that is not elevated forward, then retry."; + } + if (refusal.foregroundHung) { + return prefix + holder + " is not responding, so Windows kept the foreground with it."; + } + if (refusal.attachError != 0) { + return prefix + "Windows refused to let this helper share the input queue of " + holder + " (Windows error " + + std::to_string(refusal.attachError) + "), so the foreground lock kept that window in front."; + } + return prefix + "Windows kept the foreground with " + holder + + " although this helper shared its input queue; that application may be taking the foreground back."; +} + +void RequireProcessInHelperSession(DWORD processId, std::string_view failureCode) { + if (!ProcessInHelperSession(processId)) { + Fail(std::string(failureCode), + "The application does not run in the helper's Windows session, so the helper cannot drive it."); + } +} + void ActivateWindow(HWND window, const CancellationToken& token) { const ActivationOutcome outcome = ActivateWindowInternal(window, token); if (outcome.activated) { return; } - if (!outcome.sawForeground) { - Fail(kErrorWindowActivation, - "The session has no interactive foreground desktop, so the window could not be activated."); - } - Fail(kErrorWindowActivation, "The target window did not become the foreground window."); + Fail(kErrorWindowActivation, DescribeActivationRefusal(ReadActivationRefusal(window, outcome))); } ApplicationManager::~ApplicationManager() { @@ -667,6 +856,11 @@ ApplicationManager::~ApplicationManager() { CloseHandle(entry.second.process); entry.second.process = nullptr; } + // Closing the last handle to a containment job ends whatever it still holds. + if (entry.second.job != nullptr) { + CloseHandle(entry.second.job); + entry.second.job = nullptr; + } } for (PendingCleanupProcess& pending : pendingCleanupProcesses_) { if (pending.process != nullptr) { @@ -781,23 +975,27 @@ void ApplicationManager::SetWindowClosedPublisher(std::functionsecond.leaseId != id) { + ++iterator; + continue; + } + windowEvents_.Forget(iterator->first); + const auto byHandle = windowIdsByHandle_.find(iterator->second.window); + if (byHandle != windowIdsByHandle_.end() && byHandle->second == iterator->first) { + windowIdsByHandle_.erase(byHandle); + } + iterator = windowsById_.erase(iterator); + } + const auto byHandle = windowIdsByHandle_.find(primaryWindow); + if (byHandle != windowIdsByHandle_.end() && windowsById_.find(byHandle->second) == windowsById_.end()) { + windowEvents_.Forget(byHandle->second); + windowIdsByHandle_.erase(byHandle); + } + const bool processStillLeased = + std::any_of(leases_.begin(), leases_.end(), [processId](const auto& other) { + return other.second.processId == processId; + }); + if (!processStillLeased) { + try { + windowEvents_.Stop(processId); + } catch (...) { + } + } + throw; } + stored.process = process; + stored.job = job; return stored; } @@ -864,11 +1100,15 @@ const ApplicationLease& ApplicationManager::Launch(const json::Value& params, co } } + RequireInteractiveWindowStation(kErrorUnsupported); const std::vector preexisting = FindWindowsWithTitle(windowTitle); FILETIME launchStartedAt{}; GetSystemTimeAsFileTime(&launchStartedAt); LaunchProcessGuard launchProcesses; LaunchRootIdentity launchRoot; + // Null for packaged activation: Windows creates that process, so the helper + // owns only the exact activated process and never claims its descendants. + winrt::handle containmentJob; try { if (!aumid.empty()) { winrt::com_ptr manager; @@ -909,15 +1149,20 @@ const ApplicationLease& ApplicationManager::Launch(const json::Value& params, co if (!arguments.empty()) { commandLine += L' ' + arguments; } + containmentJob = CreateContainmentJob(); STARTUPINFOW startup{}; startup.cb = sizeof(startup); PROCESS_INFORMATION information{}; - if (CreateProcessW(executablePath.c_str(), commandLine.data(), nullptr, nullptr, FALSE, 0, nullptr, + // The process starts suspended so it joins the Job Object before it can + // run code or start a descendant outside it. + if (CreateProcessW(executablePath.c_str(), commandLine.data(), nullptr, nullptr, FALSE, + CREATE_SUSPENDED, nullptr, workingDirectory.empty() ? nullptr : workingDirectory.c_str(), &startup, &information) == FALSE) { FailLastError(kErrorLaunchFailed, "Starting the unpackaged application", GetLastError()); } - CloseHandle(information.hThread); + winrt::handle mainThread; + mainThread.attach(information.hThread); winrt::handle created; created.attach(information.hProcess); launchRoot.processId = information.dwProcessId; @@ -925,14 +1170,29 @@ const ApplicationLease& ApplicationManager::Launch(const json::Value& params, co const DWORD duplicateError = launchRoot.process ? ERROR_SUCCESS : GetLastError(); launchProcesses.Track(launchRoot.processId, std::move(created)); if (!launchRoot.process) { + TerminateProcess(launchProcesses.Find(launchRoot.processId), 1); FailLastError(kErrorLaunchFailed, "Duplicating the created process handle for identity tracking", duplicateError); } + if (AssignProcessToJobObject(containmentJob.get(), launchRoot.process.get()) == FALSE) { + const DWORD error = GetLastError(); + TerminateProcess(launchRoot.process.get(), 1); + // The helper never breaks away from, or works around, a job it runs in. + FailLastError(kErrorUnsupported, + "Placing the unpackaged application in the helper's containment Job Object " + "(a job the helper runs in may forbid it), so the helper cannot own its " + "process tree", + error); + } if (!TryReadProcessStartTime(launchRoot.process.get(), launchRoot.startTime)) { Fail(kErrorLaunchFailed, "The created application process identity could not be read."); } + if (ResumeThread(mainThread.get()) == static_cast(-1)) { + FailLastError(kErrorLaunchFailed, "Resuming the contained unpackaged application", + GetLastError()); + } launchRoot.trusted = true; } @@ -945,7 +1205,10 @@ const ApplicationLease& ApplicationManager::Launch(const json::Value& params, co while (matched == nullptr) { token.ThrowIfCancelled(); std::vector> candidates; - const std::unordered_map parents = CaptureParentProcessIds(); + // A contained launch proves descent by job membership; packaged activation + // has no job, so it falls back to the start-time-ordered parent chain. + const std::unordered_map parents = + containmentJob ? std::unordered_map{} : CaptureParentProcessIds(); for (const HWND window : FindWindowsWithTitle(windowTitle)) { if (std::find(preexisting.begin(), preexisting.end(), window) != preexisting.end()) { continue; @@ -957,7 +1220,10 @@ const ApplicationLease& ApplicationManager::Launch(const json::Value& params, co if (!candidate || !TryReadProcessStartTime(candidate.get(), candidateStartTime) || !ProcessStartedForLaunch(candidate.get(), launchStartedAt) || - !IsCausallyRelatedProcess(owner, candidateStartTime, launchRoot, parents) || + !ProcessInHelperSession(owner) || + !(containmentJob + ? ProcessIsInJob(candidate.get(), containmentJob.get()) + : IsCausallyRelatedProcess(owner, candidateStartTime, launchRoot, parents)) || !ProcessMatchesLaunchIdentity(candidate.get(), aumid, executablePath)) { continue; } @@ -1003,12 +1269,28 @@ const ApplicationLease& ApplicationManager::Launch(const json::Value& params, co launchProcesses.Track(matchedProcessId, std::move(owned)); Fail(kErrorCleanupFailed, "A secondary launch process could not be cleaned up: " + extraCleanupFailure); } - return CreateLease("launched", matchedProcessId, owned.detach(), matched, windowTitle, params); + const char* containment = containmentJob ? kContainmentJobObject : kContainmentUncontained; + const ApplicationLease& lease = CreateLease("launched", matchedProcessId, owned.get(), matched, + windowTitle, params, containment, containmentJob.get()); + owned.detach(); + containmentJob.detach(); + return lease; } catch (...) { const std::exception_ptr original = std::current_exception(); - TrackRelatedLaunchProcesses(launchRoot, aumid, executablePath, launchStartedAt, - launchProcesses); - const std::string cleanupFailure = launchProcesses.Cleanup(); + std::string cleanupFailure; + if (containmentJob) { + // Ending the job reaches every contained descendant, not only the + // processes this launch saw. + const CancellationToken idle; + cleanupFailure = EndContainedProcesses(containmentJob.get(), kJobDrainMs, idle); + } else { + TrackRelatedLaunchProcesses(launchRoot, aumid, executablePath, launchStartedAt, + launchProcesses); + } + const std::string trackedFailure = launchProcesses.Cleanup(); + if (!trackedFailure.empty()) { + cleanupFailure += (cleanupFailure.empty() ? "" : "; ") + trackedFailure; + } for (TrackedLaunchProcess& tracked : launchProcesses.ReleaseRemaining()) { TrackPendingCleanupProcess(tracked.processId, tracked.process.detach()); } @@ -1024,6 +1306,7 @@ const ApplicationLease& ApplicationManager::Attach(const json::Value& params, co const std::string endpoint = params.StringField("endpoint", "windows"); const std::wstring leasePath = application->WideField("leasePath"); std::wstring windowTitle = application->WideField("windowTitle"); + RequireInteractiveWindowStation(kErrorUnsupported); if (!leasePath.empty()) { const std::string contents = ReadFileWithRetry(leasePath, token); @@ -1067,13 +1350,30 @@ const ApplicationLease& ApplicationManager::Attach(const json::Value& params, co if (difference > kStartTimeToleranceTicks) { Fail(kErrorLeaseInvalid, "The leased process identifier was reused by a different process."); } - const std::wstring leaseImage = lease.WideField("executablePath"); + RequireProcessInHelperSession(processId, kErrorLeaseInvalid); + // Identity the lease names must be proven, so evidence that cannot be read + // refuses the attach instead of passing it. + const std::wstring leaseImage = NormalizeExecutablePath(lease.WideField("executablePath")); if (!leaseImage.empty()) { - const std::wstring actualImage = ReadProcessImagePath(process.get()); - if (!actualImage.empty() && _wcsicmp(actualImage.c_str(), leaseImage.c_str()) != 0) { + const std::wstring actualImage = NormalizeExecutablePath(ReadProcessImagePath(process.get())); + if (actualImage.empty()) { + Fail(kErrorLeaseInvalid, "The leased process executable could not be read to verify the lease."); + } + if (_wcsicmp(actualImage.c_str(), leaseImage.c_str()) != 0) { Fail(kErrorLeaseInvalid, "The leased process does not run the expected executable."); } } + const std::wstring leaseAumid = lease.WideField("aumid"); + if (!leaseAumid.empty()) { + const std::wstring actualAumid = ReadProcessApplicationUserModelId(process.get()); + if (actualAumid.empty()) { + Fail(kErrorLeaseInvalid, + "The leased process application identity could not be read to verify the lease."); + } + if (_wcsicmp(actualAumid.c_str(), leaseAumid.c_str()) != 0) { + Fail(kErrorLeaseInvalid, "The leased process is not the expected packaged application."); + } + } const std::wstring leaseTitle = lease.WideField("windowTitle"); if (!leaseTitle.empty()) { if (!windowTitle.empty() && windowTitle != leaseTitle) { @@ -1100,7 +1400,10 @@ const ApplicationLease& ApplicationManager::Attach(const json::Value& params, co "The leased application shows " + std::to_string(matches.size()) + " windows titled \"" + ToUtf8(windowTitle) + "\"."); } - return CreateLease("attached", processId, process.detach(), matches.front(), windowTitle, params); + const ApplicationLease& attached = CreateLease("attached", processId, process.get(), matches.front(), + windowTitle, params, kContainmentExternal); + process.detach(); + return attached; } if (windowTitle.empty()) { @@ -1117,13 +1420,32 @@ const ApplicationLease& ApplicationManager::Attach(const json::Value& params, co std::vector matches; winrt::handle matchedProcess; DWORD matchedProcessId = 0; + // A same-titled window whose owner cannot be identified might be the target + // or an impostor, so it makes the target ambiguous rather than being skipped. + std::size_t unverifiable = 0; for (const HWND window : FindWindowsWithTitle(windowTitle)) { token.ThrowIfCancelled(); DWORD candidateId = 0; GetWindowThreadProcessId(window, &candidateId); + if (candidateId == 0) { + continue; + } winrt::handle candidate(OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE, candidateId)); - if (candidate && IsProcessAlive(candidate.get()) && - ProcessMatchesLaunchIdentity(candidate.get(), aumid, executablePath)) { + if (!candidate) { + if (GetLastError() != ERROR_INVALID_PARAMETER) { + unverifiable += 1; + } + continue; + } + if (!IsProcessAlive(candidate.get())) { + continue; + } + const IdentityEvidence evidence = ReadIdentityEvidence(candidate.get(), aumid, executablePath); + if (evidence == IdentityEvidence::Unreadable) { + unverifiable += 1; + continue; + } + if (evidence == IdentityEvidence::Matches) { if (matches.empty()) { matchedProcessId = candidateId; matchedProcess = std::move(candidate); @@ -1131,6 +1453,11 @@ const ApplicationLease& ApplicationManager::Attach(const json::Value& params, co matches.push_back(window); } } + if (unverifiable > 0) { + Fail(kErrorAmbiguousTarget, + std::to_string(unverifiable) + " window(s) titled \"" + ToUtf8(windowTitle) + + "\" belong to a process whose identity cannot be read, so the target cannot be proven unique."); + } if (matches.empty()) { Fail(kErrorAttachFailed, "No window titled \"" + ToUtf8(windowTitle) + "\" is currently open."); } @@ -1145,7 +1472,10 @@ const ApplicationLease& ApplicationManager::Attach(const json::Value& params, co !ProcessMatchesLaunchIdentity(matchedProcess.get(), aumid, executablePath)) { Fail(kErrorAttachFailed, "The application identity changed while attaching."); } - return CreateLease("attached", processId, matchedProcess.detach(), matches.front(), windowTitle, params); + const ApplicationLease& attached = CreateLease("attached", processId, matchedProcess.get(), matches.front(), + windowTitle, params, kContainmentExternal); + matchedProcess.detach(); + return attached; } std::vector ApplicationManager::Windows(const std::string& leaseId, const CancellationToken& token) { @@ -1203,7 +1533,9 @@ void ApplicationManager::CloseApplication(const std::string& leaseId, const Canc while (IsProcessAlive(lease.process) && !deadline.Expired()) { token.Wait(50); } - if (IsProcessAlive(lease.process)) { + // A contained root is ended with its job below, so a root that cannot be + // ended alone never leaves its descendants running. + if (lease.job == nullptr && IsProcessAlive(lease.process)) { if (TerminateProcess(lease.process, 0) == FALSE && IsProcessAlive(lease.process)) { FailLastError(kErrorCleanupFailed, "Terminating the owned application process", GetLastError()); } @@ -1216,6 +1548,17 @@ void ApplicationManager::CloseApplication(const std::string& leaseId, const Canc } } } + // Descendants of a contained launch, and a root that ignored the close + // request, are ended with the job rather than one by one, and the lease + // survives until the job reports none still running. + if (lease.job != nullptr) { + const std::string failure = EndContainedProcesses(lease.job, kJobDrainMs, token); + if (!failure.empty()) { + Fail(kErrorCleanupFailed, "Closing the owned application left contained processes running: " + failure); + } + CloseHandle(lease.job); + lease.job = nullptr; + } // A mutation abandoned against an application this helper launched can no // longer land once that process is verified gone, so closing it ends the @@ -1293,6 +1636,12 @@ void ApplicationManager::Dispose(const CancellationToken& token) { terminationErrors.emplace(process, GetLastError()); } } + for (const std::string& leaseId : leaseIds) { + const auto entry = leases_.find(leaseId); + if (entry != leases_.end() && entry->second.job != nullptr) { + TerminateJobObject(entry->second.job, 1); + } + } waitForOwnedProcesses(kDisposeForcedMs); for (auto iterator = pendingCleanupProcesses_.begin(); @@ -1333,7 +1682,15 @@ void ApplicationManager::Dispose(const CancellationToken& token) { DescribeHresult(HRESULT_FROM_WIN32(terminationError->second)); continue; } - CloseApplication(leaseId, token); + // One lease whose contained processes outlive it must not keep the others open. + try { + CloseApplication(leaseId, token); + } catch (const HelperError& error) { + if (!failures.empty()) { + failures += "; "; + } + failures += error.what(); + } } if (!failures.empty()) { Fail(kErrorCleanupFailed, "Disposing native application leases failed: " + failures); @@ -1548,6 +1905,7 @@ json::Value ApplicationManager::SerializeLease(const ApplicationLease& lease) co json::Value value = json::Value::Object(); value.Set("id", json::Value::String(lease.id)); value.Set("ownership", json::Value::String(lease.ownership)); + value.Set("containment", json::Value::String(lease.containment)); value.Set("processId", json::Value::Integer(static_cast(lease.processId))); const std::string started = FormatFileTimeIso8601(lease.startTime); if (!started.empty()) { diff --git a/packages/agentic/desktop-driver/native/windows/src/application.h b/packages/agentic/desktop-driver/native/windows/src/application.h index 56daaa156c..e1a1426653 100644 --- a/packages/agentic/desktop-driver/native/windows/src/application.h +++ b/packages/agentic/desktop-driver/native/windows/src/application.h @@ -8,10 +8,12 @@ #include #include #include +#include #include #include "common.h" #include "events.h" +#include "inputauthority.h" #include "json.h" namespace furn { @@ -24,21 +26,36 @@ struct WindowInfo { bool primary{false}; }; +// How far the helper's ownership of a leased application reaches. +// kContainmentJobObject: an unpackaged launch and every descendant run in a +// Job Object this helper created, which ends them on close or helper exit. +// kContainmentUncontained: a packaged activation. Windows creates the process, +// so only the activated process or verified descendant whose window is +// leased is owned, without a containment job. +// kContainmentExternal: an attached application this helper never owns. +inline constexpr char kContainmentJobObject[] = "job-object"; +inline constexpr char kContainmentUncontained[] = "uncontained"; +inline constexpr char kContainmentExternal[] = "external"; + struct ApplicationLease { std::string id; std::string ownership; // "attached" or "launched" + std::string containment; std::string endpoint; std::string storyRootTestId; DWORD processId{0}; FILETIME startTime{}; std::wstring windowTitle; HANDLE process{nullptr}; + // The containment Job Object of a kContainmentJobObject launch, else null. + HANDLE job{nullptr}; HWND primaryWindow{nullptr}; }; // Owns application identity, launch/attach leases, and the opaque window table. -// Attached applications are never terminated; owned launches close only the -// exact windows and process that this helper created. +// Attached applications are never terminated or placed in a Job Object; owned +// launches close only the exact windows, process, and contained descendants +// that this helper created. class ApplicationManager { public: ~ApplicationManager(); @@ -81,6 +98,9 @@ class ApplicationManager { // monitor to inject notifications. const ApplicationLease& AdoptWindowForTesting(HWND window, const std::wstring& title); WindowEventMonitor& WindowEventsForTesting() { return windowEvents_; } + void UseLeaseRegistrationHookForTesting(std::function hook) { + leaseRegistrationHookForTesting_ = std::move(hook); + } private: static constexpr std::size_t kMaximumRetiredWindowIds = 256; @@ -107,7 +127,8 @@ class ApplicationManager { bool ForegroundBelongsToLease(const ApplicationLease& lease, HWND foreground) const; json::Value PublicationDiagnostic(const ApplicationLease& lease) const; ApplicationLease& CreateLease(std::string ownership, DWORD processId, HANDLE process, HWND primaryWindow, - const std::wstring& title, const json::Value& params); + const std::wstring& title, const json::Value& params, + std::string containment, HANDLE job = nullptr); void TrackPendingCleanupProcess(DWORD processId, HANDLE process); struct PendingCleanupProcess { @@ -127,6 +148,7 @@ class ApplicationManager { std::unordered_set retiredIds_; std::vector pendingRetirements_; WindowEventMonitor windowEvents_; + std::function leaseRegistrationHookForTesting_; }; std::vector EnumerateTopLevelWindows(DWORD processId); @@ -135,7 +157,28 @@ std::wstring ReadWindowTitle(HWND window); bool TryReadProcessStartTime(HANDLE process, FILETIME& startTime); std::wstring ReadProcessImagePath(HANDLE process); std::wstring QuoteWindowsCommandLineArgument(std::wstring_view value); +// Fails with `failureCode` unless `processId` runs in this helper's Windows +// session. An unreadable session is refused rather than assumed. +void RequireProcessInHelperSession(DWORD processId, std::string_view failureCode); void ActivateWindow(HWND window, const CancellationToken& token); bool TryActivateWindow(HWND window, const CancellationToken& token); +// What the helper saw when Windows kept the foreground away from a window it +// tried to activate. Foreign windows are named only by an opaque handle and +// their process id, never by title or class. +struct ActivationRefusal { + bool sawForeground{false}; + // Empty when no window held the foreground at the end of the attempt. + std::string foreground; + DWORD foregroundProcess{0}; + bool foregroundInTargetProcess{false}; + bool foregroundHung{false}; + ProcessIntegrity foregroundIntegrity; + ProcessIntegrity helperIntegrity; + // The Windows error of the latest refused input-queue attachment, or 0. + DWORD attachError{0}; +}; + +std::string DescribeActivationRefusal(const ActivationRefusal& refusal); + } // namespace furn diff --git a/packages/agentic/desktop-driver/native/windows/src/selftest.cpp b/packages/agentic/desktop-driver/native/windows/src/selftest.cpp index a357f57b6d..d08bd1a0ba 100644 --- a/packages/agentic/desktop-driver/native/windows/src/selftest.cpp +++ b/packages/agentic/desktop-driver/native/windows/src/selftest.cpp @@ -1242,6 +1242,37 @@ void TestWindowCloseWithoutEvents() { "a window this helper never issued is reported as untracked"); } +void TestLeaseRegistrationFailure() { + WindowThread windows; + const HWND window = windows.Create(L"FurnSelfTestLeaseFailure", L"Lease failure window"); + ApplicationManager applications; + HANDLE attemptedProcess = nullptr; + applications.UseLeaseRegistrationHookForTesting([&](HANDLE process, HANDLE) { + attemptedProcess = process; + throw std::runtime_error("Injected lease registration failure."); + }); + bool failed = false; + try { + applications.AdoptWindowForTesting(window, L"Lease failure window"); + } catch (const std::runtime_error&) { + failed = true; + } + DWORD flags = 0; + SetLastError(ERROR_SUCCESS); + Check(failed && attemptedProcess != nullptr && GetHandleInformation(attemptedProcess, &flags) == FALSE && + GetLastError() == ERROR_INVALID_HANDLE, + "failed lease registration closes the process handle"); + Check(applications.PrimaryLease() == nullptr && + !applications.WindowEventsForTesting().IsObserving(GetCurrentProcessId()), + "failed lease registration removes the lease and its event observation"); + + applications.UseLeaseRegistrationHookForTesting({}); + const std::string leaseId = applications.AdoptWindowForTesting(window, L"Lease failure window").id; + Check(applications.WindowIdsForLease(leaseId).size() == 1, + "a new lease can register the window after a failed registration"); + applications.CloseApplication(leaseId, CancellationToken{}); +} + void TestAttachedCloseKeepsQuarantine() { ResetMutationQuarantineForTesting(); WindowThread windows; @@ -1639,6 +1670,86 @@ void TestInjectionIntegrity() { "integrity levels are named for the messages that report them"); } +void TestActivationRefusal() { + const auto level = [](DWORD value) { + ProcessIntegrity integrity; + integrity.known = true; + integrity.level = value; + return integrity; + }; + ActivationRefusal held; + held.sawForeground = true; + held.foreground = "hwnd:0000002a"; + held.foregroundProcess = 4242; + held.helperIntegrity = level(SECURITY_MANDATORY_MEDIUM_RID); + held.foregroundIntegrity = level(SECURITY_MANDATORY_MEDIUM_RID); + + ActivationRefusal desktopless; + Check(Contains(DescribeActivationRefusal(desktopless), "no interactive foreground desktop"), + "a session without any foreground window reports that there is no interactive desktop"); + + ActivationRefusal lost = held; + lost.foreground.clear(); + Check(Contains(DescribeActivationRefusal(lost), "secure desktop"), + "a foreground lost during activation names locking, disconnection, or a secure desktop"); + + ActivationRefusal sibling = held; + sibling.foregroundInTargetProcess = true; + sibling.foregroundIntegrity = level(SECURITY_MANDATORY_HIGH_RID); + Check(Contains(DescribeActivationRefusal(sibling), "another window of the target application"), + "a foreground window of the target's own process is reported before integrity"); + + ActivationRefusal elevated = held; + elevated.foregroundIntegrity = level(SECURITY_MANDATORY_HIGH_RID); + elevated.attachError = ERROR_ACCESS_DENIED; + const std::string elevatedMessage = DescribeActivationRefusal(elevated); + Check(Contains(elevatedMessage, "runs at high integrity and this helper at medium") && + Contains(elevatedMessage, "hwnd:0000002a of process 4242"), + "an elevated foreground holder names both integrity levels and the opaque window and process"); + + ActivationRefusal unreadable = held; + unreadable.foregroundIntegrity = ProcessIntegrity{}; + unreadable.foregroundIntegrity.error = ERROR_ACCESS_DENIED; + Check(Contains(DescribeActivationRefusal(unreadable), "probably elevated"), + "a foreground holder whose token cannot be read is reported as probably elevated"); + + ActivationRefusal hung = held; + hung.foregroundHung = true; + hung.attachError = ERROR_ACCESS_DENIED; + Check(Contains(DescribeActivationRefusal(hung), "is not responding"), + "a hung foreground holder is reported before a refused attachment"); + + ActivationRefusal refused = held; + refused.attachError = ERROR_ACCESS_DENIED; + Check(Contains(DescribeActivationRefusal(refused), "input queue") && + Contains(DescribeActivationRefusal(refused), "Windows error 5"), + "a refused input-queue attachment names its Windows error"); + + const std::string reclaimed = DescribeActivationRefusal(held); + Check(Contains(reclaimed, "taking the foreground back") && + Contains(reclaimed, "did not become the foreground window"), + "a refusal with a shared input queue reports that the holder may take the foreground back"); +} + +void TestHelperSessionCheck() { + bool accepted = true; + try { + RequireProcessInHelperSession(GetCurrentProcessId(), kErrorAttachFailed); + } catch (const HelperError&) { + accepted = false; + } + Check(accepted, "the helper's own process runs in the helper's session"); + + std::string refusedCode; + try { + RequireProcessInHelperSession(0xFFFFFFF0u, kErrorLeaseInvalid); + } catch (const HelperError& error) { + refusedCode = error.code(); + } + Check(refusedCode == kErrorLeaseInvalid, + "a process whose session cannot be read is refused with the caller's failure code"); +} + void TestInputAuthorityOnThisMachine() { const ProcessIntegrity self = ReadProcessIntegrity(0); Check(self.known && self.level >= SECURITY_MANDATORY_LOW_RID, "the helper reads its own integrity level"); @@ -3324,11 +3435,14 @@ int RunSelfTest() { TestWindowEventPublisher(); TestWindowEventRegistration(); TestWindowCloseWithoutEvents(); + TestLeaseRegistrationFailure(); TestAttachedCloseKeepsQuarantine(); TestWindowEventHooks(); TestDriverWindowEvents(); TestInputEnvironment(); TestInjectionIntegrity(); + TestActivationRefusal(); + TestHelperSessionCheck(); TestInputAuthorityOnThisMachine(); TestInputReevaluation(); TestKeyboardGuard(); diff --git a/packages/agentic/desktop-driver/references/current-status.md b/packages/agentic/desktop-driver/references/current-status.md index a08eb0a78e..fd1818ac11 100644 --- a/packages/agentic/desktop-driver/references/current-status.md +++ b/packages/agentic/desktop-driver/references/current-status.md @@ -35,7 +35,7 @@ and its sub-issues, which record dependencies and parallel waves. | Story catalog/select/reset | Done, experimental integration | Local lifetime/signal context, authenticated epochs persisted per native-verified app incarnation, versioned marker conformance, prompt disconnect failure, and stale preview rejection. Bounded macOS Paper/Fabric marker and stale-reference checks passed at `6fca14788`; native cancellation/fault injection remain unqualified. Unknown navigation effects still quarantine. | | Story args on protected driver | Intentionally unsupported | `story-args-unsupported`, including the session-owning grant and controlled orchestrator. HTTP and foreign WebSocket args are refused/not relayed without logging values; legacy unprotected args remain separate. | | Exclusive Storybook control | Work in progress: native qualification | Deterministic endpoint evidence: controlled HTTP mutations return 403; foreign WS selection/prepare/args never reach the runtime; authenticated driver prepare/select uses F4 settlement and fencing. Non-agent channel remains legacy unprotected. Native endpoint evidence not yet run: macOS Paper/Fabric, Windows Fabric/Win32 Paper. Preview context checks preserve chrome/secondary references. | -| Supervisor crash containment and automatic reclaim | Work in progress outside driver | Exact ownership ledger, surviving-resource reconciliation, and lifelines belong to desktop-test. | +| Supervisor crash containment and automatic reclaim | Work in progress outside driver | Exact ownership ledger, surviving-resource reconciliation, and lifelines belong to desktop-test. The Windows helper's Job Object ends an unpackaged application it launched when the helper dies; packaged launches are `uncontained`. | | Application-exit/reconnect continuity | Work in progress | Bounded macOS Paper/Fabric full-service restart checks passed at `6fca14788`: private authenticated-epoch record plus exact live-incarnation proof yields renderer-specific relaunch-required, effect none. Initial absence and exited/replaced apps stay bridge-unavailable; failed/unknown probes are contract-tested only. No transparent restoration or quarantine recovery; inspected RN Storybook 10.5.4 / Storybook 10.6.3 transport does not reconnect. | | Recording/replay export, event-tail API, visual comparison | Work in progress/deferred | No agent-session-to-WDIO export; window-events still returns its full bounded ring. | | Intel macOS and distributed/remote control | Unsupported | Current macOS helper is arm64; service is loopback-only. | @@ -412,3 +412,32 @@ Processes, listeners, per-user claim, and default descriptor were absent after cleanup. Artifacts remain under `apps/storybook/artifacts/desktop//run.json`; earlier reporting and physical-input failures are not erased. + +## 2026-11-08 UTC Windows application ownership and foreground diagnosis + +Source `9d3e11516` plus the Windows helper changes for +[#4441](https://github.com/microsoft/fluentui-react-native/issues/4441) and +F10-W ([#4447](https://github.com/microsoft/fluentui-react-native/issues/4447)). +Same host, with the console session disconnected throughout. + +- **Foreground diagnosis (#4441).** Activation now re-attaches to the + foreground holder when it changes during an attempt, and + `window-activation-failed` names the holder by opaque handle and process id + with its cause. The helper self-test covers each cause; a live physical + click on Windows Fabric was not rerun, so that row stays Fail. +- **Application ownership (F10-W).** Leases report `containment`. Unpackaged + launches run in a helper-owned Job Object and end with the helper; + packaged launches are `uncontained` and survive it in a fenced claim; + attach is `external` and fails closed. The fixture contracts and live REX + and packaged-Storybook launch probes passed, which moves launch-capable + discovery to Pass on both endpoints. Runs and survivor handling are in + `packages/agentic/desktop-test/references/current-status.md`. +- **Measurements.** Windows Fabric and Win32 Paper discovery, observe, delta, + and toggle text and latency are now recorded in + `packages/agentic/desktop-driver-mcp/references/current-status.md`. On + Windows Fabric three React Native Test App menu-bar items get new + references on every read, so an idle `delta` is never empty. +- **Connected fixture rerun.** All 11 `win32Fixture` cases passed, including + window capture and 500-cycle retention (20 retained elements at cycles 100 + and 500). Separately registered secondary windows and Win32 fresh-preview + fencing remain unqualified. diff --git a/packages/agentic/desktop-driver/references/remaining-work.md b/packages/agentic/desktop-driver/references/remaining-work.md index 08e4cb8eb8..e5e39c63c8 100644 --- a/packages/agentic/desktop-driver/references/remaining-work.md +++ b/packages/agentic/desktop-driver/references/remaining-work.md @@ -550,16 +550,16 @@ Source ownership follows [contributing](contributing.md), The [Windows provider](../native/windows/README.md) is shared, but Windows Fabric and Win32 Paper retain distinct app/runtime behavior and qualification. -| Work area | Source owner | Remaining evidence | -| ------------------------ | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Incremental UIA reads | `native/windows/src/automation.cpp` and `native/windows/src/driver.cpp` | `observe` is implemented ([contract](../native/windows/README.md#bounded-observation)): it pages siblings one call at a time, so every budget applies mid-level, and a 10,000-item fixture tree returns a 5,000-node partial sample. Remaining: `tree` and `find` still cache the whole subtree and fail `tree-too-large`, incomplete searches must never authorize unique mutation. `observe` has paged real React Native trees ([M3](#m3-implement-bounded-native-observations-and-identities-on-both-oses)). | -| Identity and reclamation | UIA records, window/process records, SessionManager | Windows implemented ([contract](../native/windows/README.md#element-identity-and-retention)), including pinned `observe` records and `releaseElements`. Remaining: macOS token-recycling evidence (ids are never reused and actions check the pid and role; fingerprints wait on it), and PID reuse against a real application. Real React Native sessions on Windows Fabric and Win32 Paper reached a retention plateau ([M3](#m3-implement-bounded-native-observations-and-identities-on-both-oses)). | -| Actions and settlement | UIA mutation worker and FDR1 dispatch | Windows implemented ([contract](../native/windows/README.md#unsettled-mutations), [effects](../native/windows/README.md#mutation-effects)) and qualified against the stuck and hung Win32 fixture, directly and behind a protected service. Remaining: quarantine persistence and the trusted `recover` operation (M2), re-observing application effects after a late completion, a genuinely hung React Native app, and real UIA failures to confirm which provider errors are safe to classify as `none`. | -| Input authority | `native/windows/src/input.cpp` and application activation | Windows implemented ([contract](../native/windows/README.md#input-authority)), and the Win32 Paper smoke passed physical pointer and keyboard actions. Remaining: live lock, RDP disconnect, and elevation transitions (the self-test injects them), a `uiAccess` decision, delivery evidence for `SendInput` beyond its return value, and foreground matching that is finer than the owning process. | -| Events | UIA MTA worker and bounded event dispatch | Windows implemented with `WinEvent` hooks ([contract](../native/windows/README.md#window-events-and-identity)): callbacks enqueue on a dedicated thread without provider calls, overflow is bounded, and `IsWindow` polling is the fallback. Remaining: event delivery across integrity levels, same-class handle recycling whose destroy event is lost, and UIA structure-change events (not used). | -| Application ownership | `native/windows/src/application.cpp` and trusted supervisor | Not started: packaged AUMID and unpackaged executable identity under duplicate or changing titles, ACL validation, stale claims, and Job Object restrictions. The fixture has only a lifetime watchdog. | -| Popups and islands | UIA traversal and window ownership | Owned dialogs verified: the fixture rejects owner clicks and publishes destroy events, and a real native Callout test passed on Win32 Paper. Remaining: menu popups, which need activation to open and so are unqualified, and Fabric islands. | -| Geometry and capture | Windows geometry/capture modules | Window/element PNG capture, physical hit-tested click, and crop alignment are verified on the fixture at 100% and 150%. Remaining: 200% and mixed-DPI monitor moves, negative origins, minimized windows, cancellation during capture, and React Native application qualification. | +| Work area | Source owner | Remaining evidence | +| ------------------------ | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| Incremental UIA reads | `native/windows/src/automation.cpp` and `native/windows/src/driver.cpp` | `observe` is implemented ([contract](../native/windows/README.md#bounded-observation)): it pages siblings one call at a time, so every budget applies mid-level, and a 10,000-item fixture tree returns a 5,000-node partial sample. Remaining: `tree` and `find` still cache the whole subtree and fail `tree-too-large`, incomplete searches must never authorize unique mutation. `observe` has paged real React Native trees ([M3](#m3-implement-bounded-native-observations-and-identities-on-both-oses)). | +| Identity and reclamation | UIA records, window/process records, SessionManager | Windows implemented ([contract](../native/windows/README.md#element-identity-and-retention)), including pinned `observe` records and `releaseElements`. Remaining: macOS token-recycling evidence (ids are never reused and actions check the pid and role; fingerprints wait on it), and PID reuse against a real application. Real React Native sessions on Windows Fabric and Win32 Paper reached a retention plateau ([M3](#m3-implement-bounded-native-observations-and-identities-on-both-oses)). The React Native Test App's React, Debug, and System menu-bar items on Windows Fabric get a new reference on every read; each idle `delta` reports them as removed and added (about 200 tokens). Reference reuse requires a matching UIA runtime identity, but the cause of this churn is unconfirmed. Confirm their runtime identity before choosing a stable fallback key. | +| Actions and settlement | UIA mutation worker and FDR1 dispatch | Windows implemented ([contract](../native/windows/README.md#unsettled-mutations), [effects](../native/windows/README.md#mutation-effects)) and qualified against the stuck and hung Win32 fixture, directly and behind a protected service. Remaining: quarantine persistence and the trusted `recover` operation (M2), re-observing application effects after a late completion, a genuinely hung React Native app, and real UIA failures to confirm which provider errors are safe to classify as `none`. | +| Input authority | `native/windows/src/input.cpp` and application activation | Windows implemented ([contract](../native/windows/README.md#input-authority)), and the Win32 Paper smoke passed physical pointer and keyboard actions. Activation re-attaches to a changed foreground holder, and a refusal names the holder and its cause ([#4441](https://github.com/microsoft/fluentui-react-native/issues/4441)); the cause classification is self-tested, but a live Windows Fabric physical click has not been rerun. Remaining: that rerun, live lock, RDP disconnect, and elevation transitions (the self-test injects them), a `uiAccess` decision, delivery evidence for `SendInput` beyond its return value, and foreground matching that is finer than the owning process. | +| Events | UIA MTA worker and bounded event dispatch | Windows implemented with `WinEvent` hooks ([contract](../native/windows/README.md#window-events-and-identity)): callbacks enqueue on a dedicated thread without provider calls, overflow is bounded, and `IsWindow` polling is the fallback. Remaining: event delivery across integrity levels, same-class handle recycling whose destroy event is lost, and UIA structure-change events (not used). | +| Application ownership | `native/windows/src/application.cpp` and trusted supervisor | Implemented ([F10-W](https://github.com/microsoft/fluentui-react-native/issues/4447), [contract](../native/windows/README.md#application-identity)): an unpackaged launch runs inside a helper-owned kill-on-close Job Object (`job-object`), a packaged activation is `uncontained`, attach is `external` and fails closed on unreadable or cross-session identity, and the lease reports `containment`. Qualified with the fixture contracts and REX and packaged Storybook launch probes. Remaining: naming a launched application in the workload claim so a fenced claim identifies an uncontained survivor (F11), breakaway-requiring apps, and graceful descendant close. | +| Popups and islands | UIA traversal and window ownership | Owned dialogs verified: the fixture rejects owner clicks and publishes destroy events, and a real native Callout test passed on Win32 Paper. Remaining: menu popups, which need activation to open and so are unqualified, and Fabric islands. | +| Geometry and capture | Windows geometry/capture modules | Window/element PNG capture, physical hit-tested click, and crop alignment are verified on the fixture at 100% and 150%. Remaining: 200% and mixed-DPI monitor moves, negative origins, minimized windows, cancellation during capture, and React Native application qualification. | Keep UIA operations on correctly initialized/marshaled COM workers. Document the bounded-call settlement strategy explicitly; abandoning a thread and diff --git a/packages/agentic/desktop-driver/src/host/types.ts b/packages/agentic/desktop-driver/src/host/types.ts index 13b2541ed7..9e4df0031f 100644 --- a/packages/agentic/desktop-driver/src/host/types.ts +++ b/packages/agentic/desktop-driver/src/host/types.ts @@ -80,6 +80,12 @@ export type DesktopHostInfo = { }; export type ApplicationLease = { + /** + * How far the provider's ownership reaches, when it reports it: `job-object` contains an unpackaged Windows launch + * and its descendants, `uncontained` owns only the identity-verified process whose window it leased, and `external` + * is an attached application the provider never ends. Absent from providers that make no containment claim. + */ + containment?: 'external' | 'job-object' | 'uncontained'; id: string; ownership: 'attached' | 'launched'; processId?: number; diff --git a/packages/agentic/desktop-driver/src/native/windows/win32Fixture.contract.test.ts b/packages/agentic/desktop-driver/src/native/windows/win32Fixture.contract.test.ts index e3bd57bee7..c64c1aaa41 100644 --- a/packages/agentic/desktop-driver/src/native/windows/win32Fixture.contract.test.ts +++ b/packages/agentic/desktop-driver/src/native/windows/win32Fixture.contract.test.ts @@ -4,6 +4,11 @@ // desktop: yarn test --runInBand win32Fixture. Only the first two scenarios show a window (topmost, non-activating, for // about a second each); the others keep it off every monitor, and none of them steals the foreground. A runner that // disables input through the host policy skips the capture scenario (see windowsContractTest). +import { spawn } from 'node:child_process'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; + import { NativeHostProcess } from '../../hosts/native/NativeHostProcess'; import type { NativeHostRequestResult } from '../../hosts/native/NativeHostProcess'; import type { NativeObserveRequest } from '../../host/types'; @@ -20,7 +25,7 @@ const captureTest = windowsContractTest('capture'); const megabyte = 1024 * 1024; type Rect = { height: number; width: number; x: number; y: number }; -type Lease = { id: string; processId: number }; +type Lease = { containment?: string; id: string; ownership?: string; processId: number }; type WindowInfo = { id: string; rect: Rect; title: string }; type ElementInfo = { automationId?: string; id: string; name?: string; rect: Rect; role: string }; type Retention = { privateBytes: number; retainedElementLimit: number; retainedElements: number; workingSetBytes: number }; @@ -442,4 +447,99 @@ describe('Windows helper against a plain Win32 application', () => { await session.dispose(); } }); + + windowsTest('contains an unpackaged launch with its descendants and ends them all when it closes', async () => { + const pidFile = path.join(os.tmpdir(), `furn-fixture-descendant-${process.pid}-${Date.now()}.txt`); + const session = await FixtureSession.start('contained', { args: ['--child-pid-file', pidFile] }); + let descendant: number | undefined; + try { + expect(session.lease).toMatchObject({ containment: 'job-object', ownership: 'launched' }); + ({ descendant } = await readDescendant(pidFile)); + expect(isRunning(descendant)).toBe(true); + + await session.call('closeApplication', { lease: session.lease }); + expect(isRunning(session.lease.processId)).toBe(false); + expect(isRunning(descendant)).toBe(false); + } finally { + await session.dispose(); + endStray(descendant); + fs.rmSync(pidFile, { force: true }); + } + }); + + windowsTest('ends a contained launch and its descendants when the helper exits without closing them', async () => { + const pidFile = path.join(os.tmpdir(), `furn-fixture-orphan-${process.pid}-${Date.now()}.txt`); + const session = await FixtureSession.start('orphan', { args: ['--child-pid-file', pidFile] }); + let descendant: number | undefined; + try { + const published = await readDescendant(pidFile); + descendant = published.descendant; + const helper = required((session.host as unknown as { child: { pid?: number } }).child.pid, 'the helper process id'); + expect(published.parent).toBe(helper); + + process.kill(helper); + await waitFor( + 'the contained processes to end with the helper', + async () => !isRunning(session.lease.processId) && !isRunning(published.descendant), + { + timeoutMs: 10_000, + }, + ); + } finally { + await session.dispose(); + endStray(session.lease.processId); + endStray(descendant); + fs.rmSync(pidFile, { force: true }); + } + }); + + windowsTest('attaches to an application it did not launch without containing, closing, or disposing it', async () => { + const title = `furn-fixture-external-${process.pid}-${Date.now()}`; + const executablePath = await fixtureExecutable(); + const external = spawn(executablePath, ['--title', title, '--offscreen', '1', '--lifetime-ms', '120000'], { stdio: 'ignore' }); + const host = await NativeHostProcess.start({ artifact: await helperArtifact() }); + try { + const lease = await waitFor( + 'the external fixture to accept an attach', + async () => + (await host.request('attach', { application: { executablePath, windowTitle: title } }).catch(() => undefined))?.result, + { intervalMs: 100, timeoutMs: 20_000 }, + ); + expect(lease).toMatchObject({ containment: 'external', ownership: 'attached', processId: external.pid }); + + await host.request('closeApplication', { lease }); + await host.dispose(); + expect(isRunning(required(external.pid, 'the external fixture process id'))).toBe(true); + } finally { + await host.dispose().catch(() => undefined); + external.kill(); + } + }); }); + +function isRunning(processId: number): boolean { + try { + process.kill(processId, 0); + return true; + } catch (error) { + return (error as NodeJS.ErrnoException).code === 'EPERM'; + } +} + +// Ends a process a failed scenario left behind; the scenarios themselves prove that cleanup. +function endStray(processId: number | undefined): void { + if (processId !== undefined && isRunning(processId)) { + process.kill(processId); + } +} + +function readDescendant(file: string): Promise<{ descendant: number; parent: number }> { + return waitFor( + 'the fixture to publish its descendant', + async () => { + const [descendant, parent] = fs.existsSync(file) ? fs.readFileSync(file, 'utf8').trim().split(' ').map(Number) : []; + return descendant > 0 && parent > 0 ? { descendant, parent } : undefined; + }, + { timeoutMs: 10_000 }, + ); +} diff --git a/packages/agentic/desktop-test/references/current-status.md b/packages/agentic/desktop-test/references/current-status.md index 610a03a16f..5292e9cf67 100644 --- a/packages/agentic/desktop-test/references/current-status.md +++ b/packages/agentic/desktop-test/references/current-status.md @@ -17,25 +17,25 @@ and its sub-issues. ## Capability matrix -| Capability | State | Limit or next gate | -| -------------------------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| App/suite configuration and standalone installed-app use | Done | Storybook is optional; runtime boundary and standalone-consumer contracts reject React, React Native, and Storybook imports/dependencies. Executable config is trusted operator code, not a sandbox. | -| Native service and helper composition | Done | Generic supervisor and supervised Storybook child use the same real `driverService` factory, helper policy, authority and settled close. | -| Standalone WDIO/Jasmine execution | Done | WDIO owns its session. Storybook CSF callbacks use a runner-owned session borrowed by a Node worker. | -| Required services, reporting, structured results | Done | One collector; bounded JSON/NDJSON summaries. Service-ready is not app/context-ready. | -| `serve --agent` descriptor publication | Done | Protects driver routes; no automatic build/launch from MCP. Normal WDIO cannot use the agent-served path yet. | -| Cleanup failure fence | Done, conservative | Failed or timed-out disposal retains the claim with an exact resource generation and unresolved effect; manual inspection is required. No automatic reclaim. | -| Complete lifecycle settlement | Done, conservative | Guarded work settles before successful close; late acquisitions are disposed; required-service failures stop dependants; owned resources dispose in reverse order. | -| Typed generic resource contributions | Done | Static contribution plans validate IDs/dependencies and record readiness, generation, identity, ownership, and settled disposal through public `resources` and `ownership` subpaths. | -| Durable quarantine wiring | Done | Both native service paths use owner-only storage and exact-incarnation probes; restart is not recovery proof. Live endpoint qualification remains separate. | -| Supervisor crash containment | Work in progress | Cooperative Node service lifelines and correlated service readiness implemented; portable parent/wrapper crash, late-spawn, failed-withdrawal and stalled-child contracts. Live macOS survivors and Windows containment remain unqualified; no automatic reclaim. Windows: non-detached children are hard-terminated with a crashed owner (observed A/B), so the three crash-disposal contracts are skipped there. | -| Storybook resource contributions | Work in progress | Current integration substitutes its CLI lifecycle; retain the channel/driver child until relocation is justified and qualified. | -| MCP/WDIO handoff | Work in progress | Must await drain/deletion; attached-app handoff is independent of future supervisor-owned launch. | -| Supervisor-owned app lifetime | Work in progress | Current session-owned launch/externally owned attach semantics remain; never silently retain or terminate another owner's app. | -| Cross-service/multi-target claims | Work in progress | Configured aliases now have distinct registered IDs while retaining physical identity; exact-application exclusion and input-mutex qualification remain open. | -| Bounded persisted run/status/artifact queries | Done | Harness-local read service/client; atomic snapshots, terminal evidence, scoped expiring grants, bounded pages and allowlisted opaque artifact IDs. No management transport. | -| Workload management/control API | Work in progress | Future management selects only declared workload IDs, not commands/paths/environment; lifecycle/handoff gates still apply. | -| Automatic service reuse and per-user daemon | Deferred | Requires exact identity/config matching and evidence of need. Never adopt an unknown port occupant. | +| Capability | State | Limit or next gate | +| -------------------------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| App/suite configuration and standalone installed-app use | Done | Storybook is optional; runtime boundary and standalone-consumer contracts reject React, React Native, and Storybook imports/dependencies. Executable config is trusted operator code, not a sandbox. | +| Native service and helper composition | Done | Generic supervisor and supervised Storybook child use the same real `driverService` factory, helper policy, authority and settled close. | +| Standalone WDIO/Jasmine execution | Done | WDIO owns its session. Storybook CSF callbacks use a runner-owned session borrowed by a Node worker. | +| Required services, reporting, structured results | Done | One collector; bounded JSON/NDJSON summaries. Service-ready is not app/context-ready. | +| `serve --agent` descriptor publication | Done | Protects driver routes; no automatic build/launch from MCP. Normal WDIO cannot use the agent-served path yet. | +| Cleanup failure fence | Done, conservative | Failed or timed-out disposal retains the claim with an exact resource generation and unresolved effect; manual inspection is required. No automatic reclaim. | +| Complete lifecycle settlement | Done, conservative | Guarded work settles before successful close; late acquisitions are disposed; required-service failures stop dependants; owned resources dispose in reverse order. | +| Typed generic resource contributions | Done | Static contribution plans validate IDs/dependencies and record readiness, generation, identity, ownership, and settled disposal through public `resources` and `ownership` subpaths. | +| Durable quarantine wiring | Done | Both native service paths use owner-only storage and exact-incarnation probes; restart is not recovery proof. Live endpoint qualification remains separate. | +| Supervisor crash containment | Work in progress | Cooperative Node service lifelines and correlated service readiness implemented; portable parent/wrapper crash, late-spawn, failed-withdrawal and stalled-child contracts. Live macOS survivors remain unqualified; no automatic reclaim. Windows: the helper's Job Object ends an unpackaged app it launched when the helper dies (qualified with REX); packaged launches are `uncontained` and survive in a fenced claim. Non-detached children are hard-terminated with a crashed owner (observed A/B), so the three crash-disposal contracts are skipped there. | +| Storybook resource contributions | Work in progress | Current integration substitutes its CLI lifecycle; retain the channel/driver child until relocation is justified and qualified. | +| MCP/WDIO handoff | Work in progress | Must await drain/deletion; attached-app handoff is independent of future supervisor-owned launch. | +| Supervisor-owned app lifetime | Work in progress | Current session-owned launch/externally owned attach semantics remain; never silently retain or terminate another owner's app. | +| Cross-service/multi-target claims | Work in progress | Configured aliases now have distinct registered IDs while retaining physical identity; exact-application exclusion and input-mutex qualification remain open. | +| Bounded persisted run/status/artifact queries | Done | Harness-local read service/client; atomic snapshots, terminal evidence, scoped expiring grants, bounded pages and allowlisted opaque artifact IDs. No management transport. | +| Workload management/control API | Work in progress | Future management selects only declared workload IDs, not commands/paths/environment; lifecycle/handoff gates still apply. | +| Automatic service reuse and per-user daemon | Deferred | Requires exact identity/config matching and evidence of need. Never adopt an unknown port occupant. | See [lifecycle](lifecycle.md), [commands](commands.md), and `@fluentui-react-native/desktop-driver/references/current-status.md` for the @@ -64,14 +64,14 @@ did not retain a portable raw-report locator; do not imply otherwise. ## Full-submission checklist -| Area | Remaining evidence/work | -| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| macOS | Live failed-cleanup and service-restart cases; Paper separately; supervisor death with Metro/channel/helper survivors; exact attached-app preservation. | -| Windows / Win32 | Same-branch MCP restart/revocation/dispose/args tests; physical console Ctrl+C; interactive input/capture rerun; process-tree containment and ownership checks. | -| Storybook | Authenticated mutation ingress, context fencing/reconnect, consistent helper build policy, manifest provenance and separate nonces. | -| Recovery | Durable uncertainty is wired in both paths; live restart qualification, ledger and exact-resource reconciliation still precede automatic reclaim. | -| Concurrency | No physical-input suites in parallel on one interactive desktop. Separate machines may qualify independent endpoints. | -| Reliability | Establish the required repeated-run window rather than interpreting aggregate past successes as a pass. | +| Area | Remaining evidence/work | +| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| macOS | Live failed-cleanup and service-restart cases; Paper separately; supervisor death with Metro/channel/helper survivors; exact attached-app preservation. | +| Windows / Win32 | Same-branch MCP restart/revocation/dispose/args tests; physical console Ctrl+C and the idle `serve --agent` after interrupt; interactive input/capture rerun; naming launched (especially uncontained packaged) apps in the claim. | +| Storybook | Authenticated mutation ingress, context fencing/reconnect, consistent helper build policy, manifest provenance and separate nonces. | +| Recovery | Durable uncertainty is wired in both paths; live restart qualification, ledger and exact-resource reconciliation still precede automatic reclaim. | +| Concurrency | No physical-input suites in parallel on one interactive desktop. Separate machines may qualify independent endpoints. | +| Reliability | Establish the required repeated-run window rather than interpreting aggregate past successes as a pass. | Tracking: live macOS, Windows, and Win32 requalification [#4441](https://github.com/microsoft/fluentui-react-native/issues/4441); @@ -630,3 +630,68 @@ serially in desktop-test (97 passed, four skipped), desktop-driver (813 passed, 72 skipped), desktop-driver-mcp (26 passed), and scripts (76 passed). The desktop-test `agent-cli` fixture passed without a live smoke workload; no product behavior was changed to suppress that failure. + +## Windows application ownership and foreground follow-up - 2026-11-08 UTC + +Source: `9d3e11516` (F16, stacked on +[#4468](https://github.com/microsoft/fluentui-react-native/pull/4468)) plus +the Windows application-ownership (F10-W, +[#4447](https://github.com/microsoft/fluentui-react-native/issues/4447)) and +foreground-diagnosis +([#4441](https://github.com/microsoft/fluentui-react-native/issues/4441)) +helper changes. Same Windows 11 Enterprise build 26300, AMD64 host; Node +26.13.0. The console session was **disconnected** (RDP, `LogonUI` in the +session) for the launch and measurement cases below. Foreground, physical input, +Windows Graphics Capture, and retention require separate connected-session +evidence. + +**Updated matrix: Windows Fabric 22 Pass, 1 Partial, 1 Fail; Win32 Paper +22 Pass, 2 Partial.** Launch-capable discovery moves from Partial to Pass on +both endpoints. Separately registered secondary windows (both), Win32 +fresh-preview fencing, and Windows physical input keep their earlier results; +they need a connected, unlocked session. + +| Case | Windows Fabric | Win32 Paper | +| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Launch-capable discovery | Pass. `desktop_session` status listed `launchModes: ['launch']`; `open` launched the packaged app in 341 ms and `close` ended `ReactApp.exe`. Run `0876d93b-f689-47e5-8379-4c09d95d6cc9`. | Pass. REX FluentTester (`apps/win32`) listed `['launch']`; `open` launched in 625 ms and `close` ended `ReactTest.exe`. Run `101c5916-027d-40cf-a26a-163535df4c03`. | +| Attach-only refusal | Unchanged: Storybook targets are always attach-only and advertise only `attach`. | Pass: the Storybook Win32 target refused `launch` before acquiring resources (run `411c5218`). | +| Helper death after launch | Expected `uncontained`: killing the helper left the packaged `ReactApp.exe` running. The claim was fenced (`webdriver` disposal failed, one unresolved effect). The survivor was ended manually after its identity was checked. | Pass, `job-object`: killing the helper ended `ReactTest.exe` within 5 s. The claim was fenced the same way. | +| Agent MCP measurements | Recorded in the adapter's status reference (run `caba9e12-d9da-42a0-8b06-7300940e8318`). | Recorded there (run `5f75aac2-d74c-4969-aba3-bd8c925d5725`). | + +The launch-capable targets are not Storybook targets. Win32 used +`apps/win32/desktop.config.mts`. Windows used a temporary, uncommitted +`installed` host naming the registered Storybook package AUMID; the +committed Storybook targets are attach-only. Each probe used the SDK stdio +client and the default descriptor. In both crash variants the service exited +with code 1 and wrote a failed `run.json` naming the helper's unexpected +exit. Neither the claim nor the settlement journal names the surviving +uncontained application, because the journal records applications only for +mutations and quarantines. Recording a launched application as a claim +resource belongs to F11's retained-application handoff +([#4448](https://github.com/microsoft/fluentui-react-native/issues/4448)). + +**Native contracts.** With `FURN_NATIVE_DRIVER_TEST=1`, `nativeDriver` +passed. While the session was still connected, `win32Fixture` passed 17 with +2 skipped, before review fixes. While disconnected, the three new +containment cases passed, but window capture and the 500-cycle retention +case failed. The retention case grew from 316 to 1,516 retained elements, +exactly three per cycle. A control run of the same case on the unchanged +helper failed identically while disconnected. After reconnection, +`FURN_NATIVE_DRIVER_TEST=1 yarn test win32Fixture --runInBand` passed all +11 cases, including capture and retention: retained elements stayed at 20 +from cycle 100 through cycle 500. + +**`serve --agent` interrupt.** Interrupting a Storybook `serve --agent` with +a console Ctrl+C three times (Win32 runs `411c5218` and `5f75aac2`, Windows +run `caba9e12`) settled every owned +resource. Metro, the channel, the helper, and the descriptor were gone, and +the ports were free. The claim then stayed `active` with no unsettled +resource or unresolved effect, `run.json` stayed `incomplete`, and the CLI +process stayed idle without exiting. Each time, the exact owner was ended +only after that proof, and then its stale claim was removed. The physical +console Ctrl+C case is otherwise out of scope for this pass. + +**Reconciled claims.** Every stale or fenced claim in this pass was removed +by hand only after its owner was proved dead and its resources were proved +settled, or after the fenced launch probe's survivor was ended. Nothing +reclaims a claim automatically. diff --git a/packages/agentic/desktop-test/references/native-qualification.md b/packages/agentic/desktop-test/references/native-qualification.md index 46ae480346..9a26805786 100644 --- a/packages/agentic/desktop-test/references/native-qualification.md +++ b/packages/agentic/desktop-test/references/native-qualification.md @@ -201,6 +201,15 @@ Windows: `--windows` is always Fabric and `--win32` is always Paper. app return `relaunch-required`; recovery needs an app relaunch. - An externally stopped `storybook run` exits nonzero and writes a failed `run.json`. Record it as expected for that case; it is not a driver failure. +- Win32's production bundle embeds the instance it connects to. Before + `run --win32` against an agent-served instance, rebundle with that + instance's environment as described in + `@fluentui-react-native/storybook-desktop/references/platforms/win32.md`; + a stale bundle never reaches the channel. +- A console Ctrl+C to `desktop-test serve --agent` has left the CLI idle after + every resource settled, with its claim still `active` and `run.json` + `incomplete`. Record that, prove the owner and resources as in + [cleanup](#cleanup-and-endpoint-limits), and end only that process. - If `storybook run --windows` fails while enabling Developer Mode, do not change that OS setting for qualification. An already installed, verified app can instead be launched by its exact AUMID resolved from the built diff --git a/packages/agentic/storybook-desktop/references/platforms/win32.md b/packages/agentic/storybook-desktop/references/platforms/win32.md index 3bdbc5992c..bc8cc78dde 100644 --- a/packages/agentic/storybook-desktop/references/platforms/win32.md +++ b/packages/agentic/storybook-desktop/references/platforms/win32.md @@ -11,6 +11,19 @@ Win32 is the prebuilt REX Paper host. Bundle before run; native app build is unsupported. Use `yarn storybook bundle --win32` and `yarn storybook smoke --win32 --mode stories` (or `stories-and-tests`). +The production bundle embeds the Storybook instance it connects to: the +channel port and instance id, plus the driver manifest's bridge nonce and +digests when bundled with one. `smoke --win32` bundles with its own instance, +but `bundle --win32` and `run --win32` pass none, so a plain bundle connects to +port 7007 without a bridge nonce. Before `run --win32` against +`driver --win32 --agent` or `desktop-test serve --agent`, rebundle from the app +with the serving instance's `STORYBOOK_WS_PORT` (its `storybookPort`), +`FURN_STORYBOOK_INSTANCE_ID` (its `instanceId`), `FURN_STORYBOOK_PLATFORM=win32`, +and `STORYBOOK_DRIVER_MANIFEST` set to the absolute path of the app's +`storybook-desktop.generated/driver-manifest.win32.json`. The driver keeps that +nonce, so the bundle stays valid, until the instance's ports, renderer, or +story catalog change. + Keep app-owned story inclusion in `desktop.config.mts`. The shared runtime uses desktop chrome for Win32 because the host does not provide normal window dimensions. Preserve its persistent sidebar, preview, bottom addon panel, and diff --git a/packages/agentic/storybook-desktop/references/troubleshooting.md b/packages/agentic/storybook-desktop/references/troubleshooting.md index c05b700dcb..424835b198 100644 --- a/packages/agentic/storybook-desktop/references/troubleshooting.md +++ b/packages/agentic/storybook-desktop/references/troubleshooting.md @@ -36,9 +36,19 @@ the agent identity names a different build: rebuild and register the app, then restart the driver. A Windows Debug app that shows "bundler is not running" or leaves stories at `story-not-ready` is not reading the driver's Metro; it loads from port 8081, so stop whatever else holds that port before `driver --agent`. -Physical input to a host started from a background process can be refused with -"The target window did not become the foreground window" (rejected, no effect); -bring the window forward, or use the semantic `activate` action. +Physical input can be refused with `window-activation-failed`, "The target +window did not become the foreground window: …" (rejected, no effect). The +message names the foreground holder by opaque handle and process id and the +cause: an elevated window, a window that is not responding, another window of +the app, or a lost foreground (lock, disconnect, or secure desktop). Address +that window and retry, or use the semantic `activate` action. A physical click +is not retried automatically. + +On Windows Fabric, only `smoke` writes the application lease that WDIO sessions +verify, so `storybook test --windows` fails with "Opening the application lease +file failed" against a separately launched app. Run +`STORYBOOK_SMOKE_STORY= yarn storybook smoke --windows --mode +stories-and-tests` and read the selected callbacks in its `run.json`. For macOS CocoaPods codegen failures, rerun the documented `prep` stage once when ReactCodegen has a stale generated source list; diagnose the first From d57587247a0e4ede4e651e10fb4e40dd9440395a Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Sun, 8 Nov 2026 14:48:47 -0800 Subject: [PATCH 2/2] Record connected Windows desktop qualification Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 19ee4435-64e4-4799-b8fc-f3b7742f2c92 --- .../references/current-status.md | 30 +++++++++++- .../references/current-status.md | 41 ++++++++++++++-- .../desktop-test/references/current-status.md | 49 ++++++++++++++++++- 3 files changed, 113 insertions(+), 7 deletions(-) diff --git a/packages/agentic/desktop-driver-mcp/references/current-status.md b/packages/agentic/desktop-driver-mcp/references/current-status.md index e9081330a3..be788a2ea1 100644 --- a/packages/agentic/desktop-driver-mcp/references/current-status.md +++ b/packages/agentic/desktop-driver-mcp/references/current-status.md @@ -7,7 +7,7 @@ owner_paths: # Current adapter and measurement status -**Work in progress, updated 2026-11-05.** The adapter is a thin client, not a +**Work in progress, updated 2026-11-08.** The adapter is a thin client, not a supervisor. Keep this package name until actual harness-owned management tools land; a later `desktop-mcp` facade must retain driver-only use and plan published compatibility. Done below describes implementation, not full native qualification. @@ -310,3 +310,31 @@ Win32 needed none. All sessions closed and cleanup removed owned processes, listeners, and the workload claim; no default descriptor remained. These runs issued no descriptor grant and do not change the descriptor matrix's Partial or Fail outcomes. + +## 2026-11-08 UTC connected descriptor-path checks + +Source `fec94cec4995c7372b798877c5412ddcb156523b`, Windows 11 Enterprise +build 26300, AMD64. An MCP SDK stdio client used the default private +descriptor and attached to the real, instance-matched Storybook app under an +exclusive claim. These are manual operations, not selected suite tests. + +| Endpoint | Driver run / MCP session | Physical checkbox | Target PNG | +| -------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | --------------------------------------------- | +| Windows Fabric | `af97fdb3-68de-4ce9-836e-935331528c8e` / `6ab236be-dc25-4b53-97f9-4e6ce8875ab2` | Pass: 2 applied `physical-pointer` actions, unchecked -> checked -> unchecked | Pass: 42,436 bytes, resource SHA-256 verified | +| Win32 Paper | `3294d66d-9332-4639-95fe-8d3047f47e46` / `8d75052d-ddae-48f9-a1c1-2c8abcf8a019` | Pass: 2 applied `physical-pointer` actions, unchecked -> checked -> unchecked | Pass: 31,639 bytes, resource SHA-256 verified | + +Each session selected `components-checkbox--default`, checked every state, +read the PNG through its MCP resource, verified its signature and digest, +and closed. The Windows case supersedes the earlier failed physical-click +attempt for this bounded descriptor-path operation. The first Windows +readiness attempt ended after 30 rejected, effect-none retries while Metro +was still building; a later attempt passed. + +On Win32, a session-local injection closed the authenticated bridge after +selection. A newly observed preview checkbox was unavailable (`find: none`) +while the chrome root remained present; fresh-preview mutation fencing and +chrome mutation remain Partial, not passes. An initial 10-second wait timed +out before the observed bridge retirement; the subsequent attempt waited for +retirement. No raw image or grant is retained in this reference. Driver +shutdown, app cleanup, and the failed Win32 app-run reports are +recorded in `packages/agentic/desktop-test/references/current-status.md`. diff --git a/packages/agentic/desktop-driver/references/current-status.md b/packages/agentic/desktop-driver/references/current-status.md index fd1818ac11..9b8a1baf1c 100644 --- a/packages/agentic/desktop-driver/references/current-status.md +++ b/packages/agentic/desktop-driver/references/current-status.md @@ -7,7 +7,7 @@ owner_paths: # Current capability and qualification status -**Work in progress, updated 2026-11-06.** "Done" below means the stated +**Work in progress, updated 2026-11-08.** "Done" below means the stated implementation exists, not that every native endpoint is qualified or that the complete orchestration product is ready for submission. Historical measurements remain tied to their original revision; they were not rerun by this update. @@ -437,7 +437,38 @@ Same host, with the console session disconnected throughout. `packages/agentic/desktop-driver-mcp/references/current-status.md`. On Windows Fabric three React Native Test App menu-bar items get new references on every read, so an idle `delta` is never empty. -- **Connected fixture rerun.** All 11 `win32Fixture` cases passed, including - window capture and 500-cycle retention (20 retained elements at cycles 100 - and 500). Separately registered secondary windows and Win32 fresh-preview - fencing remain unqualified. + +## 2026-11-08 UTC connected Windows qualification + +Source `fec94cec4995c7372b798877c5412ddcb156523b`, Windows 11 Enterprise +build 26300, AMD64, with the console connected. The opt-in `nativeDriver` +contract passed 6 tests with 2 skipped. Under an exclusive workload claim, +`FURN_NATIVE_DRIVER_TEST=1 yarn test win32Fixture --runInBand` passed all +11 tests; retained elements were 20 at cycle 100 and 23 at cycle 500. +The full `FURN_NATIVE_DRIVER_TEST=1 yarn test --runInBand` suite then passed +909 tests with 31 skipped across 65 passed and 2 skipped suites. Its separate +fixture run retained 20 elements at both cycles 100 and 500; the exclusive +claim was released. + +A separate generic Win32 fixture probe (`dfb100b1-94b2-4007-946e-9172c1f97d54`) +switched between the exact main and secondary dialog handles, read controls +in each, and verified the dialog closed. Capture of the minimized main +window returned `unsupported operation` without restoring it; an explicitly +restored window produced a valid PNG. This is not the Storybook F4 +separately registered secondary-window case, which remains Partial. + +Connected physical-input Storybook smokes passed on both endpoints, including +the checkbox and popup cases. The separate real MCP descriptor path also +passed two physical checkbox clicks and checked-state assertions on each +endpoint, and returned hash-verified target PNGs. This replaces the earlier +Windows physical-click failure for that bounded case, not for the full +native matrix. Run IDs, selection counts, receipts, and cleanup are in +`packages/agentic/desktop-test/references/current-status.md`; MCP session +evidence is in `packages/agentic/desktop-driver-mcp/references/current-status.md`. + +The Win32 authenticated bridge was disconnected after a settled story. +Chrome remained observable, but a fresh preview reference was not exposed +after the disconnect, so fresh-preview fencing remains Partial. The first +probe timed out after 10 seconds; bridge retirement occurred about 19 seconds +after injection. A later attempt waited for retirement and retained the +same Partial result. Physical Ctrl+C and DPI changes were not exercised. diff --git a/packages/agentic/desktop-test/references/current-status.md b/packages/agentic/desktop-test/references/current-status.md index 5292e9cf67..785725a73a 100644 --- a/packages/agentic/desktop-test/references/current-status.md +++ b/packages/agentic/desktop-test/references/current-status.md @@ -7,7 +7,7 @@ owner_paths: # Current lifecycle and qualification status -**Work in progress, updated 2026-11-06.** Done means the listed implementation, +**Work in progress, updated 2026-11-08.** Done means the listed implementation, not full cross-platform qualification. This package is the intended neutral workload host; the existing Storybook lifecycle takeover is transitional. No new coordinator package, daemon, dynamic plugin loader, or package rename @@ -695,3 +695,50 @@ console Ctrl+C case is otherwise out of scope for this pass. by hand only after its owner was proved dead and its resources were proved settled, or after the fenced launch probe's survivor was ended. Nothing reclaims a claim automatically. + +## Connected Windows physical-input follow-up - 2026-11-08 UTC + +Source `fec94cec4995c7372b798877c5412ddcb156523b`; Windows 11 Enterprise +build 26300, AMD64, Node 26.13.0. With the console connected, the following +separate, non-agent smokes ran from `apps/storybook` with +`yarn storybook smoke -- --mode stories-and-tests --input physical +--reporter json` and `STORYBOOK_SMOKE_STORY` set to the listed story. +Each had zero failures, skips, unsupported cases, incomplete work, retries, +or flaky cases. The totals include navigation work, not just authored tests. + +| Endpoint | Story and authored assertion | Selected / executed / passed | Physical-click receipts | Run ID | +| -------------- | ----------------------------------------------------------------- | ---------------------------- | ----------------------- | -------------------------------------- | +| Windows Fabric | `components-checkbox--default`: unchecked -> checked -> unchecked | 203 / 203 / 203 | 2 | `ef1ed966-3be3-4cc1-b940-ac0afbb02155` | +| Win32 Paper | `components-checkbox--default`: unchecked -> checked -> unchecked | 177 / 177 / 177 | 2 | `54e6a815-21a4-418c-bfda-848e28549ffe` | +| Windows Fabric | `native-callout--default`: open, light-dismiss, recreate | 203 / 203 / 203 | 3 | `1e521138-f529-45a1-974e-74f90edd42ac` | +| Win32 Paper | `native-callout--default`: open, light-dismiss, recreate | 177 / 177 / 177 | 3 | `44d9dd17-7132-4ebd-8b1e-18fa923ee355` | + +Artifacts are `apps/storybook/artifacts/desktop//run.json`. The +Windows totals contain 202 navigation cases and one authored case; Win32 +contains 176 and one. Popup interaction does not establish F4's separately +registered Storybook secondary-window identity. + +The connected native fixture contract passed 11 tests under the per-user +claim; its retained-element counts were 20 and 23 at cycles 100 and 500. +The separate generic fixture probe passed exact secondary-handle switching +and minimized-capture refusal as described in the driver status reference. +Windows `doctor --permissions` remains Unsupported. + +The real MCP descriptor path independently passed physical checkbox +transitions and target capture on both endpoints. Standalone agent driver +runs `af97fdb3-68de-4ce9-836e-935331528c8e` (Windows) and +`3294d66d-9332-4639-95fe-8d3047f47e46` (Win32) each ended with a +terminal passed lifecycle report and zero selected tests; the manual MCP +operations are not suite selections. The first Windows probe exhausted its +30 safe `bridge-unavailable`/effect-none attempts while the cold Metro bundle +was still building; the later probe passed after the app connected. + +After MCP session close, Windows accepted an exact-app window close. On +Win32 the window closed but its exact REX process remained; it was stopped +only after identity verification. Both deliberately stopped Win32 app runs, +`665e6e85-f0ce-4612-a34d-f140d2bab433` and +`fc71d8fd-ffa4-464e-96ea-616d88d49e0e`, report failed, not graceful cleanup. +The standalone drivers were stopped by a session-local injected SIGTERM, +not physical Ctrl+C. Both owned app/service processes exited, the recorded +ports were free, and the per-user claim and default descriptor were absent. +The separate `serve --agent` interrupt limitation above remains open.