-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(webapp): grace-stamp runOpsMintKind flips from the global admin flags page #4268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
d-cs
wants to merge
3
commits into
main
Choose a base branch
from
fix-global-mint-flag-grace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+256
−33
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| // A runOpsMintKind change on the global admin flags page must go through the graced flip path | ||
| // (prev + flippedAt stamped), not a bare upsert. Real testcontainers Postgres, never mocked. | ||
| import type { PrismaClient } from "@trigger.dev/database"; | ||
| import { postgresTest } from "@internal/testcontainers"; | ||
| import { describe, expect, vi } from "vitest"; | ||
| import { FEATURE_FLAG, type FeatureFlagKey } from "~/v3/featureFlags"; | ||
| import { makeSetMultipleFlags, replaceGlobalFeatureFlags } from "~/v3/featureFlags.server"; | ||
|
|
||
| vi.setConfig({ testTimeout: 60_000 }); | ||
|
|
||
| const MINT_KEYS: FeatureFlagKey[] = [ | ||
| FEATURE_FLAG.runOpsMintKind, | ||
| FEATURE_FLAG.runOpsMintKindPrev, | ||
| FEATURE_FLAG.runOpsMintKindFlippedAt, | ||
| ]; | ||
|
|
||
| // Mint trio + two ordinary boolean flags, to exercise the sweep alongside the carved-out mint keys. | ||
| const CATALOG_KEYS: FeatureFlagKey[] = [ | ||
| ...MINT_KEYS, | ||
| FEATURE_FLAG.mollifierEnabled, | ||
| FEATURE_FLAG.hasAiAccess, | ||
| ]; | ||
|
|
||
| const NEVER_PROTECTED = () => false; | ||
|
|
||
| async function readFlags( | ||
| prisma: PrismaClient, | ||
| keys: FeatureFlagKey[] | ||
| ): Promise<Record<string, unknown>> { | ||
| const rows = await prisma.featureFlag.findMany({ | ||
| where: { key: { in: keys } }, | ||
| select: { key: true, value: true }, | ||
| }); | ||
| const m: Record<string, unknown> = {}; | ||
| for (const row of rows) m[row.key] = row.value; | ||
| return m; | ||
| } | ||
|
|
||
| describe("replaceGlobalFeatureFlags — graces runOpsMintKind, preserves replace semantics", () => { | ||
| postgresTest( | ||
| "a runOpsMintKind flip stamps prev + flippedAt (graced, not a bare upsert)", | ||
| async ({ prisma }) => { | ||
| await makeSetMultipleFlags(prisma)({ [FEATURE_FLAG.runOpsMintKind]: "cuid" }); | ||
|
|
||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.runOpsMintKind]: "runOpsId" }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
|
|
||
| const m = await readFlags(prisma, MINT_KEYS); | ||
| expect(m[FEATURE_FLAG.runOpsMintKind]).toBe("runOpsId"); | ||
| expect(m[FEATURE_FLAG.runOpsMintKindPrev]).toBe("cuid"); | ||
| expect(typeof m[FEATURE_FLAG.runOpsMintKindFlippedAt]).toBe("string"); | ||
| } | ||
| ); | ||
|
|
||
| postgresTest( | ||
| "derived stamp fields supplied in the body are ignored (computed server-side)", | ||
| async ({ prisma }) => { | ||
| await makeSetMultipleFlags(prisma)({ [FEATURE_FLAG.runOpsMintKind]: "cuid" }); | ||
|
|
||
| await replaceGlobalFeatureFlags(prisma, { | ||
| // Caller forges the stamp: prev="runOpsId", flippedAt=epoch. Both must be ignored. | ||
| requestedFlags: { | ||
| [FEATURE_FLAG.runOpsMintKind]: "runOpsId", | ||
| [FEATURE_FLAG.runOpsMintKindPrev]: "runOpsId", | ||
| [FEATURE_FLAG.runOpsMintKindFlippedAt]: "1970-01-01T00:00:00.000Z", | ||
| }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
|
|
||
| const m = await readFlags(prisma, MINT_KEYS); | ||
| expect(m[FEATURE_FLAG.runOpsMintKindPrev]).toBe("cuid"); | ||
| expect(m[FEATURE_FLAG.runOpsMintKindFlippedAt]).not.toBe("1970-01-01T00:00:00.000Z"); | ||
| } | ||
| ); | ||
|
|
||
| postgresTest( | ||
| "re-applying the same runOpsMintKind does not reset the grace clock", | ||
| async ({ prisma }) => { | ||
| await makeSetMultipleFlags(prisma)({ [FEATURE_FLAG.runOpsMintKind]: "cuid" }); | ||
|
|
||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.runOpsMintKind]: "runOpsId" }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
| const first = await readFlags(prisma, MINT_KEYS); | ||
|
|
||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.runOpsMintKind]: "runOpsId" }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
| const second = await readFlags(prisma, MINT_KEYS); | ||
|
|
||
| expect(second[FEATURE_FLAG.runOpsMintKind]).toBe("runOpsId"); | ||
| expect(second[FEATURE_FLAG.runOpsMintKindPrev]).toBe(first[FEATURE_FLAG.runOpsMintKindPrev]); | ||
| expect(second[FEATURE_FLAG.runOpsMintKindFlippedAt]).toBe( | ||
| first[FEATURE_FLAG.runOpsMintKindFlippedAt] | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| postgresTest( | ||
| "the mint trio survives a replace that omits runOpsMintKind (not swept)", | ||
| async ({ prisma }) => { | ||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.runOpsMintKind]: "runOpsId" }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
| const before = await readFlags(prisma, MINT_KEYS); | ||
|
|
||
| // A later save that edits only an unrelated flag and omits the mint keys entirely. | ||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.mollifierEnabled]: true }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
|
|
||
| const after = await readFlags(prisma, MINT_KEYS); | ||
| expect(after[FEATURE_FLAG.runOpsMintKind]).toBe("runOpsId"); | ||
| expect(after[FEATURE_FLAG.runOpsMintKindPrev]).toBe(before[FEATURE_FLAG.runOpsMintKindPrev]); | ||
| expect(after[FEATURE_FLAG.runOpsMintKindFlippedAt]).toBe( | ||
| before[FEATURE_FLAG.runOpsMintKindFlippedAt] | ||
| ); | ||
| const mollifier = await readFlags(prisma, [FEATURE_FLAG.mollifierEnabled]); | ||
| expect(mollifier[FEATURE_FLAG.mollifierEnabled]).toBe(true); | ||
| } | ||
| ); | ||
|
|
||
| postgresTest( | ||
| "non-mint flags keep replace semantics: submitted upserts, omitted deletes", | ||
| async ({ prisma }) => { | ||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.mollifierEnabled]: true }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
|
|
||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.hasAiAccess]: true }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
|
|
||
| const m = await readFlags(prisma, [FEATURE_FLAG.mollifierEnabled, FEATURE_FLAG.hasAiAccess]); | ||
| expect(m[FEATURE_FLAG.hasAiAccess]).toBe(true); | ||
| expect(m[FEATURE_FLAG.mollifierEnabled]).toBeUndefined(); | ||
| } | ||
| ); | ||
|
|
||
| postgresTest("protected omitted flags are not deleted", async ({ prisma }) => { | ||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.mollifierEnabled]: true }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: NEVER_PROTECTED, | ||
| graceMs: 60_000, | ||
| }); | ||
|
|
||
| // A replace that omits mollifierEnabled but marks it protected must keep it. | ||
| await replaceGlobalFeatureFlags(prisma, { | ||
| requestedFlags: { [FEATURE_FLAG.hasAiAccess]: true }, | ||
| catalogKeys: CATALOG_KEYS, | ||
| isProtected: (key) => key === FEATURE_FLAG.mollifierEnabled, | ||
| graceMs: 60_000, | ||
| }); | ||
|
|
||
| const m = await readFlags(prisma, [FEATURE_FLAG.mollifierEnabled]); | ||
| expect(m[FEATURE_FLAG.mollifierEnabled]).toBe(true); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🌐 Web query:
Does Prisma support calling $transaction from inside an already-open interactive $transaction callback?💡 Result:
Yes, Prisma supports calling $transaction from inside an already-open interactive $transaction callback as of version 7.5.0, released in March 2026 [1]. This functionality allows for nested interactive transactions in SQL databases (PostgreSQL, MySQL, SQLite, and SQL Server) by utilizing database savepoints [1][2]. When you invoke $transaction within an existing interactive transaction, Prisma manages the transaction depth and automatically uses savepoints to support nested rollback behavior [2]. This means that if an inner transaction fails, only its changes are rolled back, rather than the entire outer transaction [1][2]. Please note that this feature is specifically supported for SQL providers; MongoDB does not support nested transactions [2]. Prior to this update, attempting to nest $transaction calls was not supported and would typically result in errors or unintended behavior [3].
Citations:
Make the mint flip and flag sweep atomic
replaceGlobalFeatureFlagscommitsapplyGlobalMintKindFlipand the remaining flag writes in separate transactions. If the second step fails,runOpsMintKindstays persisted while the rest of the submitted changes are dropped, leaving the admin action half-applied. Fold both writes into one transaction by letting the mint-flip helper accept atxclient (or an equivalent internal variant).