-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(run-store): stop run-create failing on a brief write stall #4514
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
matt-aitken
merged 1 commit into
main
from
feature/tri-12968-fix-5s-interactive-transaction-timeout-fails-68-run
Aug 5, 2026
+156
−17
Merged
Changes from all commits
Commits
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: fix | ||
| --- | ||
|
|
||
| Triggering a task no longer intermittently fails to create the run when a database write briefly stalls. |
96 changes: 96 additions & 0 deletions
96
internal-packages/run-store/src/PostgresRunStore.createRunNoTx.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,96 @@ | ||
| import { heteroRunOpsPostgresTest } from "@internal/testcontainers"; | ||
| import type { RunOpsPrismaClient } from "@internal/run-ops-database"; | ||
| import { describe, expect } from "vitest"; | ||
| import { PostgresRunStore } from "./PostgresRunStore.js"; | ||
| import type { CreateRunInput } from "./types.js"; | ||
|
|
||
| const NEW_ID_26 = "k".repeat(24) + "01"; | ||
|
|
||
| function makeDedicatedStore(prisma17: RunOpsPrismaClient) { | ||
| return new PostgresRunStore({ | ||
| prisma: prisma17 as never, | ||
| readOnlyPrisma: prisma17 as never, | ||
| schemaVariant: "dedicated", | ||
| }); | ||
| } | ||
|
|
||
| function trackInteractiveTx(prisma17: RunOpsPrismaClient) { | ||
| const original = prisma17.$transaction.bind(prisma17); | ||
| const state = { interactiveCalls: 0 }; | ||
| (prisma17 as { $transaction: unknown }).$transaction = ( | ||
| arg: unknown, | ||
| options?: { timeout?: number; maxWait?: number } | ||
| ) => { | ||
| if (typeof arg === "function") { | ||
| state.interactiveCalls += 1; | ||
| return (original as (fn: unknown, o?: unknown) => unknown)(arg, { ...options, timeout: 1 }); | ||
| } | ||
| return (original as (a: unknown, o?: unknown) => unknown)(arg, options); | ||
| }; | ||
| return state; | ||
| } | ||
|
|
||
| function buildCreateRunInput(params: { | ||
| runId: string; | ||
| friendlyId: string; | ||
| suffix: string; | ||
| }): CreateRunInput { | ||
| return { | ||
| data: { | ||
| id: params.runId, | ||
| engine: "V2", | ||
| status: "PENDING", | ||
| friendlyId: params.friendlyId, | ||
| runtimeEnvironmentId: `env_${params.suffix}`, | ||
| environmentType: "DEVELOPMENT", | ||
| organizationId: `org_${params.suffix}`, | ||
| projectId: `proj_${params.suffix}`, | ||
| taskIdentifier: "my-task", | ||
| payload: '{"hello":"world"}', | ||
| payloadType: "application/json", | ||
| traceContext: { trace: "ctx" }, | ||
| traceId: `trace_${params.runId}`, | ||
| spanId: `span_${params.runId}`, | ||
| runTags: [], | ||
| queue: "task/my-task", | ||
| isTest: false, | ||
| taskEventStore: "taskEvent", | ||
| depth: 0, | ||
| createdAt: new Date("2024-01-01T00:00:00.000Z"), | ||
| }, | ||
| snapshot: { | ||
| engine: "V2", | ||
| executionStatus: "RUN_CREATED", | ||
| description: "Run was created", | ||
| runStatus: "PENDING", | ||
| environmentId: `env_${params.suffix}`, | ||
| environmentType: "DEVELOPMENT", | ||
| projectId: `proj_${params.suffix}`, | ||
| organizationId: `org_${params.suffix}`, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| describe("createRun on the dedicated store does not wrap a single-write create in an interactive transaction", () => { | ||
| heteroRunOpsPostgresTest( | ||
| "a create with no associated waitpoint survives an interactive-tx budget of 1ms (run + snapshot persist)", | ||
| async ({ prisma17 }) => { | ||
| const tx = trackInteractiveTx(prisma17); | ||
| const store = makeDedicatedStore(prisma17); | ||
| const runId = `run_${NEW_ID_26}`; | ||
|
|
||
| await store.createRun( | ||
| buildCreateRunInput({ runId, friendlyId: "run_no_tx", suffix: "no_tx" }) | ||
| ); | ||
|
|
||
| expect(tx.interactiveCalls).toBe(0); | ||
|
|
||
| const run = await prisma17.taskRun.findFirstOrThrow({ where: { id: runId } }); | ||
| expect(run.status).toBe("PENDING"); | ||
| const snap = await prisma17.taskRunExecutionSnapshot.findFirst({ | ||
| where: { runId, executionStatus: "RUN_CREATED" }, | ||
| }); | ||
| expect(snap).not.toBeNull(); | ||
| } | ||
| ); | ||
| }); |
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
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.