Repository navigation
feat(agent): lk agent restart, rollback, promote, delete and secrets through the Public API when signed in - #1140
Conversation
a2c895c to
582fe2f
Compare
582fe2f to
1fc4d1f
Compare
…of agents The Public API client makes AgentService's writes on a cloud agent: restart, rollback (to a version, or the previous one when none is named), promote a deployment to production, delete the agent or one deployment, and set and remove secrets. A secret's value goes out as base64, as protojson sends bytes, with its kind by name. IsAgentBuilderAgent reads the refusal to roll back, promote or delete an Agent Builder agent. An invalid secret's google.rpc.BadRequest detail is read with the FieldViolations that main already has.
…ough the Public API Under --user-auth, these commands now call the Public API's AgentService in place of the token bridge, so a member can make the writes that their role allows: - lk agent restart, rollback and promote: a WRITE member. - lk agent delete, whole or --deployment: a project admin. - lk agent update-secrets: a project admin. It merges, as without --overwrite it does with an API key. lk has no flag to remove a secret; the request's remove names map to AgentService's remove. - lk agent update: its secrets merge as update-secrets does, then the agent restarts, as cloud agents' UpdateAgent does. With no secrets it only restarts the agent. update-secrets --overwrite, which replaces every secret, stays on the bridge: AgentService only merges. The bridge needs a project admin and says so. AgentService's refusals read as lk's own. A member whose role is too low hears which role the command needs, not that they lack access to the project. An invalid secret gets a line by name. A rollback, promote or delete of an Agent Builder agent points at Agent Builder in the dashboard.
Every other agent command starts its error with "unable to <verb> agent:"; restart returned the error as it came, with an API key and under --user-auth alike.
"this command needs a project admin (this needs ADMIN on the project)"
said the role twice. lk now quotes the Public API's refusal only when it
says more than the role lk names, such as the permissions a server that
checks them lists ("this needs agent:delete on the project").
The script fake logged only each request's method and path, so the writes script passed with delete's --deployment, rollback's --version, promote's deployment and update-secrets' secrets dropped. `requests -v` also prints each URL's query and each JSON body, with secret values replaced, and the writes script uses it.
…loud agents' UpdateAgent The comment said that update under --user-auth does what cloud agents' UpdateAgent does. It calls AgentService's UpdateAgentSecrets, or RestartAgent with no secrets: both roll the agent, but cloud agents' UpdateAgent also saves the agent and marks its production deployment Updating.
… key The Public API no longer refuses a secret name because it starts with LIVEKIT_ (livekit/public-api-server#242): it passes the name to cloud agents, which drops the names that it sets on each agent itself, as it does for lk with an API key. lk still drops LIVEKIT_URL, LIVEKIT_API_KEY and LIVEKIT_API_SECRET before it sends, in both modes. The writes script now sends LIVEKIT_AGENT_NAME in both modes and checks that LIVEKIT_URL is dropped in both. The refusal script, TestSecretsError and TestFieldViolations use violations that the Public API still sends.
The Public API now refuses to restart an Agent Builder agent or change its secrets, as it refuses a rollback, promote or delete, with FailedPrecondition "agent is an Agent Builder agent; manage it in Agent Builder". lk agent restart, update and update-secrets under --user-auth now word that refusal as rollback, promote and delete do, and the wording covers every write: "manage it in Agent Builder", then the Public API's message.
…mmand to use AgentService refuses a write to an Agent Builder agent with FailedPrecondition, a message that names the AgentBuilderService RPC to call instead, and a ResourceInfo detail with the Agent Builder agent's ID. lk now names the lk agent builder command that makes the write, with that ID, in place of the dashboard: - rollback and promote: lk agent builder deploy AB_ID --version VERSION_ID - delete: lk agent builder delete AB_ID - update-secrets, and update with secrets: lk agent builder update-secrets AB_ID - restart, and update without secrets: the API can't restart it The Public API's words stay in the error that lk wraps. The script's refusals are the Public API's own texts for each RPC.
The Public API sends a violation for each field that is wrong, so a secret named twice in one request, or a violation it sends twice, made lk print the same line more than once. secretsError now prints each line once, in the order of the first violation that makes it.
1fc4d1f to
b6948db
Compare
There was a problem hiding this comment.
Devin Review found 3 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| if err := a.client.DeleteAgent(ctx, a.projectID, req.GetAgentId(), req.GetDeployment()); err != nil { | ||
| return nil, agentWriteError(err, req.GetAgentId(), projectAdmin, builderDelete) |
There was a problem hiding this comment.
🔴 Whole-agent deletion suggested for deployment
When Agent Builder refuses a deployment-only delete, DeleteAgent recommends deleting the whole agent. Following that advice with session auth and confirming deletes every saved version as well.
Learn more
The deleteAgent command uses --deployment to distinguish deleting one deployment from deleting the whole agent. The Public API delete operation documents a refusal when Agent Builder manages the agent. On that refusal, the CLI uses the same recovery hint for both scopes. The Builder command provided by the companion PR deletes the agent, its versions, and its deployment, as documented by AgentBuilderServiceDeleteAgent.
Example: An admin requests deletion of staging from CA_1. The API refuses because the agent is managed as AB_1. If the admin follows the Builder delete hint with --user-auth and confirms, the operation removes AB_1 and all its versions, not just staging.
Recommended fix: Use a deployment-specific refusal when req.GetDeployment() is nonempty. Do not suggest a whole-agent delete in that case. Add a refusal script that sends --deployment staging and checks that the error does not suggest Builder deletion.
Was this helpful? React with 👍 or 👎 to provide feedback.
| func builderSecrets(id string) string { | ||
| return "; update its secrets with `lk agent builder update-secrets " + id + "`" | ||
| } |
There was a problem hiding this comment.
🟡 Missing Agent Builder secrets command
When Agent Builder refuses a secret update, builderSecrets points to lk agent builder update-secrets. The companion Builder CLI does not register that command, so the suggested recovery fails.
Learn more
Both UpdateAgentSecrets and UpdateAgent use the shared secrets write path for a merge. On an Agent Builder refusal, the path prints a Builder subcommand. The dependency branch origin/topherhindman/devx-973-builder-commands has no update-secrets subcommand, even though AgentBuilderServiceUpdateAgentSecrets is available in the REST client. The refusal script asserts only the error text, so it cannot catch the unavailable command.
Example: An admin runs lk --user-auth agent update-secrets --id CA_1 --secrets API_TOKEN=example and receives a hint to run lk agent builder update-secrets AB_1. Even with --user-auth, the companion CLI has no such subcommand.
Recommended fix: Until the Builder secrets command is implemented and included in the merge dependency, give a supported recovery path, such as the Agent Builder dashboard.
Was this helpful? React with 👍 or 👎 to provide feedback.
| func (c *Client) RollbackAgent(ctx context.Context, projectID, agentID, version string) error { | ||
| body := oapi.AgentServiceRollbackAgentJSONRequestBody{} | ||
| if version != "" { | ||
| body.Version = &version | ||
| } | ||
| resp, err := c.gen.AgentServiceRollbackAgentWithResponse(ctx, projectID, agentID, body) |
There was a problem hiding this comment.
🟡 Empty-version rollback sends invalid request
Calling RollbackAgent with an empty version sends {} instead of rolling back to the previous version. The rollback request requires an explicit version.
Learn more
The wrapper advertises that an empty version rolls back to the previous one. The generated request contract instead requires a version from the agent's version list. The empty-version test returns a canned success and verifies the empty request, not the server's required field.
Example: A caller requests a rollback with version == "" for an agent running v2 with v1 available. The client sends {} rather than naming v1, so the documented rollback mode does not work against the REST contract.
Recommended fix: Require a nonempty version in the wrapper, document that requirement, and replace the canned success test with a test that verifies an empty version is rejected before sending a request.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if deploymentName(dstDeployment) != productionDeployment { | ||
| return bridgeError(a.bridge.PromoteAgent(ctx, agentID, srcDeployment, dstDeployment)) | ||
| } | ||
| if _, err := a.client.PromoteAgent(ctx, a.projectID, agentID, srcDeployment); err != nil { | ||
| return agentWriteError(err, agentID, projectWriter, builderDeployVersion) | ||
| } |
Under
--user-auth, the agent writes that the Public API serves now go throughAgentServicein place of the token bridge:lk agent restart,rollback,promote,delete,update-secretsandupdate. The bridge needsAgent.Admin, so before this only a project admin could make any of them. Now a WRITE member can restart, roll back and promote. Delete and secrets still need a project admin, and the refusal says so.Stacked on #1139.
Commands
--user-authagent restartRestartAgentagent rollback --versionRollbackAgentagent promote --deploymentPromoteAgent(to production)agent delete,delete --deploymentDeleteAgentagent update-secretsUpdateAgentSecrets(merge)agent updateUpdateAgentSecretswith its secrets, orRestartAgentwith noneagent update-secrets --overwritecreate,deploy(source and image), runtimelogs,private-link *list,status,config,versions,secrets,dockerfile, buildlogsAgentService(#1138, #1139)secrets: ADMIN)What's in it
feat(public):RestartAgent,RollbackAgent,PromoteAgent,DeleteAgent,UpdateAgentSecrets, plusFieldViolations(thegoogle.rpc.BadRequestdetail) andIsAgentBuilderAgent. A secret's value goes out as base64, as protojson sendsbytes, and its kind goes out by name.feat(agent):userAuthAgentAPIcalls them and maps the errors.Decisions
AgentServicenever overwrites.update-secretswithout--overwritemaps toset. lk has no flag to remove a secret today. The request'sremovefield maps toAgentService'sremove, but nothing in lk sets it.--overwritestays on the bridge. It replaces every secret, whichAgentServicedoesn't do. A non-admin gets the bridge's "this command needs a project admin" refusal.lk agent update. Under--user-authlk sends the secrets toUpdateAgentSecrets(merge), and with no secrets callsRestartAgent. Both roll the agent, as cloud agents'UpdateAgentdoes with an API key, but the upstream calls differ: cloud agents'UpdateAgentalso saves the agent and marks its production deploymentUpdating, with or without secrets;RestartAgentonly touches the agent so that it reconciles, andUpdateAgentSecretssaves the merged secrets without marking itUpdating.secret 1KEY: name must have only letters, …. A write to an Agent Builder agent names the lk command to use, with theAB_ID from the refusal'sResourceInfodetail:lk agent builder deploy AB_… --version …for rollback and promote,lk agent builder delete AB_…for delete, andlk agent builder update-secrets AB_…for secrets. A restart says the API can't restart it. Each invalid-secret line prints once. When the role is too low, the hint says a project API key also works: "pass --legacy-auth", as chore(auth): prepare for migration to user-auth as default #1156's hints do. lk words other refusals ("version not found") as the Public API does.Output differences vs the API-key path
lk agent restartnow starts withunable to restart agent:, as every other agent command's error does. This is intentional.LIVEKIT_*is the same in both modes. lk dropsLIVEKIT_URL,LIVEKIT_API_KEYandLIVEKIT_API_SECRETbefore it sends (ignoredSecrets,cmd/lk/agent.go). The Public API passes any other name to cloud agents (livekit/public-api-server#242), which drops the names that it sets on each agent itself (itsSecretExclusionList) without an error and keeps the rest.lk agent delete. Under--user-auth, the Public API deletes it, as the dashboard does (livekit/public-api-server#242).--user-auththey are refused, by design in livekit/public-api-server#242.--user-auththis is "version not found" or "version is not available: …". With an API key, cloud agents answers without a code.Open questions
update-secrets --overwritebecome native, as a list of the names plus a merge withremove? That is not atomic, which is why this PR keeps the bridge.RestartAgent's REST route hasbody: "*", but its request has only path fields, so the generated client sends no body. Vanguard reads an empty body as an empty message. This has not run against a real PAS yet.Blockers
pkg/publicgenerated from livekit/public-api-server@372fb27e (production v2026-12-02-2258).Testing
GOPRIVATE= go build ./...,go vet ./cmd/lk/... ./pkg/...,go test ./cmd/lk/... ./pkg/...andgolangci-lint run ./cmd/lk/... ./pkg/public/...pass.agent-writes-with-user-auth: each command, once with an API key against fake cloud agents and once under--user-authagainst the fake Public API, prints the same success line. That coversdeletewhole and per deployment, andupdatewith and without secrets.--overwritestill gets the bridge's refusal. The request log shows no token request for the native writes.agent-writes-refused-with-user-auth: the role refusals for restart (WRITE), delete and secrets (ADMIN), invalid secrets by name, an Agent Builder agent, and a plain NotFound.IsAgentBuilderAgent, whatupdate-secretsandupdatesend,--overwritereaching only the bridge,secretsErrorandagentWriteError.Review fixes
LIVEKIT_secrets (582fe2f): the Public API no longer refuses aLIVEKIT_name, soagent-writes-with-user-authsendsLIVEKIT_AGENT_NAMEin both modes and checks thatLIVEKIT_URLis dropped in both, and the refusal script,TestSecretsErrorandTestFieldViolationsuse violations that the Public API still sends. Same checks as above: pass.requests -vprints each URL's query and each JSON body, with every secret value replaced byREDACTED, andagent-writes-with-user-authuses it: delete--deployment, rollback--version, promote's deployment, and the secret names ofupdate-secretsandupdate. Dropping any of them inuserAuthAgentAPInow fails the script (checked by mutation).userAuthAgentAPI.UpdateAgent's comment no longer says it does what cloud agents'UpdateAgentdoes; it says how the calls differ (see Decisions).Demo
Recorded on staging, not uploaded yet:
~/hosted-agents-work/demos/M3/m3-agent-writes.mp4(write-up~/hosted-agents-work/demos/M3/README.md). Local Public API from this branch against staging cloud-agents (staging database read-only); lk from #1140. READ is refused a restart; WRITE restarts and rolls back; WRITE is refused secrets and delete; ADMIN sets a secret, is refused a reservedLIVEKIT_name, and deletes the agent. The reserved-name refusal predates livekit/public-api-server#242's change: that update now succeeds, as it does with an API key. Promote isn't shown: the staging plan allows no extra deployment.Depends on #1136 (the hints name
lk agent builder).