fix(ipc): bound AgentSession.aclose() during job shutdown#5875
Merged
Conversation
Add WorkerOptions.session_close_timeout (default 60s) and wrap the session.aclose() call in _JobProc._run_job_task with asyncio.wait_for. On timeout, log and continue so on_session_end, ShuttingDown ack, room.disconnect, and user-registered shutdown callbacks still run when the close path is stuck.
davidzhao
approved these changes
May 28, 2026
Member
|
Should this be a worker arg vs a parameter inside the AgentSession ctor? |
…kerOptions Drop the new WorkerOptions.session_close_timeout knob and the 5-file plumbing. The timeout is a defensive guardrail for a bug we plan to root-cause, not a tunable. Hardcode 60.0s as _SESSION_ACLOSE_TIMEOUT in job_proc_lazy_main.py; convert to an option later if we ever need to.
pakoshkin
pushed a commit
to Anecdote-AI/agents
that referenced
this pull request
May 29, 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.
Summary
AgentSession.aclose()is called from_JobProc._run_job_taskduring job shutdown, with no timeout. If it blocks (stuckon_exit, hung provideraclose, an unresolved speech task, etc.), nothing in the supervisor recovers —_shutting_down_futhas no timeout and only resolves once the child sendsShuttingDown, which happens aftersession.aclose()returns. The result is that user-registeredJobContext.add_shutdown_callbackcallbacks silently never run.This wraps the
session.aclose()call withasyncio.wait_foragainst a hardcoded_SESSION_ACLOSE_TIMEOUT = 60.0sinjob_proc_lazy_main.py. On timeout we log and proceed, so the rest of the shutdown sequence (on_session_end,ShuttingDownack,room.disconnect, shutdown callbacks) still runs.Hardcoded for now as a defensive guardrail; can be converted to an option later if a tunable knob turns out to be needed.