Repository navigation
fix(executor): confine fork/respawn state transport to the exec boundary (Refs #3049) - #3736
Merged
Merged
Conversation
…ary (Refs #3049) GNU's fork and exec boundaries differ exactly where rubash conflated them: a forked subshell shares the parent's variable table in-process (execute_cmd.c execute_in_subshell), while a newly exec'd shell receives only the export environment (variables.c maybe_make_export_env / make_env_array_from_var_list) — internal state like readonly/array attributes is never environment data. Rubash emulates the fork by respawning `rubash -c`, so the parent's table is serialized into `__RUBASH_*` environment keys. Two leaks followed: 1. A respawned process's environ permanently carries its birth transport, and compose_child_environment's process-env mirror arm re-projected every `__RUBASH_*` entry into REAL children. The attribute lists landed in the exec'd bats-exec-test, whose VarTable::from_values applied them: BATS_TEST_TAGS was born `declare -ar`, its registration assignment failed "readonly variable", and bats-core test #71 deadlocked. 2. VarTable::from_values imported the `__RUBASH_*_VARS` attribute strings before respawn provenance was validated, so even a non-respawn birth applied a foreign parent's attributes. Fixes: - executor/init.rs::new_inner: decide respawn provenance on the raw environment BEFORE from_values; for non-respawn births strip the whole transport family (new predicate compound_exec::fork_respawn_transport_key) from both the import map and the process env, so residue can neither be imported nor ride the child-env mirror onward. - executor/init.rs: gate the __RUBASH_STATE_FILE splice on validated respawn provenance, and restore spliced entries to the process env WITHOUT journaling (execve-shape restoration, not a session write). - executor/init.rs::initialize_fresh_shell_env_vars: for keep_shlvl (validated respawn) skip mark_initial_exported_vars entirely — the exported set is already imported from the transported __RUBASH_EXPORTED_VARS list, and the recompute promoted the parent's UNEXPORTED variables (which ride the respawn env as the fork channel) to att_exported, snowballing into exec'd children. - executor/readonly_functions.rs::compose_child_environment: project `__RUBASH_*` mirror entries only when this session journaled a set for them (the G-03 mirrored-assignment contract). This also reproduces the rubash#2259 adjudication — a script's own entry-stamped __RUBASH_SCRIPT_NAME keeps projecting while ambient foreign copies stay blocked — and additionally blocks the ambient frame stamps __RUBASH_CURRENT_LINE/__RUBASH_CURRENT_FILE (GNU's line_number/BASH_SOURCE are C globals, never environ data). Fork-shaped respawns are untouched: env_map bases still select via rubash_spawn_inherited_state and mint their own stamps. Evidence (WSL, GNU Bash 5.3.20 oracle): - tests/issue3049_bats71_ctrl_c_hang.rs: 2/2 — the real bats-core #71 chain (bats -> bats-exec-suite -> bats-exec-file -> bats-exec-test) completes in ~10s; previously hung past the 120s cap. - issue2259_interactive_marker_leak_regressions: 6/6 (was 5/6 on base — ambient_frame_stamps_do_not_reach_script_children fixed). - 19 adjacent env/spawn-boundary suites green (2058/2423/2723/2586/ 1074/1083/1274/1276/2565/2894/1461/1497/1766/1806/s6/1654/70/2064/ 2884). issue2136: 9/10, the orphan arm is environment-bound flaky under WSL subreaper reparenting (fails identically on base). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666
force-pushed
the
fix/3049-child-state-transport-boundary
branch
from
November 15, 2026 18:40
884e0aa to
64af72a
Compare
This was referenced Nov 15, 2026
Closed
caomengxuan666
added a commit
that referenced
this pull request
Nov 17, 2026
…awn strip (Refs #3856) (#3857) 0a405d8 (#3736) added __RUBASH_FD_ to fork_respawn_transport_key, so Executor::new_inner deleted every fd-delivery stamp for any birth that is not a validated internal respawn — before init.rs could collect them into inherited_fd_handles. exec/external/comsub/pipeline children are never respawns, so all fd>=3 delivery through the env channel died on Windows (unix masks it via pin+adoption). The keys are per-spawn delivery minted fresh for THIS child and consumed+stripped at entry — not respawn residue — so they do not belong to the #3049 family. Verified: tests/issue3311_exec_child_fd_delivery 4/4 red->green; exec-own/exec-amb/plain-own fd>=3 writes reach children again.
caomengxuan666
added a commit
that referenced
this pull request
Nov 17, 2026
#3560) (#3858) * fix(executor): keep __RUBASH_FD_* delivery stamps out of the non-respawn strip (Refs #3856) 0a405d8 (#3736) added __RUBASH_FD_ to fork_respawn_transport_key, so Executor::new_inner deleted every fd-delivery stamp for any birth that is not a validated internal respawn — before init.rs could collect them into inherited_fd_handles. exec/external/comsub/pipeline children are never respawns, so all fd>=3 delivery through the env channel died on Windows (unix masks it via pin+adoption). The keys are per-spawn delivery minted fresh for THIS child and consumed+stripped at entry — not respawn residue — so they do not belong to the #3049 family. Verified: tests/issue3311_exec_child_fd_delivery 4/4 red->green; exec-own/exec-amb/plain-own fd>=3 writes reach children again. * fix(executor): revoke delivered fd N on command-local N>&- / N<&- (Refs #3560) The external fd delivery stamped every ambient fd>=3 into the child's __RUBASH_FD_* env keys (and unix pins) before the redirect walk, and the walk's close arm only skipped the entry — so `cmd 3>&-` left the ambient stamps in place and the child still saw fd 3. GNU services the close with r_close_this inside the ordered do_redirections walk (redir.c:237; close_buffered_fd at redir.c:1239) in the forked child. Route the numbered close through apply_pending_close_at — the same revocation a {var} pending close uses: env stamps removed, pins dropped, carriers retired to the dead list, walk bindings cleared, and the table step snapshots into fd_var_close_restore so undo_child_fd_var_redirects restores the parent's binding at command end (the close is child-scoped, never a parent exec N>&-). Depends on the __RUBASH_FD_* delivery-strip fix (#3856): on master the env channel is dead anyway, so this pin is only observable once delivery works. Verified: pin 5/5 green here, 4/5 red without this commit; GNU bash 5.3.20 script probes match byte-for-byte.
This was referenced Nov 20, 2026
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
rubash -c, serializing the whole variable table into__RUBASH_*env keys. A respawned process's environ then permanently carried its birth transport, andcompose_child_environment's process-env mirror re-projected it into real exec'd children —VarTable::from_valuesapplied the parent's attribute lists, soBATS_TEST_TAGSwas borndeclare -arinsidebats-exec-testand bats-core test Missing external command resolution costs ~60-85ms; consider caching negative lookups #71 deadlocked on its readonly registration assignment.compose_child_environmentnow projects__RUBASH_*names only when this session journaled a write for them (the G-03 mirrored-assignment contract); ambient frame stamps__RUBASH_CURRENT_LINE/__RUBASH_CURRENT_FILEnever project (GNU'sline_number/BASH_SOURCEare C globals, never environ data).Executor::new_innerdecides respawn provenance on the raw env beforeVarTable::from_valuesimports attribute strings; non-respawn births strip the whole transport family (newfork_respawn_transport_keypredicate) from both the import map and process env. The__RUBASH_STATE_FILEsplice is gated on validated respawn and restores entries unjournaled.keep_shlvl(validated respawn) skipsmark_initial_exported_vars— the transported__RUBASH_EXPORTED_VARSlist already carries the parent's exported set; the recompute promoted the parent's unexported variables riding the fork channel.rubash_spawn_inherited_state.GNU ground:
execute_cmd.c execute_in_subshell(fork shares the table in-process) vsvariables.c maybe_make_export_env/make_env_array_from_var_list(exec hands over only the export environment).Test plan
tests/issue3049_bats71_ctrl_c_hang.rs: 2/2 — real bats Missing external command resolution costs ~60-85ms; consider caching negative lookups #71 chain completes in ~10s (was hung past 120s cap)issue2259_interactive_marker_leak_regressions: 6/6 (was 5/6 on base —ambient_frame_stamps_do_not_reach_script_childrenfixed)issue2136_respawn_provenance: 9/10 — orphan arm is environment-bound flaky under WSL subreaper reparenting (verified identical on base)Generated with Devin