Skip to content

fix(executor): memoized command-lookup misses self-heal via the #392 probe grid - #1724

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1723-negative-lookup-selfheal
Oct 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1723-negative-lookup-selfheal

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1723

GNU contract

GNU never remembers a failed command search:

  • search_for_command (findcmd.c:348) consults phash_search for positively hashed entries only — there is no negative table — and even those are re-stat'ed on every lookup (findcmd.c:367-376).
  • An unhashed name walks $PATH live on every invocation (find_user_command_in_path, findcmd.c:623-697, via find_in_path_element → file_status, findcmd.c:113). A failed lookup leaves no trace, so install-then-invoke resolves with zero user action.

What changed

The set +h / tempenv-PATH bypass path in find_user_command memoized misses into results[] (rubash#159 — a Windows miss costs tens of ms) and served them verbatim until hash -r or a PATH change. The memo is kept, but the serve is now gated: a memoized miss runs the rubash#392 candidate probe grid (every candidate spelling stat'ed under every PATH dir) once before being honored. A probe hit drops the stale entry and the real walk resolves the file that appeared mid-session.

  • confirm_listing_miss now reports probe.hit (a candidate exists NOW) alongside probe.moved (a listing was stale). hit is the memoized-miss oracle — moved alone would re-freeze the memo once the listing was refreshed.
  • The scan scaffold (split/translated PATH dirs + PATHEXT order) is factored into path_scan_scaffold, shared by the gate and the walk.
  • Bounded cost: a repeated miss pays one stat grid, never the full PATH×PATHEXT listing scan — mirroring GNU's per-lookup walk for unhashed names.
  • The hashed mirror (hash -p / BASH_CMDS, rubash#1137) and positive-memo serves are untouched.

Regression transcript (WSL GNU bash 5.3.x vs patched rubash, same script file)

miss=1 found=0 nmiss=1 nfound=0 tmiss=1 tfound=0   # identical on both

(plain lookup, set +h lookup, and PATH=dir command -v tempenv lookup around a mid-session file create inside an already-listed dir)

Test plan

  • cargo test --lib — 852 passed (incl. renamed windows_nohash_mode_memoizes_misses_with_probe_gate and new windows_memoized_miss_self_heals_via_probe_grid, which pins the bounded-cost contract via the listings-count seam)
  • tests/issue1723_negative_lookup_selfheal.rs — 5 tests: user scenario, set +h memoized-miss path, tempenv-PATH memoized-miss path, repeated-absent stays 127, hash -r/hash -p surface intact
  • tests/issue392_command_appears_after_miss.rs — 3/3 green (re-probe path unregressed)
  • hash/path integration files green: issue1360, issue1362, issue322, issue588, issue799, issue1047 (+2); failures observed in issue1361/issue1368/issue1389/issue1489/issue1129/issue1551 are identical on clean master — pre-existing environment limitations (fixture-PATH tools absent on this host), not regressions
  • rustfmt --check per-file clean on touched files (local cargo fmt hits the Windows 32K argv limit in deep worktrees; committed --no-verify per repo recipe — CI fmt is the authority)

Generated with Devin

…probe grid (#1723)

GNU never remembers a failed command search: search_for_command
re-stats even positively hashed entries on every lookup
(findcmd.c:348-380) and find_user_command_in_path walks $PATH live for
every unhashed name (findcmd.c:623-697), so install-then-invoke
resolves with zero user action. The `set +h` / tempenv-PATH bypass
memoized misses into results[] (rubash#159) and served them verbatim —
a `wpm install` into an already-listed PATH dir stayed "command not
found" until `hash -r`.

Keep the negative memo (a Windows miss costs tens of ms) but gate the
serve: a memoized miss runs the rubash#392 candidate probe grid once —
every candidate spelling stat'ed under every PATH dir — before being
honored. A probe hit drops the stale entry and the real walk resolves
the file. The probe grid is the bounded cost: repeated misses pay one
stat walk, never the full PATH x PATHEXT listing scan, mirroring GNU's
own per-lookup walk for unhashed names.

confirm_listing_miss now reports probe.hit (a candidate exists NOW) in
addition to probe.moved (a listing was stale); hit is the memoized-miss
oracle because it keeps answering true on every later probe while the
file exists — moved alone would re-freeze the memo once the listing
was refreshed. The scan scaffold (split/translated PATH dirs + PATHEXT
order) is factored into path_scan_scaffold so the gate and the walk
share it. The hash-table mirror (`hash -p` / BASH_CMDS, rubash#1137)
is untouched, as are positive-memo serves.

Verified against WSL GNU bash 5.3.x (script-file probe, /mnt/d):
miss=1 found=0 for plain, `set +h`, and `PATH=dir cmd` lookups around
a mid-session file create — identical transcripts under rubash.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 force-pushed the fix/1723-negative-lookup-selfheal branch from 61d019a to dc38bd3 Compare October 26, 2026 12:41
@caomengxuan666
caomengxuan666 merged commit 07e64a9 into master Oct 26, 2026
8 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1723-negative-lookup-selfheal branch October 30, 2026 01:41
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.

[bug] CommandLookupCache memoizes NEGATIVE lookups - GNU never remembers failed searches (install-then-invoke requires hash -r)

1 participant