feat(webui): configure idle compaction timeout (NAN-305) (#6383)

* feat(webui): configure idle compaction timeout (NAN-305)

* fix(webui): clarify idle compaction timeout and tradeoff

* refactor(webui): remove unused idle compaction minimum

* fix(webui): match idle compaction loading skeleton
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 13:41:05 +08:00
1 parent c6babb20e8
commit f11ea5f9e0
25 files changed
+523 -15

No files matched your search

+4
View File
@@ -30,6 +30,7 @@ import { ThreadLoadingFixture } from "./thread-loading-fixture";
import { AnswerOrderFixture } from "./answer-order-fixture";
import { SidebarActivityFixture } from "./sidebar-activity-fixture";
import { HistoryHydrationFixture } from "./history-hydration-fixture";
import { IdleCompactionFixture, installIdleCompactionApi } from "./idle-compaction-fixture";
const history: UIMessage[] = [
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
@@ -168,6 +169,7 @@ function AppsFixture() {
/></main>;
}
if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi();
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
await initializeI18n();
createRoot(document.getElementById("root")!).render(<TooltipProvider>
{parameters.get("case") === "answer-order"
@@ -180,6 +182,8 @@ createRoot(document.getElementById("root")!).render(<TooltipProvider>
? <MarkdownEmphasisFixture />
: parameters.get("case") === "typography"
? <ClientProvider client={railClient} token="fixture"><TypographyFixture /></ClientProvider>
: parameters.get("case") === "idle-compaction"
? <IdleCompactionFixture />
: parameters.get("case") === "history-hydration"
? <HistoryHydrationFixture />
: parameters.get("case") === "history-boundary"
+65
View File
@@ -0,0 +1,65 @@
import { useState } from "react";
import { SettingsView } from "@/components/settings/SettingsView";
import { RUNTIME_CONFIG_FIELDS } from "@/components/settings/system/runtime-config-fields";
import { settings } from "@/dev/gallery/settings";
import { NanobotClient } from "@/lib/nanobot-client";
import type { RuntimeConfigValue, SettingsPayload } from "@/lib/types";
import { ClientProvider } from "@/providers/ClientProvider";
const path = "agents.defaults.session_ttl_minutes";
const storageKey = "fixture.idle-compaction-minutes";
const client = new NanobotClient({ url: "ws://127.0.0.1:1", reconnect: false });
let failNext = false;
const initial: SettingsPayload = {
...settings,
runtime_config: Object.fromEntries(RUNTIME_CONFIG_FIELDS.map((field) => [field.path,
field.kind === "boolean" ? false : field.kind === "toggle" ? field.options?.[0] ?? ""
: field.kind === "list" ? [] : field.kind === "number" ? 20 : field.kind === "duration" ? 60 : "",
])),
};
initial.runtime_config![path] = Number(localStorage.getItem(storageKey) ?? 720);
let persisted = initial;
client.requestMutation = async <T,>(action: string, payload?: Record<string, unknown>): Promise<T> => {
if (action !== "settings.runtime_config.update") throw new Error(`Unexpected mutation: ${action}`);
if (failNext) {
failNext = false;
throw new Error("Fixture save failed");
}
const values = payload?.values as Record<string, RuntimeConfigValue>;
if (path in values) localStorage.setItem(storageKey, String(values[path]));
persisted = { ...persisted, runtime_config: { ...persisted.runtime_config, ...values }, requires_restart: true,
restart_required_sections: ["runtime"] };
return persisted as T;
};
export function installIdleCompactionApi() {
const fetch = window.fetch.bind(window);
window.fetch = async (input, init) => {
const url = new URL(input instanceof Request ? input.url : String(input), location.href);
if (url.origin !== location.origin || !url.pathname.startsWith("/api/")) return fetch(input, init);
const bodies: Record<string, unknown> = {
"/api/settings": persisted,
"/api/settings/nanobot-features": { features: [], enabled_count: 0, requires_restart: false },
"/api/settings/api-service": { installed: false, running: false, managed: false, host: "127.0.0.1",
port: 8900, timeout: 120, endpoint: "http://127.0.0.1:8900/v1", command: "nanobot serve" },
};
return Response.json(bodies[url.pathname] ?? {});
};
}
export function IdleCompactionFixture() {
const [snapshot, setSnapshot] = useState(initial);
return <ClientProvider client={client} token="fixture">
<div className="flex min-h-screen flex-col">
<div className="flex gap-3 p-2 text-xs">
<button onClick={() => { failNext = true; }}>Fail next save</button>
<output aria-label="Persisted minutes">{String(snapshot.runtime_config?.[path])}</output>
</div>
<SettingsView theme="light" initialSection="runtime" initialSettings={initial}
onSettingsChange={setSnapshot} onToggleTheme={() => {}} onBackToChat={() => {}}
onModelNameChange={() => {}} onRestart={() => {}} />
</div>
</ClientProvider>;
}
+59
View File
@@ -0,0 +1,59 @@
import { expect, test } from "@playwright/test";
for (const locale of ["en", "zh-CN"]) {
for (const width of [390, 1280]) {
test(`idle compaction settings in ${locale} at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await page.addInitScript((language) => localStorage.setItem("nanobot.locale", language), locale);
await page.goto("/browser/fixture.html?case=idle-compaction");
const chinese = locale === "zh-CN";
const input = page.getByRole("textbox", { name: chinese ? "空闲时限" : "Idle timeout" });
const toggle = page.getByRole("switch", { name: chinese ? "空闲自动压缩" : "Auto-compact idle sessions" });
const persisted = page.getByRole("status", { name: "Persisted minutes" });
await expect(input).toHaveValue("720");
for (const draft of ["37", "0"]) {
await input.fill(draft);
await page.getByRole("button", { name: chinese ? "取消" : "Cancel", exact: true }).click();
await expect(input).toHaveValue("720");
await expect(persisted).toHaveText("720");
}
await input.fill("721");
await expect(persisted).toHaveText("720");
await page.getByText(chinese ? "分钟" : "minutes", { exact: true }).click();
await expect(persisted).toHaveText("721");
await expect(toggle).toBeEnabled();
await toggle.click();
await expect(persisted).toHaveText("0");
await expect(input).toHaveCount(0);
await page.reload();
await expect(toggle).not.toBeChecked();
await toggle.click();
await expect(input).toHaveValue("15");
await expect(toggle).toBeEnabled();
await input.fill("-1");
await input.press("Enter");
await expect(input).toHaveAttribute("aria-invalid", "true");
await expect(input).toHaveValue("-1");
await expect(persisted).toHaveText("15");
await input.fill("37");
// Arm the failure without moving focus and committing the draft first.
await page.getByRole("button", { name: "Fail next save" }).evaluate((button: HTMLButtonElement) => button.click());
await input.press("Enter");
await expect(page.getByText("Fixture save failed")).toBeVisible();
await expect(input).toHaveValue("37");
await input.press("Enter");
await expect(persisted).toHaveText("37");
await expect(page.getByText("Fixture save failed")).toHaveCount(0);
await page.reload();
await expect(input).toHaveValue("37");
await input.scrollIntoViewIfNeeded();
const bounds = await input.boundingBox();
expect(bounds).not.toBeNull();
expect(bounds!.x).toBeGreaterThanOrEqual(0);
expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width);
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width);
await page.screenshot({ path: test.info().outputPath(`idle-compaction-${locale}-${width}.png`), fullPage: true });
});
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ const previewSettings: SettingsPayload = {
max_tokens: 8192, context_window_tokens: 200_000, temperature: 0.1, reasoning_effort: null }],
model_call_order: ["default"],
runtime_config: Object.fromEntries(RUNTIME_CONFIG_FIELDS.map((field) => [field.path,
field.kind === "boolean" ? true : field.kind === "toggle" ? field.options?.[1] ?? "" : field.kind === "list" ? [] : field.kind === "number" ? 20 : field.kind === "duration" ? 3600 : "",
field.kind === "boolean" ? true : field.kind === "toggle" ? field.options?.[1] ?? "" : field.kind === "list" ? [] : field.kind === "number" ? 20 : field.kind === "duration" ? 3600 : field.kind === "idle-compaction" ? 15 : "",
])),
};
let detailState = "loaded";