Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .server-changes/fix-batch-idempotency-per-item-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: fix
---

Fix batchTrigger requests that set a per-item idempotency key failing with an error instead of creating and deduplicating the runs
14 changes: 10 additions & 4 deletions internal-packages/run-store/src/PostgresRunStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface RunOpsCapableClient {
// Standalone entity keyed by (environmentId, name); present on both schemas.
waitpointTag: RunOpsDelegate<"upsert" | "findMany">;
$queryRaw: PrismaClient["$queryRaw"];
$queryRawUnsafe: PrismaClient["$queryRawUnsafe"];
$executeRaw: PrismaClient["$executeRaw"];
}

Expand Down Expand Up @@ -1691,11 +1692,16 @@ export class PostgresRunStore implements RunStore {
return [];
}
const prisma = (client ?? this.readOnlyPrisma) as RunOpsCapableClient;
const branches = args.idempotencyKeys.map(
(key) =>
Prisma.sql`SELECT "friendlyId", "idempotencyKey", "idempotencyKeyExpiresAt" FROM "TaskRun" WHERE "runtimeEnvironmentId" = ${args.runtimeEnvironmentId} AND "taskIdentifier" = ${args.taskIdentifier} AND "idempotencyKey" = ${key}`
const params: string[] = [];
const branches = args.idempotencyKeys.map((key) => {
const base = params.length;
params.push(args.runtimeEnvironmentId, args.taskIdentifier, key);
return `SELECT "friendlyId", "idempotencyKey", "idempotencyKeyExpiresAt" FROM "TaskRun" WHERE "runtimeEnvironmentId" = $${base + 1} AND "taskIdentifier" = $${base + 2} AND "idempotencyKey" = $${base + 3}`;
});
return prisma.$queryRawUnsafe<IdempotencyKeyRunMatch[]>(
branches.join(" UNION ALL "),
...params
);
return prisma.$queryRaw<IdempotencyKeyRunMatch[]>(Prisma.join(branches, " UNION ALL "));
}

// --- run-ops persistence ---
Expand Down