Skip to content

fix(cua-driver-rs)(install): re-register cua-driver-serve task on every install when it already exists - #1685

Merged
f-trycua merged 1 commit into
mainfrom
install-local-resync-autostart
May 24, 2026
Merged

fix(cua-driver-rs)(install): re-register cua-driver-serve task on every install when it already exists#1685
f-trycua merged 1 commit into
mainfrom
install-local-resync-autostart

Conversation

@f-trycua

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

Copy link
Copy Markdown
Collaborator

Summary

Repro: user has `cua-driver-serve` registered (from a previous `install.ps1 -AutoStart`). They upgrade — `install-local.ps1` (no `-AutoStart`) drops a fresh binary, retargets the `current` junction. PATH now resolves to the fresh binary. But the scheduled task's `` is a hard-coded absolute path to the OLD release-install dir — that binary is still on disk and still has the pre-#1654 unwrapped task-action shape.

Result: `cua-driver autostart kick` runs the OLD binary, which displays a visible console window at logon. Even though everything ELSE on the system is now the new binary.

Discovered while debugging "why does autostart kick still show the console" with a user on Windows. Confirmed by checking `strings <task's-command-path> | grep 'WindowStyle Hidden'` → 0 hits (pre-fix binary); the fresh source build had 2 hits.

Fix

Both `install.ps1` and `install-local.ps1` now sniff for an existing `cua-driver-serve` task post-install:

```powershell
if (-not $AutoStart) {
schtasks.exe /Query /TN "cua-driver-serve" 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) {
# Re-register against the freshly-installed binary
Register-CuaDriverAutostart -InstalledBinary $installedBinary
}
}
```

Idempotent. Covers the upgrade path explicitly. If no task is registered, behaviour is unchanged — initial autostart opt-in still requires `-AutoStart` (or `cua-driver autostart enable`).

End-to-end

```
$ schtasks /Query /TN cua-driver-serve /XML | findstr powershell.exe

(empty — old binary's REGISTER_PS used direct cua-driver.exe action)

$ .\install-local.ps1
==> registering Scheduled Task 'cua-driver-serve' (because pre-existing task detected)
Re-registered. Task action now uses this build's hidden-console wrapper.

$ schtasks /Query /TN cua-driver-serve /XML | findstr powershell.exe
powershell.exe
-NoProfile -WindowStyle Hidden -NonInteractive ...

$ cua-driver autostart kick

no visible window

```

Test plan

  • PowerShell parser accepts both files (`[Parser]::ParseFile` returns no errors)
  • Sniff branch only runs when task exists; `schtasks /Query` returns non-zero when missing
  • Reviewer: run `install-local.ps1` on a Windows host that has `cua-driver-serve` registered with the legacy shape, confirm the action transitions to the wrapped powershell.exe form
  • Reviewer: run on a Windows host with NO task, confirm no new registration happens

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved installer behavior to automatically update existing auto-start scheduled tasks when installing a new version, ensuring the task points to the current binary without requiring manual reconfiguration.

Review Change Stack

…ry install when it already exists

Symptom: user upgrades cua-driver (e.g. via install-local.ps1 to pick
up the hidden-console wrapper from #1654), then runs
`cua-driver autostart kick`, then sees a visible console window
again. Repro confirmed: the scheduled task's <Command> path stayed
hard-pointed at the previous release-install dir (a binary lacking
the wrapper code), so kick spawned the OLD binary.

Both install.ps1 and install-local.ps1 only re-registered the task
when -AutoStart was passed. Users on the upgrade path don't pass it
(they're not opting INTO autostart - they already have it).

Fix: both scripts now sniff for an existing `cua-driver-serve` task
post-install and re-register it pointing at the freshly-installed
binary, even without -AutoStart. The re-register is idempotent and
covers the upgrade case explicitly. If no task is registered, nothing
changes (still need -AutoStart to opt in initially).

End-to-end: user runs install-local.ps1, the just-built binary's
REGISTER_PS produces the wrapped task action, kick now spawns
hidden.

Replaced em-dashes in added comments with ASCII hyphens - the file
gets rewritten as UTF-8 on edit, but PS 5.1's parser had read older
em-dashes in the same file as windows-1252 successfully (mixed-
encoding), and treating new bytes as UTF-8 surfaced unterminated-
string errors. Stay on ASCII in newly-added blocks to avoid drift.
@vercel

vercel Bot commented May 24, 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 May 24, 2026 2:04pm

Request Review

@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: da240ebb-7afb-4d08-a4ca-cf611910a637

📥 Commits

Reviewing files that changed from the base of the PR and between 89fd8e9 and c380704.

📒 Files selected for processing (2)
  • libs/cua-driver/scripts/install-local.ps1
  • libs/cua-driver/scripts/install.ps1

📝 Walkthrough

Walkthrough

Both install.ps1 and install-local.ps1 now re-register an existing cua-driver-serve Scheduled Task when the -AutoStart flag is omitted, ensuring the task points to the newly built or installed cua-driver.exe instead of a stale binary path. Task lookup is error-tolerant, and failures are reported to the user with remediation guidance.

Changes

Scheduled Task Re-registration Without AutoStart

Layer / File(s) Summary
Scheduled task re-registration without AutoStart
libs/cua-driver/scripts/install-local.ps1, libs/cua-driver/scripts/install.ps1
When -AutoStart is omitted, both scripts query for an existing cua-driver-serve scheduled task. If the task is found, it is re-registered to use the newly built/installed cua-driver.exe binary by invoking Register-CuaDriverAutostart. Error handling allows the installation to continue if the task does not exist, and user-facing messages indicate re-registration success or failure requiring manual remediation.

Possibly Related PRs

  • trycua/cua#1654: Modifies scheduled task re-registration so the task's action launches the correct newly installed cua-driver binary via the hidden PowerShell wrapper.
  • trycua/cua#1630: Updates Windows autostart handling for the cua-driver-serve scheduled task registration details via the autostart enable flow.
  • trycua/cua#1550: Introduces cua-driver autostart CLI and updates install scripts to delegate scheduled-task registration through that command.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 A task once forgotten, now springs back to life—
The script checks and re-registers, cutting through strife!
Fresh binaries bound to old schedules anew,
With gentle error-handling, the installation shines true! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: re-registering the cua-driver-serve scheduled task on install when it already exists. It directly aligns with the primary objective of fixing the upgrade path bug.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch install-local-resync-autostart

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.

@f-trycua
f-trycua merged commit a9ddde6 into main May 24, 2026
5 of 7 checks passed
@f-trycua
f-trycua deleted the install-local-resync-autostart branch May 24, 2026 14:06
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