Skip to content

fix(sessions): reap a run Stop cannot unwind when idle shutdown is disabled - #1017

Merged
agegr merged 2 commits into
mainfrom
claude/issue-656-stuck-running
Sep 30, 2026
Merged

agegr merged 2 commits into
mainfrom
claude/issue-656-stuck-running

Conversation

@agegr

@agegr agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Refs #656

Problem

A turn only stays "running" indefinitely when the pi SDK awaits a promise that ignores the abort signal, such as a third-party extension handler or tool. Stop cannot cancel that, because AgentSession.abort() waits for an idle state that never arrives. #575 made Stop set forceShutdownOnIdle, so the next idle-timer tick shuts the wrapper down and the session recovers without a server restart. PI_WEB_IDLE_TIMEOUT_MS=0, added later, returned from resetIdleTimer() before arming any timer, so with idle shutdown disabled that safety net silently disappeared and a stuck session again needed a server restart.

Changes

  • resetIdleTimer(): 0 still never shuts down an idle session, but after Stop the forced cleanup is armed at the 10-minute default.
  • abort / abort_bash arm the timer right after raising the flag instead of relying on the reset that ran before it.
  • AGENTS.md: document how Stop behaves on runs that cannot be cancelled.

Testing

  • New: with PI_WEB_IDLE_TIMEOUT_MS=0, a run whose abort never settles is torn down 10 minutes after Stop and not before (fails without the fix); a Stop that unwinds keeps the session alive.
  • node --experimental-strip-types --test lib/rpc-manager*.test.mjs, tsc --noEmit, eslint on changed files.
  • Provider-side failures were also checked against a fake OpenAI-compatible server (no answer, stalled body, [DONE] without close, socket reset, 500, empty completion): all end the run on their own and Stop cancels them within milliseconds.

🤖 Generated with Claude Code

agegr and others added 2 commits September 30, 2026 21:36
…sabled (#656)

A turn can only stay "running" forever when the SDK awaits a promise that
ignores the abort signal, typically a third-party extension handler or
tool. Stop cannot cancel that: AgentSession.abort() waits for idle, which
never comes. #575 made Stop set forceShutdownOnIdle so the next idle-timer
tick shuts the wrapper down anyway and the session recovers without a
server restart.

PI_WEB_IDLE_TIMEOUT_MS=0 (added later) returned from resetIdleTimer()
before arming any timer, so with idle shutdown disabled that safety net
silently disappeared and a stuck session needed a server restart, the
exact symptom reported in #656. The abort path also only reset the timer
before raising the flag, relying on a timer the 0 setting never arms.

Keep 0 meaning "never shut down an idle session", but still arm the
forced cleanup after Stop, at the 10-minute default, and arm it right
after raising the flag. A Stop whose run does unwind clears the flag as
before, so the session then stays alive indefinitely.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every command other than get_state reset the idle timer, so a reload's
get_tools, typing `/`, or pressing Stop again re-armed the forced cleanup
for another full timeout. A user retrying on a stuck run kept it alive
indefinitely. Once the forced timer is armed, later resets keep its
deadline until the run is no longer running.

Also covers abort_bash with PI_WEB_IDLE_TIMEOUT_MS=0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit 9ede521 into main Sep 30, 2026
2 checks passed
@agegr
agegr deleted the claude/issue-656-stuck-running 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
…sabled (agegr#1017)

* fix(sessions): reap a run Stop cannot unwind when idle shutdown is disabled (agegr#656)

A turn can only stay "running" forever when the SDK awaits a promise that
ignores the abort signal, typically a third-party extension handler or
tool. Stop cannot cancel that: AgentSession.abort() waits for idle, which
never comes. agegr#575 made Stop set forceShutdownOnIdle so the next idle-timer
tick shuts the wrapper down anyway and the session recovers without a
server restart.

PI_WEB_IDLE_TIMEOUT_MS=0 (added later) returned from resetIdleTimer()
before arming any timer, so with idle shutdown disabled that safety net
silently disappeared and a stuck session needed a server restart, the
exact symptom reported in agegr#656. The abort path also only reset the timer
before raising the flag, relying on a timer the 0 setting never arms.

Keep 0 meaning "never shut down an idle session", but still arm the
forced cleanup after Stop, at the 10-minute default, and arm it right
after raising the flag. A Stop whose run does unwind clears the flag as
before, so the session then stays alive indefinitely.

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

* fix(sessions): keep the forced cleanup deadline after Stop (agegr#656)

Every command other than get_state reset the idle timer, so a reload's
get_tools, typing `/`, or pressing Stop again re-armed the forced cleanup
for another full timeout. A user retrying on a stuck run kept it alive
indefinitely. Once the forced timer is armed, later resets keep its
deadline until the run is no longer running.

Also covers abort_bash with PI_WEB_IDLE_TIMEOUT_MS=0.

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
…sabled (agegr#1017)

* fix(sessions): reap a run Stop cannot unwind when idle shutdown is disabled (agegr#656)

A turn can only stay "running" forever when the SDK awaits a promise that
ignores the abort signal, typically a third-party extension handler or
tool. Stop cannot cancel that: AgentSession.abort() waits for idle, which
never comes. agegr#575 made Stop set forceShutdownOnIdle so the next idle-timer
tick shuts the wrapper down anyway and the session recovers without a
server restart.

PI_WEB_IDLE_TIMEOUT_MS=0 (added later) returned from resetIdleTimer()
before arming any timer, so with idle shutdown disabled that safety net
silently disappeared and a stuck session needed a server restart, the
exact symptom reported in agegr#656. The abort path also only reset the timer
before raising the flag, relying on a timer the 0 setting never arms.

Keep 0 meaning "never shut down an idle session", but still arm the
forced cleanup after Stop, at the 10-minute default, and arm it right
after raising the flag. A Stop whose run does unwind clears the flag as
before, so the session then stays alive indefinitely.

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

* fix(sessions): keep the forced cleanup deadline after Stop (agegr#656)

Every command other than get_state reset the idle timer, so a reload's
get_tools, typing `/`, or pressing Stop again re-armed the forced cleanup
for another full timeout. A user retrying on a stuck run kept it alive
indefinitely. Once the forced timer is armed, later resets keep its
deadline until the run is no longer running.

Also covers abort_bash with PI_WEB_IDLE_TIMEOUT_MS=0.

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.

1 participant