From 167246dfc6b128c58dceeaca68eb5522792bd17f Mon Sep 17 00:00:00 2001 From: jester Date: Sat, 20 Dec 2025 17:33:13 +0000 Subject: [PATCH] Fix: Add agent provisioning progress logging - Add step-by-step logging to waitForAgentRunning() - Shows state, installStep, and progress updates - Logs errors and poll failures for debugging - Fixes invisible provisioning process issue from Dec 19 split --- src/api/provisionAgent.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/api/provisionAgent.js b/src/api/provisionAgent.js index 1709383..f0b9186 100644 --- a/src/api/provisionAgent.js +++ b/src/api/provisionAgent.js @@ -230,6 +230,7 @@ async function waitForAgentRunning({ ip, timeoutMs = 10 * 60_000 }) { if (AGENT_TOKEN) headers["Authorization"] = `Bearer ${AGENT_TOKEN}`; const deadline = Date.now() + timeoutMs; + let lastLoggedStep = null; while (Date.now() < deadline) { try { @@ -237,10 +238,32 @@ async function waitForAgentRunning({ ip, timeoutMs = 10 * 60_000 }) { if (resp.ok) { const data = await resp.json(); const state = (data.state || "").toLowerCase(); - if (state === "running") return data; - if (state === "error") throw new Error(data.error || "agent error"); + const step = data.installStep || data.currentStep || "unknown"; + const progress = data.progress || ""; + + // Log state changes and progress + if (step !== lastLoggedStep) { + console.log(`[AGENT ${ip}] state=${state} step=${step} ${progress}`); + lastLoggedStep = step; + } + + if (state === "running") { + console.log(`[AGENT ${ip}] ✓ Provisioning complete`); + return data; + } + + if (state === "error") { + const errorMsg = data.error || "agent error"; + console.error(`[AGENT ${ip}] ✗ ERROR:`, errorMsg); + throw new Error(errorMsg); + } } - } catch {} + } catch (err) { + // Only log non-connection errors (agent might not be up yet) + if (!err.message.includes("ECONNREFUSED") && !err.message.includes("fetch failed")) { + console.error(`[AGENT ${ip}] Poll error:`, err.message); + } + } await sleep(3000); }