Repository navigation
fix(ipc): close the session as JOB_SHUTDOWN when the job shuts down - #2962
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 93d1a37 The changes in this PR will be included in the next version bump. This PR includes changesets to release 42 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
chenghao-mou
approved these changes
Nov 9, 2026
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.
Ports livekit/agents#8039.
Job finalization now closes the primary
AgentSessionthrough its reason-aware internal path withCloseReason.JOB_SHUTDOWN, preserving the existing timeout and cleanup order while avoiding the publicclose()path that reportsUSER_INITIATED.Source diff coverage
Source diff coverage
livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py: Adapted toagents/src/job_lifecycle.ts, because the JS job runner delegates primary-session closure tofinalizeSession. It now invokes the internal reason-aware close withJOB_SHUTDOWN.agents/src/voice/agent_session.tssupplies the awaitable internal close counterpart the target lacked, andagents/etc/agents.api.mdrecords that internal API.tests/test_ipc.py: Adapted toagents/src/job_lifecycle.test.ts, the JS unit-test counterpart for the delegated shutdown sequence. Existing close failure/timeout fakes use the internal path, and the source-equivalent test proves shutdown bypasses publicclose()and records onlyJOB_SHUTDOWN.No source files were omitted as not applicable.
Testing
pnpm test agents(4,320 passed, 5 skipped)pnpm --filter @livekit/agents buildpnpm --filter @livekit/agents lintpnpm test agents/src/job_lifecycle.test.ts agents/src/voice/agent_session.test.tsgit diff --checkIncludes a patch changeset for
@livekit/agents.Ported from livekit/agents#8039
Original PR description
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 fix(voice): cancel parked preemptive generation before pausing the activity #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.