diff --git a/apps/web/lib/active-runs.ts b/apps/web/lib/active-runs.ts index 182ee4bfbcb..58168455ca8 100644 --- a/apps/web/lib/active-runs.ts +++ b/apps/web/lib/active-runs.ts @@ -356,12 +356,35 @@ function updateIndex( ) { try { const idxPath = indexFile(); - if (!existsSync(idxPath)) {return;} - const index = JSON.parse( + let index: Array>; + if (!existsSync(idxPath)) { + // Auto-create index with a bootstrap entry for this session so + // orphaned .jsonl files become visible in the sidebar. + index = [{ + id: sessionId, + title: opts.title || "New Chat", + createdAt: Date.now(), + updatedAt: Date.now(), + messageCount: opts.incrementCount || 0, + }]; + writeFileSync(idxPath, JSON.stringify(index, null, 2)); + return; + } + index = JSON.parse( readFileSync(idxPath, "utf-8"), ) as Array>; - const session = index.find((s) => s.id === sessionId); - if (!session) {return;} + let session = index.find((s) => s.id === sessionId); + if (!session) { + // Session file exists but wasn't indexed — add it. + session = { + id: sessionId, + title: opts.title || "New Chat", + createdAt: Date.now(), + updatedAt: Date.now(), + messageCount: 0, + }; + index.unshift(session); + } session.updatedAt = Date.now(); if (opts.incrementCount) { session.messageCount =