Skip to content

fix(bash): let Stop end a command whose output a survivor holds open - #1016

Merged
agegr merged 3 commits into
mainfrom
claude/issue-647-stop-running-script
Sep 30, 2026
Merged

agegr merged 3 commits into
mainfrom
claude/issue-647-stop-running-script

Conversation

@agegr

@agegr agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Fixes #647

Problem

Stop could not end a bash tool call running scripts until they finished, and a steering message sent meanwhile waited for them too.

pi's local shell backend kills the command's process tree on abort (process-group SIGKILL on POSIX, taskkill /T on Windows) and then waits for every inherited stdout/stderr handle to fall idle, re-arming a 100ms grace on each chunk (waitForChildProcess). A descendant the kill cannot reach (its own session on POSIX, or on Windows an orphan whose parent already exited, earendil-works/pi#9129) keeps that wait alive for as long as it writes. The tool call never returns, so AgentSession.abort() and the Stop request hang. Reproduced on macOS: with an escaped writer, Stop returned only when the script ended.

Separately, the Steer tooltip promised to "interrupt the current run and inject this message now". pi actually delivers a steering message after the current response and its tool calls finish, so a steer sent during a long script waits for it.

(On Windows, pi 0.84.3, which Pi Web shipped when this was reported, could also fail to spawn taskkill at all, earendil-works/pi#6596; that is fixed by the SDK upgrade already on main.)

Changes

  • createProjectCommandBashOperations (used for agent bash and ! commands) bounds the post-abort wait: pi's own abort path gets 1s to settle, after which the wrapper rejects with pi's aborted error ("Command aborted" / a cancelled ! run). Output arriving after the release is dropped. The normal abort path is unchanged.
  • The Steer tooltip (en, zh-CN, zh-TW) now says when the message is delivered and points to Stop.

Not covered: processes the kill cannot reach keep running (needs an upstream Job Object change, earendil-works/pi#9129); the Windows powershell tool uses pi's operations directly.

Testing

  • node --experimental-strip-types --test lib/project-command-env.test.mjs: new tests for a stuck backend released after the grace, pi's own abort result passing through untouched, and a real detached writer holding stdout no longer blocking the bash tool (POSIX). Both survivor tests time out without the fix.
  • lib/rpc-manager*.test.mjs, lib/subagent*.test.mjs, lib/i18n/registry.test.mjs, components/ChatInput.test.mjs pass; tsc --noEmit and eslint clean.
  • Manual (macOS, AgentSessionWrapper + fake model): Stop with an escaped writer returns ~1s after abort; ordinary Python process trees are still killed within ~100ms.

🤖 Generated with Claude Code

agegr and others added 3 commits September 30, 2026 21:36
…647)

On Stop, pi's local shell backend kills the command's process tree
(process-group SIGKILL on POSIX, `taskkill /T` on Windows) and then waits
for every inherited stdout/stderr handle to fall idle, re-arming a 100ms
grace timer on each chunk (waitForChildProcess, earendil-works/pi#5303).
A descendant the kill cannot reach keeps that wait alive for as long as
it writes: a process in its own session on POSIX, or an orphan whose
parent already exited on Windows, which `taskkill /T` cannot follow
(earendil-works/pi#9129). The bash tool call then never returns, so the
Stop request, the Stop button and any queued steering all wait until
the script finishes on its own.

Pi Web already routes agent and `!` shell commands through its own
BashOperations wrapper, so it now bounds that wait there: once the
signal aborts, pi's normal path gets one second to settle (it takes
well under that when the tree is gone) before the wrapper rejects with
pi's own "aborted" error, which the bash tool reports as
"Command aborted" and the `!` executor as a cancelled run. Output that
arrives after the release is dropped instead of being appended to a
result that has already been finalized. The unreachable process itself
keeps running; killing it needs an upstream change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Steer button's tooltip promised to "interrupt the current run and
inject this message now". Steering does not interrupt anything: pi
queues the message and delivers it after the current assistant response
and its tool calls finish, before the next model call (pi docs
rpc-commands.md, sdk.md). A message steered during a long Python run
therefore waits for the script, which the tooltip gave no reason to
expect. Describe the real timing and point to Stop, which is what
interrupts the running tool calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…647)

pi's `timeout` kills the process tree and then waits on the inherited
output handles exactly like Stop does, so a descendant the kill cannot
reach kept the tool call pending past its timeout with no "Command timed
out" result. The wrapper now also releases the command one grace period
after the timeout, with pi's own `timeout:<seconds>` error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit f5e768e into main Sep 30, 2026
2 checks passed
@agegr
agegr deleted the claude/issue-647-stop-running-script branch October 1, 2026 13:28
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
解开 agegr#981 的 DirectoryPicker 冲突后,这一段(390e70f..f52fd84)实测 0 冲突:

- agegr#992 移动端输入框停在键盘上方并给打字更多空间
- agegr#997 限制每客户端 SSE 积压
- agegr#1001 可配置发送键(Enter / Ctrl+Enter)
- agegr#1006 从 pi 的 provider catalog 解析 discovery endpoint
- agegr#1017 空闲关闭被禁用时回收 Stop 无法解除的运行
- agegr#1016 Stop 结束输出被幸存进程持住的命令
- agegr#1015 保留用户消息里输入的换行
- agegr#1019 在 Safari / iOS 16.2 上可加载(新增 browserslist,无新依赖)
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…gegr#1016)

* fix(bash): let Stop end a command whose output a survivor holds open (agegr#647)

On Stop, pi's local shell backend kills the command's process tree
(process-group SIGKILL on POSIX, `taskkill /T` on Windows) and then waits
for every inherited stdout/stderr handle to fall idle, re-arming a 100ms
grace timer on each chunk (waitForChildProcess, earendil-works/pi#5303).
A descendant the kill cannot reach keeps that wait alive for as long as
it writes: a process in its own session on POSIX, or an orphan whose
parent already exited on Windows, which `taskkill /T` cannot follow
(earendil-works/pi#9129). The bash tool call then never returns, so the
Stop request, the Stop button and any queued steering all wait until
the script finishes on its own.

Pi Web already routes agent and `!` shell commands through its own
BashOperations wrapper, so it now bounds that wait there: once the
signal aborts, pi's normal path gets one second to settle (it takes
well under that when the tree is gone) before the wrapper rejects with
pi's own "aborted" error, which the bash tool reports as
"Command aborted" and the `!` executor as a cancelled run. Output that
arrives after the release is dropped instead of being appended to a
result that has already been finalized. The unreachable process itself
keeps running; killing it needs an upstream change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(chat): say when a steering message is delivered (agegr#647)

The Steer button's tooltip promised to "interrupt the current run and
inject this message now". Steering does not interrupt anything: pi
queues the message and delivers it after the current assistant response
and its tool calls finish, before the next model call (pi docs
rpc-commands.md, sdk.md). A message steered during a long Python run
therefore waits for the script, which the tooltip gave no reason to
expect. Describe the real timing and point to Stop, which is what
interrupts the running tool calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(bash): release a timed-out command the same way as a stopped one (agegr#647)

pi's `timeout` kills the process tree and then waits on the inherited
output handles exactly like Stop does, so a descendant the kill cannot
reach kept the tool call pending past its timeout with no "Command timed
out" result. The wrapper now also releases the command one grace period
after the timeout, with pi's own `timeout:<seconds>` error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…gegr#1016)

* fix(bash): let Stop end a command whose output a survivor holds open (agegr#647)

On Stop, pi's local shell backend kills the command's process tree
(process-group SIGKILL on POSIX, `taskkill /T` on Windows) and then waits
for every inherited stdout/stderr handle to fall idle, re-arming a 100ms
grace timer on each chunk (waitForChildProcess, earendil-works/pi#5303).
A descendant the kill cannot reach keeps that wait alive for as long as
it writes: a process in its own session on POSIX, or an orphan whose
parent already exited on Windows, which `taskkill /T` cannot follow
(earendil-works/pi#9129). The bash tool call then never returns, so the
Stop request, the Stop button and any queued steering all wait until
the script finishes on its own.

Pi Web already routes agent and `!` shell commands through its own
BashOperations wrapper, so it now bounds that wait there: once the
signal aborts, pi's normal path gets one second to settle (it takes
well under that when the tree is gone) before the wrapper rejects with
pi's own "aborted" error, which the bash tool reports as
"Command aborted" and the `!` executor as a cancelled run. Output that
arrives after the release is dropped instead of being appended to a
result that has already been finalized. The unreachable process itself
keeps running; killing it needs an upstream change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(chat): say when a steering message is delivered (agegr#647)

The Steer button's tooltip promised to "interrupt the current run and
inject this message now". Steering does not interrupt anything: pi
queues the message and delivers it after the current assistant response
and its tool calls finish, before the next model call (pi docs
rpc-commands.md, sdk.md). A message steered during a long Python run
therefore waits for the script, which the tooltip gave no reason to
expect. Describe the real timing and point to Stop, which is what
interrupts the running tool calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(bash): release a timed-out command the same way as a stopped one (agegr#647)

pi's `timeout` kills the process tree and then waits on the inherited
output handles exactly like Stop does, so a descendant the kill cannot
reach kept the tool call pending past its timeout with no "Command timed
out" result. The wrapper now also releases the command one grace period
after the timeout, with pi's own `timeout:<seconds>` error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

执行多脚本,py的是,无法停止,补充内容,必须等脚本执行结束

1 participant