Handle NixOS switchInhibitors: detect reboot-required case and show correct UI state

Agent-Logs-Url: https://github.com/naturallaw777/staging_alpha/sessions/d72be7a1-ec3f-41da-9753-611b95bc9903

Co-authored-by: naturallaw777 <99053422+naturallaw777@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-29 20:04:59 +00:00
committed by GitHub
parent 17fbd5fd2c
commit e821da6c2a
3 changed files with 56 additions and 11 deletions
@@ -51,19 +51,26 @@ async function pollRebuildStatus() {
if (data.running) return; if (data.running) return;
_rebuildFinished = true; _rebuildFinished = true;
stopRebuildPoll(); stopRebuildPoll();
if (data.result === "reboot_required") {
onRebuildDone("reboot_required");
} else {
onRebuildDone(data.result === "success"); onRebuildDone(data.result === "success");
}
} catch (err) { } catch (err) {
if (!_rebuildServerDown) { _rebuildServerDown = true; if ($rebuildStatus) $rebuildStatus.textContent = "Applying changes…"; } if (!_rebuildServerDown) { _rebuildServerDown = true; if ($rebuildStatus) $rebuildStatus.textContent = "Applying changes…"; }
} }
} }
function onRebuildDone(success) { function onRebuildDone(result) {
if ($rebuildSpinner) $rebuildSpinner.classList.remove("spinning"); if ($rebuildSpinner) $rebuildSpinner.classList.remove("spinning");
if ($rebuildClose) $rebuildClose.disabled = false; if ($rebuildClose) $rebuildClose.disabled = false;
if (success) { if (result === true) {
if ($rebuildStatus) $rebuildStatus.textContent = "✓ Done"; if ($rebuildStatus) $rebuildStatus.textContent = "✓ Done";
// Auto-reload the page after a short delay so tiles and toggles reflect the new state // Auto-reload the page after a short delay so tiles and toggles reflect the new state
setTimeout(function() { window.location.reload(); }, 1200); setTimeout(function() { window.location.reload(); }, 1200);
} else if (result === "reboot_required") {
if ($rebuildStatus) $rebuildStatus.textContent = "✓ Done — reboot required";
if ($rebuildReboot) $rebuildReboot.style.display = "inline-flex";
} else { } else {
if ($rebuildStatus) $rebuildStatus.textContent = "✗ Something went wrong"; if ($rebuildStatus) $rebuildStatus.textContent = "✗ Something went wrong";
if ($rebuildSave) $rebuildSave.style.display = "inline-flex"; if ($rebuildSave) $rebuildSave.style.display = "inline-flex";
+19 -5
View File
@@ -111,14 +111,20 @@ async function pollUpdateStatus() {
if (data.log) appendLog(data.log); if (data.log) appendLog(data.log);
_updateLogOffset = data.offset; _updateLogOffset = data.offset;
} }
if (data.result === "success") { if (data.result === "reboot_required") {
appendLog("[Server restarted — update completed, reboot required.]\n");
} else if (data.result === "success") {
appendLog("[Server restarted — update completed successfully.]\n"); appendLog("[Server restarted — update completed successfully.]\n");
} else { } else {
appendLog("[Server restarted — update encountered an error.]\n"); appendLog("[Server restarted — update encountered an error.]\n");
} }
_updateFinished = true; _updateFinished = true;
stopUpdatePoll(); stopUpdatePoll();
if (data.result === "reboot_required") {
onUpdateDone("reboot_required");
} else {
onUpdateDone(data.result === "success"); onUpdateDone(data.result === "success");
}
return; return;
} }
appendLog("[Server reconnected]\n"); appendLog("[Server reconnected]\n");
@@ -129,19 +135,27 @@ async function pollUpdateStatus() {
if (data.running) return; if (data.running) return;
_updateFinished = true; _updateFinished = true;
stopUpdatePoll(); stopUpdatePoll();
if (data.result === "success") onUpdateDone(true); if (data.result === "reboot_required") {
else onUpdateDone(false); onUpdateDone("reboot_required");
} else if (data.result === "success") {
onUpdateDone(true);
} else {
onUpdateDone(false);
}
} catch (err) { } catch (err) {
if (!_serverWasDown) { _serverWasDown = true; appendLog("\n[Server restarting — waiting for it to come back…]\n"); if ($modalStatus) $modalStatus.textContent = "Server restarting…"; } if (!_serverWasDown) { _serverWasDown = true; appendLog("\n[Server restarting — waiting for it to come back…]\n"); if ($modalStatus) $modalStatus.textContent = "Server restarting…"; }
} }
} }
function onUpdateDone(success) { function onUpdateDone(result) {
if ($modalSpinner) $modalSpinner.classList.remove("spinning"); if ($modalSpinner) $modalSpinner.classList.remove("spinning");
if ($btnCloseModal) $btnCloseModal.disabled = false; if ($btnCloseModal) $btnCloseModal.disabled = false;
if (success) { if (result === true) {
if ($modalStatus) $modalStatus.textContent = "✓ Update complete"; if ($modalStatus) $modalStatus.textContent = "✓ Update complete";
if ($btnReboot) $btnReboot.style.display = "inline-flex"; if ($btnReboot) $btnReboot.style.display = "inline-flex";
} else if (result === "reboot_required") {
if ($modalStatus) $modalStatus.textContent = "✓ Update complete — reboot required";
if ($btnReboot) $btnReboot.style.display = "inline-flex";
} else { } else {
if ($modalStatus) $modalStatus.textContent = "✗ Update failed"; if ($modalStatus) $modalStatus.textContent = "✗ Update failed";
if ($btnSave) $btnSave.style.display = "inline-flex"; if ($btnSave) $btnSave.style.display = "inline-flex";
+26 -2
View File
@@ -143,8 +143,21 @@ let
echo "" echo ""
if [ "$RC" -eq 0 ]; then if [ "$RC" -eq 0 ]; then
echo " Step 2/3: nixos-rebuild switch " echo " Step 2/3: nixos-rebuild "
if ! nixos-rebuild switch --flake /etc/nixos --print-build-logs 2>&1; then if nixos-rebuild switch --flake /etc/nixos --print-build-logs 2>&1; then
echo "[OK] switch succeeded"
elif grep -q "switchInhibitors\|Pre-switch checks failed" "$LOG" 2>/dev/null; then
echo ""
echo " Build succeeded a reboot is required to apply this update"
echo " (Critical system components changed; running nixos-rebuild boot instead)"
if nixos-rebuild boot --flake /etc/nixos --print-build-logs 2>&1; then
echo "REBOOT_REQUIRED" > "$STATUS"
exit 0
else
echo "[ERROR] nixos-rebuild boot also failed"
RC=1
fi
else
echo "[ERROR] nixos-rebuild switch failed" echo "[ERROR] nixos-rebuild switch failed"
RC=1 RC=1
fi fi
@@ -197,6 +210,17 @@ let
echo " Rebuild completed successfully" echo " Rebuild completed successfully"
echo "" echo ""
echo "SUCCESS" > "$STATUS" echo "SUCCESS" > "$STATUS"
elif grep -q "switchInhibitors\|Pre-switch checks failed" "$LOG" 2>/dev/null; then
echo ""
echo " Build succeeded a reboot is required to apply this rebuild"
echo " (Critical system components changed; running nixos-rebuild boot instead)"
if nixos-rebuild boot --flake /etc/nixos --print-build-logs 2>&1; then
echo "REBOOT_REQUIRED" > "$STATUS"
else
echo "[ERROR] nixos-rebuild boot also failed"
echo "FAILED" > "$STATUS"
exit 1
fi
else else
echo "" echo ""
echo "" echo ""