Skip to content

fix(agent): name the real cause when a Python agent fails to import - #1102

Draft
u9g wants to merge 9 commits into
mainfrom
jason/python-import-failure-diagnosis
Draft

u9g wants to merge 9 commits into
mainfrom
jason/python-import-failure-diagnosis

Conversation

@u9g

@u9g u9g commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1094.

#1094 removes the Python SDK probe that ran before launch. After that, every import failure gets the same hint: "sync or install the project's dependencies". That's wrong for an SDK older than 1.6.0. It has no livekit.agents.__main__, so a fully synced project fails with No module named livekit.agents.__main__ and is told to sync.

This PR keeps #1094's startup path, a single interpreter launch, and only checks the SDK after the process has exited with an import failure:

  • livekit-agents not installed (uv): "run uv sync and try again"
  • livekit-agents not installed (other managers): "install the project's dependencies"
  • installed but older than 1.6.0: "livekit-agents version X is too old, please upgrade to 1.6.0 or newer"
  • anything else: the existing generic hint

It also stops the hint firing on an ImportError the agent catches at runtime (in a job, for example), since it now needs a failed exit.

Tests: TestStartPythonAgentReportsSDKOlderThanThinCLI sets up a 1.5.0 SDK with no __main__. It fails on #1094's head with the "sync or install" hint and passes here. The not-installed case in TestStartPythonAgentImportsOnceAndReportsMissingDependencies now expects "run uv sync".

Timing, lk agent dev → registered worker against a local livekit-server --dev, livekit-agents 1.8.10, median of 10 runs. The PTY harness answers OSC 11/DA1 like a real terminal:

startup save → re-registered
main 741 ms 1361 ms
#1094 662 ms 1315 ms
this PR 657 ms 1313 ms

theomonnom and others added 9 commits November 1, 2026 21:21
Removing the pre-launch SDK probe left every import failure with one hint:
sync or install dependencies. An SDK older than 1.6.0 has no
livekit.agents.__main__, so its users were told to sync a project that was
already synced.

Diagnose after the process exits on an import failure instead: probe the
installed SDK then, and say it is missing (run `uv sync`), too old (upgrade
to 1.6.0), or fall back to the generic hint. A healthy startup still launches
one interpreter, and an ImportError a job catches no longer warns.
@theomonnom
theomonnom force-pushed the fix/python-agent-dev-startup branch from c1b5dc8 to a54548d Compare November 12, 2026 23:38
Base automatically changed from fix/python-agent-dev-startup to main November 13, 2026 00:13
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.

2 participants