Conversation
…nhandled paren subshell) Fix NousResearch#68915 Root cause: 1. The rewriter produced 'A && { B & } C' for 'A && B & C', which is a bash syntax error because bash requires a ';' or newline before the next command after '&'. 2. Parenthesised subshells '(A && B) &' were deliberately skipped but have the same subshell-wait + pipe-hold deadlock bug class. Fix: 1. When the '&' background operator is followed by a command on the same line, insert a ';' separator: 'A && { B & }; C'. 2. Rewrite '(A && B) &' to '{ A && B & }' (same brace-group strategy). 3. Process all rewrites back-to-front with correct sort order to avoid stale indices corrupting the output string. Tests: added TestTrailingCommand (3 tests) and updated TestQuotingAndParens (3 tests) for parenthesised subshell handling.
|
Reviewed against #68915. I checked out the rewriter in isolation and ran every output through This is a correct fix for two genuine gaps, not the whole issue — and that's the right scope.
CI: the one red required check ( Minor (non-blocking): in the merge/dedup step, the overlap key reads Scope note for maintainers: this closes the parse-time rewriter gaps (expected-behavior option 1 in the issue). The defense-in-depth pieces the issue also lists — a stuck-process timeout in the main conversation loop (option 2/3) — remain separate follow-ups and aren't in scope here. Nice, focused fix with real |
|
Closed as duplicate per maintainer feedback. |
背景
修复 #68915: Worker deadlock when agent backgrounds a server via shell
&当前 main 上已有的
_rewrite_compound_background存在两个问题:A && B & C被重写为A && { B & } C,bash 报syntax error near unexpected token(A && B) &被故意跳过,但它和A && B &有同样的子 shell-wait + pipe-hold deadlock 问题根因分析
&是语句终结符,后面紧跟的命令需要;或换行分隔。原重写器没有处理&后面有同命令的情况,导致输出A && { B & } C是无效的 bash 语法。(A && B) &同样会 fork 一个 subshell 来等待 B 完成,B 如果是长期运行的服务进程就会 deadlock。修复方式
&后面同一行有后续命令时,在 brace group 后插入;分隔符:A && { B & }; C(A && B) &重写为{ A && B & }验证
bash -n验证语法正确Closes #68915