Repository navigation
fix(executor): slice the process-global command lookup cache per session (rubash#2078) - #2149
Conversation
…ion (rubash#2078) The command-resolution cache in executor/path.rs (rubash#159) was a process-global SINGLE-fingerprint store: one results/listings/probes set guarded by one env fingerprint, plus one `hashed` map mirroring every session's user-visible `__RUBASH_HASH_TABLE`. The mirror deliberately survives fingerprint resets (rubash#1137), so two Sessions held in one process (the embed API's supported shape, contract Q5) cross- contaminated their parse/resolution results: - Session A `hash -p X tool`, then Session B resolves `tool`: B's find_user_command consulted the one global mirror before its PATH walk and returned (and executed) A's path. - Session B `hash -r` or any PATH bind flushed the one global mirror and dropped Session A's remembered locations (the command died with 127). Fix, in the issue's key-extension shape (chosen over re-homing the cache into Session because every cache entry point already receives the session's env map, while the builtin faces receive only VarTable): the static store becomes a map of per-session slices keyed by SESSION_SCOPE_KEY (`__RUBASH_SESSION_SCOPE`), stamped fresh per Executor::new entry; an env that already carries the token keeps it, so a lineage re-entering the constructor on a cloned env (the fork-copy shape command_substitution_executor uses) stays on the parent's slice - exactly the sharing the hashed_cache_fork_guard brackets assume. The token is in-memory only: `__RUBASH_*` names are excluded from the initial export set (env_helpers is_initial_export_candidate) and from the spawn env (rubash_spawn_inherited_state filter). Env maps without the token (hand-built test maps, composed child-env lookups) share the "" fallback slice with the old single-store behavior. Slices are capped at 16 live scopes with clear-on-overflow - a pure cache, so eviction is a cold cycle, never a correctness change. GNU anchor: findcmd.c:367-380 search_for_command consults THAT shell's own hashed_filenames, and sv_path (variables.c:5919) -> phash_flush (hashcmd.c:57) flushes that shell's table; nothing in GNU shares a hash table between shells. Verification: - tests/issue2078_session_parse_cache_regressions (new, 4 pins, two Sessions driven through the Tier-C API in one test process): 4/4 pass on the fix; pins 1-2 fail on pristine master with the issue's exact signatures (B executes A's binary, count [A,A] vs expected [A,B]; A's pinned command exits 127 after B's hash -r). - cargo test --release --lib: 1063 passed, 0 failed. - Hash/session integration suites (issue1360/1361/1362/1368/1382/1489/ 1551/1648/2066, session_api, session_api_interrupt): every failure is byte-identical on pristine master - pre-existing, environment-bound. - scripts/true-baseline.sh type builtins shopt invocation (WSL GNU Bash 5.3 patch 20): fix == pristine (type 6 env=0 harness shell-name asymmetry, /tmp/bash vs /tmp/rubash.exe; all three others 0). fmt disclosure: `cargo fmt` fails in this environment (os error 206, the documented hook precedent); rustfmt --edition 2021 was run explicitly over every changed file instead, and this commit uses --no-verify for that reason only.
|
主会话审阅(2026-10-30,含 GNU bash 5.3.20 oracle 实测): 行为锚核实通过——本单要求的行为就是 5.3.20 的模型,主会话在自编 oracle(bash 5.3.20)上逐条验过:① 合并前需改一处(语义,非风格): 记录在案、不拦的两点:① scope 令牌从克隆 env 继承(lineage 复入)在本设计内成立,令牌不出进程、且同进程的 session 同属一个宿主,故不按 #2129 的跨界伪造面处理;但请在令牌注释里写清这条边界(环境若由不可信输入拼装,宿主不得直喂 Executor)。② 无令牌 env 共用 CI:其余全绿;Windows 金标 1 红为 |
…rubash#2078 review) The 16-scope cap cleared the WHOLE store on overflow, including the hashed mirror of still-live sessions. The mirror is not a cache: it is the user-visible hash table (hash -p pins, hash listing), and GNU keeps a shell's hashed_filenames for the shell's whole lifetime — entries die only by that shell's own PATH assignment (sv_path, variables.c:5919 = hashcmd.c:57 phash_flush) or hash -r. A per-request host rolling past 16 scopes would silently drop a live session's pins, re-entering pin 2's failure shape (pinned command falls back to PATH/127) through the cap instead of a sibling's hash -r. Split the store: CommandLookupStores holds the pure resolution slices (results/listings/probes/scaffold — capped, single-slice LRU eviction, never a global clear) apart from the per-scope hash-table mirrors, which are never evicted and are bounded by each scope's own hash usage. Mirror-only operations (hash -p write, PATH-bind flush, fork guard) no longer create or churn resolution slices either. New pin 5 in tests/issue2078_session_parse_cache_regressions.rs: a live session's hash -p pin and hash listing survive 20 churn sessions rolling the cap. It fails on the pre-split tree (clear-on-overflow) and passes here; pins 1-4 unchanged and green.
|
主会话接管返工完成(作者侧不迭代,按惯例主会话侧收尾):新 commit 01491f0 压在本 PR 原提交之上,未改作者提交。 按审阅意见拆开了两类数据: 新增 pin 5(17+ scope 滚动后存活 session 的 |
Closes #2078
Root cause
The command-resolution cache in
src/executor/path.rs(introduced by #159) was a process-global single-fingerprint store: oneresults/listings/probesset guarded by one env fingerprint, plus onehashedmap mirroring every session's user-visible__RUBASH_HASH_TABLE. The mirror deliberately survives fingerprint resets (#1137), so twoSessions held in one process (the embed API's supported shape, contract Q5) cross-contaminated their parse/resolution results:hash -p X tool, then Session B resolvestool: B'sfind_user_commandconsulted the one global mirror before its PATH walk (path.rshashed consult) and returned — and executed — A's path.hash -r(or any PATH bind →flush_command_hash_table) flushed the one global mirror and dropped Session A's remembered locations; A's pinned command then died with 127.Fix — the issue's key-extension shape
The static store becomes a map of per-session slices keyed by
SESSION_SCOPE_KEY(__RUBASH_SESSION_SCOPE), stamped fresh perExecutor::newentry (src/executor/init.rs):command_substitution_executoruses) stays on the parent's slice, exactly the sharing thehashed_cache_fork_guardbrackets assume;__RUBASH_*names are excluded from the initial export set (env_helpers::is_initial_export_candidate) and from the spawn env (rubash_spawn_inherited_statefilter), so it never crosses a process boundary;""fallback slice with the old single-store behavior;Chosen over re-homing the cache into
Session: every cache entry point already receives the session's env map (and the builtin faces receive onlyVarTable), so key extension isolates the whole class with a fraction of the ripple a per-Session instance would need.GNU anchor:
findcmd.c:367-380 search_for_commandconsults THAT shell's ownhashed_filenames, andsv_path(variables.c:5919) →phash_flush(hashcmd.c:57) flushes that shell's table — nothing in GNU shares a hash table between shells.Verification
tests/issue2078_session_parse_cache_regressions.rs(new, 4 pins, twoSessions driven through the Tier-C API in one test process; execution-based observables):d5c172ae: pins 1-2 fail with the issue's exact signatures — pin 1: B executes A's binary (count["A","A"], expected["A","B"]); pin 2: A's pinned command exits 127 after B'shash -r. Pins 3-4 are guards that hold on both (interleaved fingerprints; single-session Q5 semantics).cargo test --release --lib: 1063 passed, 0 failed.issue1360/1361/1362/1368/1382/1489/1551/1648/2066,session_api,session_api_interrupt): every failure is byte-identical on pristine master — pre-existing, environment-bound.scripts/true-baseline.sh type builtins shopt invocation(WSL GNU Bash 5.3 patch 20): fix == pristine (type 6 env=0— the harness's own/tmp/bashvs/tmp/rubash.exeshell-name asymmetry;builtins/shopt/invocationall 0).Disclosure
cargo fmtfails in this environment (os error 206, the documented hook precedent);rustfmt --edition 2021was run explicitly over every changed file instead, and the commit uses--no-verifyfor that reason only.Do not merge — awaiting review.