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
|
||||
`/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
|
||||
|
||||
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;
|
||||
} | null>(null);
|
||||
const restartSawDisconnectRef = useRef(false);
|
||||
const restartStartedAtRef = useRef(0);
|
||||
const [restartToast, setRestartToast] = useState<string | null>(null);
|
||||
const [isRestarting, setIsRestarting] = useState(false);
|
||||
const [pairingRequests, setPairingRequests] = useState<PairingRequestInfo[]>([]);
|
||||
@@ -2220,10 +2221,11 @@ function Shell({
|
||||
const chatId = activeSession?.chatId ?? client.defaultChatId;
|
||||
if (!chatId) return;
|
||||
restartSawDisconnectRef.current = false;
|
||||
restartStartedAtRef.current = Date.now();
|
||||
setIsRestarting(true);
|
||||
rememberRestartRoute();
|
||||
try {
|
||||
window.localStorage.setItem(RESTART_STARTED_KEY, String(Date.now()));
|
||||
window.localStorage.setItem(RESTART_STARTED_KEY, String(restartStartedAtRef.current));
|
||||
} catch {
|
||||
// ignore storage errors
|
||||
}
|
||||
@@ -2309,7 +2311,8 @@ function Shell({
|
||||
});
|
||||
};
|
||||
const unsubscribe = client.onStatus((status) => {
|
||||
const startedAt = (() => {
|
||||
// Another tab can consume the reload marker before this tab reconnects.
|
||||
const startedAt = restartStartedAtRef.current || (() => {
|
||||
try {
|
||||
return Number(window.localStorage.getItem(RESTART_STARTED_KEY) ?? "0");
|
||||
} catch {
|
||||
@@ -2318,6 +2321,7 @@ function Shell({
|
||||
})();
|
||||
if (!startedAt) return;
|
||||
if (status !== "open") {
|
||||
restartStartedAtRef.current = startedAt;
|
||||
restartSawDisconnectRef.current = true;
|
||||
return;
|
||||
}
|
||||
@@ -2330,6 +2334,7 @@ function Shell({
|
||||
// ignore storage errors
|
||||
}
|
||||
const refreshGeneration = ++settingsRefreshGenerationRef.current;
|
||||
restartStartedAtRef.current = 0;
|
||||
setIsRestarting(false);
|
||||
setRestartToast(t("app.restart.completed", { seconds: (elapsedMs / 1000).toFixed(1) }));
|
||||
window.setTimeout(() => setRestartToast(null), 3_500);
|
||||
|
||||
@@ -27,6 +27,8 @@ const requestMutationSpy = vi.fn();
|
||||
const discardTemporaryChatSpy = vi.fn();
|
||||
const newTemporaryChatSpy = vi.fn<() => Promise<string>>();
|
||||
const sendMessageSpy = vi.fn();
|
||||
const sendSystemCommandSpy = vi.fn().mockResolvedValue(undefined);
|
||||
let mockDefaultChatId: string | null = null;
|
||||
const statusHandlers = new Set<(status: ConnectionStatus) => void>();
|
||||
const runStatusHandlers = new Set<(chatId: string, startedAt: number | null) => void>();
|
||||
const sessionUpdateHandlers = new Set<(
|
||||
@@ -242,7 +244,8 @@ vi.mock("@/lib/nanobot-client", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@/lib/nanobot-client")>();
|
||||
class MockClient {
|
||||
status = "idle" as const;
|
||||
defaultChatId: string | null = null;
|
||||
defaultChatId = mockDefaultChatId;
|
||||
sendSystemCommand = sendSystemCommandSpy;
|
||||
connect = connectSpy;
|
||||
onStatus = (handler: (status: ConnectionStatus) => void) => {
|
||||
statusHandlers.add(handler);
|
||||
@@ -317,6 +320,8 @@ describe("App layout", () => {
|
||||
`00000000-0000-4000-8000-${String(++temporaryChatCounter).padStart(12, "0")}`
|
||||
));
|
||||
sendMessageSpy.mockReset();
|
||||
sendSystemCommandSpy.mockReset().mockResolvedValue(undefined);
|
||||
mockDefaultChatId = null;
|
||||
statusHandlers.clear();
|
||||
runStatusHandlers.clear();
|
||||
sessionUpdateHandlers.clear();
|
||||
@@ -1238,6 +1243,24 @@ describe("App layout", () => {
|
||||
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 () => {
|
||||
let restartCompleted = false;
|
||||
let refreshedSettingsRequests = 0;
|
||||
|
||||
Reference in new issue
Block a user