Repository navigation
fix(executor): record the unbind of BASH_ALIASES/BASH_CMDS so post-unset binds stay plain (Refs #3573) - #3577
Merged
Merged
Conversation
…set binds stay plain (Refs #3573) GNU variables.c:3839 unbind_variable (and :1197-1198: an unset dynamic variable loses its special meaning, even if subsequently set). unset of the two owner-table-backed dynamic assoc variables never recorded UNSET_DYNAMIC_VARS, so the #3220 door never stood down, declare -p kept serving the owner view, and alias/hash mutations resurrected the variable. Record the unbind at all three recording sites and honor it in the publisher, the element-bind arms and the element-unset arms. The generic compound path is untouched (already correct for fresh names). Regression pin: tests/issue3573_unset_dynamic_assoc.rs (14 cells, fail-first banked on pre-fix tip d374e78).
Member
Author
|
队长复核 PASS(头 腿(全部落地,队长独立核查日志):
订正:PR 正文与钉注释引的 合入:Refs #3573(合后队长手关 #3573);#3220 在本 PR 之后合。合入轮 update-branch 至 live 尖 + 合并形重验(issue3521 + issue3573 两钉茎 + lib 名集)。 |
caomengxuan666
marked this pull request as ready for review
November 14, 2026 15:57
This was referenced Nov 14, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 14, 2026
) (#3510) Refs #3488 — implements the ruling (a) recorded on the issue (user ruling, 2026-11-14). ## 根因 bats-core 的 timeout 监督靠进程同一性工作:bats-exec-test 的 `bats_start_timeout_countdown` 在测试壳内设 TERM trap,倒计时到期后 `bats_kill_processes_of` 用 `ps` 枚举测试壳的整棵后代树并逐 pid 发 TERM。GNU 下前台 `sleep` 是真子进程(jobs.c:2265 make_child,壳在 jobs.c:3064 wait_for 里等),投递杀掉子进程、等待立即返回、挂起的 trap 在下一命令边界运行(execute_cmd.c:643 run_pending_traps),内层约 1s 结束。 rubash 的进程内 sleep 仿真没有进程同一性(#2995 的缺口):树里根本没有 sleep 子进程可杀;投向壳本身的那一份投递又被 virtual-child 模型按「同组发送者 = 只投壳」归类而递延到 sleep 跑完,于是内层跑满约 10s(实测 rubash 10271ms/10439ms vs GNU 1021ms),timeout.bats #2/#3 只有最后一行 `((SECONDS < 10))` 不过。 ## 改动 政策层翻转,不动 trap 递延机制本体: - `src/executor/command_registry.rs`:sleep 行的 resolvable 策略 Replace → Yield(附 2026-11-14 裁决注释,体例同 stty 行的用户裁定注记);模块文档与 `ResolvablePolicy::Yield` 的文档同步改述;一致性测试里「无行 Yield」的断言改为「Yield 行恰为 sleep」并注明裁决出处;TimedProducer 面补登 per-face 记录 (Replace, FailClosed)——该模型只查 fail-closed 谓词(可解析则建模、不可解析则退让),行策略翻转后账本须如实记其自有规则,`per_face_stand_down_records_are_exact` 同步扩为五条。TimedConsumer 的 KD-4 记录与 timed 模型代码一律不动(审计 R6:timed 面是语义模型、不是分发)。 - `src/executor/command_dispatch_primary.rs`:Sleep 臂在 unix 下追加一道既有政策谓词 `registered_stand_down("sleep")`——行策略翻为 Yield 后该谓词在可解析轴为真,unix 上可解析形态全面退让 `execute_external` 真 spawn。#2398/#2836/#1497 三道历史退让在 unix 上被其涵盖、保留存档;非 unix 面不求值该子句,fastpath 原样保留(Windows 无此 watchdog 契约)。不可解析形态与不可解析名称(#1545 的 127 路径)行为不变。 - `docs/builtins.md`:fastpath 表 sleep 行补 stand_down=Yield 裁定注记(体例同 stty 行),清单引言加 unix 例外一句。 - `tests/issue3488_bats_timeout_real_sleep.rs`(新钉,首笔提交):断言 ① 前台 sleep 期间壳的子进程清单(ps 枚举,与 bats 同法)里有真 sleep 进程;② 树级 TERM 投递在 1s 后落地、墙钟 < 3s 且 TERM trap 在边界运行。钉内脚本形态已对 GNU bash 5.3.20 实测(watchdog 形态 1.03s、trap 运行、rc 42)。 ## GNU 锚点 - jobs.c:2265 make_child(外部命令皆真 fork);jobs.c:3064 wait_for - trap.c:553 trap_handler → trap.c:545 set_trap_state(投递只记录);trap.c:328 run_pending_traps;execute_cmd.c:643(命令边界运行挂起 trap) - builtins/evalstring.c:125 should_suppress_fork(-c 尾命令 exec-replace 与本改动正交、原样保留) ## 本 PR 删除了什么 未删除任何产品代码路径:进程内 sleep 本体(builtins/sleep.rs、sleep_interruptibly、virtual-child 机制)保留给非 unix 面。替换掉的只有与新裁决矛盾的账本表述:command_registry.rs 里「Yield 无行使用」的模块文档与枚举文档两处、一致性测试中「无行 Yield」断言一处(改为精确定集断言),以及 builtins.md 中 sleep 行的旧备注。 ## 验证状态 队长复核 PASS(评论 6880263205;卷宗 ~/workspace/review-3510/CAPTAIN-VERIFY.md §10)。原正文的待核标记与过期验证节已由以下已核实腿结果替代: - 钉 `tests/issue3488_bats_timeout_real_sleep.rs`:头 2/2;基底 fail-first 0/2(rc=101,与一轮签名逐字同一)。 - issue2859 stem 头 6/6;邻居 issue1545 13/13;Mach-O 单测 2/2。 - lib 双边:头 1248/0/4 vs 基底 1246/0/4,失败名集差 ∅(头多 2 = 新增 Mach-O 单测)。 - `RUSTFLAGS="-D warnings"`:rc=0,0 诊断(lib 重编,非空闲;全量 1474 次调用见 r2)。 - Linux 126 保持:自制 32 字节 thin Mach-O,GNU 126 / 基底 126 / 头 126,strace 无 execve;`/bin/sleep` 对照 rc 0。 - macOS 验收:新头 CI run 43609822916,macOS 1245/1/4(基线 1242/1、旧头 1241/2),issue2859 六格全绿,三任务唯一失败名皆 issue2875(已知基线)。 - 1034/2241 与 bats L4 的环境噪声裁断成立(三方双边复核皆绿)。 - 合入轮:尖在合入轮中由 55fd6a0 前进至 ca89c83(#3577 合入);update-branch 至 ca89c83 得新头 7347904,交集重算 ∅(5219be90..ca89c83,63 文件);合并形态钉在终头 7347904 上重跑 2/2;终头 CI run 43615209642 三任务唯一失败名皆 issue2875(已知基线)。 残差:截断 Mach-O(< 28 字节头)在 macOS 上被承认为原生、execve 失败路径未实测——不拦本 PR,已立跟进单 #3625(P3-low)。 Refs #3488.
caomengxuan666
added a commit
that referenced
this pull request
Nov 14, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 14, 2026
…(Refs #3211) (#3220) Refs #3211 ## 根因(机制定性) 动态变量整表复合赋值缺属主落点钩子。GNU 把 BASH_ALIASES / BASH_CMDS 注册为带元素 assign hook 的动态变量(variables.c:1882-1897 `initialize_dynamic_variables`): | 变量 | hook | 语义 | | --- | --- | --- | | BASH_ALIASES | assign_aliasvar(variables.c:1785) | `valid_alias_name` 校验后 `add_alias`;非法名报错跳过该元素、其余照落、语句 rc 不变 | | BASH_CMDS | assign_hashcmd(variables.c:1715) | `phash_insert(key, value, 0, 0)`:被点名条目 hits 重置、未点名条目原样保留 | 整表赋值无第二条路:`subst.c:3441 do_compound_assignment` → `arrayfunc.c:700 assign_compound_array_list` 逐元素经 `bind_assoc_var_internal` / `bind_array_var_internal` 调钩子;标量 绑定走 `bind_variable_internal` 的 assign_func 臂、以 key `"0"` 调 钩子(variables.c:3140),`+=` 标量先 `make_variable_value` ASS_APPEND 读现值拼接(variables.c:3328)。非追加复合形只换 cell 投影、**从不清属主表**——列表外属主条目保留。declare / typeset / export 的操作数绑定同走 bind_variable 家族、钩子同路。 rubash 侧:#3107 的 `sync_dynamic_assoc_vars` 只在「属主 → 镜像」 方向发布;整表赋值落通用路径只写镜像 + typed 存储,下一命令边界 `sync_dynamic_assoc_cells` 对账时以未被触碰的属主表重建两者,赋值 被丢弃。对照 DIRSTACK 早有属主落点门 `apply_dirstack_assignment`, assoc 对偶一直缺位——本 PR 补上。 ## 普查(全部动态变量整表赋值落点,GNU 探针 27 格实测) | 变量 | GNU 机制 | rubash 处置 | | --- | --- | --- | | BASH_ALIASES | assign_aliasvar 逐元素落 alias 表 | **本 PR 新增门**(复合/标量/追加/kvpair/列表内 `[k]+=`) | | BASH_CMDS | assign_hashcmd 逐元素落 hash 表 | **本 PR 新增门**(同上;hits 语义 = 只重置被点名条目) | | DIRSTACK | assign_dirstack → set_dirstack_element([0]/越界忽略) | 既有门(回归锁钉覆盖) | | GROUPS / BASH_ARGC / BASH_ARGV / BASH_SOURCE / BASH_LINENO / FUNCNAME | null_array_assign no-op + att_noassign | 既有 noassign 臂吞(非追加形);追加形普查与残余见车道 REPORT | | BASH_REMATCH | 无钩子普通数组(match 时重建) | 通用路径即正道 | | PIPESTATUS | 无钩子普通数组;赋值语句自身管线状态在边界覆写读值 | 通用路径 + 既有 note 机制 | declare / typeset / export 三门与 local 影子、unset 后整表赋值的 基底行为由车道普查对基底二进制逐格核对后回填(见 `~/workspace/fix-3211/REPORT.md` §2,工作区文件不入仓)。 ## 修法 `apply_shell_assignment_inner` 在 DIRSTACK 臂旁加动态 assoc 门 `apply_dynamic_assoc_assignment`(`dynamic_arrays.rs`,与 DIRSTACK 门同居):复合形经与通用路径同一 `rewrite_compound_element_subscripts` + `append_assoc_value` 扫描 后逐条路由属主(aliases 表 / `set_hashed_path`);`=` 形以空表为 扫描种子(列表内追加在本列表内组合)、`+=` 形以属主现表为种子算 终值且只路由列表点名的键;标量形 = key `"0"` 单条,`+=` 先读属主 [0] 拼接。门控与 DIRSTACK 同口径:readonly 由上游臂先行拒绝, unset 标记 / local / tempenv 影子让位普通 cell。收尾统一 `sync_dynamic_assoc_vars()` 发布。 回归钉 `tests/issue3211_dynamic_whole_assignment.rs`:普查每个 动态变量的整表赋值形 + 元素赋值回归锁 + unset 后普通变量锁。 ## 验证(队长已核,见 PR #3220 评论 6880965406) - 合并形钉(终头 `3e7c069f`,update-branch 至 `#3455` 合入后的尖 `12aa434e`):**10/10**。 - Fail-first(顶-up 形,基底 `c01a5417`):**3 passed / 7 failed**——7 红格恰为门控格,3 守卫格在基底上绿;翻转真实(基底 3/7 → 合并头 10/10)。 - 尖端 sanity:被拆出的 #3573 面格在尖 `ca89c83a` 上 **1/1** 绿(已由合入的 #3577 修复),故本钉删该格安全;邻居 #3573 钉在终头上 **14/14**。 - Lib 双边:终头 1249/0/4 vs 基底 1206/0/4,失败名集差 **∅**(两边皆 0 FAILED 行)。 - 交集 vs 活尖:两产品文件 hunk 级无重叠(本 PR 的 hunk 在 dynamic_arrays.rs:1870、temporary_assignments.rs:1783;区间内最近 hunk 相距 ≥51 行);update-branch 已干净应用。 ## 本 PR 删除了什么 无删除:纯新增(赋值门 + 回归钉)。通用路径对这两个变量名的整表 赋值自本 PR 起不可达(由门接管),但代码不删——影子/unset 情形仍 走通用路径绑定普通 cell。
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.
修了什么
unset BASH_ALIASES/unset BASH_CMDS从不记录 UNSET_DYNAMIC_VARS:dynamic_parameter_is_set 只服务标量动态登记表,不含这两个 owner 表驱动的 assoc 变量。后果有四:declare -A BASH_ALIASES=());本次按 GNU variables.c:3839(unbind_variable;:1197-1198 解绑后“失去特殊含义”)在三处解绑记录点(unset builtin、view_unset_variable、jobs 内 unbind)补记,并在 publisher、元素绑定臂、元素解绑臂兑现该标记。通用复合赋值路径本身不动(新鲜名字本来就是对的,见钉锁)。
回归钉:tests/issue3573_unset_dynamic_assoc.rs(14 格;fail-first 在 d374e78 预修二进制上实测:11 格红、3 格锁绿;期望全部取自 GNU bash 5.3.20 oracle)。
GNU 锚点:variables.c:3839 unbind_variable、:1197-1198;subst.c:3441 do_compound_assignment;arrayfunc.c:507 assign_array_from_string、:700 assign_compound_array_list。
删了什么
无(纯修复 + 新增钉文件)。
碰撞