Skip to content

fix(lk): agent runs with --dev and a full key set are an error - #1090

Open
Topherhindman wants to merge 1 commit into
mainfrom
topherhindman/agent-dev-flag-beats-env
Open

Topherhindman wants to merge 1 commit into
mainfrom
topherhindman/agent-dev-flag-beats-env

Conversation

@Topherhindman

Copy link
Copy Markdown
Contributor

Fixes DEVX-902

#1084 made --dev with an API key or secret an error, but the check is in project resolution. lk agent dev and lk agent start skip project resolution when the URL, API key and secret are all given, from flags or from LIVEKIT_URL, LIVEKIT_API_KEY and LIVEKIT_API_SECRET. So in a shell with all three set, --dev was ignored and the agent got the env's server and key:

$ LIVEKIT_URL=wss://env.livekit.cloud LIVEKIT_API_KEY=APIenv LIVEKIT_API_SECRET=secretenv lk agent start --dev
Detected Node.js agent (src/main.js in ./my-agent)
agent got LIVEKIT_URL=wss://env.livekit.cloud LIVEKIT_API_KEY=APIenv

With only some of them set, the agent commands already failed with #1084's error. Now they fail with a full set too:

$ LIVEKIT_URL=wss://env.livekit.cloud LIVEKIT_API_KEY=APIenv LIVEKIT_API_SECRET=secretenv lk agent start --dev
Detected Node.js agent (src/main.js in ./my-agent)
--dev can't be combined with API key credentials; unset LIVEKIT_API_KEY and LIVEKIT_API_SECRET or drop --dev

It says "remove --api-key and --api-secret" when the values come from the flags. The debugger's --audio run uses the same code, so it gets the fix too. --dev alone, or with --url, is unchanged, and so is a full set of credentials without --dev.

Tests:

  • TestResolveCredentials_DevWithCredentialsIsAnError: a full set from env, a full set from flags, and an env key alone all fail with the message. The first two fail on main.
  • TestResolveCredentials_DevAlone: --dev and --dev --url still give the agent devkey and secret.
  • A script test (agent-dev-with-env-credentials.txtar): lk agent dev --dev and lk agent start --dev with all three env vars, and lk agent start --dev with all three flags, fail with the message and send no request. It fails on main.
  • go build ./..., go vet ./... and go test ./... pass.

resolveCredentials skips the project lookup when the URL, API key and
secret are all given, from flags or LIVEKIT_* env vars. That lookup is
where #1084 made --dev with an API key or secret an error, so `lk agent
dev --dev` and `lk agent start --dev` in a shell with all three set
quietly ran the agent against the env's server with the env's key,
instead of the dev server. With only some of them set, they already
failed.

resolveCredentials now checks --dev against the key and secret before
it decides whether to look anything up, and returns the same error, e.g.
"--dev can't be combined with API key credentials; unset LIVEKIT_API_KEY
and LIVEKIT_API_SECRET or drop --dev". The debugger's --audio run goes
through it too. --dev alone, or with --url, is unchanged.
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.

1 participant