[object Object]

← back to Bertha

chore(alshi-dash): update 1 file (.js) [+19/-16]

ee69ff3fd386a580f20ff1b1fd23728d61cbc3cd · 2026-02-14 19:01:18 +0000 · DW Commit Agent

Files touched

Diff

commit ee69ff3fd386a580f20ff1b1fd23728d61cbc3cd
Author: DW Commit Agent <commit-agent@dw-agents.com>
Date:   Sat Feb 14 19:01:18 2026 +0000

    chore(alshi-dash): update 1 file (.js) [+19/-16]
---
 kalshi-dash/server.js | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/kalshi-dash/server.js b/kalshi-dash/server.js
index 9a70901..6379d0a 100644
--- a/kalshi-dash/server.js
+++ b/kalshi-dash/server.js
@@ -3149,25 +3149,28 @@ server.listen(PORT, '0.0.0.0', () => {
   console.log(`[Ken] Data sources: Kalshi | Reddit (70+) | ${NEWS_FEEDS.length} news feeds | HN | GDELT TV | YouTube | Manifold | r/Kalshi | r/Polymarket | Lemmy | Lobsters | Tildes | Bluesky | Mastodon | Metaculus | Polymarket`);
   console.log(`[Ken] ═══════════════════════════════════════`);
 
-  // Initial Reddit sweep after 5s
-  setTimeout(() => {
-    redditIntelligenceLoop().catch(e => console.error('[Ken] Reddit init error:', e.message));
-  }, 5000);
+  // Mutex: prevent concurrent sweeps from overlapping and doubling memory
+  let sweepRunning = false;
+
+  async function runSweepSafe(name, fn) {
+    if (sweepRunning) { console.log(`[Ken] Skipping ${name} — another sweep in progress`); return; }
+    sweepRunning = true;
+    try { await fn(); } catch (e) { console.error(`[Ken] ${name} error:`, e.message); }
+    sweepRunning = false;
+    if (global.gc) global.gc();
+  }
 
-  // Initial market scan after 20s (give Reddit time to populate)
-  setTimeout(() => {
-    autonomousScan().catch(e => console.error('[Ken] Initial scan error:', e.message));
-  }, 20000);
+  // Initial: run reddit sweep first, THEN market scan (never concurrent)
+  setTimeout(async () => {
+    await runSweepSafe('Reddit init', redditIntelligenceLoop);
+    await runSweepSafe('Initial scan', autonomousScan);
+  }, 5000);
 
-  // Market scan every 15 minutes
-  setInterval(() => {
-    autonomousScan().catch(e => console.error('[Ken] Scan error:', e.message));
-  }, SCAN_INTERVAL_MS);
+  // Market scan every 15 minutes (skips if reddit sweep running)
+  setInterval(() => runSweepSafe('Scan', autonomousScan), SCAN_INTERVAL_MS);
 
-  // Reddit/news every 30 minutes
-  setInterval(() => {
-    redditIntelligenceLoop().catch(e => console.error('[Ken] Reddit error:', e.message));
-  }, REDDIT_INTERVAL_MS);
+  // Reddit/news every 30 minutes (skips if market scan running)
+  setInterval(() => runSweepSafe('Reddit', redditIntelligenceLoop), REDDIT_INTERVAL_MS);
 
   // Resolve old predictions every hour
   setInterval(() => {

← e1e8fbe chore(alshi-dash): update 1 file (.js) [+30/-21]  ·  back to Bertha  ·  chore(alshi-dash): update 1 file (.js) [+218/-20] 1d7b7c1 →