Repository navigation
Description
Why this is being filed
I did an external differential run (GNU bash 5.2.21/5.3.0 as oracle, Windows x64) and then read docs/pitfall-taxonomy-and-governance.md, docs/dual-store-invariant.md, docs/semantic-ownership.tsv and #641. This is an outside observation about how the families are grouped — not a bug. If this is already written down somewhere I did not read, close it.
The observation
The taxonomy lists these as separate 乙类 families, and #641 frames the store separately:
- S3 重定向/fd 模型 — "Windows 无真实 fd;内建输出通路 N 条各自打补丁"
- S6 子壳隔离 — "非 fork,靠手工快照/恢复清单,新增状态即新泄漏点"
- S9 trap/job/signal — "无子进程所有权模型"
- Umbrella: the dual-store capture-replay invariant — root cause of #616/#618/#607/#608/#609/#619 and the map for later agents #641 dual-store — "typed cell + mirror string … maintained by capture-replay"
From outside they read as one pattern: a piece of state is duplicated across N sites and kept consistent by hand, so every new site or new field is a new divergence point. The taxonomy's §1 already says the carrier has "\x1f 解码散布 50+ 文件" and calls that "M1 持续发生的结构性原因" — that is the same sentence, with N = 50+.
Mapping the recent external findings onto it (my own, for concreteness):
| family | the "N sites" | recent instance |
|---|---|---|
| carrier / M1 | 50+ decode sites | #707 tr [:cntrl:] skips carried bytes; niubash#383 / #695 wc -c measures the encoding |
| dual-store | writers + the mirror | #641 perf line (908× at K=5000) + "correctness bugs where the two stores disagree" |
| S6 subshell | manual snapshot/restore list | #702 set -E not inherited by ( ) |
| S3 fd model | N builtin output paths | #699 2>&1 >file order, write-error routing; #701 read from /dev/fd/N |
| S9 traps | (no ownership model) | #702; #345 (closed), #441 (closed) |
| M5 / S13 | merge plane | "merge 丢修复" is the same pattern in the process dimension |
§2's conclusion — "两个根因喂养了大半个事故库" — already names it for S1/S2. The question is whether it generalises to the runtime-state families and the store, because that changes the priority order.
The falsifiable part
If the frame is right, then the leading indicator is "sites touched per new state", not the bug count:
- adding a property to the execution context should touch one place (a context struct), not a snapshot/restore list;
- adding a consumer of expanded text should be impossible to forget (
carrier_textshould not be passable across a module boundary without decoding — a newtype, not a convention); - adding a writer to the variable store should not require a mirror update at all.
Prediction: if mirroring is the root, new S3/S6/S9 instances should keep arriving even when no new state was added — which is what the closed list behind #713 shows (≥ 10 fixes, four open today). If instead a 4-week window shows no new instances once no new state is added, the frame is wrong → close this.
What I would not ask for
Not "refactor everything". The cheap, order-preserving first steps are the ones where the boundary is already drawn:
- carrier: make the encoded form un-nameable outside the codec (newtype /
#[repr]-private) so a consumer cannot hold carrier text by accident — turns M1 from a discipline into a type error. - fd table: make it a value with sequenced operations, so
2>&1 >filecannot be applied out of order (redirection & fd:2>&1 >fileorder, builtin write-error routing, closed-stderr status, subshell-uncapturedcderror, bare-catsame-file #699). - context: one
ContextStatewhose clone semantics define the sub-shell contract, so a new field is compiler-visible rather than a forgotten list entry (errexit/trap:set -emisfires inuntil ... break|continue;set -Enot inherited by( )subshells #702, S6).
Each is local, and each removes a class rather than an instance — which is §4 rule 4 ("fix the invariant, not the symptom") applied to the runtime plane instead of the expansion plane.
Credit where due: platform-fd-inheritance.md is exactly the right way to close a cell (documented divergence + primary-source argument), and semantic-ownership.tsv is already the right shape for an owner registry. This issue is only asking whether the grouping is one pattern instead of four.
Activity
caomengxuan666 commentedon Oct 17, 2026
核查结论(逐项读了代码与台账后)
框架对一半,且对的那一半正是杠杆所在。"状态镜像于 N 处、手工同步"对进程内所有权成立(随每新增状态增长的那种);但 dual-store 的 mirror 与
__RUBASH_FD_*/FUNCTION_STDIN属于 forkless 传输基座——GNU 靠 fork 的零代码拷贝,rubash 没有这个原语,这部分镜像不可消灭,只能类型化(§3.6 ADR 已裁决不追 fork 机制、只复刻四条语义)。逐家族核查:逐家族证据盘点
ShellState已落地(src/shell/state.rs:1-9即隔离边界声明;clone_for_child_save@283、Clone@318);env_vars等数十字段已收拢。落点证据:落地时实测两份手工清单(7 项 vs ~55 项)已漂移并打穿 alias/function 泄漏(§3.6 S6 实施记录);边界化之后此类泄漏零复发(现状 issue 里无一例状态泄漏)env_vars里的冒号拼接字符串(TRAP_LIST/TRAP_PREFIX/TRAP_RESET@src/builtins/trap.rs:9-20,928);reset_for_subshell被 7 处调用点各自触发(ast_exec.rs:498、command_substitution.rs:902/1256、compound_exec.rs:1460、embedded_mutations.rs:2037、pipeline_stages.rs:111、read_io.rs:583);ERR/errexit 判定门散在 4+ 处(function_calls.rs:485-641、ast_exec.rs:1302、command_dispatch.rs:248-262、trap_exec.rs:1198)。#719 修 #702 时只能给调用点新增变体reset_for_subshell_child(两个入口生效),命令替换/管道/read 三条路径有意保留旧路径——结果 #720 立刻在同一接缝报出 4 个新 case(嵌套子壳过度触发、f() ( )平坦域、procsub、until 里的 return 归因)。修完即复发=手工清单的判据fd_table.write_endpoint(2)(compound_exec.rs:2318),但进程级eprintln!在主入口之外仍有 175 处(全仓 219),io::stdout()/stderr()直写散布 48 文件(77 处);重定向通道write_default_stderr58 处/17 文件。三条通路并存 → #271、#510、#699 R1.2/R1.3(write-error 进不了命令自己的2>file)src/executor/fd_table.rs:1-80:Rc<FileFd>天然共享偏移;redirection.rs:891apply_ordered_output_redirects有序 apply)——边界已画出。残余镜像:__RUBASH_FD_*env 键 36 处/10 文件(compound_exec.rs:536-561、external_inner.rs:791 等;semantic-ownership.tsv redir 行已挂账 "remove remaining fd env mirror");FUNCTION_STDIN(_OFFSET)传输镜像 165 引用/24 文件、18 处写点,其单位不变量靠 #711 的注释+测试钉住而非类型2>&1 >file失序)说明仍有未走有序 apply 的旁路路径env_vars.insert+ 16 文件 34 处sync_typed_*;VarTable 的Deref让数百处值操作免改而扩散(var_table.rs:130-140 注释自认)。但:性能 908×/223× 是结构性成本已测;失同步 correctness 实际挂账命名的只有 #651 一条——#635-#639/#621 追到的是展开阶段序,非镜像失同步shell_text_to_raw_bytes/bytes_to_shell_text仍散布 39 文件,但 M1/M4 收口已落地(markers.rs 注册表 + 三边界入口);#707 属 M7 残余诚实权衡(反例)
pipeline_exec.rs:777-780等 3 处),naive 的"统一为 raw"会把正确代码修成 bug(该 PR 实测复现了泄漏)。镜像不是万恶之源——无类型才是。这否定了 "给每个镜像点找单一 owner" 的机械化改法。raw_attribute至今未进 stable)。消灭__RUBASH_FD_*的唯一途径是等/自建平台层,不是重构 shell 内部。env_vars字符串变成 typed 字段——好处是 reset 变成一个 typed 函数而非 7 个调用点 × 语义组合;坏处是 trap 与set -o(functrace/errtrace 联动 @ set/options.rs:343-349)和 fix(executor): until-break errexit attribution and -E subshell ERR inheritance (#702) #719 变体的三条 "有意保留" 路径需要一次说清,回归面是 trap/loop 全族。建议路径(增量边界,非大改)
按今日 open 事故密度排序,先做两件:
env_vars字符串(trap.rs:9-20)收进ShellStatetyped 字段,subshell 契约 =clone_for_child_save()的一个 typed twist(errtrace/functrace 组合在唯一一处决定 DEBUG/ERR/RETURN 的去留),7 个reset_for_subshell调用点收敛为同一个函数;同时把 set -E ERR-trap edge cases: nested subshell fire count, f() ( ) flat region, process substitution, return-in-until attribution #720 第 4 条点名的那把总闸(command_dispatch.rs:262 归因门)一并定为一处语义。文件面:src/builtins/trap.rs、src/shell/state.rs、上表 7 个调用点文件、src/executor/trap_exec.rs。这是 fix(executor): until-break errexit attribution and -E subshell ERR inheritance (#702) #719 被迫打补丁变体的那个洞的正解。fd_table.write_endpoint(2)"(通道已在,compound_exec.rs:2318),把 175 处eprintln!分批迁入;零行为变更即可先静态化。不做:dual-store 大改(留给 #616/#618 按 docs/dual-store-invariant.md 的 perf-slice 地图推进,reader-side 规则已由 #638/#650 验证);
__RUBASH_FD_*/FUNCTION_STDIN不消灭(forkless 传输基座,#711 结论:类型化+注释钉住,不是重构对象)。可证伪
给维护者的显式选项
选哪条由维护者定;本评论只主张:镜像分两类治理——进程内所有权状态的镜像用边界消灭,forkless 传输的镜像用类型钉住。
caomengxuan666 commentedon Oct 17, 2026
Supporting detail for the question in this issue, from a static pass over
origin/master(d24ee0f0). Counts are measured; the recommendation is mine.Why the registry is a vocabulary, not a chokepoint
markers.rs(963 lines) is thorough — one declaration site,Boundary::{Output,Storage,Reparse}, aMARKERStable, encode/decode constants,user_reachable, andtests/marker_leak_golden.rs. But the spread it was supposed to reduce is unchanged:markers::, 788 references total.replace(markers::…)decode chains across 31 filesreplace(CTLESC, "")So the registry standardised the names; it did not reduce the number of places that must remember to decode. That is the mirroring pattern this issue describes, in the carrier plane.
Clearest single instance:
materialize_expanded_command_word(command_prepare.rs:5) is the argv chokepoint, andpipeline_exec.rs:2415-2446re-implements it inline — precisely the M1 shape that §1 of the taxonomy predicts.Recommendation
Decode-at-the-boundary, hardened with a type, one subsystem at a time. Not a repo-wide
CarrierText/DecodedTextsplit — the repo already ruled that out (pitfall-taxonomy-and-governance.md:104-108), and that call looks right.Concretely: a
VisibleTextnewtype (private field, noDeref/AsRef/Display,#[must_use]decode), applied in this order:locale.rs:369→ the sinks. Smallest call-site count, highest leak visibility.pipeline_exec.rs's inline copy.Ranked against the alternatives: the repo-wide newtype contradicts an existing owner decision; the lint-only route ships in <1 day but by construction cannot catch the actual M1 mode — "forgot to call the helper" has no textual signature.
What must not change
Byte-exact GNU parity; the in-band protocol itself; the zero-copy hot paths; glob's legitimate in-band
CTLESCconsumption. Main risk: an over-broad raw escape hatch re-opens the class — the hatch (if any) has to be narrower than the type, or the type buys nothing.Related
caomengxuan666 commentedon Oct 17, 2026
Cross-issue ownership book landed as a doc PR (link above):
docs/audit/state-ownership-invariants.md. It turns this issue's question into a test — who writes it / who reads it / what a child inherits — and answers it seam by seam with file:line evidence, keeping the transport substrate (dual-store,__RUBASH_FD_*,FUNCTION_STDIN) out of the anti-pattern bucket on the #711 counter-example.Two mechanical additions to the design brief above:
set -emisfires inuntil ... break|continue;set -Enot inherited by( )subshells #702, set -E ERR-trap edge cases: nested subshell fire count, f() ( ) flat region, process substitution, return-in-until attribution #720 filed four residuals within hours) re-opens the class, not just the instance. This is what makes "P1 before P2" defensible rather than taste.TrapOwner, and the same for diagnostic writes; the lookup bucket's guard is the deterministic swap-exchange trigger (being built for niubash#392).Decisions requested in §4 of the doc: accept P1 (trap owner) first, P2 direction, dispatch P3 immediately (independent), and whether the recurrence signature becomes a formal re-open rule. #713's inherit/own matrix will be appended when that audit lands (marked pending in v1).
docs(audit): state-ownership invariants - mirrored vs owned, with rec…
caomengxuan666 commentedon Oct 17, 2026
Closing this one on its own terms — the body said "If this is already written down somewhere I did not read, close it", and after reading further it is:
docs/pitfall-taxonomy-and-governance.md§1 already states the N-site form for the carrier family ("\x1f解码散布 50+ 文件" → "M1 持续发生的结构性原因"). That is this issue's sentence withN = 50+filled in.What remains actionable from here is the concrete children, which are all open and untouched by this close:
markers.rsis not the single declaration point (12 consts outsideMARKERS)So: the observation is right, but it is the map's job, and the map is #641. Thanks — closing to keep the tracker free of a second map.