-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(run-ops): webapp write path — trigger/batch minting, idempotency routing, run lifecycle #4118
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
Merged
+7,188
−665
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f7bea8f
feat(run-ops): webapp write path — trigger/batch minting, idempotency…
d-cs efb3560
fix(run-ops split): resolve parent run through an injectable run stor…
d-cs 1bb77ad
refactor(run-ops): drop known-migrated from write-path + read repos; …
d-cs 804a6a6
chore(run-ops split): strip test-enumeration labels from pr07 comment…
d-cs 8ff98c2
style(run-ops): apply oxfmt
d-cs 0d687d3
fix(run-ops split): self-default resolveWaitpointThroughReadThrough t…
d-cs 1fc0e35
fix(run-ops split): route idempotent-run waitpoint block and batch-se…
d-cs c34fa09
test(run-ops split): repair mollifier claim-resolution db.server mock
d-cs 43426e9
test(webapp): mock eager-Redis import-time singletons in global test …
d-cs 3c57e43
test(webapp): stop CI-fatal env-Redis dials in unit tests — force laz…
d-cs 89b4ea9
test(webapp): stop unit tests reaching env-configured Redis/Postgres …
d-cs fba183a
chore: add server-changes for pr06
d-cs 30bfdda
chore(run-ops): fix lint/format for main lint rules
d-cs c1371f2
fix(run-ops test): make engine/marqs no-op mock recursive for nested …
d-cs ea22f52
test(run-ops split): keyset-order hydrate + terminal-metadata read-se…
d-cs 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: feature | ||
| --- | ||
|
|
||
| Route the webapp write path — trigger/batch run minting, idempotency-key resolution, and run lifecycle writes — through the run store so runs can be created and mutated on the dedicated run-ops database. |
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
100 changes: 100 additions & 0 deletions
100
apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
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,100 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { RunId } from "@trigger.dev/core/v3/isomorphic"; | ||
| import { | ||
| resolveIdempotencyDedupClient, | ||
| type ResolveIdempotencyClientDeps, | ||
| } from "./idempotencyResidency.server"; | ||
|
|
||
| // Distinct sentinel objects so we can assert WHICH client was selected by reference. | ||
| const FALLBACK = { __tag: "fallback" } as never; | ||
| const NEW_CLIENT = { __tag: "new" } as never; | ||
| const LEGACY_CLIENT = { __tag: "legacy" } as never; | ||
|
|
||
| function makeDeps(over: Partial<ResolveIdempotencyClientDeps>): ResolveIdempotencyClientDeps { | ||
| return { | ||
| isSplitEnabled: async () => true, | ||
| fallbackClient: FALLBACK, | ||
| newClient: NEW_CLIENT, | ||
| legacyClient: LEGACY_CLIENT, | ||
| resolveMintKind: async () => "ksuid", | ||
| classify: (id) => { | ||
| if (id.length === 27) return "NEW"; | ||
| if (id.length === 25) return "LEGACY"; | ||
| throw new Error(`unclassifiable: ${id.length}`); | ||
| }, | ||
| isMigrated: undefined, | ||
| ...over, | ||
| }; | ||
| } | ||
|
|
||
| const env = { organizationId: "org_1", id: "env_1", orgFeatureFlags: {} }; | ||
|
|
||
| describe("resolveIdempotencyDedupClient", () => { | ||
| it("returns the fallback client unchanged when split is disabled", async () => { | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: undefined }, | ||
| makeDeps({ isSplitEnabled: async () => false }) | ||
| ); | ||
| expect(client).toBe(FALLBACK); | ||
| }); | ||
|
|
||
| it("routes a root run to the NEW client when the env mints ksuid", async () => { | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: undefined }, | ||
| makeDeps({ resolveMintKind: async () => "ksuid" }) | ||
| ); | ||
| expect(client).toBe(NEW_CLIENT); | ||
| }); | ||
|
|
||
| it("routes a root run to the LEGACY client when the env mints cuid", async () => { | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: undefined }, | ||
| makeDeps({ resolveMintKind: async () => "cuid" }) | ||
| ); | ||
| expect(client).toBe(LEGACY_CLIENT); | ||
| }); | ||
|
|
||
| it("routes a child to the NEW client when the ksuid parent is NEW-resident", async () => { | ||
| const ksuidParent = RunId.toFriendlyId("a".repeat(27)); | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: ksuidParent }, | ||
| makeDeps({ resolveMintKind: async () => "cuid" }) // mint flag must NOT win for a child | ||
| ); | ||
| expect(client).toBe(NEW_CLIENT); | ||
| }); | ||
|
|
||
| it("routes a child to the LEGACY client when the cuid parent is LEGACY-resident", async () => { | ||
| const cuidParent = RunId.toFriendlyId("b".repeat(25)); | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: cuidParent }, | ||
| makeDeps({ resolveMintKind: async () => "ksuid" }) // mint flag must NOT win for a child | ||
| ); | ||
| expect(client).toBe(LEGACY_CLIENT); | ||
| }); | ||
|
|
||
| it("routes a swept (migrated) cuid-parent child to the NEW client", async () => { | ||
| const cuidParent = RunId.toFriendlyId("c".repeat(25)); | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: cuidParent }, | ||
| makeDeps({ isMigrated: async () => true }) | ||
| ); | ||
| expect(client).toBe(NEW_CLIENT); | ||
| }); | ||
|
|
||
| it("routes a non-migrated cuid-parent child to the LEGACY client even when isMigrated is provided", async () => { | ||
| const cuidParent = RunId.toFriendlyId("d".repeat(25)); | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: cuidParent }, | ||
| makeDeps({ isMigrated: async () => false }) | ||
| ); | ||
| expect(client).toBe(LEGACY_CLIENT); | ||
| }); | ||
|
|
||
| it("falls back to the fallback client when a present parent id is unclassifiable", async () => { | ||
| const client = await resolveIdempotencyDedupClient( | ||
| { environmentForMint: env, parentRunFriendlyId: "run_not-a-valid-length" }, | ||
| makeDeps({}) | ||
| ); | ||
| expect(client).toBe(FALLBACK); | ||
| }); | ||
| }); |
56 changes: 56 additions & 0 deletions
56
apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
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,56 @@ | ||
| import { ownerEngine, RunId, type Residency } from "@trigger.dev/core/v3/isomorphic"; | ||
| import type { PrismaClientOrTransaction } from "@trigger.dev/database"; | ||
|
|
||
| type MintKind = "cuid" | "ksuid"; | ||
|
|
||
| export type ResolveIdempotencyClientDeps = { | ||
| isSplitEnabled: () => Promise<boolean>; | ||
| fallbackClient: PrismaClientOrTransaction; | ||
| newClient: PrismaClientOrTransaction; | ||
| legacyClient: PrismaClientOrTransaction; | ||
| resolveMintKind: (environment: { | ||
| organizationId: string; | ||
| id: string; | ||
| orgFeatureFlags?: unknown; | ||
| }) => Promise<MintKind>; | ||
| classify?: (id: string) => Residency; | ||
| isMigrated?: (id: string) => Promise<boolean>; | ||
| }; | ||
|
|
||
| export async function resolveIdempotencyDedupClient( | ||
| args: { | ||
| environmentForMint: { organizationId: string; id: string; orgFeatureFlags?: unknown }; | ||
| parentRunFriendlyId: string | undefined; | ||
| }, | ||
| deps: ResolveIdempotencyClientDeps | ||
| ): Promise<PrismaClientOrTransaction> { | ||
| if (!(await deps.isSplitEnabled())) { | ||
| return deps.fallbackClient; | ||
| } | ||
|
|
||
| const classify = deps.classify ?? ownerEngine; | ||
| const clientFor = (residency: Residency): PrismaClientOrTransaction => | ||
| residency === "NEW" ? deps.newClient : deps.legacyClient; | ||
|
|
||
| if (args.parentRunFriendlyId) { | ||
| let parentInternalId: string; | ||
| try { | ||
| parentInternalId = RunId.fromFriendlyId(args.parentRunFriendlyId); | ||
| } catch { | ||
| return deps.fallbackClient; | ||
| } | ||
| let residency: Residency; | ||
| try { | ||
| residency = classify(parentInternalId); | ||
| } catch { | ||
| return deps.fallbackClient; | ||
| } | ||
| if (residency === "LEGACY" && deps.isMigrated && (await deps.isMigrated(parentInternalId))) { | ||
| return deps.newClient; | ||
| } | ||
| return clientFor(residency); | ||
| } | ||
|
|
||
| const kind = await deps.resolveMintKind(args.environmentForMint); | ||
| return clientFor(kind === "ksuid" ? "NEW" : "LEGACY"); | ||
| } |
53 changes: 53 additions & 0 deletions
53
apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
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,53 @@ | ||
| import type { PrismaReplicaClient } from "~/db.server"; | ||
| import { | ||
| $replica as defaultLegacyReplica, | ||
| runOpsNewReplica as defaultNewClient, | ||
| runOpsSplitReadEnabled as defaultSplitReadEnabled, | ||
| } from "~/db.server"; | ||
| import { readThroughRun } from "~/v3/runOpsMigration/readThrough.server"; | ||
|
|
||
| type ResolveWaitpointDeps = { | ||
| newClient?: PrismaReplicaClient; | ||
| legacyReplica?: PrismaReplicaClient; | ||
| splitEnabled?: boolean; | ||
| isPastRetention?: (id: string) => boolean; | ||
| }; | ||
|
|
||
| // Safe defaults matching the deps `complete`/`callback` pass, so a bare caller still fans | ||
| // out to the dedicated run-ops replica (NEW-resident waitpoints) before control-plane. | ||
| export type ResolveWaitpointReadThroughDefaults = { | ||
| newClient: PrismaReplicaClient; | ||
| legacyReplica: PrismaReplicaClient; | ||
| splitEnabled: boolean; | ||
| }; | ||
|
|
||
| const productionDefaults: ResolveWaitpointReadThroughDefaults = { | ||
| newClient: defaultNewClient, | ||
| legacyReplica: defaultLegacyReplica, | ||
| splitEnabled: defaultSplitReadEnabled, | ||
| }; | ||
|
|
||
| export async function resolveWaitpointThroughReadThrough<T>(opts: { | ||
| waitpointId: string; | ||
| environmentId: string; | ||
| read: (client: PrismaReplicaClient) => Promise<T | null>; | ||
| deps?: ResolveWaitpointDeps; | ||
| defaults?: ResolveWaitpointReadThroughDefaults; | ||
| }): Promise<T | null> { | ||
| const defaults = opts.defaults ?? productionDefaults; | ||
|
|
||
| const result = await readThroughRun({ | ||
| runId: opts.waitpointId, | ||
| environmentId: opts.environmentId, | ||
| readNew: (client) => opts.read(client), | ||
| readLegacy: (replica) => opts.read(replica), | ||
| deps: { | ||
| splitEnabled: opts.deps?.splitEnabled ?? defaults.splitEnabled, | ||
| newClient: opts.deps?.newClient ?? defaults.newClient, | ||
| legacyReplica: opts.deps?.legacyReplica ?? defaults.legacyReplica, | ||
| isPastRetention: opts.deps?.isPastRetention, | ||
| }, | ||
| }); | ||
|
|
||
| return result.source === "new" || result.source === "legacy-replica" ? result.value : null; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.