Skip to content

Commit 9e39ed9

Browse files
committed
fix(webapp): route admin org flag saves through the transaction helper
The org feature-flag admin actions opened their locked read-modify-write with a raw prisma.$transaction, bypassing the shared helper's tracing, maxWait and transaction-start retry. Route all three through $transaction from db.server so a flag save can retry through pool contention instead of failing outright.
1 parent 4b9a1f7 commit 9e39ed9

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

apps/webapp/app/routes/admin.api.v1.orgs.$organizationId.feature-flags.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { json } from "@remix-run/server-runtime";
33
import type { Prisma } from "@trigger.dev/database";
44
import { z } from "zod";
55
import { env } from "~/env.server";
6-
import { prisma } from "~/db.server";
6+
import { $transaction, prisma } from "~/db.server";
77
import { requireAdminApiRequest } from "~/services/personalAccessToken.server";
88
import { controlPlaneResolver } from "~/v3/runOpsMigration/controlPlaneResolver.server";
99
import { globalFlagsRegistry } from "~/v3/globalFlagsRegistry.server";
@@ -101,7 +101,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
101101

102102
// Lock the org row for the whole read -> merge -> stamp -> write so a concurrent flag save
103103
// can't clobber the grace metadata (read-then-write race). PK lookup, one row, held to commit.
104-
const updatedOrganization = await prisma.$transaction(async (tx) => {
104+
const updatedOrganization = await $transaction(prisma, "adminOrgFlagsMergeSave", async (tx) => {
105105
const rows = await tx.$queryRaw<{ featureFlags: unknown }[]>`
106106
SELECT "featureFlags" FROM "Organization" WHERE "id" = ${organizationId} FOR UPDATE`;
107107

apps/webapp/app/routes/admin.api.v2.orgs.$organizationId.feature-flags.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { json } from "@remix-run/server-runtime";
33
import { Prisma } from "@trigger.dev/database";
44
import { z } from "zod";
55
import { env } from "~/env.server";
6-
import { prisma } from "~/db.server";
6+
import { $transaction, prisma } from "~/db.server";
77
import { requireUser } from "~/services/session.server";
88
import { controlPlaneResolver } from "~/v3/runOpsMigration/controlPlaneResolver.server";
99
import { globalFlagsRegistry } from "~/v3/globalFlagsRegistry.server";
@@ -118,7 +118,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
118118
// Clear all flags, but preserve the one-way per-org residency latch so an ever-enabled org can
119119
// never drop out of the census. Locked read-then-write so a concurrent enabling save (which also
120120
// takes FOR UPDATE) can't slip a latch in between the read and the wipe.
121-
const updated = await prisma.$transaction(async (tx) => {
121+
const updated = await $transaction(prisma, "adminOrgFlagsClear", async (tx) => {
122122
const rows = await tx.$queryRaw<{ featureFlags: unknown }[]>`
123123
SELECT "featureFlags" FROM "Organization" WHERE "id" = ${organizationId} FOR UPDATE`;
124124

@@ -197,7 +197,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
197197

198198
// Lock the org row for the whole read -> stamp -> write so a concurrent flag save can't clobber
199199
// the grace metadata (read-then-write race). PK lookup, one row, held to commit.
200-
const updated = await prisma.$transaction(async (tx) => {
200+
const updated = await $transaction(prisma, "adminOrgFlagsSave", async (tx) => {
201201
const rows = await tx.$queryRaw<{ featureFlags: unknown }[]>`
202202
SELECT "featureFlags" FROM "Organization" WHERE "id" = ${organizationId} FOR UPDATE`;
203203

0 commit comments

Comments
 (0)