Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(ui): honest update failures, finish-staged-update state, toasts below the top bar

Ruben Lütkedb507d127610
diff --git a/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx b/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx
index 4583eae99a..e3eb83646a 100644
--- a/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx
+++ b/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx
@@ -73,6 +73,148 @@ describe("TopBar update button", () => {
expect(screen.queryByText("Update available")).toBeNull();
});
+ it("surfaces the backend's failure detail instead of a generic error", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async (url: string) => {
+ if (url.startsWith("/api/update/status")) {
+ return {
+ ok: true,
+ status: 200,
+ json: async () => ({
+ managed: true,
+ current: "1.0.11",
+ latest: "1.0.12",
+ update_available: true,
+ notes: null,
+ }),
+ };
+ }
+ if (url === "/api/update/apply") {
+ return {
+ ok: false,
+ status: 502,
+ json: async () => ({
+ detail: "git fetch failed: could not resolve host github.com",
+ }),
+ };
+ }
+ return { ok: true, status: 200, json: async () => ({ ok: true }) };
+ }),
+ );
+
+ render(<TopBar />);
+ fireEvent.click(
+ await screen.findByRole("button", { name: /update available/i }),
+ );
+
+ await waitFor(() => {
+ expect(
+ useEventStore
+ .getState()
+ .toasts.some(
+ (toast) =>
+ toast.kind === "error" &&
+ toast.message.includes("Update failed") &&
+ toast.message.includes("could not resolve host github.com"),
+ ),
+ ).toBe(true);
+ });
+ });
+
+ it("reports a staged update honestly when every restart attempt fails", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async (url: string) => {
+ if (url.startsWith("/api/update/status")) {
+ return {
+ ok: true,
+ status: 200,
+ json: async () => ({
+ managed: true,
+ current: "1.0.11",
+ latest: "1.0.12",
+ update_available: true,
+ notes: null,
+ }),
+ };
+ }
+ if (url === "/api/update/apply") {
+ return { ok: true, status: 200, json: async () => ({ ok: true }) };
+ }
+ if (url.startsWith("/api/settings/restart-app")) {
+ return {
+ ok: false,
+ status: 503,
+ json: async () => ({ detail: "self-restart unavailable on this host" }),
+ };
+ }
+ return { ok: true, status: 200, json: async () => ({ ok: true }) };
+ }),
+ );
+
+ render(<TopBar />);
+ fireEvent.click(
+ await screen.findByRole("button", { name: /update available/i }),
+ );
+
+ // Three restart attempts with a retry pause happen before the verdict.
+ await waitFor(
+ () => {
+ expect(
+ useEventStore
+ .getState()
+ .toasts.some(
+ (toast) =>
+ toast.kind === "warning" &&
+ toast.message.includes("restart") &&
+ toast.message.includes("self-restart unavailable"),
+ ),
+ ).toBe(true);
+ },
+ { timeout: 8000 },
+ );
+ }, 10000);
+
+ it("offers to finish a staged update even without a fresh release offer", async () => {
+ mockUpdateStatus({
+ managed: true,
+ current: "1.0.11",
+ latest: null,
+ update_available: false,
+ notes: null,
+ published_at: null,
+ pending_update: { version: "1.0.12", target_revision: "b".repeat(40) },
+ });
+ render(<TopBar />);
+ await waitFor(() => expect(screen.getByText("Finish update")).toBeTruthy());
+ expect(screen.getByText("v1.0.12")).toBeTruthy();
+ });
+
+ it("announces a rolled-back update instead of failing silently", async () => {
+ mockUpdateStatus({
+ managed: true,
+ current: "1.0.11",
+ latest: "1.0.12",
+ update_available: true,
+ notes: null,
+ published_at: null,
+ last_result: { ok: false, rolled_back: true, completed_at: 123 },
+ });
+ render(<TopBar />);
+ await waitFor(() => {
+ expect(
+ useEventStore
+ .getState()
+ .toasts.some(
+ (toast) =>
+ toast.kind === "warning" &&
+ toast.message.includes("rolled back"),
+ ),
+ ).toBe(true);
+ });
+ });
+
it("warns when the update cannot fully repair desktop registration", async () => {
vi.stubGlobal(
"fetch",
diff --git a/jarvis/ui/web/frontend/src/components/ToastLayer.tsx b/jarvis/ui/web/frontend/src/components/ToastLayer.tsx
index 92c74d3ed1..4cfd49ccda 100644
--- a/jarvis/ui/web/frontend/src/components/ToastLayer.tsx
+++ b/jarvis/ui/web/frontend/src/components/ToastLayer.tsx
@@ -44,7 +44,10 @@ export function ToastLayer() {
// z-[60]: the onboarding gate overlays the whole app at z-50 and renders
// later in the DOM; toasts (e.g. failed permission requests during
// first-run setup) must stay visible above it.
- <div className="pointer-events-none fixed right-4 top-4 z-[60] flex w-[320px] flex-col gap-2">
+ // top-14: below the TopBar (h-10 + margin) — at top-4 a toast covered the
+ // very Update/Restart buttons whose outcome it reports, so an "Update
+ // failed" toast hid the half-rounded update pill behind it.
+ <div className="pointer-events-none fixed right-4 top-14 z-[60] flex w-[320px] flex-col gap-2">
{toasts.map((toast) => {
const Icon = ICON_FOR_KIND[toast.kind];
// A saved-file toast in the desktop shell is a native drag handle: press
diff --git a/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx b/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx
index 02494d1fde..a4f16a211d 100644
--- a/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx
+++ b/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx
@@ -147,13 +147,29 @@ export function TopBar() {
);
}
+// The restart can fail transiently right after an apply (the backend is busy,
+// the desktop shell still warming) — retry briefly before giving up honestly.
+const RESTART_ATTEMPTS = 3;
+const RESTART_RETRY_MS = 1500;
+
+const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
+
+/** Append the server's error detail so a failure is diagnosable, not generic. */
+function withDetail(message: string, detail: string | null): string {
+ const trimmed = (detail ?? "").trim();
+ if (!trimmed) return message;
+ return `${message} (${trimmed.slice(0, 180)})`;
+}
+
/**
- * Shown ONLY when the backend reports a managed install with a newer published
- * release (``status.update_available``). One click pulls the new code
- * (`POST /api/update/apply`) and then restarts to load it, reusing the same
- * mission-guard (409 → force) flow as the restart button. Hovering reveals the
- * release notes. On a dev tree / manual clone the status is ``managed: false``,
- * so this renders nothing and can never trigger a self-update.
+ * Shown when the backend reports a managed install with a newer published
+ * release (``status.update_available``) — or with a staged-but-not-installed
+ * transaction (``status.pending_update``) left behind by an earlier attempt.
+ * One click stages the new code (`POST /api/update/apply`) and then restarts
+ * to install it, reusing the same mission-guard (409 → force) flow as the
+ * restart button. Hovering reveals the release notes. On a dev tree / manual
+ * clone the status is ``managed: false``, so this renders nothing and can
+ * never trigger a self-update.
*/
function UpdateButton() {
const t = useT();
@@ -163,6 +179,7 @@ function UpdateButton() {
const [forceArmed, setForceArmed] = useState(false);
const [showNotes, setShowNotes] = useState(false);
const resetTimer = useRef<number | null>(null);
+ const rollbackNotified = useRef<string | null>(null);
const clearResetTimer = useCallback(() => {
if (resetTimer.current !== null) {
@@ -172,65 +189,125 @@ function UpdateButton() {
}, []);
useEffect(() => clearResetTimer, [clearResetTimer]);
- if (!status?.managed || !status.update_available) return null;
+ // A rolled-back install is otherwise invisible: the app comes back on the
+ // old version and the button simply re-renders. Say it happened, once.
+ const lastResult = status?.last_result;
+ useEffect(() => {
+ if (!lastResult || lastResult.ok) return;
+ const key = String(lastResult.completed_at ?? "unknown");
+ if (rollbackNotified.current === key) return;
+ rollbackNotified.current = key;
+ pushToast("warning", t("topbar.update_rolled_back"));
+ }, [lastResult, pushToast, t]);
+
+ if (!status?.managed) return null;
+ const hasOffer = status.update_available;
+ const hasStaged = Boolean(status.pending_update);
+ if (!hasOffer && !hasStaged) return null;
+ const shownVersion = status.latest ?? status.pending_update?.version ?? null;
async function run(force: boolean) {
clearResetTimer();
setBusy(true);
setShowNotes(false);
+
+ // 1. Stage the new code. The server re-verifies the managed-install guard,
+ // so a spoofed client can't force a reset on an unmanaged checkout. This is
+ // idempotent — with a transaction already staged it succeeds even offline.
try {
- // 1. Pull the new code. The server re-verifies the managed-install guard,
- // so a spoofed client can't force a reset on an unmanaged checkout.
const applyRes = await fetch("/api/update/apply", { method: "POST" });
- const applyBody = await applyRes.json().catch(() => ({}));
+ const applyBody = (await applyRes.json().catch(() => ({}))) as {
+ detail?: string;
+ deps_warning?: string | null;
+ desktop_integration_warning?: string | null;
+ };
if (!applyRes.ok) {
- throw new Error(
- (applyBody as { detail?: string }).detail ?? `HTTP ${applyRes.status}`,
+ // 403 unmanaged / 409 nothing newer / 502 git or GitHub failure — the
+ // backend's detail says WHICH, and the user must get to see it.
+ setBusy(false);
+ setForceArmed(false);
+ pushToast(
+ "error",
+ withDetail(
+ t("topbar.update_failed"),
+ applyBody.detail ?? `HTTP ${applyRes.status}`,
+ ),
);
+ return;
}
- if ((applyBody as { deps_warning?: string | null }).deps_warning) {
+ if (applyBody.deps_warning) {
pushToast("warning", t("topbar.update_deps_warning"));
}
- if (
- (applyBody as { desktop_integration_warning?: string | null })
- .desktop_integration_warning
- ) {
+ if (applyBody.desktop_integration_warning) {
pushToast("warning", t("topbar.update_desktop_warning"));
}
- // 2. Restart to load it — reuse the existing route + its mission guard.
- const url = force
- ? "/api/settings/restart-app?force=true"
- : "/api/settings/restart-app";
- const restartRes = await fetch(url, { method: "POST" });
- if (restartRes.status === 409) {
- let count = 0;
- try {
- const body = await restartRes.json();
- count = body?.detail?.missions?.length ?? 0;
- } catch {
- /* malformed body — still arm the override */
- }
- setBusy(false);
- setForceArmed(true);
- clearResetTimer();
- resetTimer.current = window.setTimeout(() => {
- setForceArmed(false);
- resetTimer.current = null;
- }, CONFIRM_TIMEOUT_MS);
- pushToast("warning", `${count} ${t("topbar.restart_missions_running")}`);
- return;
- }
- if (!restartRes.ok) throw new Error(`restart-failed:${restartRes.status}`);
- // Success — the code is pulled and the window goes away shortly; keep the
- // busy state so the button never flips back before the app dies.
- pushToast("info", t("topbar.updating"));
} catch {
- // apply failed (403 on an unmanaged host, 502/500 on a git error) or the
- // restart 503'd on a headless host: recover the control with an honest toast.
setBusy(false);
setForceArmed(false);
- pushToast("error", t("topbar.update_failed"));
+ pushToast(
+ "error",
+ withDetail(t("topbar.update_failed"), t("topbar.update_network_error")),
+ );
+ return;
+ }
+
+ // 2. Restart to install it — reuse the existing route + its mission guard,
+ // retrying a transient failure before giving up. The update stays staged
+ // either way, so the honest fallback is "restart to finish", not "failed".
+ let restartDetail: string | null = null;
+ for (let attempt = 0; attempt < RESTART_ATTEMPTS; attempt++) {
+ if (attempt > 0) await wait(RESTART_RETRY_MS);
+ try {
+ const url = force
+ ? "/api/settings/restart-app?force=true"
+ : "/api/settings/restart-app";
+ const restartRes = await fetch(url, { method: "POST" });
+ if (restartRes.status === 409) {
+ let count = 0;
+ try {
+ const body = await restartRes.json();
+ count = body?.detail?.missions?.length ?? 0;
+ } catch {
+ /* malformed body — still arm the override */
+ }
+ setBusy(false);
+ setForceArmed(true);
+ clearResetTimer();
+ resetTimer.current = window.setTimeout(() => {
+ setForceArmed(false);
+ resetTimer.current = null;
+ }, CONFIRM_TIMEOUT_MS);
+ pushToast(
+ "warning",
+ `${count} ${t("topbar.restart_missions_running")}`,
+ );
+ return;
+ }
+ if (restartRes.ok) {
+ // Success — the code is staged and the window goes away shortly; keep
+ // the busy state so the button never flips back before the app dies.
+ pushToast("info", t("topbar.updating"));
+ return;
+ }
+ const body = (await restartRes.json().catch(() => ({}))) as {
+ detail?: unknown;
+ };
+ restartDetail =
+ typeof body.detail === "string"
+ ? body.detail
+ : `HTTP ${restartRes.status}`;
+ } catch {
+ restartDetail = t("topbar.update_network_error");
+ }
}
+ // The download IS staged — a manual restart (or the next successful click)
+ // finishes it. Saying "failed" here would be dishonest and untraceable.
+ setBusy(false);
+ setForceArmed(false);
+ pushToast(
+ "warning",
+ withDetail(t("topbar.update_staged_restart_failed"), restartDetail),
+ );
}
function onClick() {
@@ -242,7 +319,9 @@ function UpdateButton() {
? t("topbar.updating")
: forceArmed
? t("topbar.restart_force")
- : t("topbar.update_available");
+ : hasOffer
+ ? t("topbar.update_available")
+ : t("topbar.update_finish_restart");
return (
<div
@@ -267,16 +346,16 @@ function UpdateButton() {
className={cn("h-3.5 w-3.5", busy && "animate-pulse")}
/>
{label}
- {!busy && !forceArmed && status.latest && (
+ {!busy && !forceArmed && shownVersion && (
<span className="rounded bg-primary/20 px-1 text-[10px] tabular-nums">
- v{status.latest}
+ v{shownVersion}
</span>
)}
</button>
{showNotes && status.notes && (
<div className="absolute right-0 top-full z-50 mt-1 w-80 rounded-md border border-border bg-background p-3 text-left shadow-lg">
<div className="mb-1 text-xs font-semibold text-foreground">
- {t("topbar.update_available")} · v{status.latest}
+ {t("topbar.update_available")} · v{shownVersion}
</div>
<div className="max-h-64 overflow-y-auto whitespace-pre-wrap text-[11px] leading-relaxed text-muted-foreground">
{status.notes.slice(0, 800)}
diff --git a/jarvis/ui/web/frontend/src/hooks/useUpdate.ts b/jarvis/ui/web/frontend/src/hooks/useUpdate.ts
index 97d9c34c42..0757307aaf 100644
--- a/jarvis/ui/web/frontend/src/hooks/useUpdate.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useUpdate.ts
@@ -15,6 +15,22 @@ export interface UpdateStatus {
published_at: string | null;
release_url?: string | null;
check_failed?: boolean;
+ /**
+ * A downloaded-but-not-yet-installed transaction staged by an earlier apply
+ * (the restart finishes it). Reported live so a failed/skipped restart still
+ * surfaces as "finish the update" instead of silently starting over.
+ */
+ pending_update?: { version: string | null; target_revision: string } | null;
+ /**
+ * The relauncher's verdict on the last finalized update. ``ok: false`` means
+ * the install failed after the restart and the app was rolled back — the UI
+ * must say so, or the failure is indistinguishable from "nothing happened".
+ */
+ last_result?: {
+ ok: boolean;
+ rolled_back: boolean;
+ completed_at?: number | null;
+ } | null;
}
// Slow poll: a new release is a rare event, so 6h keeps the button fresh
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 6932fc647b..4db414e157 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -39,9 +39,13 @@
"update_available": "Update verfügbar",
"updating": "{name} wird aktualisiert…",
"update_failed": "Update fehlgeschlagen",
- "update_hint": "Neue Version herunterladen und installieren",
+ "update_hint": "Neue Version herunterladen und {name} zur Installation automatisch neu starten",
"update_deps_warning": "Aktualisiert — einige Komponenten brauchen evtl. eine manuelle Neuinstallation",
- "update_desktop_warning": "Aktualisiert — das Betriebssystem konnte den App-Starter nicht vollständig reparieren"
+ "update_desktop_warning": "Aktualisiert — das Betriebssystem konnte den App-Starter nicht vollständig reparieren",
+ "update_finish_restart": "Update abschließen",
+ "update_staged_restart_failed": "Update heruntergeladen — starte {name} neu, um die Installation abzuschließen",
+ "update_rolled_back": "Das letzte Update konnte nicht installiert werden — {name} wurde auf die vorherige Version zurückgesetzt",
+ "update_network_error": "Netzwerkfehler"
},
"nav": {
"chats": "Chats",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 4b2d5147cc..fabca2889c 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -39,9 +39,13 @@
"update_available": "Update available",
"updating": "Updating {name}…",
"update_failed": "Update failed",
- "update_hint": "Download and install the new version",
+ "update_hint": "Download the new version and restart {name} automatically to install it",
"update_deps_warning": "Updated — some components may need a manual reinstall",
- "update_desktop_warning": "Updated — the operating system could not fully repair the app launcher"
+ "update_desktop_warning": "Updated — the operating system could not fully repair the app launcher",
+ "update_finish_restart": "Finish update",
+ "update_staged_restart_failed": "Update downloaded — restart {name} to finish installing it",
+ "update_rolled_back": "The last update could not be installed — {name} was rolled back to the previous version",
+ "update_network_error": "network error"
},
"nav": {
"chats": "Chats",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 8cbbc48eab..b904edf68f 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -39,9 +39,13 @@
"update_available": "Actualización disponible",
"updating": "Actualizando {name}…",
"update_failed": "Error al actualizar",
- "update_hint": "Descargar e instalar la nueva versión",
+ "update_hint": "Descargar la nueva versión y reiniciar {name} automáticamente para instalarla",
"update_deps_warning": "Actualizado — algunos componentes pueden requerir reinstalación manual",
- "update_desktop_warning": "Actualizado — el sistema operativo no pudo reparar por completo el iniciador de la aplicación"
+ "update_desktop_warning": "Actualizado — el sistema operativo no pudo reparar por completo el iniciador de la aplicación",
+ "update_finish_restart": "Finalizar actualización",
+ "update_staged_restart_failed": "Actualización descargada — reinicia {name} para terminar la instalación",
+ "update_rolled_back": "La última actualización no se pudo instalar — {name} volvió a la versión anterior",
+ "update_network_error": "error de red"
},
"nav": {
"chats": "Chats",