Skip to content

fix(source): source 边界上的语法错误中止降级为 reader discard,不再终止会话(#451 类 B) - #481

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/enter1-continuation
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/enter1-continuation

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

closes #451

问题(类 B:hang:enter1)

source <file> 结束后,交互会话对第一条后续输入无响应(eco 签名 hang:enter1:ECO>;样本:Kohei-Wada/dotfiles@264319e bin/update-nvim.sh、sloria/doitlive@168333b examples/walkthrough.sh)。

根因

不是 continuation 状态残留,而是 source 边界上的中止分类错误。GNU evalstring.c parse_and_execute 对 sourced 文件的语法错误按普通失败中止剩余文本(evalstring.c:585-601,无 jump_to_top_level):交互 shell 报错后继续读下一条(WSL GNU 5.3.0 实测),非交互脚本继续执行后续命令。

引擎里 run_source_impl 的 execute_ast 分支把该中止的 ExitCode(2) 记成 reader exit jump,而 source builtin(execute_source_with_args 尾部 handler 与 run_source_groups 的两个中止分支)消费掉了解分类用的 parse-error 标志。于是所有 exit_jump && !parse_error 形状的驱动闸门把 reader-discard 误读成真实 exit:

  • 交互会话在诊断打印后立即结束(ConPTY 下表现为 source 后第一条探针命令永不执行 → HANG);
  • 非交互脚本以 rc 2 中止,GNU 则继续(printf 'source bad\necho AFTER\n' | bash 打印 AFTER,rc 0)。

触发形态:sourced 文件尾部带不完整构造——未闭合 if/f() {、行尾 |/&&、未闭合反引号块(walkthrough 的 ```python 围栏正是此形态)。最小复现(修复前):

printf 'source bad.sh\necho ECOSRC\n' | rubash -i   # 诊断后 rc=2,ECOSRC 永不执行;GNU 打印 ECOSRC

修复

source 边界消费 parse-error 中止时同步消费其记录的 exit jump(三处:incomplete-group 分支、complete-group 分支、execute_source_with_args 尾部)。文件内真实 exit 走 parse_error == false 路径返回 Err,仍正常 unwind(exit 5/exit 7 语义由回归钉死)。

验证

  • 新增 tests/issue451_source_parse_discard_regressions.rs(8 用例):未闭合 if/函数体/反引号块尾、行尾 |/&&、非交互继续、exit 仍生效×2;全部通过。
  • oracle 对照:上述各形态 GNU 5.3.0 行为一致(报错、继续、rc 0)。
  • ConPTY 实测(pywinpty+pyte):source walkthrough.sh 后 echo ECOSRC 修复前被吞、修复后正常执行。
  • 套件:interactive/lexer/parser/source 相关 10 个测试文件 498 用例全绿(含 issue419 interactive_syntax_error_does_not_end_session、issue426 sourced_exit、issue433 prompt_command)。
  • cargo test --lib 中 2 个失败(pwd 盘符格式、/mnt/c 解析)在干净 HEAD 上同样失败,为环境相关预存问题,与本单无关。

注:eco 重跑中 update-nvim.sh 现判 SLOW(下载耗时)、walkthrough.sh 判 upstream-heavy-external(>15s 外部命令循环),triage 记录见 docs/audit/findings/wt98b-goldtri-triage-results.json;本修覆盖其中引擎侧真因(会话被误杀),外部耗时因素不属引擎范围。

… not an exit jump (rubash#451 class B)

GNU evalstring.c parse_and_execute aborts the remaining sourced text on
a syntax error as an ORDINARY failure (evalstring.c:585-601, no
jump_to_top_level), so the sourcing driver keeps reading: an interactive
shell reports the diagnostic and prompts again, a non-interactive script
continues with its next command (verified WSL GNU 5.3.0).

The engine recorded that abort's ExitCode(2) as a reader exit jump
(run_source_impl's execute_ast arm) while the source builtin consumed
the parse-error flag that classifies it (execute_source_with_args' tail
handler and run_source_groups' two abort arms), so every driver gate of
the shape 'exit_jump && !parse_error' read a reader-discard as a real
exit: the interactive session died right after the diagnostic — the eco
hang:enter1 family, where the first probe line typed after 'source
<file>' never ran (Kohei-Wada/dotfiles bin/update-nvim.sh, sloria/doitlive
examples/walkthrough.sh shapes) — and non-interactive scripts aborted
with rc 2 where GNU continues.

When the source boundary consumes a parse-error abort it now consumes
the recorded jump with it (a real 'exit' inside the file returns Err
with the flag clear and still unwinds, pinned by regression). New suite
tests/issue451_source_parse_discard_regressions.rs pins the unclosed
if/function/backtick tails, the trailing | and && connectors, the
non-interactive continue, and the two exit-still-wins cases.
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.

[engine] 交互挂起族:U 字节注入(#434 同族)与 continuation 误判——eco 审计 HANG 集群

1 participant