🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(pretty-json-view): prevent infinite recursion and optimize child row processing (#8302)
marliessophie571698ab2eb0
diff --git a/web/src/components/table/utils/jsonExpansionUtils.ts b/web/src/components/table/utils/jsonExpansionUtils.tsindex 7d6d50ddf5..5580e5423b 100644--- a/web/src/components/table/utils/jsonExpansionUtils.ts+++ b/web/src/components/table/utils/jsonExpansionUtils.ts@@ -13,6 +13,10 @@ export function getRowChildren(row: JsonTableRow): JsonTableRow[] {return row.subRows;}if (row.rawChildData) {+ // Prevent infinite recursion by limiting depth; 25 levels of nesting should make a reasonable assumption+ if (row.level > 25) {+ return [];+ }return transformJsonToTableData(row.rawChildData,row.key,diff --git a/web/src/components/ui/PrettyJsonView.tsx b/web/src/components/ui/PrettyJsonView.tsxindex dacca5566d..c134261b36 100644--- a/web/src/components/ui/PrettyJsonView.tsx+++ b/web/src/components/ui/PrettyJsonView.tsx@@ -225,6 +225,7 @@ function findOptimalExpansionLevel(rows: JsonTableRow[],currentLevel: number,cumulativeCount: number,+ visitedData = new WeakSet(),): number {const rowsAtThisLevel = rows.length;const newCumulativeCount = cumulativeCount + rowsAtThisLevel;@@ -240,8 +241,21 @@ function findOptimalExpansionLevel(// Get all children for next levelconst childRows: JsonTableRow[] = [];+for (const row of rows) {- if (row.hasChildren) {+ if (row.hasChildren && row.rawChildData) {+ if (typeof row.rawChildData !== "object" || row.rawChildData === null) {+ continue; // Skip non-objects+ }++ // Skip if we've already processed this exact data to prevent cycles+ if (visitedData.has(row.rawChildData)) {+ continue;+ }++ // Mark data as visited+ visitedData.add(row.rawChildData);+const children = getRowChildren(row);childRows.push(...children);}@@ -255,6 +269,7 @@ function findOptimalExpansionLevel(childRows,currentLevel + 1,newCumulativeCount,+ visitedData,);}