From e467cdaf237208c67cccfba93dd9be107566c9e8 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Thu, 6 Aug 2026 18:28:13 -0400 Subject: [PATCH] The scheduler AI dock read the poll envelope as the job, so every answer hung on thinking --- Plugin/unraid/api/ai.php | 14 +++++++++----- Plugin/unraid/pages/scheduler.php | 10 +++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Plugin/unraid/api/ai.php b/Plugin/unraid/api/ai.php index 7d3843a..52df843 100644 --- a/Plugin/unraid/api/ai.php +++ b/Plugin/unraid/api/ai.php @@ -80,11 +80,15 @@ // CSRF prepend never reaches here and a request that dies inside the include never reaches the // action log below, and those two look identical from outside — which is what made a POST that // the browser demonstrably sent leave no trace anywhere on the server. -@file_put_contents('/var/log/varaverk/ai.log', - date('Y-m-d H:i:s') . ' ENTER ' . ($_SERVER['REQUEST_METHOD'] ?? '?') - . ' ' . ($_SERVER['REQUEST_URI'] ?? '?') - . ' ct=' . substr($_SERVER['CONTENT_TYPE'] ?? '-', 0, 40) - . ' len=' . ($_SERVER['CONTENT_LENGTH'] ?? '-') . "\n", FILE_APPEND | LOCK_EX); +// Polls are excluded here for the same reason they are excluded from the action log below: one +// line per second per open tab buries every line worth reading. +if (strpos($_SERVER['REQUEST_URI'] ?? '', 'action=poll') === false) { + @file_put_contents('/var/log/varaverk/ai.log', + date('Y-m-d H:i:s') . ' ENTER ' . ($_SERVER['REQUEST_METHOD'] ?? '?') + . ' ' . ($_SERVER['REQUEST_URI'] ?? '?') + . ' ct=' . substr($_SERVER['CONTENT_TYPE'] ?? '-', 0, 40) + . ' len=' . ($_SERVER['CONTENT_LENGTH'] ?? '-') . "\n", FILE_APPEND | LOCK_EX); +} header('Content-Type: application/json'); header('Cache-Control: no-store, no-cache'); diff --git a/Plugin/unraid/pages/scheduler.php b/Plugin/unraid/pages/scheduler.php index aa6f213..18019d0 100644 --- a/Plugin/unraid/pages/scheduler.php +++ b/Plugin/unraid/pages/scheduler.php @@ -2429,11 +2429,15 @@ function vvAiDockSend() { }).catch(e => vvAiDockDone('Request failed: ' + e, true)); } -function vvAiDockPoll(token) { +function vvAiDockPoll(token, started) { + started = started || Date.now(); clearTimeout(vvAiPoll); + if (Date.now() - started > 300000) return vvAiDockDone('Timed out waiting for a response.', true); vvAiPoll = setTimeout(() => { fetch('/plugins/varaverk/api/ai.php?action=poll&token=' + encodeURIComponent(token)) - .then(r => r.json()).then(j => { + .then(r => r.json()).then(d => { + if (!d.ok) return vvAiDockDone(d.error || 'Poll failed', true); + const j = d.job || {}; if (j.status === 'done') { vvAiHist.push({ role: 'assistant', content: j.answer || '' }); vvAiDockDone(j.answer || '(empty answer)', false, j.sources || []); @@ -2443,7 +2447,7 @@ function vvAiDockPoll(token) { return; } if (j.status === 'error') return vvAiDockDone(j.error || 'Unknown error', true); - vvAiDockPoll(token); + vvAiDockPoll(token, started); }).catch(e => vvAiDockDone('Poll failed: ' + e, true)); }, 1000); }