Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

⭕ fix: Handle Circular References in `CONSOLE_JSON` Log Truncation (#4958)

Andrés Restrepo43d10a4e4305
diff --git a/api/config/parsers.js b/api/config/parsers.js
index 7cedd014cb..a3bab7d3cb 100644
--- a/api/config/parsers.js
+++ b/api/config/parsers.js
@@ -187,17 +187,33 @@ const debugTraverse = winston.format.printf(({ level, message, timestamp, ...met
});
const jsonTruncateFormat = winston.format((info) => {
+ const truncateLongStrings = (str, maxLength) => {
+ return str.length > maxLength ? str.substring(0, maxLength) + '...' : str;
+ };
+
+ const seen = new WeakSet();
+
const truncateObject = (obj) => {
+ if (typeof obj !== 'object' || obj === null) {
+ return obj;
+ }
+
+ // Handle circular references
+ if (seen.has(obj)) {
+ return '[Circular]';
+ }
+ seen.add(obj);
+
+ if (Array.isArray(obj)) {
+ return obj.map(item => truncateObject(item));
+ }
+
const newObj = {};
Object.entries(obj).forEach(([key, value]) => {
if (typeof value === 'string') {
newObj[key] = truncateLongStrings(value, 255);
- } else if (Array.isArray(value)) {
- newObj[key] = value.map(condenseArray);
- } else if (typeof value === 'object' && value !== null) {
- newObj[key] = truncateObject(value);
} else {
- newObj[key] = value;
+ newObj[key] = truncateObject(value);
}
});
return newObj;