From f5c6fa186f3b3cab9c0b5c03362c7ae570ec2dfe Mon Sep 17 00:00:00 2001 From: kumarabhirup Date: Thu, 19 Feb 2026 21:52:01 -0800 Subject: [PATCH] web: auto-create index entries for unindexed sessions in active-runs --- apps/web/lib/active-runs.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) 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 =