Skip to content

fix(ipc): bound AgentSession.aclose() during job shutdown#5875

Merged
longcw merged 4 commits into
mainfrom
longc/session-close-timeout
May 29, 2026
Merged

fix(ipc): bound AgentSession.aclose() during job shutdown#5875
longcw merged 4 commits into
mainfrom
longc/session-close-timeout

Conversation

@longcw
Copy link
Copy Markdown
Contributor

@longcw longcw commented May 28, 2026

Summary

AgentSession.aclose() is called from _JobProc._run_job_task during job shutdown, with no timeout. If it blocks (stuck on_exit, hung provider aclose, an unresolved speech task, etc.), nothing in the supervisor recovers — _shutting_down_fut has no timeout and only resolves once the child sends ShuttingDown, which happens after session.aclose() returns. The result is that user-registered JobContext.add_shutdown_callback callbacks silently never run.

This wraps the session.aclose() call with asyncio.wait_for against a hardcoded _SESSION_ACLOSE_TIMEOUT = 60.0s in job_proc_lazy_main.py. On timeout we log and proceed, so the rest of the shutdown sequence (on_session_end, ShuttingDown ack, 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.

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.
@chenghao-mou chenghao-mou requested a review from a team May 28, 2026 06:20
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@theomonnom
Copy link
Copy Markdown
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.
@longcw longcw changed the title feat(ipc): add session_close_timeout to bound AgentSession.aclose() during shutdown fix(ipc): bound AgentSession.aclose() during job shutdown May 29, 2026
@longcw longcw merged commit ab6e8a1 into main May 29, 2026
23 checks passed
@longcw longcw deleted the longc/session-close-timeout branch May 29, 2026 03:21
pakoshkin pushed a commit to Anecdote-AI/agents that referenced this pull request May 29, 2026
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.

3 participants