Skip to content

fix(executor): convert kept dynamic tempenv binds under posix special builtins (Refs #2771) - #3683

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2771-posix-tempenv-conversion
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2771-posix-tempenv-conversion

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-FIX】

Problem

Under set -o posix, a tempenv prefix on a special builtin is kept rather than restored. Kept dynamic names (SECONDS, RANDOM, …) must convert to a real dynamic bind: SECONDS=100 : should leave $SECONDS ticking from 100, and RANDOM=7 : should seed the generator. Pin issue2771_posix_function_tempenv_conversion had 4 red cells: the in-function keep arm never converted, and the top-level keep converted into a static plain cell (100 forever).

Root cause

GNU merge_temporary_env (variables.c:4662) pops the tempvar before its bind_variable replay, so the dynamic assign hook fires on the kept value. Rubash replayed apply_shell_assignment while the name was still registered in the live tempenv frame — dynamic_bind_targets_plain_cell saw the shadow, stood the hook down, and the value landed on a second plain cell. Additionally the in-function keep arm in command_dispatch never invoked the conversion at all.

Fix

  • convert_kept_tempenv_dynamic_binds: before the replay, remove the name's registration in the current tempenv frame (above the last mark) and drop the frame's pre-bind snapshot — the pop GNU performs.
  • command_dispatch in-function posix keep arm: call convert_kept_tempenv_dynamic_binds(&merge_names) after merge_converted_tempenv_bindings.

Legs

  • Pin issue2771_posix_function_tempenv_conversion: 4 red on master → 5/5 green
  • GNU 5.3.20 script-file comparison byte-identical (in-f:100 / in-g:100 / in-f2:101 / top-after:102 / draws:19344,26956)
  • Adjacent tempenv/dynamic pins green: 1556, 1567, 1569, 1620, 2720, 3071, 1082, 1083, 1115, 1765
  • issue3211 reds reproduce on pristine master (regression from eaa357fc, unrelated — pre-existing)
  • RUSTFLAGS=-D warnings cargo build --locked clean

… builtins (Refs #2771)

GNU merge_temporary_env (variables.c:4662) pops the tempvar before its
bind_variable replay, so a kept SECONDS=/RANDOM= prefix on a posix
special builtin reaches the dynamic assign hook. The rubash keep arms
replayed apply_shell_assignment while the frame registration still
shadowed the cell — dynamic_bind_targets_plain_cell stood the hook
down and the value landed on a plain static cell.

Retire the name's frame registration and pre-bind snapshot inside
convert_kept_tempenv_dynamic_binds before the replay (the pop GNU
performs), and run the conversion on the in-function keep arm in
command_dispatch that never called it.
@caomengxuan666
caomengxuan666 merged commit 35437c4 into master Nov 15, 2026
8 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
fix(executor): re-derive POSIX mode on POSIXLY_CORRECT bind (Refs #3661)

GNU `sv_strict_posix` (variables.c:5820, 6257-6266) fires on every bind/unbind
of POSIXLY_CORRECT, not only on `set -o posix`. rubash split the two
directions: `apply_posix_mode_transition` keeps the `set -o` path's variable
binding; new `sync_posix_mode_from_variable` only re-derives the mode and
never writes the variable. Hooks sit at every bind/unbind funnel.
Written-text keying (expr.c:352, printf.def:112-113): arithmetic-element and
printf-element spellings do NOT flip the mode; statement-element and
declare/local-element operands DO.

Refs #3661 (the #2902 §2 gate: modernish dies rc=128 in capability
detection because a runtime `POSIXLY_CORRECT=1` assignment never armed
posix mode). #3661 stays open until the captain hand-closes it on this
merge; the #2902 re-run is dispatchable after that.

## 本 PR 删除了什么

No product code or files are deleted. The fix commit is +194/−3 across 12
source files (the −3 is the refactored transition body in `options.rs`).
The nail-correction commit rewrites the expectations of 4 existing nail
cells and the file header's probe summary, per GNU-oracle evidence; no nail
cell was removed (one was added: `temp_prefix_special_builtin_persists`).

## Captain verification (merge round R4, head 5e816ac, base 35437c4)

- Pin `issue3661_posixly_correct_runtime_hook_regressions`: 21/21 green on
  the merged shape (fail-first banked at delivery: 17 red / 3 green on base;
  GNU oracle matrix 25/25 SAME; neighbors 20 stems / 55 cells banked).
- `RUSTFLAGS="-D warnings" cargo check --locked --lib --bins`: rc=0, zero
  warnings. `rustfmt --check` on all 13 changed .rs files: rc=0.
- Full lib bilateral banked at delivery: 1249/0/4 both sides, failure
  name-set diff empty.
- CI on the R4 head (run 43723537799, head == 5e816ac): 3 failing jobs
  (Rust tests, Rust tests (macOS), GNU regression goldens and canaries),
  each failing ONLY on the issue2875 baseline cell
  (`api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell`);
  niu-canary success. PASS comment 6894681605 stands.
- Intersection (merge-base 2e02e90..35437c4 vs the PR's 13 files): exactly
  the 3 captain-released files — command_prepare.rs (tip #3482, ~3,900
  lines apart), temporary_assignments.rs (tip #3683 @@ -827 vs PR @@ -1460,
  ~600 lines, different functions), variable_state.rs (tip #3667 pure
  insertions in different functions). Rebase clean, zero conflicts.
- Zero-intersection exception for the tip move after R4: the tip moved
  35437c4 -> fc1b848 (user merged #3682, Refs #3189) while R4's legs
  were banked; the increment touches exactly one file,
  `src/executor/conditional/extglob.rs`, which is not among the PR's 13
  files (programmatic intersection: 0). The merged tree is therefore the
  R4-verified shape plus #3682's file only; no update-branch re-verify
  round is required. #3682's own CI was captain-named baseline-only
  (run 43721665167).
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