From a29670e93d9bbab98533ac6116c198f0bcc1ec26 Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Sun, 5 Jul 2026 21:30:53 -0500 Subject: [PATCH] Fix WEB HOST stats never populating (DO server had no monitoring agent installed) and a timezone bug in freshness checks (America/Chicago default timezone + strtotime() on naive UTC MySQL timestamps caused sites/proxmox/ollama facts to never refresh, and could have suppressed the KB intent generator's scheduled runs) --- api/endpoints/do_server.php | 2 +- api/endpoints/facts_collector.php | 13 +++++++++---- api/endpoints/kb_intent_generator.php | 9 ++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/api/endpoints/do_server.php b/api/endpoints/do_server.php index 349c2ee..379e78f 100644 --- a/api/endpoints/do_server.php +++ b/api/endpoints/do_server.php @@ -39,7 +39,7 @@ foreach ($svcNames as $s) { // Site health from kb_facts $siteLabels = [ - "jarvis" => "jarvis.orbishosting.com:1972", + "jarvis" => "jarvis.orbishosting.com", "tomsjavajive" => "tomsjavajive.com", "epictravelexp"=> "epictravelexpeditions.com", "parkersling" => "parkerslingshotrentals.com", diff --git a/api/endpoints/facts_collector.php b/api/endpoints/facts_collector.php index c72a47d..70f5da9 100644 --- a/api/endpoints/facts_collector.php +++ b/api/endpoints/facts_collector.php @@ -21,13 +21,18 @@ function collect_all(): array { // Returns true if a fact category has been updated within $secs seconds. // Prevents expensive external calls when data is still fresh. + // Comparison is done entirely in SQL (via NOW()) rather than PHP's time()/strtotime() + // — this file's config.php sets date_default_timezone_set('America/Chicago'), which + // makes strtotime() misinterpret MySQL's naive (UTC) datetime strings as being in + // Chicago time, throwing every freshness check off by the UTC offset (previously + // caused "sites" to always look artificially fresh and never actually refresh). $fresh = function(string $cat, int $secs): bool { $row = JarvisDB::query( - 'SELECT updated_at FROM kb_facts WHERE category=? ORDER BY updated_at DESC LIMIT 1', - [$cat] + 'SELECT (updated_at > DATE_SUB(NOW(), INTERVAL ? SECOND)) AS is_fresh FROM kb_facts WHERE category=? ORDER BY updated_at DESC LIMIT 1', + [$secs, $cat] ); - if (empty($row[0]['updated_at'])) return false; - return (time() - strtotime($row[0]['updated_at'])) < $secs; + if (empty($row)) return false; + return (bool) $row[0]['is_fresh']; }; diff --git a/api/endpoints/kb_intent_generator.php b/api/endpoints/kb_intent_generator.php index 1bc4c26..275b822 100644 --- a/api/endpoints/kb_intent_generator.php +++ b/api/endpoints/kb_intent_generator.php @@ -71,11 +71,14 @@ function normalize_pattern(string $pat): string { /* ── run guard: skip if ran within last 4 hours ── */ /* Set JARVIS_FORCE_RUN=1 (env) or pass --force (argv) to bypass */ -$lastRun = JarvisDB::single( - "SELECT updated_at FROM kb_facts WHERE category='kb_generator' AND fact_key='last_run'" +/* Comparison done in SQL (NOW()) rather than PHP time()/strtotime() — this process's + date_default_timezone_set('America/Chicago') makes strtotime() misread MySQL's naive + (UTC) timestamps as Chicago time, throwing elapsed-time checks off by the UTC offset. */ +$recentRun = JarvisDB::single( + "SELECT (updated_at > DATE_SUB(NOW(), INTERVAL 14400 SECOND)) AS is_recent FROM kb_facts WHERE category='kb_generator' AND fact_key='last_run'" ); $forceRun = !empty(getenv('JARVIS_FORCE_RUN')) || (isset($argv[1]) && $argv[1] === '--force'); -if (!$forceRun && $lastRun && (time() - strtotime($lastRun['updated_at'])) < 14400) { +if (!$forceRun && $recentRun && $recentRun['is_recent']) { log_line('Skipping – ran within last 4 hours. Use --force to override.'); exit(0); }