Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(annotation-queues): map duplicate-name updates to conflict instead of 500 (#16922)

cursor[bot]418ea20184db
diff --git a/web/src/__tests__/server/annotation-queue-items-trpc.servertest.ts b/web/src/__tests__/server/annotation-queue-items-trpc.servertest.ts
index fe1a2d07c7..8c522b8a30 100644
--- a/web/src/__tests__/server/annotation-queue-items-trpc.servertest.ts
+++ b/web/src/__tests__/server/annotation-queue-items-trpc.servertest.ts
@@ -226,4 +226,56 @@ describe("annotation queues trpc", () => {
expect(queueCount).toBe(2);
});
});
+
+ describe("annotationQueues.update", () => {
+ it("rejects a rename that collides with another queue in the project", async () => {
+ const setup = await createOrgProjectAndApiKey();
+ orgIds.push(setup.org.id);
+ const { caller } = createCallerForProjectRole(
+ setup,
+ "ADMIN",
+ "cloud:pro",
+ );
+ const scoreConfig = await createScoreConfig(setup.project.id);
+
+ const first = await caller.annotationQueues.create({
+ projectId: setup.project.id,
+ name: "queue-alpha",
+ scoreConfigIds: [scoreConfig.id],
+ });
+ await caller.annotationQueues.create({
+ projectId: setup.project.id,
+ name: "queue-beta",
+ scoreConfigIds: [scoreConfig.id],
+ });
+
+ await expect(
+ caller.annotationQueues.update({
+ projectId: setup.project.id,
+ queueId: first.id,
+ name: "queue-beta",
+ scoreConfigIds: [scoreConfig.id],
+ }),
+ ).rejects.toMatchObject({
+ code: "CONFLICT",
+ message: "A queue with this name already exists in the project",
+ });
+ });
+
+ it("returns not found when the queue does not exist in the project", async () => {
+ const setup = await createOrgProjectAndApiKey();
+ orgIds.push(setup.org.id);
+ const { caller } = createCallerForProjectRole(setup);
+ const scoreConfig = await createScoreConfig(setup.project.id);
+
+ await expect(
+ caller.annotationQueues.update({
+ projectId: setup.project.id,
+ queueId: uuidv4(),
+ name: "missing-queue",
+ scoreConfigIds: [scoreConfig.id],
+ }),
+ ).rejects.toMatchObject({ code: "NOT_FOUND" });
+ });
+ });
});
diff --git a/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.stories.tsx b/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.stories.tsx
index a641437dba..13ec0c66f8 100644
--- a/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.stories.tsx
+++ b/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.stories.tsx
@@ -91,7 +91,7 @@ export const Edit = meta.story({
scoreConfigs={scoreConfigs}
projectId="project-1"
queueId="queue-1"
- queueNames={[]}
+ queueNames={["Support review queue", "Other queue"]}
onManageScoreConfigsClick={fn()}
hasQueueAssignmentsReadAccess={false}
isSubmitting={false}
diff --git a/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.tsx b/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.tsx
index 7d629487b6..e0101b1d20 100644
--- a/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.tsx
+++ b/web/src/features/annotation-queues/components/AnnotationQueueFormDialogContent.tsx
@@ -86,6 +86,7 @@ export function AnnotationQueueFormDialogContent({
allNames: queueNameOptions,
form,
errorMessage: "Queue name already exists.",
+ whitelistedName: mode === "edit" ? initialValues.name : undefined,
});
const handleScoreConfigValueChange = (values: Record<string, string>[]) => {
diff --git a/web/src/features/annotation-queues/components/AnnotationQueueFormDialogController.tsx b/web/src/features/annotation-queues/components/AnnotationQueueFormDialogController.tsx
index 95b711d436..0d297c7fdc 100644
--- a/web/src/features/annotation-queues/components/AnnotationQueueFormDialogController.tsx
+++ b/web/src/features/annotation-queues/components/AnnotationQueueFormDialogController.tsx
@@ -70,7 +70,7 @@ export function AnnotationQueueFormDialogController(
);
const allQueueNamesAndIds = api.annotationQueues.allNamesAndIds.useQuery(
{ projectId },
- { enabled: hasQueueAccess && mode === "create" && open },
+ { enabled: hasQueueAccess && open },
);
const utils = api.useUtils();
@@ -170,9 +170,7 @@ export function AnnotationQueueFormDialogController(
projectId={projectId}
queueId={queueId}
queueNames={
- mode === "create"
- ? (allQueueNamesAndIds.data?.map((queue) => queue.name) ?? [])
- : []
+ allQueueNamesAndIds.data?.map((queue) => queue.name) ?? []
}
onManageScoreConfigsClick={() => {
capture("score_configs:manage_configs_item_click", {
diff --git a/web/src/features/annotation-queues/server/annotationQueuesRouter.ts b/web/src/features/annotation-queues/server/annotationQueuesRouter.ts
index d26eb1fbb1..22016ed8d2 100644
--- a/web/src/features/annotation-queues/server/annotationQueuesRouter.ts
+++ b/web/src/features/annotation-queues/server/annotationQueuesRouter.ts
@@ -10,6 +10,7 @@ import {
AnnotationQueueStatus,
CreateQueueData,
filterAndValidateDbScoreConfigList,
+ isBaseError,
LangfuseNotFoundError,
optionalPaginationZod,
Prisma,
@@ -425,6 +426,23 @@ export const queueRouter = createTRPCRouter({
throw new LangfuseNotFoundError("Queue not found in project");
}
+ const existingQueueWithName =
+ await ctx.prisma.annotationQueue.findFirst({
+ where: {
+ projectId: input.projectId,
+ name: input.name,
+ id: { not: input.queueId },
+ },
+ select: { id: true },
+ });
+
+ if (existingQueueWithName) {
+ throw new TRPCError({
+ code: "CONFLICT",
+ message: "A queue with this name already exists in the project",
+ });
+ }
+
const updatedQueue = await ctx.prisma.annotationQueue.update({
where: { id: input.queueId, projectId: input.projectId },
data: {
@@ -445,10 +463,21 @@ export const queueRouter = createTRPCRouter({
return updatedQueue;
} catch (error) {
- logger.error(error);
- if (error instanceof TRPCError) {
+ if (error instanceof TRPCError || isBaseError(error)) {
throw error;
}
+
+ if (
+ error instanceof Prisma.PrismaClientKnownRequestError &&
+ error.code === "P2002"
+ ) {
+ throw new TRPCError({
+ code: "CONFLICT",
+ message: "A queue with this name already exists in the project",
+ });
+ }
+
+ logger.error(error);
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Updating annotation queue failed.",