Skip to content

fix(cli): apply connect credentials to the agent server - #7929

Merged
longcw merged 1 commit into
livekit:mainfrom
BlueX888:fix/cli-connect-ignores-credentials
Oct 19, 2026
Merged

longcw merged 1 commit into
livekit:mainfrom
BlueX888:fix/cli-connect-ignores-credentials

Conversation

@BlueX888

Copy link
Copy Markdown
Contributor

fix(cli): apply connect credentials to the agent server

What breaks

The legacy connect command parses --url / --api-key / --api-secret but uses them only to talk to the room API (api.LiveKitAPI(url, api_key, api_secret)). Unlike start/dev, which apply CLI values via server.update_options(...), connect never updates the AgentServer — so server.simulate_job builds the job's connection from construction-time/env values. With no LIVEKIT_URL/LIVEKIT_API_KEY/LIVEKIT_API_SECRET in the environment (or with different env credentials), the simulated job carries empty/wrong credentials and the agent cannot join the room.

Fix

In connect, before server startup, build a kwargs dict from truthy url/api_key/api_secret and call server.update_options(**kwargs) — mirroring _run_worker (cli.py). simulate_job then mints its token/join URL from the same credentials used for the room API, and skipped flags still fall back to env values.

Tests

tests/test_cli_connect_options.py drives the command through the existing _build_cli(server)/CliRunner pattern with faked LiveKitAPI, server.run and simulate_job, asserting the server's _ws_url/_api_key/_api_secret are the CLI values at simulate_job time.

  • On base: fails — assert [('', '', '')] == [('ws://flag-host:7880', 'cli-key', 'cli-secret')] (the job connection was built before applying the flags).
  • With the fix: passes; neighboring CLI suites show identical results at base and head apart from the new test (the two environmental failures — Windows CRLF assertion and the conftest leaked-task guard — reproduce identically at base).

The connect command parsed --url/--api-key/--api-secret but only used them for the room API, so simulate_job built the job token and join URL from server construction-time/env values. With no env credentials the simulated job raised 'api_key and api_secret must be set'; with different env credentials the agent joined the env deployment instead of the room created via the flags.

Apply the CLI values via server.update_options() before running the server, mirroring _run_worker (start/dev).
@BlueX888
BlueX888 requested a review from a team as a code owner October 18, 2026 16:02

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

Copy link
Copy Markdown
Contributor

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 bugs or issues to report.

Devin Review

@longcw
longcw merged commit f5ee4a8 into livekit:main Oct 19, 2026
17 checks passed
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