Skip to content

fix(env): unbind drops inherited process-env copies (#917 rework) - #943

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/drop-process-env-mirror
Oct 21, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/drop-process-env-mirror

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Rework of the inherited-name unset regression flagged in the #917 review comment.

Probe matrix (inherited FOO=parent/LANGC=xx, vs the GNU column in the #917 comment)

All 9 previously-divergent shapes now match:

Probe GNU This branch
unset FOO; echo "[$FOO]" [] []
set -u; unset FOO; echo "${FOO}" FOO: unbound variable, no after same (exit 1)
unset LANGC; Y=$(printf hi); echo "[$LANGC][$Y]" [][hi] [][hi]
unset FOO; echo "[$((FOO))]" (FOO=7) [0] [0]
unset FOO; export FOO; declare -p FOO declare -x FOO declare -x FOO
unset 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 FOO rc=1, fresh-name export→printenv→unset chain, array non-export (#534), unset PATH/PATH= restore, declare -p unbound, and x=$(unset FOO) parent-env integrity. Extra edge probes: export -n keeps the bound value ([parent], printenv rc=1), flat-subshell ( unset FOO ) restore, local scoping, reassign-then-unset — all consistent.

Tests

  • cargo test env/unset/nounset files: issue534/538/635/638/639/645/651/311/529/535/705 — 98 tests green.
  • Comsub/subshell/assign neighbors: issue_s6, issue319, issue154, posixexp2, issue772, issue845, assign_prefix_subshell, assignment_chain, issue421, issue428, issue297_300, issue148 — 96 tests green.
  • Perf sanity: 2000 export+unset loop ≈0.5s (non-locking getenv per unset; [perf] export/unset per-op cost ~100x: 2k dynamic export+unset 13x slower than bash #916 win intact).

Adjacent gaps noticed (pre-existing, not introduced here — left untouched per ticket scope)

  • wait -p NAME scalar 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.
  • A 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_env restores 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

#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>
@caomengxuan666
caomengxuan666 merged commit 096f02c into master Oct 21, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/drop-process-env-mirror branch October 21, 2026 08:45
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>
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>
caomengxuan666 added a commit that referenced this pull request Oct 23, 2026
[P3][env] wait -p / coproc 路径 unbind 残留(与 #943 同源)
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.

1 participant