Skip to content

fix(executor): hash consult returns the fs path of the served spelling - #3847

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3845-pipeline-stage-stderr-comsub
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3845-pipeline-stage-stderr-comsub

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #3845

Root cause

golden_issue1230_exec_redirect_undo leaked .../cat.exe: No such file or directory to stderr from fixture line 9 (echo "cap4 size: $(cat cap4 | wc -c)").

find_user_command's hash-mirror consult (src/executor/path.rs) returned phash_search's stored string verbatim as the exec PathBuf. The hash table stores the shell-domain display spelling (/d/..., ./elem/name) for hash -t fidelity. On unix that string already is the filesystem path execute_cmd.c:6133 shell_execve hands to execve; on Windows it is not spawnable, so Command::new ENOENTs and the spawn diagnostic reaches the shell's stderr (inside a comsub, fd 2 is inherited — subst.c command substitution does not capture stderr, so a real spawn failure does print there; the bug is that the spawn fails at all).

Sequence in the fixture: line 6 cat cap2 resolves cat and records /d/Git/usr/bin/cat.exe in the hash table + fs-path mirror; line 9's comsub pipeline resolves cat through the mirror consult, gets the /d/ spelling back, and the concurrent pipeline-stage spawn fails ENOENT.

Was #3631 the cause? — No.

Bisected locally with script-file reproduction (tests/regression/fixtures/issue1230-exec-redirect-undo.sh, PATH C:\Windows\System32;D:\Git\usr\bin mirroring the harness shape):

The true introducer is #3554 (46bb796b2), whose diff replaced return Some(path.clone()) (the mirror's fs path) with PathBuf::from(served) for the CHKDOT/RELPATH re-validation arm (rubash#3359/#3551). #3631's sequential-2>&1 fold never runs for this shape — the comsub pipeline takes the concurrent external path.

Invariant restored

find_user_command returns the filesystem path of the spelling GNU would exec, not the spelling itself. The fix returns shell_path_to_windows(served, env_vars) — the same funnel record_command_resolution used to build the mirror:

  • unix: identity (hash spelling already is the fs path) — zero behavior change.
  • Windows: /d/Git/usr/bin/cat.exe → D:\Git\usr\bin\cat.exe (spawnable).
  • ./elem/name stays relative → re-resolves at spawn cwd → post-cd ENOENT semantics of rubash#2696 preserved.
  • The checkhash probe now stats the real file instead of a <cwd>\d\... ghost path.

Display faces are unaffected: hash -t / type / command -v / hash -l / BASH_CMDS read phash_search/hashed_entries directly and still print /d/... forms (verified).

GNU anchors

  • execute_cmd.c:6126-6133 shell_execve — execve(command, args, env) runs the recorded string verbatim.
  • findcmd.c:365-380 search_for_command — phash_search consult before the PATH walk.
  • hashcmd.c:126-191 phash_search CHKDOT/RELPATH serve arm.
  • subst.c command_substitute — comsub captures stdout only; stderr stays inherited, so genuine spawn failures do reach the terminal (routing was already correct).

Test evidence

  • Fixture script-file run vs WSL /usr/local/bin/bash 5.3.20(1)-release: stdout byte-identical, stderr empty (was: one extra /d/...cat.exe line).
  • Fail-first: red on a41909d3e pre-fix, green with fix.
  • New pin executor::path::tests::hash_consult_returns_spawnable_fs_path_for_display_spelling: red before (/c/... returned), green after.
  • cargo test --lib both sides: head {issue2084_session_end_restores_host_process_state} / base {same} — diff empty (1375 passed / 1 baseline fail each).
  • Hash/path stem family: identical failure sets on base vs fixed binaries (all pre-existing Windows-env baseline: unix PATH expectations, missing C:\Program Files\Git\usr\bin); issue3551_hash_chkdot 4/4 green.
  • RUSTFLAGS="-D warnings" cargo check --lib --tests: 0 warnings. rustfmt --check src/executor/path.rs: clean. scripts/check-marker-literals.py: OK.
  • Local note: cargo test --test regression golden_issue1230_exec_redirect_undo cannot go green on this box — minimal_path() needs C:\Program Files\Git\usr\bin, absent here (Git lives at D:\Git); it fails identically before/after for missing coreutils, unrelated to this fix. CI runners have the expected layout.

Generated with Devin

…g (Refs #3845)

find_user_command's hash-mirror consult handed phash_search's stored
string to callers verbatim as a PathBuf. The hash table keeps the
shell-domain display spelling (/d/..., ./elem/name) for `hash -t`
fidelity; on unix that string already is the filesystem path
execute_cmd.c:6133 shell_execve execve()s, but on Windows it is not
spawnable — Command::new ENOENTs and the diagnostic escapes to the
shell's stderr, e.g. `cat cap4 | wc -c` inside a command substitution
after any earlier `cat` run recorded the entry (golden issue1230).

Introduce: #3554 (46bb796) replaced `return Some(path.clone())` —
the mirror's fs path — with the verbatim served spelling for the
CHKDOT/RELPATH re-validation arm. #3631 is innocent: the parent tree
(9148457) reproduces the leak identically.

Return shell_path_to_windows(served) instead — the same funnel
record_command_resolution used to build the mirror. It is the
identity on unix, maps /d/... to D:\..., and keeps ./elem/name
relative so the post-cd ENOENT re-resolution of rubash#2696 is
preserved. The checkhash probe now stats the real file too.

Pin: executor::path::tests::
hash_consult_returns_spawnable_fs_path_for_display_spelling (red
before, green after).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit d0a9cf0 into master Nov 17, 2026
17 of 22 checks passed
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.

regression: golden_issue1230 — pipeline-stage spawn diagnostic leaks to stderr inside comsub (suspect #3631)

1 participant