Repository navigation
feat(lk): write evals and session labels under --user-auth - #1153
jmcclanahan wants to merge 3 commits into
Conversation
Adds client calls for the Public API's eval writes: ValidateEval, CreateEval, UpdateEval, SaveEvalDraft, DiscardEvalDraft, PublishEvalDraft, RollbackEval, DeleteEval, UndeleteEval, UpdateEvalDefaults, the session label writes and UpdateSessionLabelSettings. Definitions go to the API verbatim. APIError now keeps the error envelope's gRPC code, so a caller can tell a stale draft etag (Aborted) from a stale base revision (FailedPrecondition), and FieldViolations reads a BadRequest detail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds lk agent eval validate|create|update|save|discard|publish|rollback| delete|undelete, lk agent eval defaults set, lk agent eval label create|update|delete|undelete and lk agent eval label settings set. Publish, rollback, undelete and label create/undelete start LLM judging or labeling, so they ask first, as the MCP tools do; discard asks too. --yes skips the question, and a run that can't ask refuses. A refused request lists the fields the API named. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Devin Review found 4 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| if err != nil { | ||
| return evalSave{}, err | ||
| } | ||
| return evalSave{definition: definition, etag: cmd.String("etag")}, nil |
There was a problem hiding this comment.
🔴 Empty etag permits draft overwrite
With explicit --etag "", saveEvalDraft adopts the current draft’s etag instead of requiring no draft. It overwrites a draft created since the caller checked.
Learn more
The save request uses an empty etag for an eval without a draft. The CLI currently collapses an explicitly empty flag and an omitted flag into the same string. saveEvalDraft responds to either by reading the latest draft and using its etag, which satisfies the API check even when that draft was created after the caller last checked.
Example: A script reads a published eval with no draft and passes --etag "". A teammate saves a draft before the script runs save. The CLI fetches the teammate’s etag and replaces their draft rather than sending the empty etag and getting a conflict.
Recommended fix: Preserve whether --etag was set using cmd.IsSet("etag"). Auto-fetch the latest etag only when the flag is absent. Test an explicitly empty etag against an eval that now has a draft.
Was this helpful? React with 👍 or 👎 to provide feedback.
| current, err := client.GetSessionLabelSettings(ctx, projectID) | ||
| if err != nil { | ||
| return readAPIError(err, "a project's session label settings", projectReadAccess) | ||
| } | ||
| s := *current |
There was a problem hiding this comment.
🔴 Concurrent label settings updates lost
When two setSessionLabelSettings calls read the same settings, the later write restores untouched fields from its stale snapshot. Both commands succeed, even though the later write erases the first command’s change.
Learn more
The CLI promises that fields without flags keep their values. UpdateSessionLabelSettings sends a full replacement, and the update request has no version precondition. That leaves the merged snapshot unprotected between the read and write.
Example: One operator raises the confidence threshold from 0.7 to 0.9 while another sets the minimum duration to 30 seconds. Both reads return 0.7. If the duration update writes second, it silently resets the threshold to 0.7.
Recommended fix: Use a server-side partial update, or add a version precondition to replacement writes and surface conflicts. A CLI-local lock cannot coordinate writers on different machines.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if etag == "" { | ||
| _, draft, err := currentDraft(ctx, client, projectID, evalID) | ||
| if err != nil { | ||
| return evalWriteError(err, projectID, evalID) | ||
| } |
There was a problem hiding this comment.
🔴 First draft discard blocks saving
After discarding an unpublished eval’s only draft, saveEvalDraft fails before writing a replacement. GetEval requires a draft or revision, and the eval now has neither.
Learn more
Creating an eval does not publish a revision, and DiscardEvalDraft removes the draft without changing the live revision. currentDraft treats a failed draft lookup as a reason to look up the published revision. That fallback cannot succeed for an eval with no versions: GetEval rejects even a successful metadata response without a version. The save request, in contrast, explicitly supports an empty etag when no draft exists.
Example: Create an eval, discard its draft before publishing, then run save with an edited definition. The CLI returns a lookup error and never sends the save request.
Recommended fix: In the save path, treat a draft lookup returning NotFound as a reason to send the save request with no etag. Let the save endpoint distinguish an unknown eval from an existing one without a draft, and test the create–discard–save sequence.
Was this helpful? React with 👍 or 👎 to provide feedback.
| } | ||
| return nil, fmt.Errorf("%s must hold a JSON object: %w", path, err) | ||
| } | ||
| _, hasEval := fields["eval"] |
There was a problem hiding this comment.
🟡 Null accepted as a definition object
When a definition file contains null, readDefinitionFile accepts it instead of rejecting it. Go decodes null into a nil map without error, so the command sends a non-object definition.
| _, hasEval := fields["eval"] | |
| if fields == nil { | |
| return nil, fmt.Errorf("%s must hold a JSON object", path) | |
| } | |
| _, hasEval := fields["eval"] |
Was this helpful? React with 👍 or 👎 to provide feedback.
Stacked on #1152 (eval reads), which is stacked on #1146. Merge order: #1146 → #1152 → this.
What
Lets a person or coding agent signed in with
--user-authwrite and ship evals fromlk: check a definition, create an eval, save a draft, publish it, roll it back. It also manages session labels (the intents and outcomes an LLM assigns to each session).lk agent eval validate | create | update | save | discard | publish | rollback | delete | undeletelk agent eval defaults set --file FILE(the project's judge defaults)lk agent eval label create | update | delete | undelete,lk agent eval label settings set--file FILE(or-for stdin), a JSON object, the same oneget --jsonprintsWhy
The Public API's EvalService writes are in production (livekit/public-api-server#212, #213), but
lkcould only read evals (#1152). Authoring from a file makes evals scriptable, and a coding agent can edit them.How
confirm: true. Discard asks too, since the draft is lost.--yesskips the question; a run that can't prompt refuses and sends nothing.save,discardandpublishtake--etagto refuse when someone else changed the draft. Without it, lk reads the current draft and acts on it. A stale etag (Aborted) says to re-read; a stale base revision (FailedPrecondition) prints thediffto run and--allow-stale-base. To tell the two apart,APIErrornow keeps the envelope's gRPCcode.FieldViolationsand thecloudAPIErrorchange are copied from feat(lk): lk agent builder manages Agent Builder agents under --user-auth #1136, so whichever of the two merges second resolves the conflict by taking one copy.label settings setreads the settings, changes only the flags given, and sends them all, because the API resets any field left out.get --jsonresponse is refused, with thejqthat extracts the definition.Testing
go build ./...,go vet ./...,go test ./...andgo test -race ./cmd/lk ./pkg/public/...pass.--yes, the violations listing, and the settings merge.eval-writes-with-user-auth.txtarruns the binary through validate, create, save, publish (refused without--yes, then with it), label create and settings set. The request log shows that a refused change sends nothing.golangci-lint(CI runs it), and the commands against staging.🤖 Generated with Claude Code