From 068435ffb9d9ce69905992ed4ef7effb2aaffb5e Mon Sep 17 00:00:00 2001 From: ypratama Date: Mon, 7 Sep 2026 11:43:24 +0700 Subject: [PATCH] Fix: strictly use active flows for online status (ignore dummy summaries) --- src/lib/actions/agentsMongo.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/actions/agentsMongo.ts b/src/lib/actions/agentsMongo.ts index db7d034..76bb3d6 100644 --- a/src/lib/actions/agentsMongo.ts +++ b/src/lib/actions/agentsMongo.ts @@ -89,7 +89,7 @@ export async function fetchAgentsFromMongo( } // 3. Optimize status check and last seen per agent using parallel indexed queries - const twentyFourHoursAgo = new Date(Date.now() - 24 * 3600000); + const fifteenMinutesAgoQuery = new Date(Date.now() - 15 * 60000); const agentResults = await Promise.all( agentSource.map(async (item: any, idx: number) => { @@ -99,7 +99,7 @@ export async function fetchAgentsFromMongo( // Execute status checks for active flow, latest flow, and latest summary in parallel const [activeFlow, latestFlow, latestSummary] = await Promise.all([ db.collection('flows').findOne( - { agent_uuid: uuid, timestamp: { $gte: twentyFourHoursAgo } }, + { agent_uuid: uuid, timestamp: { $gte: fifteenMinutesAgoQuery } }, { projection: { _id: 1 } } ), db.collection('flows').findOne( @@ -135,8 +135,7 @@ export async function fetchAgentsFromMongo( } } - const fifteenMinutesAgo = new Date(Date.now() - 15 * 60000); - const isOnline = lastSeenDate ? lastSeenDate >= fifteenMinutesAgo : !!activeFlow; + const isOnline = !!activeFlow; let statusHuman = 'No Flows Detected'; if (lastSeenDate) {