fix(webui): complete restarts independently in each tab
This commit is contained in:
1 parent
77660ea8e5
commit
cfb0f51e78
3 files changed
+35
-3
No files matched your search
@@ -42,6 +42,10 @@ current chat. Update the gateway to stop creating these topics. Existing topics
|
|||||||
are not deleted by the update; check their contents before removing them. A typed
|
are not deleted by the update; check their contents before removing them. A typed
|
||||||
`/restart` command remains part of that chat's display history.
|
`/restart` command remains part of that chat's display history.
|
||||||
|
|
||||||
|
If settings stay disabled after a restart while another tab has reconnected,
|
||||||
|
reload the affected page. Updated WebUI clients track restart completion per tab,
|
||||||
|
so one tab cannot leave another tab waiting by clearing the shared restart marker.
|
||||||
|
|
||||||
## Session storage overlaps the workspace
|
## Session storage overlaps the workspace
|
||||||
|
|
||||||
Sessions live at `<config-dir>/sessions/<workspace-id>/`, outside the agent workspace. If startup reports a conflict, compare the printed paths. A valid layout is `bot/config.json`, `bot/sessions/`, and `bot/workspace/`.
|
Sessions live at `<config-dir>/sessions/<workspace-id>/`, outside the agent workspace. If startup reports a conflict, compare the printed paths. A valid layout is `bot/config.json`, `bot/sessions/`, and `bot/workspace/`.
|
||||||
|
|||||||
+7
-2
@@ -1220,6 +1220,7 @@ function Shell({
|
|||||||
label: string;
|
label: string;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
const restartSawDisconnectRef = useRef(false);
|
const restartSawDisconnectRef = useRef(false);
|
||||||
|
const restartStartedAtRef = useRef(0);
|
||||||
const [restartToast, setRestartToast] = useState<string | null>(null);
|
const [restartToast, setRestartToast] = useState<string | null>(null);
|
||||||
const [isRestarting, setIsRestarting] = useState(false);
|
const [isRestarting, setIsRestarting] = useState(false);
|
||||||
const [pairingRequests, setPairingRequests] = useState<PairingRequestInfo[]>([]);
|
const [pairingRequests, setPairingRequests] = useState<PairingRequestInfo[]>([]);
|
||||||
@@ -2220,10 +2221,11 @@ function Shell({
|
|||||||
const chatId = activeSession?.chatId ?? client.defaultChatId;
|
const chatId = activeSession?.chatId ?? client.defaultChatId;
|
||||||
if (!chatId) return;
|
if (!chatId) return;
|
||||||
restartSawDisconnectRef.current = false;
|
restartSawDisconnectRef.current = false;
|
||||||
|
restartStartedAtRef.current = Date.now();
|
||||||
setIsRestarting(true);
|
setIsRestarting(true);
|
||||||
rememberRestartRoute();
|
rememberRestartRoute();
|
||||||
try {
|
try {
|
||||||
window.localStorage.setItem(RESTART_STARTED_KEY, String(Date.now()));
|
window.localStorage.setItem(RESTART_STARTED_KEY, String(restartStartedAtRef.current));
|
||||||
} catch {
|
} catch {
|
||||||
// ignore storage errors
|
// ignore storage errors
|
||||||
}
|
}
|
||||||
@@ -2309,7 +2311,8 @@ function Shell({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const unsubscribe = client.onStatus((status) => {
|
const unsubscribe = client.onStatus((status) => {
|
||||||
const startedAt = (() => {
|
// Another tab can consume the reload marker before this tab reconnects.
|
||||||
|
const startedAt = restartStartedAtRef.current || (() => {
|
||||||
try {
|
try {
|
||||||
return Number(window.localStorage.getItem(RESTART_STARTED_KEY) ?? "0");
|
return Number(window.localStorage.getItem(RESTART_STARTED_KEY) ?? "0");
|
||||||
} catch {
|
} catch {
|
||||||
@@ -2318,6 +2321,7 @@ function Shell({
|
|||||||
})();
|
})();
|
||||||
if (!startedAt) return;
|
if (!startedAt) return;
|
||||||
if (status !== "open") {
|
if (status !== "open") {
|
||||||
|
restartStartedAtRef.current = startedAt;
|
||||||
restartSawDisconnectRef.current = true;
|
restartSawDisconnectRef.current = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2330,6 +2334,7 @@ function Shell({
|
|||||||
// ignore storage errors
|
// ignore storage errors
|
||||||
}
|
}
|
||||||
const refreshGeneration = ++settingsRefreshGenerationRef.current;
|
const refreshGeneration = ++settingsRefreshGenerationRef.current;
|
||||||
|
restartStartedAtRef.current = 0;
|
||||||
setIsRestarting(false);
|
setIsRestarting(false);
|
||||||
setRestartToast(t("app.restart.completed", { seconds: (elapsedMs / 1000).toFixed(1) }));
|
setRestartToast(t("app.restart.completed", { seconds: (elapsedMs / 1000).toFixed(1) }));
|
||||||
window.setTimeout(() => setRestartToast(null), 3_500);
|
window.setTimeout(() => setRestartToast(null), 3_500);
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ const requestMutationSpy = vi.fn();
|
|||||||
const discardTemporaryChatSpy = vi.fn();
|
const discardTemporaryChatSpy = vi.fn();
|
||||||
const newTemporaryChatSpy = vi.fn<() => Promise<string>>();
|
const newTemporaryChatSpy = vi.fn<() => Promise<string>>();
|
||||||
const sendMessageSpy = vi.fn();
|
const sendMessageSpy = vi.fn();
|
||||||
|
const sendSystemCommandSpy = vi.fn().mockResolvedValue(undefined);
|
||||||
|
let mockDefaultChatId: string | null = null;
|
||||||
const statusHandlers = new Set<(status: ConnectionStatus) => void>();
|
const statusHandlers = new Set<(status: ConnectionStatus) => void>();
|
||||||
const runStatusHandlers = new Set<(chatId: string, startedAt: number | null) => void>();
|
const runStatusHandlers = new Set<(chatId: string, startedAt: number | null) => void>();
|
||||||
const sessionUpdateHandlers = new Set<(
|
const sessionUpdateHandlers = new Set<(
|
||||||
@@ -242,7 +244,8 @@ vi.mock("@/lib/nanobot-client", async (importOriginal) => {
|
|||||||
const actual = await importOriginal<typeof import("@/lib/nanobot-client")>();
|
const actual = await importOriginal<typeof import("@/lib/nanobot-client")>();
|
||||||
class MockClient {
|
class MockClient {
|
||||||
status = "idle" as const;
|
status = "idle" as const;
|
||||||
defaultChatId: string | null = null;
|
defaultChatId = mockDefaultChatId;
|
||||||
|
sendSystemCommand = sendSystemCommandSpy;
|
||||||
connect = connectSpy;
|
connect = connectSpy;
|
||||||
onStatus = (handler: (status: ConnectionStatus) => void) => {
|
onStatus = (handler: (status: ConnectionStatus) => void) => {
|
||||||
statusHandlers.add(handler);
|
statusHandlers.add(handler);
|
||||||
@@ -317,6 +320,8 @@ describe("App layout", () => {
|
|||||||
`00000000-0000-4000-8000-${String(++temporaryChatCounter).padStart(12, "0")}`
|
`00000000-0000-4000-8000-${String(++temporaryChatCounter).padStart(12, "0")}`
|
||||||
));
|
));
|
||||||
sendMessageSpy.mockReset();
|
sendMessageSpy.mockReset();
|
||||||
|
sendSystemCommandSpy.mockReset().mockResolvedValue(undefined);
|
||||||
|
mockDefaultChatId = null;
|
||||||
statusHandlers.clear();
|
statusHandlers.clear();
|
||||||
runStatusHandlers.clear();
|
runStatusHandlers.clear();
|
||||||
sessionUpdateHandlers.clear();
|
sessionUpdateHandlers.clear();
|
||||||
@@ -1238,6 +1243,24 @@ describe("App layout", () => {
|
|||||||
expect(window.location.hash).toBe("#/settings?section=channels");
|
expect(window.location.hash).toBe("#/settings?section=channels");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each(["before disconnect", "after disconnect"])("finishes a requested restart when another tab clears its marker %s", async (clearWhen) => {
|
||||||
|
mockDefaultChatId = "restart-fixture";
|
||||||
|
window.history.replaceState(null, "", "/#/settings?section=runtime");
|
||||||
|
mockFetchRoutes({ "/api/settings": baseSettingsPayload() });
|
||||||
|
render(<App />);
|
||||||
|
fireEvent.click(await screen.findByRole("button", { name: "Restart", exact: true }));
|
||||||
|
expect(sendSystemCommandSpy).toHaveBeenCalledWith("restart-fixture", "/restart");
|
||||||
|
expect(screen.getByRole("button", { name: "Restarting...", exact: true })).toBeDisabled();
|
||||||
|
act(() => {
|
||||||
|
if (clearWhen === "before disconnect") localStorage.removeItem("nanobot-webui.restartStartedAt");
|
||||||
|
for (const handler of statusHandlers) handler("reconnecting");
|
||||||
|
localStorage.removeItem("nanobot-webui.restartStartedAt");
|
||||||
|
for (const handler of statusHandlers) handler("open");
|
||||||
|
});
|
||||||
|
await waitFor(() => expect(screen.getByRole("button", { name: "Restart", exact: true })).toBeEnabled());
|
||||||
|
expect(createChatSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("refreshes settings after the browser reconnects from a restart", async () => {
|
it("refreshes settings after the browser reconnects from a restart", async () => {
|
||||||
let restartCompleted = false;
|
let restartCompleted = false;
|
||||||
let refreshedSettingsRequests = 0;
|
let refreshedSettingsRequests = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user