Skip to content

Commit 838980c

Browse files
fix(webapp): treat EXPIRED runs as failed in trace reconciliation
1 parent 805eae7 commit 838980c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

apps/webapp/app/presenters/v3/reconcileTrace.server.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ describe("reconcileTraceWithRunLifecycle", () => {
9090
expect(rootEvent?.data.isPartial).toBe(false);
9191
});
9292

93+
it("should reconcile expired runs correctly", () => {
94+
const expiredRun = { ...runData, status: "EXPIRED" };
95+
const result = reconcileTraceWithRunLifecycle(expiredRun, rootSpanId, initialEvents as any, millisecondsToNanoseconds(1000));
96+
97+
expect(result.rootSpanStatus).toBe("failed");
98+
const rootEvent = result.events.find((e: any) => e.id === rootSpanId);
99+
expect(rootEvent?.data.isError).toBe(true);
100+
expect(rootEvent?.data.isPartial).toBe(false);
101+
});
102+
93103
it("should use rootTaskRun createdAt if available for duration calculation", () => {
94104
const rootTaskCreatedAt = new Date("2023-12-31T23:59:50Z"); // 10s before run.createdAt
95105
const runDataWithRoot: any = {

apps/webapp/app/presenters/v3/reconcileTrace.server.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export function reconcileTraceWithRunLifecycle(
6161

6262
const updatedTotalDuration = Math.max(totalDuration, postgresRunDuration);
6363

64+
const isError = isFailedRunStatus(runData.status) || runData.status === "EXPIRED";
65+
6466
// We only need to potentially update the root event (the first one) if it matches our ID
6567
if (isActualRoot && rootEvent && rootEvent.data.isPartial) {
6668
const updatedEvents = [...events];
@@ -70,20 +72,20 @@ export function reconcileTraceWithRunLifecycle(
7072
...rootEvent.data,
7173
isPartial: false,
7274
duration: Math.max(rootEvent.data.duration ?? 0, postgresRunDuration),
73-
isError: isFailedRunStatus(runData.status),
75+
isError,
7476
},
7577
};
7678

7779
return {
7880
events: updatedEvents,
7981
totalDuration: updatedTotalDuration,
80-
rootSpanStatus: isFailedRunStatus(runData.status) ? "failed" : "completed",
82+
rootSpanStatus: isError ? "failed" : "completed",
8183
};
8284
}
8385

8486
return {
8587
events,
8688
totalDuration: updatedTotalDuration,
87-
rootSpanStatus: isFailedRunStatus(runData.status) ? "failed" : "completed",
89+
rootSpanStatus: isError ? "failed" : "completed",
8890
};
8991
}

0 commit comments

Comments
 (0)