The full-system updater runs as a detached systemd service and can finish successfully even when the browser loses its status connection. In that case the update log and status file correctly report REBOOT_REQUIRED, but the Hub modal can remain on "Updating..." with its controls disabled. There were four independent ways for the frontend to get stuck: * update status fetches had no deadline, so a request that stayed pending never rejected and never advanced the existing failure counter; * setInterval started async polls without waiting for the previous poll, allowing slow requests to overlap and responses to arrive out of order; * each log chunk used textContent +=, replacing the complete and growing Nix build log every two seconds, which could stall browser rendering and was especially visible over RDP; and * page reload, tab resume, and RDP reconnect did not reattach the modal to the update status persisted by the backend. This produced a dangerous UX mismatch: the machine had a fully staged NixOS generation and was ready to reboot, while the Hub continued telling the user that the update was still running. Bound status requests with AbortController, prevent overlapping polls, and replace the endless spinner after sustained failures with an explicit "Update status unavailable" state and Retry Status action. Reconcile state immediately on focus, visibility, online, page startup, and before starting a new update. Use no-store requests and render verbose logs incrementally with a bounded visible tail while retaining the complete report in memory. Apply the same timeout and single-flight protection to rebuild polling. Record the exact generation produced by `nixos-rebuild boot`. The Hub now keeps REBOOT_REQUIRED visible until that generation matches /run/current-system, then clears the marker after reboot. For an update started by an older updater that did not write the marker, recover the staged generation from the final nixos-rebuild log line. The dashboard sidebar also distinguishes update-in-progress and restart-required states. Regression coverage verifies generation marker/log recovery, pre- versus post-reboot detection, request timeout wiring, single-flight polling, connection-loss UX, RDP/tab resume reconciliation, bounded log rendering, page-reload recovery, and JavaScript syntax. Validation: * python3 -m unittest discover -s tests -p 'test_*.py' -v (170 passed) * node --check app/sovran_systemsos_web/static/js/*.js * python3 -m py_compile for changed Python modules * git diff --check A Nix evaluation was not available in the development sandbox; the NixOS module should still be evaluated and built in CI or on a test machine before release.
113 lines
4.1 KiB
JavaScript
113 lines
4.1 KiB
JavaScript
"use strict";
|
|
|
|
// ── Rebuild modal ─────────────────────────────────────────────────
|
|
|
|
function openRebuildModal() {
|
|
if (!$rebuildModal) return;
|
|
_rebuildLog = "";
|
|
_rebuildLogOffset = 0;
|
|
_rebuildServerDown = false;
|
|
_rebuildFinished = false;
|
|
_rebuildPollInFlight = false;
|
|
_rebuildPollFailures = 0;
|
|
if ($rebuildLog) { $rebuildLog.textContent = ""; $rebuildLog.style.display = "none"; }
|
|
var action = _rebuildIsEnabling ? "Enabling" : "Disabling";
|
|
var label = _rebuildFeatureName || "feature";
|
|
if ($rebuildStatus) $rebuildStatus.textContent = action + " " + label + "…";
|
|
if ($rebuildSpinner) $rebuildSpinner.classList.add("spinning");
|
|
if ($rebuildReboot) $rebuildReboot.style.display = "none";
|
|
if ($rebuildSave) $rebuildSave.style.display = "none";
|
|
if ($rebuildClose) $rebuildClose.disabled = true;
|
|
$rebuildModal.classList.add("open");
|
|
// Delay first poll slightly to let the rebuild service start and clear stale log
|
|
setTimeout(startRebuildPoll, 1500);
|
|
}
|
|
|
|
function closeRebuildModal() {
|
|
if ($rebuildModal) $rebuildModal.classList.remove("open");
|
|
stopRebuildPoll();
|
|
}
|
|
|
|
function appendRebuildLog(text) {
|
|
if (!text) return;
|
|
_rebuildLog += text;
|
|
// Log is collected silently for error reports — not displayed to user
|
|
}
|
|
|
|
function startRebuildPoll() {
|
|
if (_rebuildPollTimer) clearInterval(_rebuildPollTimer);
|
|
pollRebuildStatus();
|
|
_rebuildPollTimer = setInterval(pollRebuildStatus, UPDATE_POLL_INTERVAL);
|
|
}
|
|
|
|
function stopRebuildPoll() {
|
|
if (_rebuildPollTimer) { clearInterval(_rebuildPollTimer); _rebuildPollTimer = null; }
|
|
}
|
|
|
|
async function pollRebuildStatus() {
|
|
if (_rebuildFinished || _rebuildPollInFlight) return;
|
|
_rebuildPollInFlight = true;
|
|
try {
|
|
var data = await apiFetchWithTimeout(
|
|
"/api/rebuild/status?offset=" + _rebuildLogOffset,
|
|
{ cache: "no-store" },
|
|
STATUS_POLL_FETCH_TIMEOUT
|
|
);
|
|
_rebuildPollFailures = 0;
|
|
if (_rebuildServerDown) { _rebuildServerDown = false; }
|
|
if (data.log) appendRebuildLog(data.log);
|
|
_rebuildLogOffset = data.offset;
|
|
if (data.running) return;
|
|
_rebuildFinished = true;
|
|
stopRebuildPoll();
|
|
if (data.result === "reboot_required") {
|
|
onRebuildDone("reboot_required");
|
|
} else {
|
|
onRebuildDone(data.result === "success");
|
|
}
|
|
} catch (err) {
|
|
_rebuildPollFailures += 1;
|
|
// The Hub restarts itself during activation, which briefly drops this poll.
|
|
// If polling stays broken long past a normal restart, reload to
|
|
// re-authenticate and show the resulting feature state.
|
|
if (_rebuildPollFailures >= STATUS_POLL_MAX_FAILURES) {
|
|
_rebuildFinished = true;
|
|
stopRebuildPoll();
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
if (!_rebuildServerDown) { _rebuildServerDown = true; if ($rebuildStatus) $rebuildStatus.textContent = "Applying changes…"; }
|
|
} finally {
|
|
_rebuildPollInFlight = false;
|
|
}
|
|
}
|
|
|
|
function onRebuildDone(result) {
|
|
if ($rebuildSpinner) $rebuildSpinner.classList.remove("spinning");
|
|
if ($rebuildClose) $rebuildClose.disabled = false;
|
|
if (result === true) {
|
|
if ($rebuildStatus) $rebuildStatus.textContent = "✓ Done";
|
|
// Auto-reload the page after a short delay so tiles and toggles reflect the new state
|
|
setTimeout(function() { window.location.reload(); }, 1200);
|
|
} else if (result === "reboot_required") {
|
|
if ($rebuildStatus) $rebuildStatus.textContent = "✓ Done — restart required";
|
|
if ($rebuildReboot) $rebuildReboot.style.display = "inline-flex";
|
|
} else {
|
|
if ($rebuildStatus) $rebuildStatus.textContent = "✗ Something went wrong";
|
|
if ($rebuildSave) $rebuildSave.style.display = "inline-flex";
|
|
if ($rebuildReboot) $rebuildReboot.style.display = "inline-flex";
|
|
}
|
|
}
|
|
|
|
function saveRebuildErrorReport() {
|
|
var blob = new Blob([_rebuildLog], { type: "text/plain" });
|
|
var url = URL.createObjectURL(blob);
|
|
var a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = "sovran-rebuild-error-" + new Date().toISOString().split(".")[0].replace(/:/g, "-") + ".txt";
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
URL.revokeObjectURL(url);
|
|
}
|