Skip to content

fix: don't swallow _ExitCli during shutdown#5519

Open
lawrence3699 wants to merge 1 commit intolivekit:mainfrom
lawrence3699:fix/exitcli-shutdown-signal
Open

fix: don't swallow _ExitCli during shutdown#5519
lawrence3699 wants to merge 1 commit intolivekit:mainfrom
lawrence3699:fix/exitcli-shutdown-signal

Conversation

@lawrence3699
Copy link
Copy Markdown

Closes #4664

What was happening

_ExitCli is raised from the CLI signal handlers to stop the worker. Because it inherited from Exception, broad except Exception blocks could catch it before the shutdown path reached drain() / aclose().

SupervisedProc._memory_monitor_task() is one concrete path: if SIGTERM lands while psutil.Process(...) is running, the task logs and swallows _ExitCli instead of letting the worker drain.

What changed

  • make _ExitCli inherit from BaseException
  • add a regression test covering _memory_monitor_task()

Why this is correct

_ExitCli is internal control flow used only for process shutdown, and the CLI already catches it explicitly at the top level. Making it bypass generic except Exception handlers lets shutdown propagate without changing the existing explicit _ExitCli handling.

Validation

  • uv run pytest tests/test_drain_timeout.py -q
  • uv run ruff check livekit-agents/livekit/agents/cli/cli.py tests/test_drain_timeout.py

Copilot AI review requested due to automatic review settings April 22, 2026 02:13
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a shutdown control-flow issue where _ExitCli (raised by CLI signal handlers) could be accidentally caught by broad except Exception blocks, preventing the normal drain/close shutdown path from running.

Changes:

  • Change _ExitCli to inherit from BaseException so it bypasses generic except Exception handlers.
  • Add a regression test ensuring SupervisedProc._memory_monitor_task() does not log/swallow _ExitCli.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
livekit-agents/livekit/agents/cli/cli.py Makes _ExitCli a BaseException to ensure shutdown signals aren’t intercepted by broad exception handling.
tests/test_drain_timeout.py Adds a regression test covering the _memory_monitor_task() path to ensure _ExitCli propagates and isn’t logged/swallowed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@longcw longcw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the pr!

@longcw
Copy link
Copy Markdown
Contributor

longcw commented Apr 24, 2026

could you sign the CLA before we can merge?

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.

Ctrl+C (SIGINT) causes uvloop exception when stopping agent worker

4 participants