bug(windows): 0.8.4 CLI auto-install writes "\\?\"-prefixed dir to user PATH and converts it to REG_SZ
Jan version
0.8.4 (upgraded from via <in-app updater | manual installer>),
per-user install in %LOCALAPPDATA%\Programs\Jan.
Operating system
Windows 11 Pro 10.0.26200
Summary
On the first start after upgrading to 0.8.4, Jan adds its CLI directory to the user
PATH (HKCU\Environment\Path). The way it does this damages the PATH value:
- The entry is written with the extended-length prefix:
\\?\C:\Users\<user>\AppData\Local\Programs\Jan\resources\bin - The whole user PATH is rewritten as
REG_SZ. Before it wasREG_EXPAND_SZ, so any%VAR%entries are now permanently expanded. - Because of the prefix, the duplicate check never matches an existing plain entry.
uninstall_jan_clicannot remove the prefixed entry either.
The NSIS template (src-tauri/tauri.bundle.windows.nsis.template) does not touch
PATH. The write comes from the app itself.
Code path (tag v0.8.4)
src-tauri/src/core/setup.rs#L164setup_jan_cli(..., version_changed)callsinstall_jan_cli_sync(L186) after an update, or whenjanis not on PATH.src-tauri/src/core/system/commands.rs#L663install_jan_cli_synctakes the directory fromapp_handle.path().resource_dir()(L674) and callsadd_to_path_windows(&resource_bin_dir)(L699). On Windowsresource_dir()returns a\\?\-prefixed path. That path goes into PATH unchanged.commands.rs#L890add_to_path_windows:- reads the user PATH via
powershell [Environment]::GetEnvironmentVariable('Path','User'), which expands%VAR%references, - checks for duplicates with
eq_ignore_ascii_case(&install_dir_str)(L933). This compares against the\\?\form, so a normal entry for the same folder never matches, - writes the result back via
[Environment]::SetEnvironmentVariable('Path', ..., 'User')(L946). Under Windows PowerShell 5.1 this stores the value asREG_SZ.
- reads the user PATH via
commands.rs#L974remove_from_path_windows(used byuninstall_jan_cli) compares againstjan_cli_bin_dir_windows()(L878). That path has no prefix, so the\\?\entry written above is never removed.
Links: https://github.com/janhq/jan/blob/v0.8.4/src-tauri/src/core/system/commands.rs#L663-L704 https://github.com/janhq/jan/blob/v0.8.4/src-tauri/src/core/system/commands.rs#L890-L970 https://github.com/janhq/jan/blob/v0.8.4/src-tauri/src/core/system/commands.rs#L974-L1034 https://github.com/janhq/jan/blob/v0.8.4/src-tauri/src/core/setup.rs#L164-L195
Observed at the same time (cause NOT established)
Right after the upgrade, the user PATH also had these problems:
- Three existing entries were missing: a per-user Python install
(
...\Programs\Python\Python312\,...\Python312\Scripts\,...\Python\Launcher\).pythonandpywere no longer found in new shells, and build scripts that callpythonfailed. IDEs using absolute interpreter paths kept working, which made the cause hard to spot. - The complete machine PATH appeared twice inside the user PATH, and the remaining user entries were also duplicated. Total length was 4,329 characters; the machine PATH itself is 1,408.
Reading the v0.8.4 code, add_to_path_windows should neither drop entries nor copy the
machine PATH. So I cannot attribute these two points to Jan with certainty. Windows
keeps no previous value, so the state before the upgrade cannot be reconstructed. I am
reporting them because they appeared at the same moment, in case someone sees the same
pattern.
Current main
As far as I can see, the CLI auto-install and add_to_path_windows were removed on
main ("refactor(cli): stop bundling the jan agent CLI with the app"), and
scripts/install-jan-agent.ps1 -AddToPath appends a plain path. Users who ran 0.8.4
keep the damaged value, though: nothing removes the \\?\ entry or restores
REG_EXPAND_SZ.
Expected behavior
- Strip the
\\?\prefix before writing a path to PATH (e.g. with theduncecrate orsimplified()). - Edit the PATH directly in the registry and keep its value type (
REG_EXPAND_SZ), instead of reading and writing an expanded copy through PowerShell. - Compare normalized paths when checking for duplicates and when removing entries.
- Optionally, a one-time cleanup in the next release: remove a
\\?\...\Jan\resources\binentry if one is present.
Workaround
Rebuild the user PATH by hand: remove the \\?\ entry and the duplicates, re-add the
missing entries, and set the value type back to REG_EXPAND_SZ.
Source: janhq/jan