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); }