fix(webui): keep saved topics bound to their project (#6509)

* fix(webui): keep saved topics bound to their project

Lock the project as soon as the session exists, independently of loaded history. Validate both explicit updates and message admissions against the persisted directory while retaining same-project permission changes.

Related to #6505.

Co-authored-by: Xiaoyu-hub <17346801517@163.com>

* test(agent): retain goal shutdown failure stacks

Use the existing stop_loop diagnostic without changing the five-second teardown deadline or the goal assertions. The Windows failure on #6509 reached session shutdown but did not capture its worker stacks.

* test(cron): await rearm tick completion instead of disk timing

The Windows run completed the first and last jobs correctly, but rescheduling took over three seconds inside a two-second timeout. Await the original timer task, detect an early exit before callback entry, and preserve job-order, cancellation, persistence and rearming assertions. Keep real disk writes and all parameterized cases.

Also place the goal-shutdown diagnostic import in the existing first-party group.

---------

Co-authored-by: Xiaoyu-hub <17346801517@163.com>
This commit is contained in:
chengyongruandXiaoyu-hub authored and GitHub committed 2026-10-28 21:37:23 +08:00
1 parent 8f7a7d1759
commit 4a14faa47e
17 files changed
+241 -85

No files matched your search

+2 -4
View File
@@ -791,10 +791,8 @@ export function ThreadShell({
const showHeroComposer = displayMessages.length === 0 && !initialHistoryLoading;
const composerVariant = showHeroComposer ? emptyComposerVariant : "thread";
// The server owns the project lock. Old servers have no marker, so an existing
// user turn is read-only here too; the gateway remains the editing authority.
const projectLocked = session?.projectLocked === true
|| (session?.projectLocked === undefined && displayMessages.some((message) => message.role === "user" && message.deliveryStatus !== "failed"));
// Only unpersisted drafts can choose a project; history pages do not own this state.
const projectLocked = !!session && session.projectLocked !== false;
const wasShowingHeroComposerRef = useRef(showHeroComposer);
const sessionModelPreset = session?.modelPreset?.trim() || null;
const [localModelPreset, setLocalModelPreset] = useState<string | null>(null);
+1
View File
@@ -137,6 +137,7 @@ export function useSessions(): {
preview: "",
modelPreset: modelPreset ?? null,
workspaceScope: workspaceScope ?? null,
projectLocked: false,
},
...prev.filter((s) => s.key !== key),
]);
+1 -1
View File
@@ -228,7 +228,7 @@ export async function listSessions(
runStartedAt: s.run_started_at ?? null,
recoveryState: s.recovery_state ?? null,
workspaceScope: s.workspace_scope ?? null,
projectLocked: s.project_locked,
projectLocked: s.project_locked ?? true,
handle,
};
});
+1 -1
View File
@@ -457,7 +457,7 @@ export interface ChatSummary {
/** Durable recovery state that needs attention after an interrupted turn. */
recoveryState?: RecoveryState | null;
workspaceScope?: WorkspaceScopePayload | null;
/** Server-owned project binding after the first accepted user message. */
/** Persisted sessions keep their project; only unpersisted drafts can change it. */
projectLocked?: boolean;
/** Stable, server-owned @handle for this session. */
handle?: SessionHandle | null;
+3 -1
View File
@@ -1299,7 +1299,7 @@ describe("webui API helpers", () => {
);
});
it("maps generated session titles from the sessions list", async () => {
it.each([true, undefined])("maps saved sessions with project_locked=%s", async (projectLocked) => {
vi.mocked(fetch).mockResolvedValueOnce({
ok: true,
json: async () => ({
@@ -1309,6 +1309,7 @@ describe("webui API helpers", () => {
created_at: "2026-05-01T10:00:00",
updated_at: "2026-05-01T10:01:00",
title: "优化 WebUI 标题",
project_locked: projectLocked,
model_preset: "fast",
run_started_at: 1_700_000_000,
handle: {
@@ -1324,6 +1325,7 @@ describe("webui API helpers", () => {
{
key: "websocket:chat-1",
title: "优化 WebUI 标题",
projectLocked: true,
preview: "",
modelPreset: "fast",
runStartedAt: 1_700_000_000,
+2 -2
View File
@@ -5724,7 +5724,7 @@ describe("ThreadShell", () => {
expect(screen.getByRole("option", { name: /Other project/i })).toBeInTheDocument();
});
it("allows project selection before first input and locks it after acceptance without duplicating the sidebar label", async () => {
it.each([true, undefined])("locks saved topics with projectLocked=%s independently of displayed history", async (projectLocked) => {
const client = makeClient();
const scope = { project_path: "/srv/alpha", project_name: "alpha", access_mode: "restricted" as const };
const props = {
@@ -5736,7 +5736,7 @@ describe("ThreadShell", () => {
expect(await screen.findByRole("button", { name: "Switch directory" })).toBeEnabled();
expect(screen.getByTestId("thread-header")).not.toHaveTextContent("alpha");
rerender(wrap(client, <ThreadShell {...props} session={{ ...session("project-chat"), projectLocked: true }} />));
rerender(wrap(client, <ThreadShell {...props} session={{ ...session("project-chat"), projectLocked }} />));
expect(screen.queryByRole("button", { name: "Switch directory" })).not.toBeInTheDocument();
expect(screen.getByTestId("thread-header")).not.toHaveTextContent("alpha");
expect(screen.getByRole("button", { name: "Workspace access mode: Default Permission" })).toBeEnabled();
+9 -13
View File
@@ -257,18 +257,9 @@ describe("useSessions", () => {
expect(result.current.sessions.map((s) => s.key)).toEqual(["websocket:chat-a"]);
});
it("refreshes sessions when the websocket reports a session update", async () => {
it("locks a draft project when a session update reports it persisted", async () => {
vi.mocked(api.listSessions)
.mockResolvedValueOnce([
{
key: "websocket:chat-a",
channel: "websocket",
chatId: "chat-a",
createdAt: "2026-04-16T10:00:00Z",
updatedAt: "2026-04-16T10:00:00Z",
preview: "",
},
])
.mockResolvedValueOnce([])
.mockResolvedValueOnce([
{
key: "websocket:chat-a",
@@ -278,21 +269,26 @@ describe("useSessions", () => {
updatedAt: "2026-04-16T10:01:00Z",
title: "生成的小标题",
preview: "用户第一句话",
projectLocked: true,
},
]);
const client = fakeClient();
client.newChat.mockResolvedValue("chat-a");
const { result } = renderHook(() => useSessions(), {
wrapper: wrap(client),
});
await waitFor(() => expect(result.current.sessions[0]?.title).toBeUndefined());
await waitFor(() => expect(result.current.loading).toBe(false));
await act(async () => { await result.current.createChat(); });
expect(result.current.sessions[0].projectLocked).toBe(false);
act(() => {
client.emitSessionUpdate("chat-a");
client.emitSessionUpdate("chat-a", "metadata");
});
await waitFor(() => expect(result.current.sessions[0]?.title).toBe("生成的小标题"));
expect(result.current.sessions[0].projectLocked).toBe(true);
expect(api.listSessions).toHaveBeenCalledTimes(2);
});