Skip to content

The agent that grows with you

fix: dashboard update toast names a partial run's owed work, only from its own receipt

Teknium88ebf908ddb6
diff --git a/web/src/contexts/SystemActions.test.tsx b/web/src/contexts/SystemActions.test.tsx
new file mode 100644
index 00000000000..dc6bf2ac2a0
--- /dev/null
+++ b/web/src/contexts/SystemActions.test.tsx
@@ -0,0 +1,100 @@
+// @vitest-environment jsdom
+// The update toast names what a committed update still owes for every committed outcome: a
+// partial run (exit 1 after record_user_action) shows the producer's own instruction, and only
+// this action's receipt may name debt (the status route attaches the latest receipt otherwise).
+
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { act } from "react";
+import { createRoot, type Root } from "react-dom/client";
+
+const apiMocks = vi.hoisted(() => ({
+ getActionStatus: vi.fn(),
+ getStatus: vi.fn(),
+ restartGateway: vi.fn(),
+ updateHermes: vi.fn(),
+}));
+
+vi.mock("@/lib/api", () => ({ api: apiMocks }));
+
+import { I18nProvider } from "@/i18n";
+import { SystemActionsProvider } from "./SystemActions";
+import { useSystemActions } from "./useSystemActions";
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT =
+ true;
+
+const INSTRUCTION =
+ "Your local changes are parked in stash@{0}; run `git stash pop` in ~/.hermes/hermes-agent.";
+
+let container: HTMLDivElement;
+let root: Root;
+
+function Probe() {
+ const { runAction } = useSystemActions();
+ return <button onClick={() => void runAction("update")} />;
+}
+
+async function runUpdate(receiptActionId: string): Promise<string> {
+ apiMocks.updateHermes.mockResolvedValue({
+ action_id: "c".repeat(32),
+ name: "hermes-update",
+ ok: true,
+ pid: 1,
+ });
+ apiMocks.getActionStatus.mockResolvedValue({
+ exit_code: 1,
+ lines: [],
+ name: "hermes-update",
+ pid: null,
+ running: false,
+ receipt: {
+ action_id: receiptActionId,
+ outcome: "partial",
+ followups: [],
+ user_action: { step: "local_changes", reason: INSTRUCTION },
+ },
+ });
+ container = document.createElement("div");
+ document.body.append(container);
+ root = createRoot(container);
+ await act(async () =>
+ root.render(
+ <I18nProvider>
+ <SystemActionsProvider>
+ <Probe />
+ </SystemActionsProvider>
+ </I18nProvider>,
+ ),
+ );
+ await act(async () => container.querySelector("button")!.click());
+ for (let i = 0; i < 20 && !document.body.textContent?.includes("exit 1"); i++) {
+ await act(async () => new Promise((resolve) => setTimeout(resolve, 10)));
+ }
+ return document.body.textContent ?? "";
+}
+
+beforeEach(() => {
+ for (const fn of Object.values(apiMocks)) fn.mockReset();
+});
+
+afterEach(() => {
+ act(() => root.unmount());
+ container.remove();
+ document.body.innerHTML = "";
+});
+
+describe("SystemActionsProvider update toast", () => {
+ it("names a partial update's owed user action verbatim", async () => {
+ const text = await runUpdate("c".repeat(32));
+ expect(text).toContain("exit 1");
+ expect(text).toContain(`local_changes: ${INSTRUCTION}`);
+ // A rerun does not restore a parked stash.
+ expect(text).not.toContain("re-run `hermes update`");
+ });
+
+ it("never names another run's debt", async () => {
+ const text = await runUpdate("d".repeat(32));
+ expect(text).toContain("exit 1");
+ expect(text).not.toContain("local_changes");
+ });
+});
diff --git a/web/src/contexts/SystemActions.tsx b/web/src/contexts/SystemActions.tsx
index 6f228299d52..bac8607ed88 100644
--- a/web/src/contexts/SystemActions.tsx
+++ b/web/src/contexts/SystemActions.tsx
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useState } from "react";
+import { updateDebt, type UpdateDebtReceipt } from "@hermes/shared";
import { api } from "@/lib/api";
import type { ActionStatusResponse } from "@/lib/api";
import { Toast } from "@nous-research/ui/ui/components/toast";
@@ -9,13 +10,6 @@ import {
type SystemAction,
} from "./system-actions-context";
-// hermes-update status only: the receipt summary's owed post-commit steps (a committed update is
-// exit 0 even while they are owed).
-interface ReceiptDebt {
- followups?: { step: string; reason: string }[];
- user_action?: { step: string; reason: string } | null;
-}
-
const ACTION_NAMES: Record<SystemAction, string> = {
restart: "gateway-restart",
update: "hermes-update",
@@ -32,6 +26,9 @@ export function SystemActionsProvider({
null,
);
const [toast, setToast] = useState<ToastState | null>(null);
+ // The id the update POST returned: the status route attaches the latest receipt when this
+ // action has none, so only a receipt carrying this id may name owed work.
+ const [updateActionId, setUpdateActionId] = useState<string | undefined>();
const { t } = useI18n();
useEffect(() => {
@@ -58,21 +55,30 @@ export function SystemActionsProvider({
? sharedGatewayProfiles(await api.getStatus().catch(() => null))
: null;
if (cancelled) return;
- // C3: exit 0 with owed post-commit steps is still a success, but name what is owed.
- const receipt = (resp as ActionStatusResponse & { receipt?: ReceiptDebt }).receipt;
+ // C3: a committed update owes its post-commit steps whatever the exit (a partial run
+ // exits 1 after record_user_action): name them on success and on failure. Follow-ups get
+ // the rerun remedy; a user action is the producer's own instruction, verbatim (a rerun
+ // does not restore a parked stash).
+ const debt =
+ activeAction === "update"
+ ? updateDebt((resp as { receipt?: UpdateDebtReceipt }).receipt, updateActionId)
+ : null;
const owed = [
- ...(receipt?.followups ?? []),
- ...(receipt?.user_action ? [receipt.user_action] : []),
- ].map((step) => step.step);
+ debt?.followups && `${t.status.actionFinishedOwed}: ${debt.followups}`,
+ debt?.userAction,
+ ]
+ .filter(Boolean)
+ .join(". ");
+ const verdict = ok
+ ? shared
+ ? sharedGatewayRestartedMessage(shared.length)
+ : owed
+ ? ""
+ : t.status.actionFinished
+ : `${t.status.actionFailed} (exit ${resp.exit_code ?? "?"})`;
setToast({
- type: ok && !owed.length ? "success" : "error",
- message: ok
- ? shared
- ? sharedGatewayRestartedMessage(shared.length)
- : owed.length
- ? `${t.status.actionFinishedOwed}: ${owed.join(", ")}`
- : t.status.actionFinished
- : `${t.status.actionFailed} (exit ${resp.exit_code ?? "?"})`,
+ type: ok && !owed ? "success" : "error",
+ message: [verdict, owed].filter(Boolean).join(" — "),
});
return;
}
@@ -86,7 +92,13 @@ export function SystemActionsProvider({
return () => {
cancelled = true;
};
- }, [activeAction, t.status.actionFinished, t.status.actionFinishedOwed, t.status.actionFailed]);
+ }, [
+ activeAction,
+ updateActionId,
+ t.status.actionFinished,
+ t.status.actionFinishedOwed,
+ t.status.actionFailed,
+ ]);
const runAction = useCallback(
async (action: SystemAction) => {
@@ -113,6 +125,7 @@ export function SystemActionsProvider({
});
return;
}
+ setUpdateActionId((resp as { action_id?: string }).action_id);
setActiveAction(action);
}
} catch (err) {