Repository navigation
fix(ipc): close the session as JOB_SHUTDOWN when the job shuts down - #8039
Merged
chenghao-mou merged 1 commit intoNov 9, 2026
Merged
Conversation
_shutdown_job closed the primary AgentSession through the public aclose(), which always uses USER_INITIATED, before the JOB_SHUTDOWN shutdown callback AgentSession.start() registers could run. Drains, migrations, ctx.shutdown(), room disconnects and entrypoint crashes all reported USER_INITIATED. Close with JOB_SHUTDOWN instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a job shuts down with the
AgentSessionstill open, the session's close event reportsCloseReason.USER_INITIATED. That covers worker drain or migration, SIGTERM,ctx.shutdown(), a room disconnect without a participant event, and an entrypoint crash. So thecloseevent (including the one recorded in the session report) andlk.close_reasonall blame the user for a shutdown the job started._shutdown_jobcloses the primary session through the publicaclose()(added in #3541; #5875 only bounded it with a timeout), andaclose()always usesUSER_INITIATED.AgentSession.start()registers a job shutdown callback that closes withJOB_SHUTDOWN(#2398), but callbacks run later. By then the session is already closed, and only the first close counts.Fix
_shutdown_jobnow closes withsession._aclose_impl(reason=CloseReason.JOB_SHUTDOWN). That's the same callstart()already registers, so it doesn't change the public API.Testing
test_thread_job_shutdown_closes_session_as_job_shutdown(thread executor, in-process): a fake session records the close reason. Onmainit fails with[USER_INITIATED] == [JOB_SHUTDOWN]._HangingSessionfake follows the call change, and its test still passes.tests/test_ipc.pyanduv run pytest --unit --audio_eotpass, ruff is clean, andmake type-checkreports no new errors.Why no regression
PARTICIPANT_DISCONNECTEDfrom room I/O,ERROR, andsession.shutdown(), which staysUSER_INITIATED.USER_INITIATEDat job shutdown.ctx.shutdown()from user code is still a job shutdown, as theJOB_SHUTDOWNcallback from automatically close agent session when participant disconnected #2398 already treats it. Thelk.shutdown.user_initiatedspan attribute still records who started it.aclose()is no longer called at this point. That matches the existingJOB_SHUTDOWNcallback, which already goes through_aclose_impl.