Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(traces): Infinite recursion in `buildStepGroups` (#13900)

Ben Bachemedcb19e876d8
diff --git a/web/src/__tests__/buildStepData.clienttest.ts b/web/src/__tests__/buildStepData.clienttest.ts
index 654e822e8f..79ee590dbe 100644
--- a/web/src/__tests__/buildStepData.clienttest.ts
+++ b/web/src/__tests__/buildStepData.clienttest.ts
@@ -32,6 +32,47 @@ describe("buildStepData", () => {
...overrides,
});
+ describe("inverted time ranges", () => {
+ it("makes progress when a group contains inverted time ranges", () => {
+ const observations = [
+ createMockObservation({
+ id: "generation-1",
+ name: "generation-1",
+ startTime: "2026-05-27T09:17:52.469Z",
+ endTime: "2026-05-27T09:17:56.536Z",
+ }),
+ createMockObservation({
+ id: "generation-2",
+ name: "generation-2",
+ startTime: "2026-05-27T09:17:52.556Z",
+ endTime: "2026-05-27T09:17:57.301Z",
+ }),
+ createMockObservation({
+ id: "inverted-tool-1",
+ name: "inverted-tool-1",
+ startTime: "2026-05-27T09:17:55.846Z",
+ endTime: "2026-05-27T09:17:52.468Z",
+ }),
+ createMockObservation({
+ id: "inverted-tool-2",
+ name: "inverted-tool-2",
+ startTime: "2026-05-27T09:17:56.536Z",
+ endTime: "2026-05-27T09:17:52.556Z",
+ }),
+ ];
+ const result = buildStepData(observations);
+ const userObservations = result.filter((obs) => !obs.name.includes("__"));
+
+ expect(userObservations.map((obs) => obs.id)).toEqual([
+ "generation-1",
+ "generation-2",
+ "inverted-tool-1",
+ "inverted-tool-2",
+ ]);
+ expect(userObservations.every((obs) => obs.step !== null)).toBe(true);
+ });
+ });
+
describe("basic sequential timing", () => {
it("should put sequential observations in different steps", () => {
const observations: AgentGraphDataResponse[] = [
diff --git a/web/src/features/trace-graph-view/buildStepData.ts b/web/src/features/trace-graph-view/buildStepData.ts
index c228713249..38617865e7 100644
--- a/web/src/features/trace-graph-view/buildStepData.ts
+++ b/web/src/features/trace-graph-view/buildStepData.ts
@@ -66,6 +66,15 @@ function buildStepGroups(
}
});
+ // Inverted or otherwise invalid time ranges can cause cleanup to remove every
+ // observation, which would recurse with identical input until the stack overflows.
+ // To prevent this, if the cleaned group is empty, we will use the original group as a fallback
+ // and mark all of its observations as processed to avoid infinite recursion.
+ if (cleanedGroup.length === 0) {
+ cleanedGroup.push(...currentGroup);
+ currentGroup.forEach((o) => processedIds.add(o.id));
+ }
+
stepGroups.push(cleanedGroup);
// Optimization: use incrementally built processedIds set