Skip to content

feat: link the original run from replayed runs #2262

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
merged 3 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/webapp/app/presenters/v3/SpanPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export class SpanPresenter extends BasePresenter {
friendlyId: true,
},
},
replayedFromTaskRunFriendlyId: true,
},
where: span.originalRun
? {
Expand Down Expand Up @@ -331,6 +332,7 @@ export class SpanPresenter extends BasePresenter {
runtime: run.lockedToVersion?.runtime,
runtimeVersion: run.lockedToVersion?.runtimeVersion,
isTest: run.isTest,
replayedFromTaskRunFriendlyId: run.replayedFromTaskRunFriendlyId,
environmentId: run.runtimeEnvironment.id,
idempotencyKey: run.idempotencyKey,
idempotencyKeyExpiresAt: run.idempotencyKeyExpiresAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
v3DeploymentVersionPath,
v3RunDownloadLogsPath,
v3RunPath,
v3RunRedirectPath,
v3RunSpanPath,
v3RunsPath,
v3SchedulePath,
Expand Down Expand Up @@ -592,6 +593,20 @@ function RunBody({
{run.isTest ? <CheckIcon className="size-4 text-text-dimmed" /> : "–"}
</Property.Value>
</Property.Item>
{run.replayedFromTaskRunFriendlyId && (
<Property.Item>
<Property.Label>Replayed from</Property.Label>
<Property.Value>
<TextLink
to={v3RunRedirectPath(organization, project, {
friendlyId: run.replayedFromTaskRunFriendlyId,
})}
>
{run.replayedFromTaskRunFriendlyId}
</TextLink>
</Property.Value>
</Property.Item>
)}
{environment && (
<Property.Item>
<Property.Label>Environment</Property.Label>
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/app/runEngine/services/triggerTask.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export class RunEngineTriggerTaskService {
spanId: event.spanId,
parentSpanId:
options.parentAsLinkType === "replay" ? undefined : event.traceparent?.spanId,
replayedFromTaskRunFriendlyId: options.replayedFromTaskRunFriendlyId,
lockedToVersionId: lockedToBackgroundWorker?.id,
taskVersion: lockedToBackgroundWorker?.version,
sdkVersion: lockedToBackgroundWorker?.sdkVersion,
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/app/v3/services/replayTaskRun.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class ReplayTaskRunService extends BaseService {
{
spanParentAsLink: true,
parentAsLinkType: "replay",
replayedFromTaskRunFriendlyId: existingTaskRun.friendlyId,
traceContext: {
traceparent: `00-${existingTaskRun.traceId}-${existingTaskRun.spanId}-01`,
},
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/app/v3/services/triggerTask.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type TriggerTaskServiceOptions = {
scheduleInstanceId?: string;
queueTimestamp?: Date;
overrideCreatedAt?: Date;
replayedFromTaskRunFriendlyId?: string;
};

export class OutOfEntitlementError extends Error {
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/app/v3/services/triggerTaskV1.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export class TriggerTaskServiceV1 extends BaseService {
parentAttempt?.taskRun.id ??
dependentBatchRun?.dependentTaskAttempt?.taskRun.rootTaskRunId ??
dependentBatchRun?.dependentTaskAttempt?.taskRun.id,
replayedFromTaskRunFriendlyId: options.replayedFromTaskRunFriendlyId,
batchId: dependentBatchRun?.id ?? parentBatchRun?.id,
resumeParentOnCompletion: !!(dependentAttempt ?? dependentBatchRun),
depth,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "TaskRun" ADD COLUMN "replayedFromTaskRunFriendlyId" TEXT;
2 changes: 2 additions & 0 deletions internal-packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ model TaskRun {
logsDeletedAt DateTime?
replayedFromTaskRunFriendlyId String?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not happy with this name. Also it's not consistent with the other references to runs, like rootTaskRunId, parentTaskRunId, etc., where we store the internal ID as reference. But in this case it is more efficient to store the friendly ID as it avoids having to do a self-join and suffices to generate the link to the replayedFrom run. Other ideas?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In v4 the friendly IDs are run_<internalId>. There are helpers to "convert" from one to the other. Will hopefully simplify this 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, then we can go with this for now and switch to internal IDs once we deprecate v3.

/// This represents the original task that that was triggered outside of a Trigger.dev task
rootTaskRun TaskRun? @relation("TaskRootRun", fields: [rootTaskRunId], references: [id], onDelete: SetNull, onUpdate: NoAction)
rootTaskRunId String?
Expand Down
2 changes: 2 additions & 0 deletions internal-packages/run-engine/src/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export class RunEngine {
tags,
parentTaskRunId,
rootTaskRunId,
replayedFromTaskRunFriendlyId,
batch,
resumeParentOnCompletion,
depth,
Expand Down Expand Up @@ -450,6 +451,7 @@ export class RunEngine {
oneTimeUseToken,
parentTaskRunId,
rootTaskRunId,
replayedFromTaskRunFriendlyId,
batchId: batch?.id,
resumeParentOnCompletion,
depth,
Expand Down
1 change: 1 addition & 0 deletions internal-packages/run-engine/src/engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export type TriggerParams = {
tags: { id: string; name: string }[];
parentTaskRunId?: string;
rootTaskRunId?: string;
replayedFromTaskRunFriendlyId?: string;
batch?: {
id: string;
index: number;
Expand Down