Skip to content

fix(cua-driver-rs)(windows): skip cua-driver-uia spawn at High IL (suppresses AIS error dialog) - #1634

Merged
f-trycua merged 1 commit into
mainfrom
fix/cua-driver-rs-skip-uia-worker-at-high-il
May 21, 2026
Merged

fix(cua-driver-rs)(windows): skip cua-driver-uia spawn at High IL (suppresses AIS error dialog)#1634
f-trycua merged 1 commit into
mainfrom
fix/cua-driver-rs-skip-uia-worker-at-high-il

Conversation

@f-trycua

@f-trycua f-trycua commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Since PR #1630 the autostart task runs the main daemon at `RunLevel=Highest` — full High IL, full UWP UIA access. The sibling `cua-driver-uia.exe` worker is redundant in that mode, and attempting to ShellExecute the unsigned uiAccess'd worker from a High-IL parent pops a Windows AIS error dialog ("A referral was returned from the server" = AIS refusing to elevate unsigned uiAccess).

This patch gates the worker spawn on three conditions:

  1. Main daemon NOT already at High IL (PS check via `WindowsPrincipal.IsInRole(Administrator)`)
  2. `CUA_DRIVER_RS_SPAWN_UIA_WORKER=1` opt-in env var set
  3. Worker binary present on disk

Common case (Highest autostart task per #1630) trips condition 1 → no spawn → no dialog → no regression (High-IL daemon already does what the worker would).

Repro of the dialog

# As a normal admin user (non-RID-500, UAC-split-token):
irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.ps1 | iex
cua-driver autostart enable    # self-elevates, registers task at Highest
cua-driver autostart kick      # daemon starts at High IL
# ← Windows dialog appears: cua-driver-uia.exe + "A referral was returned from the server"

After this patch: same flow, no dialog. Daemon serves requests, UWP automation works (already verified by the cuademo dogfood for Calculator).

Future EV-cert flow

When the worker is EV-signed and properly elevates to UIAccess, set `CUA_DRIVER_RS_SPAWN_UIA_WORKER=1` to engage it. Default-off keeps the rollout honest — explicit opt-in during the signed-binary transition.

Surfaced

cuademo's fresh-install dogfood right after v0.2.11 — `autostart kick` brought up the daemon and immediately popped the AIS dialog.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Windows: Improved daemon process handling with stricter Administrator privilege checks. Worker process spawning now skips when already running at elevated privilege level and requires environment variable opt-in under other scenarios.
  • Documentation

    • Updated documentation for Windows daemon behavior regarding worker process spawning and environment variable configuration.

Review Change Stack

…on is at High IL (#1602)

Since PR #1630 the autostart task runs the main daemon at RunLevel=Highest,
which puts cua-driver.exe at High IL with full UWP / AppContainer UIA access.
The sibling cua-driver-uia.exe worker is therefore redundant for the common
case — and worse, attempting to ShellExecute the (currently unsigned)
uiAccess'd worker from a High-IL parent pops a Windows AIS error dialog
("A referral was returned from the server" = AIS refusing to elevate an
unsigned uiAccess binary). The dialog blocks daemon startup and visibly
confuses users.

Repro: run `cua-driver autostart enable` from a standard admin user (non-RID-500),
accept the UAC prompt, then `cua-driver autostart kick`. The main daemon starts
at High IL, tries to spawn the uia worker via ShellExecute, AIS refuses, error
dialog pops up over the desktop.

## Fix

maybe_spawn_uia_worker() now gates on three conditions:

1. Main daemon is NOT at High IL (checked via PowerShell
   WindowsPrincipal.IsInRole(Administrator)). At High IL the worker is
   redundant.

2. CUA_DRIVER_RS_SPAWN_UIA_WORKER=1 env var is set. Default-off until the
   worker is actually EV-signed (#1602) and the spawn doesn't trip AIS.

3. The worker binary actually exists on disk next to cua-driver.exe.

All three must be true for the spawn to fire. Common case (RunLevel=Highest
install via the canonical install.ps1 + cua-driver autostart enable flow):
condition (1) trips first — no spawn, no dialog, no UWP regression because
the High-IL main daemon already does what the worker would have done.

## Future EV-cert path

When we ship a signed cua-driver-uia.exe (the long-term #1602 answer), users
running the daemon at Medium IL can opt into the worker by setting
CUA_DRIVER_RS_SPAWN_UIA_WORKER=1. Default-off gives a no-surprises upgrade
path: existing users on Medium IL stay on whatever path they're already on,
and the explicit env var keeps us honest about which path is being exercised
during the signed-binary rollout.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview May 21, 2026 4:59pm

Request Review

@f-trycua
f-trycua merged commit d981674 into main May 21, 2026
3 of 5 checks passed
@f-trycua
f-trycua deleted the fix/cua-driver-rs-skip-uia-worker-at-high-il branch May 21, 2026 16:59
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a729f8ee-7f92-462c-8016-18b55fc0e396

📥 Commits

Reviewing files that changed from the base of the PR and between 46f0203 and b42d9b6.

📒 Files selected for processing (1)
  • libs/cua-driver-rs/crates/cua-driver/src/serve.rs

📝 Walkthrough

Walkthrough

The Windows daemon's UIA worker spawning is now gated by privilege level and environment variable. A new is_self_at_high_il() helper detects Administrator status via PowerShell, and maybe_spawn_uia_worker() skips spawning when already privileged or when the opt-in environment variable is not set.

Changes

UIA Worker Spawning Controls

Layer / File(s) Summary
UIA worker privilege-level gating
libs/cua-driver-rs/crates/cua-driver/src/serve.rs
New is_self_at_high_il() helper checks whether the process runs as Administrator by executing PowerShell and parsing the result. The maybe_spawn_uia_worker() function is enhanced with documentation and gating: it returns early when already at High IL, and otherwise skips by default unless CUA_DRIVER_RS_SPAWN_UIA_WORKER is set to a truthy value. A comment block near the spawn logic is removed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • trycua/cua#1604: Refines the daemon startup auto-spawning logic for cua-driver-uia.exe that was introduced in #1604, adding privilege-level and environment variable gating to the worker spawning behavior.

Poem

A rabbit guards the daemon's door,
Checking privileges forevermore,
"Are you High IL?" it whispers low,
"Then spawn the UIA worker, go!
(But only if you ask, you know!)" 🐰✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cua-driver-rs-skip-uia-worker-at-high-il

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant