Skip to content

Commit 02fd391

Browse files
d-csTrigger.dev RepoOps
authored andcommitted
feat(run-engine): handle waitpoint resume and lifecycle cleanup
Adds waitpoint resume acknowledgement and cleanup of completed waitpoints. Mono-RevId: 5dc78fa17d731927020cafb9cd106cea05f4acf1
1 parent e9cf670 commit 02fd391

37 files changed

Lines changed: 5603 additions & 507 deletions

‎apps/webapp/app/v3/runOpsMigration/unblockRouteCatalog.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export const UNBLOCK_ROUTES: readonly UnblockRoute[] = [
4747
site: WAITPOINT_SYSTEM,
4848
symbol: "completeWaitpoint (sink declaration)",
4949
},
50+
{
51+
id: "wp.completeLockedDateTime",
52+
kind: "DATETIME",
53+
site: WAITPOINT_SYSTEM,
54+
symbol: "completeWaitpoint (locked DATETIME re-entry)",
55+
},
5056
{
5157
id: "wp.ensureCompleted",
5258
kind: "RUN",

‎apps/webapp/test/createDeploymentWithNextVersion.test.ts‎

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,48 @@ describe("createDeploymentWithNextVersion", () => {
120120
async ({ prisma }) => {
121121
const { project, environment } = await seedEnvironment(prisma);
122122

123-
const concurrency = 4;
124-
// maxRetries: 0 → no retry path. Concurrent racers all attempt the same
125-
// version; one wins, the rest must surface the wrapped collision error
126-
// (not a raw P2002) so Sentry can distinguish exhaustion from any other
127-
// unique-constraint violation.
128-
const settled = await Promise.allSettled(
129-
Array.from({ length: concurrency }, (_, i) =>
130-
createDeploymentWithNextVersion(
131-
prisma,
132-
environment.id,
133-
(nextVersion) => ({
123+
let collisionVersion = "";
124+
// Insert the winner after the version is read, before the candidate is
125+
// inserted, so exhaustion does not depend on concurrent query scheduling.
126+
const deployment = createDeploymentWithNextVersion(
127+
prisma,
128+
environment.id,
129+
async (nextVersion) => {
130+
collisionVersion = nextVersion;
131+
await prisma.workerDeployment.create({
132+
data: {
133+
environmentId: environment.id,
134134
projectId: project.id,
135-
friendlyId: `deployment_${i}_${nextVersion}`,
136-
shortCode: `short_${i}_${nextVersion}`,
137-
contentHash: `hash_${i}`,
138-
}),
139-
{ maxRetries: 0 }
140-
)
141-
)
135+
version: nextVersion,
136+
friendlyId: `winner_${environment.id}`,
137+
shortCode: "winner",
138+
contentHash: "winner",
139+
},
140+
});
141+
142+
return {
143+
projectId: project.id,
144+
friendlyId: `candidate_${environment.id}`,
145+
shortCode: "candidate",
146+
contentHash: "candidate",
147+
};
148+
},
149+
{ maxRetries: 0 }
142150
);
143151

144-
const fulfilled = settled.filter((s) => s.status === "fulfilled");
145-
const rejected = settled.filter((s): s is PromiseRejectedResult => s.status === "rejected");
146-
147-
expect(fulfilled.length).toBeGreaterThanOrEqual(1);
148-
expect(rejected.length).toBeGreaterThanOrEqual(1);
149-
150-
for (const r of rejected) {
151-
expect(r.reason).toBeInstanceOf(DeploymentVersionCollisionError);
152-
const err = r.reason as DeploymentVersionCollisionError;
153-
expect(err.environmentId).toBe(environment.id);
154-
expect(err.attempts).toBe(1);
155-
expect(err.lastAttemptedVersion).toMatch(/^\d{8}\.\d+$/);
156-
expect((err.cause as { code?: string }).code).toBe("P2002");
157-
}
152+
await expect(deployment).rejects.toBeInstanceOf(DeploymentVersionCollisionError);
153+
await expect(deployment).rejects.toMatchObject({
154+
environmentId: environment.id,
155+
attempts: 1,
156+
lastAttemptedVersion: expect.stringMatching(/^\d{8}\.\d+$/),
157+
cause: { code: "P2002" },
158+
});
159+
expect(
160+
await prisma.workerDeployment.findMany({
161+
where: { environmentId: environment.id },
162+
select: { friendlyId: true, version: true },
163+
})
164+
).toEqual([{ friendlyId: `winner_${environment.id}`, version: collisionVersion }]);
158165
}
159166
);
160167
});

0 commit comments

Comments
 (0)