Skip to content

fix(cua-driver): write the update-check cache to the canonical home - #3002

Closed
rsyuzyov wants to merge 1 commit into
trycua:mainfrom
rsyuzyov:fix/version-check-home
Closed

fix(cua-driver): write the update-check cache to the canonical home#3002
rsyuzyov wants to merge 1 commit into
trycua:mainfrom
rsyuzyov:fix/version-check-home

Conversation

@rsyuzyov

@rsyuzyov rsyuzyov commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • resolve the version_check cache through bundle::user_home_subdirectory() so it lands in ~/.cua-driver/ instead of the pre-rename ~/.cua-driver-rs/
  • migrate a cache left in the old home on first read (move the file, then remove the directory only if it is empty), mirroring migrate_legacy_telemetry_home
  • add three unit tests: canonical placement, migration with the dismissed list preserved, and non-destructive cleanup when the legacy home still holds other files

This is the driver half of #2803, offered in this comment when the installer half landed as #2805. version_check is the last writer keeping the pre-rename home alive:

module home legacy handling
telemetry.rs .cua-driver migrates the id out of .cua-driver-rs, removes the emptied dir
skills.rs .cua-driver sweeps skill-pack artifacts out of .cua-driver-rs
version_check.rs .cua-driver-rs none — before this PR

Worth noting the file was already inconsistent with itself: read_config_flag a few lines up reads config.json from bundle::user_home_subdirectory(), while cache_path hard-coded the old name (plus its own inline .cua-driver-local branch, which user_home_subdirectory() already covers).

Consequences on a current install: _install-rust.sh and install.ps1 sweep ~/.cua-driver-rs post-install, and the next update check re-creates it. The telemetry migration therefore never completes, and the directory keeps looking like a v0.2.13 legacy marker on machines that have only ever run current versions.

Verification

Toolchain from rust-toolchain.toml (1.97.1), Windows 11 26100, x86_64.

  • cargo fmt --all -- --check — clean
  • cargo test -p cua-driver --bin cua-driver version_check — 25 passed, 0 failed

Behaviour checked on the built binary, not only in unit tests — HOME/USERPROFILE redirected to a throwaway profile, running check-update:

scenario stock 0.19.2 this PR
clean profile → ~/.cua-driver/version_check.json absent present
clean profile → ~/.cua-driver-rs/version_check.json created absent
profile with a pre-rename cache left in place moved to .cua-driver, dismissed_versions preserved, legacy dir removed
second run on the same profile no-op, legacy dir stays gone

The third row is the one that matters for existing installs: the dismissed-version list survives the move, so nobody gets re-nagged about a release they already dismissed.

Notes

  • Scope kept to the home directory. cache_path still resolves HOME/USERPROFILE directly and does not honour CUA_DRIVER_RS_HOME the way skills.rs does — that is a separate decision about which modules follow the env override, and I did not want to fold it into a rename fix.
  • The legacy cleanup is deliberately remove_dir, never remove_dir_all: if anything else still lives in the old home, the directory stays. There is a test for exactly that.

`version_check` still resolved its cache under the pre-rename
`~/.cua-driver-rs/`, while `telemetry.rs` and `skills.rs` had moved to
`~/.cua-driver/` and actively migrate away from the old home. Even
`read_config_flag` in this same file already reads the config from
`bundle::user_home_subdirectory()` — only the cache path lagged behind.

The effect is that every current install re-creates the legacy home the
installer just swept, so the telemetry migration can never finish and
`~/.cua-driver-rs` looks like a legacy-layout marker on machines that have
only ever run current versions (the root cause discussed in trycua#2803, whose
installer half shipped in trycua#2805).

Resolve the cache through `bundle::user_home_subdirectory()` (which also
covers the `.cua-driver-local` source-build case the old inline branch
handled), and migrate a cache left in the pre-rename home on first read:
move the file, then drop the directory only if it is empty, matching
`migrate_legacy_telemetry_home`. Keeping the file is worth the few lines
because it carries the dismissed-version list.
Copilot AI lite review requested due to automatic review settings August 9, 2026 10:10
@rsyuzyov
rsyuzyov requested a review from f-trycua as a code owner August 9, 2026 10:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Cua Driver’s version_check on-disk cache to use the canonical per-user home directory (~/.cua-driver/) instead of the legacy pre-rename home (~/.cua-driver-rs/), and adds a best-effort one-time migration to preserve dismissed-version state for existing installs.

Changes:

  • Resolve version_check.json through bundle::user_home_subdirectory() so new caches land under the canonical home.
  • Add best-effort migration from the legacy cache path, attempting to remove the legacy directory only when empty.
  • Add unit tests covering canonical placement, migration preserving dismissed_versions, and non-destructive legacy cleanup.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
libs/cua-driver/rust/crates/cua-driver/src/version_check.rs Switch cache location to canonical home, add legacy cache migration, and add unit tests for placement/migration/cleanup behavior.
libs/cua-driver/rust/crates/cua-driver/Cargo.toml Update test dependency comment to match the new canonical cache path.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +553 to +564
if !current.exists() {
if let Some(parent) = current.parent() {
let _ = std::fs::create_dir_all(parent);
}
let _ = std::fs::rename(&legacy, &current);
}
// Either the rename already took it, or the canonical cache wins and the
// stale copy goes. Both paths end with the legacy home unreferenced.
let _ = std::fs::remove_file(&legacy);
if let Some(parent) = legacy.parent() {
let _ = std::fs::remove_dir(parent);
}

Copy link
Copy Markdown
Collaborator

Thanks @rsyuzyov — I carried this forward in #3032 using git cherry-pick -x, preserving you as the author of the original commit. The draft adds the requested migration-failure guard and a deterministic regression test, and the follow-up commit credits you as coauthor. #3032 is staying draft pending CI evidence.

@rsyuzyov

Copy link
Copy Markdown
Contributor Author

Closing this in favour of #3032.

@injaneity carried the commit forward with cherry-pick -x (authorship preserved) and added the
migration-failure guard plus a deterministic regression test — which is strictly better than what is
here, and the two PRs are otherwise the same change. No point keeping a duplicate in the queue.

For whoever triages next: the root is still live on main
libs/cua-driver/rust/crates/cua-driver/src/version_check.rs still has
const HOME_SUBDIRECTORY: &str = ".cua-driver-rs", so on a clean profile check-update re-creates the
very directory install.ps1 reads as a pre-0.2.13 legacy marker (the second half of #2803, whose
installer-side half landed in #2805). #3032 is the one to review.

Happy to test a build against Windows / RDS setups if that helps move it along.

@rsyuzyov rsyuzyov closed this Aug 13, 2026
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.

3 participants