Repository navigation
fix(#822-engine): winsize bind writes both storages - #2564
Merged
Merged
Conversation
bind_lines_columns inserted only into shell_state.env_vars (the mirror read by get_env / child-env composition) while $name expansion reads shell_state.variables (the record store) FIRST with a mirror fallthrough (variable_state.rs shell_variable_value). Once a LINES/COLUMNS record existed - parent env import at Executor::new (init.rs:949 -> VariableStore::from_environment) or one user assignment - the resize/startup bind left the record stuck at its old value while the child env tracked: shell-internal and child views diverged (niubash#822, Linux PTY probes A4/A8). GNU citation (vendored tree, bash.git @9c465866): - variables.c:1039-1055 sh_set_lines_and_columns: binds LINES (:1051) then COLUMNS (:1054) via bind_variable - ONE storage in GNU; rubash's variables/env_vars split is our implementation detail, and a bind writing only one of the two is the bug. - variables.c:3225 bind_variable -> :3054 bind_variable_internal: an existing entry takes the assign_value: arm (:3151); only the value cell is replaced (:3207 var_setvalue) so attributes survive, and exported_p triggers the export-env rebuild (:3214-3215) so an exported COLUMNS stays exported with the updated value. Fix: mirror set_env's dual-write (public_accessors.rs:839): after the mirror insert, update the record's scalar in place; absent records stay absent (the mirror fallthrough keeps serving them, matching GNU's non-exporting fresh bind); the G-01 process-env mirror is unchanged. bind_interactive_console_winsize and bind_interactive_screen_size ride the same path. WSL GNU Bash 5.3.x pins (evidence/822-dual/wsl/pin-output.txt): parent exports COLUMNS=200 in a 30x100 pty -> $COLUMNS=100, child env COLUMNS=100, declare -x COLUMNS="100"; resize -> tracks both ways; user assignment COLUMNS=55 then resize -> 120 then 80/24; exported assignment -> value tracks, stays exported. Engine tests (api/consumer_tests.rs): the two record-present shapes fail on base ($COLUMNS stuck at 200/55) and pass with the fix; a no-record regression guard pins the mirror fallthrough and that the bind creates no record and exports nothing. pywinpty ConPTY matrix (headless, evidence/822-dual/matrix): import-200 stuck at 200/55 across 100/120/80 columns pre-fix, tracks with the fix; fresh-shell case byte-identical before/after.
caomengxuan666
added a commit
that referenced
this pull request
Nov 2, 2026
…telist gate GNU keeps exactly one line_number: a process-global C int written by SET_LINE_NUMBER (execute_cmd.c:295) and read by every builtin error path. rubash split it across two storages: the env_vars map (canonical) and a process-env mirror written only when the raw command words matched a 15-word whitelist (command_needs_process_line_env), so the six builtins that read std::env (alias/help/kill/shift/shopt/setattr) saw a stale or missing line under indirect invocation (x=shift; $x bogus) or host call_function dispatch. set_current_line now writes BOTH storages on every stamp (the #2564 COLUMNS both-storages shape), still deduped against the last OS write, and the whitelist gate is deleted. Map-first readers are unchanged. Pin: tests/issue2580_line_env_dual_store_regressions.rs (issue_2580_indirect_shift_diagnostic_carries_script_and_line, issue_2580_direct_shift_diagnostic_still_carries_script_and_line) — UNVERIFIED-BY-CAPTAIN (code-only delivery).
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.
What
bind_lines_columns(src/script_driver.rs) inserted only intoshell_state.env_vars(the mirror read byget_env/ child-env composition), while$nameexpansion readsshell_state.variables(the record store) first with a mirror fallthrough (executor/variable_state.rsshell_variable_value). Once a LINES/COLUMNS record existed — parent env import atExecutor::new(executor/init.rs:949->VariableStore::from_environment), or one user assignment — the resize/startup bind left the record stuck at its old value while the child env tracked: shell-internal and child views diverged (niubash#822, Linux PTY probes A4/A8).Fix: dual-write exactly like
set_env(executor/public_accessors.rs:839): after the mirror insert, update the record's scalar in place so attributes survive the rebind. Absent records stay absent (the mirror fallthrough keeps serving them — GNU's fresh bind does not export); the G-01 process-env mirror (:4150-4157shape) is unchanged.bind_interactive_console_winsizeandbind_interactive_screen_sizeride the same fixed path.GNU citation (vendored tree
bash.git @9c465866, Bash-5.3 patch 20)variables.c:1039-1055sh_set_lines_and_columns: binds LINES (:1051) then COLUMNS (:1054) viabind_variable— ONE variable storage in GNU; rubash'svariables(records) +env_vars(mirror) split is our implementation detail, and a bind path that writes only one of them is the bug.variables.c:3225bind_variable->:3054bind_variable_internal: an existing entry takes theassign_value:arm (:3151); only the value cell is replaced (:3207var_setvalue) so the attribute word survives, andexported_ptriggers the export-env rebuild (:3214-3215) — an exported COLUMNS stays exported and its exported value tracks.WSL GNU Bash 5.3.x behavioral pin (
/usr/local/bin/bash, pty via pythonpty)Raw transcript:
D:\repo\nbbuild\evidence\822-dual\wsl\pin-output.txt(driver:wsl_pin_pty_winsize.py).COLUMNS=200, pty 30x100echo $COLUMNSA1 value=100(import overridden)env | grep ^COLUMNS=COLUMNS=100(exported, new value)export -p | grep COLUMNSdeclare -x COLUMNS="100"A4 value=120,COLUMNS=120COLUMNS=55then resizeB1 55->B2 120->B3 cols=80 lines=24export COLUMNS=77then resizeC2 120,COLUMNS=120(stays exported)Engine tests (
src/api/consumer_tests.rs, Session-level, real$COLUMNSexpansion throughsession.run)issue822_winsize_bind_updates_imported_columns_record— A4 shape (imported exported record 200/55 +notify_terminal_size): fails on base ($COLUMNSstuck at200), passes with fix; also pins exported-attribute survival and reverse resize.issue822_winsize_bind_updates_user_assigned_record— A8 shape (COLUMNS=55via the real assignment machinery, then resize): fails on base (stuck at55), passes with fix.issue822_winsize_bind_creates_no_record— regression guard: no record -> mirror fallthrough tracks; bind creates no record and exports nothing.Full
cargo test --libon the fix worktree: 1130 passed, 2 failed — the 2 (api::consumer_tests::issue2084_session_end_restores_host_process_state,executor::tests::unit_tests::shell_identity_is_used_for_default_dollar_zero) fail identically on pristineorigin/masterin the same environment (verified in a clean base worktree; environment-bound, pre-existing, not touched by this change).Headless pywinpty (ConPTY) integration matrix — niu rebuilt against this engine
Layout:
D:/repo/ovl822/{rubash,niubash}sibling worktrees (niubash[patch] ../rubash-> this engine). BEFORE =ovl102build (engine2ce27e61pre-fix, copied out read-only); AFTER = rebuilt with this patch. Driver:D:\repo\nbbuild\evidence\822-dual\pty_822_dual_matrix.py; raw transcripts underD:\repo\nbbuild\evidence\822-dual\matrix\{before,after}\. All headless — no CREATE_NEW_CONSOLE, no visible windows (owner order).$COLUMNS/$LINESviaecho "PROBE cols=$COLUMNS lines=$LINES"(stages: 100x30 -> 120x40 -> 80x24):COLUMNS=55then resizesChild env (
printenv COLUMNS) in the import scenario tracks 100/120/80 in BOTH builds (the mirror always did); with the fix the shell view now agrees with it — the divergence is gone.stty sizereturns the kernel truth in all runs, isolating the old divergence to the variable storages. Observation (pre-existing, identical before/after, out of scope here): an imported-exportedLINESdoes not appear in the composed child env whileCOLUMNSdoes.Notes
core.hooksPath=/dev/null: the pre-commit hook'scargo fmt --checkfails machine-wide with os error 206; both edited files passrustfmt --edition 2021 --checkindividually (verified).src/script_driver.rs+26/-1,src/api/consumer_tests.rs+185 (tests only).