Skip to content

fix: emit session_shutdown on every dispose path - #575

Merged
agegr merged 3 commits into
agegr:mainfrom
richardmilles:fix/session-shutdown-dispose-546
Aug 25, 2026
Merged

agegr merged 3 commits into
agegr:mainfrom
richardmilles:fix/session-shutdown-dispose-546

Conversation

@richardmilles

Copy link
Copy Markdown
Contributor

Destroy/dispose now always emits session_shutdown before inner.dispose(), and idle teardown still runs when a session is stuck running so extension children can be reaped.
Fixes #546

richardmilles and others added 3 commits August 21, 2026 09:39
Ensure AgentSessionWrapper destroy/dispose always notifies extensions before inner.dispose, and force idle shutdown even when a session is stuck running so MCP children are reaped.
@agegr
agegr merged commit d728526 into agegr:main Aug 25, 2026
magnum-pr pushed a commit to magnum-pr/pi-web that referenced this pull request Sep 27, 2026
* fix: emit session_shutdown before every dispose path

Ensure AgentSessionWrapper destroy/dispose always notifies extensions before inner.dispose, and force idle shutdown even when a session is stuck running so MCP children are reaped.

* fix: preserve active sessions during shutdown cleanup

---------

Co-authored-by: Alex Yang <[email protected]>
agegr added a commit that referenced this pull request Sep 30, 2026
…sabled (#1017)

* fix(sessions): reap a run Stop cannot unwind when idle shutdown is disabled (#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]>

* fix(sessions): keep the forced cleanup deadline after Stop (#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 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
* fix: emit session_shutdown before every dispose path

Ensure AgentSessionWrapper destroy/dispose always notifies extensions before inner.dispose, and force idle shutdown even when a session is stuck running so MCP children are reaped.

* fix: preserve active sessions during shutdown cleanup

---------

Co-authored-by: Alex Yang <[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.

AgentSession.dispose() never emits session_shutdown — extension child processes still leak after #331

2 participants