Repository navigation
fix(env): unbind drops inherited process-env copies (#917 rework) - #943
Merged
Merged
Conversation
#917 gated unset_process_env behind shell_assignment_needs_process_env, so `unset` of a name inherited from the parent env removed only the table binding and left the process-env copy behind. Every read path that falls back to the process env on a table miss resurrected the inherited value (exact_case_env_var bare-$NAME reads, nounset existence checks, the fork+exec env_map base — the #182 revival class): 9/16 reviewer probes diverged from GNU/master. GNU variables.c:3839 unbind_variable removes the name from the export environment unconditionally. unset_process_env now removes any name that is actually present in the process env — the special-name gate only governs writes; the existence check is a single non-locking getenv, keeping the #916 perf win for the common never-mirrored case. The same gate had also leaked into Executor::drop's fork-time process_env_snapshot restore: once unset really removes an ordinary name, a comsub child would otherwise delete the parent's env copy permanently. The snapshot restore now writes unconditionally (keeping the pre-#916 TMPDIR exclusion), matching pre-#917 semantics exactly. Verified: 16/16 inherited-name probes match the GNU column in the #917 review comment; env/unset/nounset targeted suites plus comsub/subshell/assign neighbors green; 2000 export+unset loop ~0.5s (perf win intact). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Oct 21, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 21, 2026
…est platform status, current architecture (#982) * docs(readme): overhaul — Performance section with pinned numbers, honest platform status, current architecture - New Performance section, every number pinned to its measuring issue/PR: - Android-matrix interpreter triage closed with numbers (#607/#608/#609 -> #665/#671/#679, #666, #672/#678; net ~1.06x GNU scalar assign) - array store O(n^2)->O(1) amortized (#618/#616: assoc 445x->9.9x, indexed 736x->3.8x vs GNU at 5000 keys; docs/performance.md ledger) - literal fast-path wave with measured deltas: #967 (177->155 ms), #966 (1.41x->1.10x), #974 (~11%), #959 (3.65x->3.16x), #958 (-10%), #956/#973/#954 family - export/unset economics: #916 measured costs stated, write lane landed (#917/#918/#920, #943 correctness rework), issue open on residual - Windows process economics: #913 one hidden console per session (~22 ms/spawn -> <=1 per session; tests/console_window_gate.rs), #884 tput inline arm (1165 ms -> 47 ms, 269-row oracle matrix), WinuxCmd#1269 twin (~17 ms -> ~0.4 ms in-process), #800 face B open - Platform status made verifiable: Linux CI lanes + upstream-corpus replay job named; 19/24 Linux pass dated and cited (#500) instead of 'and climbing'; macOS now runs lib tests in CI, not just compiles - Architecture tree updated to the real src/ layout (bin/expand/fd/jobs/ shell added); builtin count 40+ -> 62 engine builtins per the test-guarded docs/builtins.md + hidden fast-path builtins - Testing section: regression suite, console gate, corpus replay commands - Compatibility baseline line updated to vendored Bash-5.3 patch 20 (#957) with local+WSL 5.3.20 oracles (#978) - zh README rewritten to full parity with EN (was still describing the pre-dialect path model, missing the identity section, claiming 5.3.0) - Last-updated stamp refreshed * docs(readme): date the Linux corpus pass from the archive — 2026-09-27 wt4/linuxrun, 17/24 per its own ledger The "(2026-09-26, #500)" tag was wrong on both counts: 09-26 is the earlier "not-yet-usable" judgment (first smoke 8/10, gap-ledger C4) that the 2026-09-27 wt4/linuxrun lane explicitly declared obsolete, and #500 only carried the figure forward — it is not the measuring record. No archived record supports 19/24: the lane's own corpus-slice table (docs/LINUX-RUN-STATUS.md, deleted in #478, archived in #477 section 4 and #581) tallies 17 suites at 0 diff + trap/redir/glob/extglob/new-exp/ read/ifs-posix with diffs = 17/24. README now reads "17/24 byte-identical (2026-09-27 wt4/linuxrun lane, ledger archived in #477/#581)" in both the platform-status paragraph and the compatibility table, EN + zh-CN at parity. Addresses review comment 6319063190 on #982. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
4 tasks done
caomengxuan666
added a commit
that referenced
this pull request
Oct 22, 2026
…971) The wait -p variable-capture unbind (job_builtins.rs execute_wait) and the coproc unbind channel (coproc_unset_vars) removed the variable-table entry but left the inherited process-env copy — the same residue class #943 fixed for `unset`: a name that predates the #916 write mirror was never removed, and every table-miss fallback resurrected it (exact_case_env_var bare-$NAME reads, nounset boundness, the child-spawn env base). GNU anchors: - builtins/wait.def:166 -> builtins/common.c:1021 builtin_unbind_variable: find_variable (variables.c:2363) resolves the nameref chain, so the readonly/non-unsettable gates test the REFERENT while diagnostics name the operand; a dead chain leaves v == 0 and the operand is makunbound literally (variables.c:3788/3959). A bracketed operand is a literal name there — `wait -p 'A[0]'` never unbinds an element, so scalars and readonly arrays survive intact (the old unset_array_element call was a second, independent divergence). - execute_cmd.c:2450 coproc_unsetvars: unbind_variable_noref(<name>_PID) literal + check_unbind_variable(<name>) nameref-resolved. - variables.c:3959 makunbound disposes the whole SHELL_VAR: mirror entry, typed cell, all attribute bits (variables.c:3839 export-env drop). The unbind now also clears the typed `variables` cell and every attribute mark (the `declare -x CP` residue is gone), records UNSET_DYNAMIC_VARS for dynamic names, routes visible locals through makunbound's invisible-mark branch (unset_outer_local_variable), and drops the __RUBASH_COPROC_*_<pid> fd-channel bookkeeping keys. Probes vs WSL GNU bash 5.3.20 (script files): wait -p/-n -p on inherited names -> unbound (set -u aborts), bracketed operand is a literal no-op, nameref unbinds the referent (readonly referent: `wait: ref: cannot unset: readonly variable`), non-unsettable BASH_SOURCE errors, LINENO stays unbound, function-local -> `declare --` invisible, coproc CP/COPROC and *_PID unbound with arith fallback 0. Regressions: tests/issue971_wait_coproc_unbind_env_regressions.rs — 12 tests, 11 fail pre-fix. Neighbors green: issue352/387/549/550 + unset/env/nounset files. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666
added a commit
that referenced
this pull request
Oct 22, 2026
…971) The wait -p variable-capture unbind (job_builtins.rs execute_wait) and the coproc unbind channel (coproc_unset_vars) removed the variable-table entry but left the inherited process-env copy — the same residue class #943 fixed for `unset`: a name that predates the #916 write mirror was never removed, and every table-miss fallback resurrected it (exact_case_env_var bare-$NAME reads, nounset boundness, the child-spawn env base). GNU anchors: - builtins/wait.def:166 -> builtins/common.c:1021 builtin_unbind_variable: find_variable (variables.c:2363) resolves the nameref chain, so the readonly/non-unsettable gates test the REFERENT while diagnostics name the operand; a dead chain leaves v == 0 and the operand is makunbound literally (variables.c:3788/3959). A bracketed operand is a literal name there — `wait -p 'A[0]'` never unbinds an element, so scalars and readonly arrays survive intact (the old unset_array_element call was a second, independent divergence). - execute_cmd.c:2450 coproc_unsetvars: unbind_variable_noref(<name>_PID) literal + check_unbind_variable(<name>) nameref-resolved. - variables.c:3959 makunbound disposes the whole SHELL_VAR: mirror entry, typed cell, all attribute bits (variables.c:3839 export-env drop). The unbind now also clears the typed `variables` cell and every attribute mark (the `declare -x CP` residue is gone), records UNSET_DYNAMIC_VARS for dynamic names, routes visible locals through makunbound's invisible-mark branch (unset_outer_local_variable), and drops the __RUBASH_COPROC_*_<pid> fd-channel bookkeeping keys. Probes vs WSL GNU bash 5.3.20 (script files): wait -p/-n -p on inherited names -> unbound (set -u aborts), bracketed operand is a literal no-op, nameref unbinds the referent (readonly referent: `wait: ref: cannot unset: readonly variable`), non-unsettable BASH_SOURCE errors, LINENO stays unbound, function-local -> `declare --` invisible, coproc CP/COPROC and *_PID unbound with arith fallback 0. Regressions: tests/issue971_wait_coproc_unbind_env_regressions.rs — 12 tests, 11 fail pre-fix. Neighbors green: issue352/387/549/550 + unset/env/nounset files. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
4 tasks done
caomengxuan666
added a commit
that referenced
this pull request
Oct 23, 2026
[P3][env] wait -p / coproc 路径 unbind 残留(与 #943 同源)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rework of the inherited-name
unsetregression flagged in the #917 review comment.unset_process_envwas gated onshell_assignment_needs_process_env(the special-name write list). The gate is correct on the write path (that is the [perf] export/unset per-op cost ~100x: 2k dynamic export+unset 13x slower than bash #916 perf win), but wrong on the unbind path: a name inherited through the parent process env predates the mirror and was never removed, sounset FOOleftFOO=parentin the process env — and every table-miss read fallback resurrected it (exact_case_env_varbare-$NAMEreads,set -uexistence checks, the fork+execenv_mapbase — the [bug] 赋值 RHS 嵌套引号命令替换复活已 unset 的环境变量(rubash#163 根因层) #182 revival class).unset_process_envnow removes any name actually present in the process env — a single non-lockingvar_osexistence check guards the lockedremove_var, so the common never-mirrored unset stays cheap. GNU reference:variables.c:3839 unbind_variabledrops the name from the export environment unconditionally.Executor::drop'sprocess_env_snapshotrestore went through the now-gatedset_process_env. Once unset really removes ordinary names, a$(unset FOO)comsub child would permanently delete the parent's process-env copy. The snapshot restore is not an assignment mirror — it now writes unconditionally (pre-perf(env): gate the process-env mirror on special names (#916) #917 semantics), keeping the pre-[perf] export/unset per-op cost ~100x: 2k dynamic export+unset 13x slower than bash #916 TMPDIR exclusion.Probe matrix (inherited
FOO=parent/LANGC=xx, vs the GNU column in the #917 comment)All 9 previously-divergent shapes now match:
unset FOO; echo "[$FOO]"[][]set -u; unset FOO; echo "${FOO}"FOO: unbound variable, noafterunset LANGC; Y=$(printf hi); echo "[$LANGC][$Y]"[][hi][][hi]unset FOO; echo "[$((FOO))]"(FOO=7)[0][0]unset FOO; export FOO; declare -p FOOdeclare -x FOOdeclare -x FOOunset FOO; ( echo bg=[$FOO] )bg=[]bg=[]FOO=x; unset FOO; echo "[$FOO]"[][]unset FOO; FOO=new; unset FOO; echo "2=[$FOO]"2=[]2=[]unset LANGC; Y="$(dirname /d/x)"; echo "[$LANGC]"[][]Passing side re-verified:
printenv FOO/cmd /c set FOOrc=1, fresh-name export→printenv→unset chain, array non-export (#534),unset PATH/PATH=restore,declare -punbound, andx=$(unset FOO)parent-env integrity. Extra edge probes:export -nkeeps the bound value ([parent], printenv rc=1), flat-subshell( unset FOO )restore,localscoping, reassign-then-unset — all consistent.Tests
cargo testenv/unset/nounset files: issue534/538/635/638/639/645/651/311/529/535/705 — 98 tests green.Adjacent gaps noticed (pre-existing, not introduced here — left untouched per ticket scope)
wait -p NAMEscalar unbind (executor/job_builtins.rs:203) and coproc unbind (:749,:772) remove the table binding without clearing the process-env copy — same residue class, but these paths never mirrored removals even pre-perf(env): gate the process-env mirror on special names (#916) #917.local FOO(declared-but-unset) binding still lets the env fallback read the inherited residue — GNU reports the local as unbound ([]). Master's build shows[outer]via the old write mirror; this branch shows[parent]via residue. Orthogonal to unset: the fallback should suppress names with a declared-unset binding.restore_shell_envrestores from a table snapshot, so it cannot unconditionally mirror ordinary names back into the process env without contradicting [perf] export/unset per-op cost ~100x: 2k dynamic export+unset 13x slower than bash #916; residue lost there is unobservable through current read paths (env_map overlay covers the table).Fixes #917
Generated with Devin