Skip to content

fix(desktop): judge machine-path-conflict from a fresh logon PATH - #6888

Merged
lidge-jun merged 1 commit into
devfrom
codex/6854-fresh-logon-path-conflict
Oct 10, 2026
Merged

lidge-jun merged 1 commit into
devfrom
codex/6854-fresh-logon-path-conflict

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

On Windows the Desktop terminal command reported phase: partial with machine-path-conflict whenever the Machine Path held a directory containing ocx.{exe,com,cmd,bat}, even when new terminals select the Desktop's ocx.exe first. On the reporter's nvm-windows host the Machine Path is REG_EXPAND_SZ with %NVM_HOME%;%NVM_SYMLINK%; the Desktop expanded those entries with its own, fully resolved environment, while a fresh logon environment keeps them literal, so nvm's ocx.cmd only arrives through the User Path after the Desktop entry.

The conflict is now decided the way a new process would search:

  • os::machine_conflict(desktop_dir) builds the user's fresh environment with CreateEnvironmentBlock(token, bInherit = FALSE) and walks its PATH in order. An ocx executable in a searchable entry before the first Desktop entry is a conflict; reaching the Desktop entry first is not. Relative entries and entries still containing % are not probed: cmd searches the working directory before PATH anyway, so their effect depends on the terminal's cwd, not on PATH order the Desktop can change. A fresh PATH without the Desktop entry reports machine-path-unobserved.
  • If the fresh block cannot be built or has no PATH, the previous registry probe is used only as a negative proof: "no Machine entry holds ocx" stays clean; a previous-style hit cannot establish order and reports machine-path-unobserved instead of a conflict.
  • The observation moved out of plan(), which ran before the HKCU write and would have seen the old User Path, into perform_in after the transaction and notification, using the committed record's entry. It still runs only for enabled, non-remove reconciles, and any issue still makes the phase partial.

Block parsing (case-insensitive PATH, drive pseudo-variables, missing vs empty PATH, unterminated blocks, invalid UTF-16) and the ordering decision are portable helpers with unit tests, so the Ubuntu desktop shell job exercises them.

Closes #6854

Verification

  • macOS host, desktop/src-tauri with the CI check scaffolding: cargo fmt --check (0), cargo clippy --all-targets -- -D warnings (0), cargo test cli_command: 53 passed, 0 failed, 2 ignored.
  • Local cargo clippy --target x86_64-pc-windows-msvc could not reach this crate (the ring build script needs an MSVC C toolchain), so Windows was checked natively instead.
  • Windows 11 build 26200 (the reporter's nvm-windows host shape), temp clone at this head 799f68fdd8: cargo clippy --all-targets -- -D warnings exit 0; cargo test cli_command: 30 passed, 0 failed.
  • Same host, a throwaway ignored probe test (not committed, file restored afterwards, no registry write) printing fresh_logon_path(): the fresh block keeps %NVM_HOME% and %NVM_SYMLINK% literal and marks them unsearchable, and the only ocx directory, C:\nvm4w\nodejs, appears in the User part of PATH; the probe process's own inherited PATH had those entries expanded. That is the difference behind the false positive. After a real install the Desktop entry is first in the User part, so the walk reaches it before C:\nvm4w\nodejs; the unit test issue host shape case covers that order.
  • Not verified on this head: a post-write comparison against a new terminal's where ocx. The earlier probe recorded in devlog/_fin/261010_cli_path_crossos_probe/029_wp3_outcome.md (W3-W5) observed new terminals selecting the Desktop's ocx.exe first on that host.
  • Hosted: desktop shell (Ubuntu fmt/clippy/test) on this PR head.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (No user docs mention this issue code.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (Raw FFI uses the current process token with query/duplicate access only; the block and token are released through RAII; only PATH is decoded.)

Read a fresh user environment block after the registry transaction and evaluate searchable PATH entries in order until the Desktop directory. Preserve the legacy registry probe only as a conservative fallback when the fresh PATH is unavailable. Cover UTF-16 parsing and PATH precedence with portable tests.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 10, 2026 09:23
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 117cd447-117a-4c0e-93c3-f833104f0dc2

📥 Commits

Reviewing files that changed from the base of the PR and between 6524ce8 and 799f68f.


📒 Files selected for processing (2)
  • desktop/src-tauri/src/cli_command.rs
  • desktop/src-tauri/src/cli_command_windows.rs

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T09:27:01.521827Z 799f68f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 799f68fdd8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +959 to +966
pub fn machine_conflict(desktop_dir: &str) -> Result<bool> {
match fresh_logon_path() {
Ok(Some(entries)) => conflict_before_desktop(&entries, desktop_dir, has_ocx),
Err(_) | Ok(None) => match legacy_machine_conflict() {
Ok(false) => Ok(false),
Ok(true) => Err("machine-path-unobserved".into()),
Err(e) => Err(e),
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the owned terminal-command contract

This changes Windows conflict detection from an unconditional Machine-Path probe to an ordered fresh-logon PATH evaluation with an unobserved fallback, but the mapped structure/desktop-terminal-command.md contract remains unchanged. Update that document in this commit to describe when an earlier entry is a conflict, when unresolved entries are ignored, and when observation fails; both modified files are explicitly owned by that document in structure/INDEX.md.

AGENTS.md reference: AGENTS.md:L38-L46

Useful? React with 👍 / 👎.

@github-actions github-actions Bot added the bug Something isn't working label Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun
lidge-jun merged commit 84b9e88 into dev Oct 10, 2026
59 of 63 checks passed
@lidge-jun
lidge-jun deleted the codex/6854-fresh-logon-path-conflict branch October 10, 2026 11:01
@lidge-jun lidge-jun mentioned this pull request Oct 10, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant