-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(core,webapp,run-engine): stamp a shard key onto run, batch and waitpoint ids #4788
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
Open
d-cs
wants to merge
17
commits into
main
Choose a base branch
from
feat/gen2-minting-tri-13430
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.
+1,231
−124
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
65a354d
feat(core): mint Postgres waitpoint ids stamped for a gen-2 shard
d-cs 0dae1c5
feat(webapp): carry the shard char through a MintTarget on run inheri…
d-cs b20792f
feat(webapp): resolve a run's mint target in one place, gated off by …
d-cs 845ab06
fix(webapp): mint a failed child run onto its parent's shard
d-cs bf32052
feat(webapp): mint a batch id onto its parent run's shard
d-cs 4359bf8
test(run-engine): add a failing census guard for waitpoint mint sites
d-cs 19731d4
feat(run-engine): stamp DATETIME and MANUAL waitpoint ids for the anc…
d-cs 25b2119
feat(run-engine): stamp a run's associated waitpoint id for the run's…
d-cs 6d85a15
feat(run-engine): stamp a BATCH waitpoint id for the batch's shard
d-cs d28aec2
feat(run-engine,webapp): mint a standalone waitpoint token on the env…
d-cs 13f6124
test(webapp): pin every mint path to today's ids while the shard gate…
d-cs 45ee043
test(run-engine): bind each waitpoint mint site to its anchor, and ma…
d-cs f9ad14c
fix(webapp): keep the caller's region on an inherited run mint
d-cs b969f8e
fix(webapp): route a gen-2 batch's completion write to its own shard
d-cs 268b6cd
fix(webapp): return not-found when waiting on a missing waitpoint token
d-cs 0ffb44c
Merge remote-tracking branch 'origin/main' into feat/gen2-minting-tri…
d-cs 46a64d1
perf(core): classify a run-ops id by shape instead of decoding its core
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
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
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
114 changes: 114 additions & 0 deletions
114
apps/webapp/app/v3/runOpsMigration/gen2MintInertness.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,114 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { classifyKind, mintWaitpointIdFor, resolveShard } from "@trigger.dev/core/v3/isomorphic"; | ||
| import { resolveInheritedMintKind } from "./resolveInheritedMintKind.server"; | ||
| import { | ||
| mintAnchoredRunFriendlyId, | ||
| mintFriendlyIdForKind, | ||
| } from "./mintAnchoredRunFriendlyId.server"; | ||
| import { batchIdForMintKind } from "./mintBatchFriendlyId.server"; | ||
| import { resolveRunMintTarget } from "./resolveRunMintTarget.server"; | ||
|
|
||
| // The gate is off when RUN_OPS_SHARDS is unset OR runOpsMintShardSet is empty. Either way | ||
| // resolveMintShard answers "new", so no shard char reaches a MintTarget. Every assertion | ||
| // below is "the id is what it was before gen-2 existed". | ||
| const offShard = vi.fn().mockResolvedValue("new" as const); | ||
| const environment = { organizationId: "org_1", id: "env_1", orgFeatureFlags: {} }; | ||
|
|
||
| describe("gate off — run mint paths", () => { | ||
| it("a root run on the run-ops path mints a gen-1 v1 id", async () => { | ||
| const target = await resolveRunMintTarget({ | ||
| environment, | ||
| region: "us-east-1", | ||
| deps: { | ||
| resolveRunIdMintKind: vi.fn().mockResolvedValue("runOpsId"), | ||
| resolveMintShard: offShard, | ||
| }, | ||
| }); | ||
| const body = mintFriendlyIdForKind(target).slice(4); | ||
| expect(body.length).toBe(26); | ||
| expect(body[24]).toBe("e"); // the region char, as today | ||
| expect(body[25]).toBe("1"); | ||
| }); | ||
|
|
||
| it("a root run on a non-cut-over org mints a cuid", async () => { | ||
| const target = await resolveRunMintTarget({ | ||
| environment, | ||
| deps: { | ||
| resolveRunIdMintKind: vi.fn().mockResolvedValue("cuid"), | ||
| resolveMintShard: offShard, | ||
| }, | ||
| }); | ||
| expect(mintFriendlyIdForKind(target).slice(4).length).toBe(25); | ||
| }); | ||
|
|
||
| it("a child of a gen-1 parent keeps the caller's region char", async () => { | ||
| // The pre-split code passed the region on BOTH arms, so a child run stamped the | ||
| // requested region. Dropping it on the inherited arm would silently stamp the default. | ||
| const target = await resolveRunMintTarget({ | ||
| environment, | ||
| parentRunFriendlyId: `run_${"a".repeat(24)}01`, | ||
| region: "us-east-1", | ||
| deps: { | ||
| resolveRunIdMintKind: vi.fn().mockResolvedValue("runOpsId"), | ||
| resolveMintShard: offShard, | ||
| }, | ||
| }); | ||
| const body = mintFriendlyIdForKind(target).slice(4); | ||
| expect(body[24]).toBe("e"); | ||
| expect(body[25]).toBe("1"); | ||
| }); | ||
|
|
||
| it("a gen-2 parent's shard still outranks the caller's region", async () => { | ||
| const target = await resolveRunMintTarget({ | ||
| environment, | ||
| parentRunFriendlyId: `run_${"a".repeat(24)}a2`, | ||
| region: "us-east-1", | ||
| deps: { | ||
| resolveRunIdMintKind: vi.fn().mockResolvedValue("runOpsId"), | ||
| resolveMintShard: offShard, | ||
| }, | ||
| }); | ||
| expect(mintFriendlyIdForKind(target).slice(4)[24]).toBe("a"); | ||
| }); | ||
|
|
||
| it("a child of a gen-1 parent mints a gen-1 v1 id", () => { | ||
| const body = mintFriendlyIdForKind(resolveInheritedMintKind(`run_${"a".repeat(24)}01`)).slice( | ||
| 4 | ||
| ); | ||
| expect(body[25]).toBe("1"); | ||
| }); | ||
|
|
||
| it("a child of a cuid parent mints a cuid", () => { | ||
| expect( | ||
| mintFriendlyIdForKind(resolveInheritedMintKind(`run_${"b".repeat(25)}`)).slice(4).length | ||
| ).toBe(25); | ||
| }); | ||
| }); | ||
|
|
||
| describe("gate off — batch and item paths", () => { | ||
| it("a batch with no shard char mints a gen-1 v1 id", () => { | ||
| const r = batchIdForMintKind({ kind: "runOpsId" }); | ||
| expect(r.id.length).toBe(26); | ||
| expect(r.id[25]).toBe("1"); | ||
| expect(classifyKind(r.id)).toBe("runOpsId"); | ||
| }); | ||
|
|
||
| it("a batch on a non-cut-over org mints a cuid", () => { | ||
| expect(batchIdForMintKind({ kind: "cuid" }).id.length).toBe(25); | ||
| }); | ||
|
|
||
| it("a batch item anchored on a gen-1 batch mints a gen-1 v1 id", () => { | ||
| const body = mintAnchoredRunFriendlyId(`batch_${"a".repeat(24)}01`).slice(4); | ||
| expect(body[25]).toBe("1"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("gate off — waitpoint paths", () => { | ||
| it("every gen-1 or legacy anchor yields a cuid waitpoint id", () => { | ||
| for (const anchor of [`${"a".repeat(24)}01`, "c".repeat(25), undefined]) { | ||
| const r = mintWaitpointIdFor(anchor); | ||
| expect(r.id.length).toBe(25); | ||
| expect(resolveShard(r.id)).toBe("legacy"); | ||
| } | ||
| }); | ||
| }); |
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
21 changes: 14 additions & 7 deletions
21
apps/webapp/app/v3/runOpsMigration/mintAnchoredRunFriendlyId.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 |
|---|---|---|
| @@ -1,15 +1,22 @@ | ||
| import { generateRunOpsId, RunId, type ResidencyKind } from "@trigger.dev/core/v3/isomorphic"; | ||
| import { generateRunOpsId, generateRunOpsIdV2, RunId } from "@trigger.dev/core/v3/isomorphic"; | ||
| import type { MintTarget } from "./mintTarget"; | ||
| import { resolveInheritedMintKind } from "./resolveInheritedMintKind.server"; | ||
|
|
||
| // Shared id-generation branch for every run-mint path: "runOpsId" -> NEW store, "cuid" -> LEGACY. | ||
| export function mintFriendlyIdForKind(mintKind: ResidencyKind, region?: string): string { | ||
| return mintKind === "runOpsId" | ||
| ? RunId.toFriendlyId(generateRunOpsId(region)) | ||
| : RunId.generate().friendlyId; | ||
| // Shared id-generation branch for every run-mint path: "runOpsId" -> a dedicated store, | ||
| // "cuid" -> LEGACY. A shardChar selects one gen-2 shard and takes index 24; without one, | ||
| // the region takes that slot exactly as it does today. | ||
| export function mintFriendlyIdForKind(target: MintTarget): string { | ||
| if (target.kind !== "runOpsId") { | ||
| return RunId.generate().friendlyId; | ||
| } | ||
|
|
||
| return RunId.toFriendlyId( | ||
| target.shardChar ? generateRunOpsIdV2(target.shardChar) : generateRunOpsId(target.region) | ||
| ); | ||
| } | ||
|
|
||
| // Anchor a batch item's mint on the BATCH's friendlyId (id-shape, zero I/O), never the per-org | ||
| // flag, so the item and its BatchTaskRun stay co-resident across a mid-batch flag flip. | ||
| export function mintAnchoredRunFriendlyId(batchFriendlyId: string, region?: string): string { | ||
| return mintFriendlyIdForKind(resolveInheritedMintKind(batchFriendlyId), region); | ||
| return mintFriendlyIdForKind({ ...resolveInheritedMintKind(batchFriendlyId), region }); | ||
| } |
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.