Agent Zero AI framework
Add backend disconnect detection and button type attributes to self-update modal
frdelf7d68d341095
diff --git a/tests/test_self_update_tag_filter.py b/tests/test_self_update_tag_filter.pyindex e2789b2fb..3387e3032 100644--- a/tests/test_self_update_tag_filter.py+++ b/tests/test_self_update_tag_filter.py@@ -54,6 +54,10 @@ def test_self_update_frontend_filters_old_tag_suggestions():assert "this.info?.defaults?.branch ||" in contentassert "Version ${tag} does not exist on branch" in contentassert "this.selectedTagExistsOnBranch" in content+ assert 'const response = await fetch("/api/health"' in content+ assert "if (response.ok && observedBackendUnavailable)" in content+ assert "Waiting for Agent Zero to disconnect before reloading the page." in content+ assert "/api/csrf_token" not in contentdef test_self_update_modal_validates_exact_tag_on_blur():@@ -70,6 +74,7 @@ def test_self_update_modal_validates_exact_tag_on_blur():assert '@blur="$store.selfUpdateStore.onTagBlur()"' in contentassert '@mousedown.prevent="$store.selfUpdateStore.selectTag(tag)"' in contentassert "$store.selfUpdateStore.tagExistenceWarning" in content+ assert 'type="button"' in contentdef test_self_update_schedule_rejects_missing_tag_on_branch(monkeypatch, tmp_path):diff --git a/webui/components/settings/external/self-update-modal.html b/webui/components/settings/external/self-update-modal.htmlindex c11bc2972..4c4c01764 100644--- a/webui/components/settings/external/self-update-modal.html+++ b/webui/components/settings/external/self-update-modal.html@@ -296,6 +296,7 @@<div class="modal-footer" data-modal-footer><button+ type="button"class="btn btn-ok"@click="$store.selfUpdateStore.scheduleUpdate()":disabled="!$store.selfUpdateStore.canScheduleUpdate"@@ -303,6 +304,7 @@Schedule Update And Restart</button><button+ type="button"class="btn btn-field"@click="$store.selfUpdateStore.refresh()":disabled="$store.selfUpdateStore.isBusy"@@ -310,6 +312,7 @@Refresh Status</button><button+ type="button"class="btn btn-cancel"@click="$store.selfUpdateStore.close()":disabled="$store.selfUpdateStore.restarting"diff --git a/webui/components/settings/external/self-update-store.js b/webui/components/settings/external/self-update-store.jsindex fabf07772..bb7b23052 100644--- a/webui/components/settings/external/self-update-store.js+++ b/webui/components/settings/external/self-update-store.js@@ -492,6 +492,7 @@ const model = {async restartAndReload() {this.restarting = true;this.clearReconnectTimer();+ let observedBackendUnavailable = false;this.setRestartState("Starting self-update","The request was saved. Agent Zero is about to restart and apply the requested branch and tag."@@ -500,7 +501,7 @@ const model = {try {const token = await API.getCsrfToken();- void fetch("/api/restart", {+ const restartResponse = await fetch("/api/restart", {method: "POST",credentials: "same-origin",keepalive: true,@@ -509,9 +510,10 @@ const model = {"X-CSRF-Token": token,},body: JSON.stringify({}),- }).catch(() => {- // The restart request usually terminates the backend mid-flight.});+ if (restartResponse && !restartResponse.ok) {+ throw new Error(`Restart request failed with HTTP ${restartResponse.status}.`);+ }} catch (_error) {// The restart request often terminates the backend mid-flight.}@@ -536,14 +538,32 @@ const model = {credentials: "same-origin",cache: "no-store",});- if (response.ok) {+ if (response.ok && observedBackendUnavailable) {const returnUrl = this.getSavedReturnUrl() || window.location.href;this.saveReturnUrl("");window.location.replace(returnUrl);return;}- lastError = `Health check returned HTTP ${response.status}.`;+ if (response.ok) {+ this.setRestartState(+ "Restarting backend",+ "Waiting for Agent Zero to disconnect before reloading the page."+ );+ lastError = "Health check is still responding before the restart has completed.";+ } else {+ observedBackendUnavailable = true;+ this.setRestartState(+ "Update in progress",+ "Agent Zero is restarting and the updater is running. This page will reload automatically when the health check becomes healthy again."+ );+ lastError = `Health check returned HTTP ${response.status}.`;+ }} catch (error) {+ observedBackendUnavailable = true;+ this.setRestartState(+ "Update in progress",+ "Agent Zero is temporarily unavailable while it restarts. Waiting for the new runtime to become healthy."+ );lastError = error?.message || String(error);}