Skip to content

Commit 8db3480

Browse files
committed
fix(ui): preserve derived titles after session patches
Reuse the most recent sessions.list options when refreshing after sessions.patch so derived-title hydration survives normal patch flows. Add unit and browser E2E coverage for patch refreshes retaining readable sidebar titles.
1 parent 0203948 commit 8db3480

3 files changed

Lines changed: 245 additions & 3 deletions

File tree

‎ui/src/e2e/chat-flow.e2e.test.ts‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,108 @@ describeControlUiE2e("Control UI mocked Gateway E2E", () => {
18741874
}
18751875
});
18761876

1877+
it("keeps derived sidebar titles and accessible state after session patch refreshes", async () => {
1878+
const context = await newBrowserContext({
1879+
locale: "en-US",
1880+
serviceWorkers: "block",
1881+
viewport: { height: 900, width: 1280 },
1882+
});
1883+
const page = await context.newPage();
1884+
const initialKey = "agent:main:session-a";
1885+
const key = "agent:main:session-b";
1886+
const readableTitle = "Readable planning title";
1887+
const sessionsWithDerivedTitle = chatSessionListResponse([
1888+
{
1889+
key: initialKey,
1890+
kind: "direct",
1891+
label: initialKey,
1892+
displayName: initialKey,
1893+
derivedTitle: "Initial readable title",
1894+
updatedAt: 3,
1895+
},
1896+
{
1897+
key,
1898+
kind: "direct",
1899+
label: key,
1900+
displayName: key,
1901+
derivedTitle: readableTitle,
1902+
updatedAt: 2,
1903+
},
1904+
]);
1905+
const sessionsWithoutDerivedTitle = chatSessionListResponse([
1906+
{
1907+
key: initialKey,
1908+
kind: "direct",
1909+
label: initialKey,
1910+
displayName: initialKey,
1911+
updatedAt: 3,
1912+
},
1913+
{
1914+
key,
1915+
kind: "direct",
1916+
label: key,
1917+
displayName: key,
1918+
updatedAt: 2,
1919+
},
1920+
]);
1921+
const gateway = await installMockGateway(page, {
1922+
methodResponses: {
1923+
"sessions.list": {
1924+
cases: [
1925+
{ match: { includeDerivedTitles: true }, response: sessionsWithDerivedTitle },
1926+
{ match: {}, response: sessionsWithoutDerivedTitle },
1927+
],
1928+
},
1929+
},
1930+
models: [
1931+
{ id: "gpt-5.5", name: "GPT-5.5", provider: "openai" },
1932+
{ id: "claude-opus-4.5", name: "Claude Opus 4.5", provider: "bedrock" },
1933+
],
1934+
sessionKey: initialKey,
1935+
});
1936+
1937+
try {
1938+
await page.goto(`${server.baseUrl}chat`);
1939+
const row = page.locator(`.sidebar-recent-session[data-session-key="${key}"]`);
1940+
await row.locator("a.sidebar-recent-session__link").click();
1941+
await expect
1942+
.poll(async () => {
1943+
const requests = await gateway.getRequests("sessions.list");
1944+
return requests.map((request) => request.params);
1945+
})
1946+
.toContainEqual(expect.objectContaining({ includeDerivedTitles: true }));
1947+
const label = row.locator(".sidebar-recent-session__name");
1948+
await expect.poll(() => label.textContent()).toBe(readableTitle);
1949+
expect(await row.getAttribute("aria-label")).toContain(readableTitle);
1950+
expect(await row.locator("a.sidebar-recent-session__link").getAttribute("aria-current")).toBe(
1951+
"page",
1952+
);
1953+
1954+
const listCountBeforePatch = (await gateway.getRequests("sessions.list")).length;
1955+
const main = page.getByRole("main");
1956+
await main.locator('[data-chat-model-select="true"]').first().click();
1957+
await main.locator('[data-chat-model-provider="bedrock"]').click();
1958+
await main.locator('[data-chat-model-option="bedrock/claude-opus-4.5"]').click();
1959+
await main.getByRole("button", { name: "Save", exact: true }).click();
1960+
1961+
const patchRequest = await gateway.waitForRequest("sessions.patch");
1962+
expect(requireRecord(patchRequest.params)).toMatchObject({
1963+
key,
1964+
model: "bedrock/claude-opus-4.5",
1965+
});
1966+
await expect
1967+
.poll(async () => {
1968+
const requests = await gateway.getRequests("sessions.list");
1969+
return requests.slice(listCountBeforePatch).map((request) => request.params);
1970+
})
1971+
.toContainEqual(expect.objectContaining({ includeDerivedTitles: true }));
1972+
await expect.poll(() => label.textContent()).toBe(readableTitle);
1973+
expect(await row.getAttribute("aria-label")).toContain("Active");
1974+
} finally {
1975+
await closeBrowserContext(context);
1976+
}
1977+
});
1978+
18771979
it("keeps long sidebar labels clipped after a session switch", async () => {
18781980
const context = await newBrowserContext({
18791981
locale: "en-US",

‎ui/src/lib/sessions/index.test.ts‎

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function deferred<T>() {
2424

2525
describe("createSessionCapability", () => {
2626
it("passes transcript fork parameters to sessions.create", async () => {
27-
const request = vi.fn(async (method: string) => {
27+
const request = vi.fn(async (method: string, _params?: unknown) => {
2828
if (method === "sessions.create") {
2929
return { key: "agent:main:forked" };
3030
}
@@ -64,7 +64,7 @@ describe("createSessionCapability", () => {
6464
it("keeps background hydration non-blocking and retains an omitted selected row", async () => {
6565
const secondList = deferred<SessionsListResult>();
6666
let listCalls = 0;
67-
const request = vi.fn(async (method: string) => {
67+
const request = vi.fn(async (method: string, _params?: unknown) => {
6868
if (method !== "sessions.list") {
6969
throw new Error(`Unexpected request: ${method}`);
7070
}
@@ -118,6 +118,139 @@ describe("createSessionCapability", () => {
118118
sessions.dispose();
119119
});
120120

121+
it("preserves derived-title hydration when refreshing after session patches", async () => {
122+
const key = "agent:main:untitled";
123+
const request = vi.fn(async (method: string, _params?: unknown) => {
124+
if (method === "sessions.list") {
125+
return sessionsResult(
126+
[
127+
{
128+
key,
129+
kind: "direct",
130+
updatedAt: 1,
131+
label: key,
132+
derivedTitle: "Readable planning title",
133+
},
134+
],
135+
1,
136+
);
137+
}
138+
if (method === "sessions.patch") {
139+
return { ok: true };
140+
}
141+
throw new Error(`Unexpected request: ${method}`);
142+
});
143+
const client = { request } as unknown as GatewayBrowserClient;
144+
const sessions = createSessionCapability({
145+
snapshot: {
146+
client,
147+
connected: true,
148+
sessionKey: key,
149+
assistantAgentId: "main",
150+
hello: null,
151+
},
152+
subscribe: () => () => undefined,
153+
subscribeEvents: () => () => undefined,
154+
});
155+
156+
await sessions.refresh({
157+
agentId: "main",
158+
activeMinutes: 0,
159+
limit: 50,
160+
includeGlobal: true,
161+
includeUnknown: true,
162+
configuredAgentsOnly: true,
163+
includeDerivedTitles: true,
164+
force: true,
165+
});
166+
await sessions.patch(key, { pinned: true }, { agentId: "main" });
167+
168+
const listCalls = request.mock.calls.filter(([method]) => method === "sessions.list");
169+
expect(listCalls).toHaveLength(2);
170+
expect(listCalls[1]?.[1]).toMatchObject({
171+
agentId: "main",
172+
includeGlobal: true,
173+
includeUnknown: true,
174+
configuredAgentsOnly: true,
175+
includeDerivedTitles: true,
176+
limit: 50,
177+
});
178+
expect(request).toHaveBeenCalledWith("sessions.patch", {
179+
key,
180+
agentId: "main",
181+
pinned: true,
182+
});
183+
sessions.dispose();
184+
});
185+
186+
it("drops pagination while preserving filters when refreshing after session patches", async () => {
187+
const key = "agent:main:page-b";
188+
const request = vi.fn(async (method: string, _params?: unknown) => {
189+
if (method === "sessions.list") {
190+
return sessionsResult(
191+
[
192+
{
193+
key,
194+
kind: "direct",
195+
updatedAt: 2,
196+
label: key,
197+
derivedTitle: "Readable second-page title",
198+
},
199+
],
200+
2,
201+
);
202+
}
203+
if (method === "sessions.patch") {
204+
return { ok: true };
205+
}
206+
throw new Error(`Unexpected request: ${method}`);
207+
});
208+
const client = { request } as unknown as GatewayBrowserClient;
209+
const sessions = createSessionCapability({
210+
snapshot: {
211+
client,
212+
connected: true,
213+
sessionKey: key,
214+
assistantAgentId: "main",
215+
hello: null,
216+
},
217+
subscribe: () => () => undefined,
218+
subscribeEvents: () => () => undefined,
219+
});
220+
221+
const baseListOptions = {
222+
agentId: "main",
223+
activeMinutes: 0,
224+
limit: 1,
225+
includeGlobal: true,
226+
includeUnknown: true,
227+
configuredAgentsOnly: true,
228+
includeDerivedTitles: true,
229+
force: true,
230+
};
231+
await sessions.refresh(baseListOptions);
232+
await sessions.refresh({
233+
...baseListOptions,
234+
offset: 1,
235+
append: true,
236+
});
237+
await sessions.patch(key, { unread: false }, { agentId: "main" });
238+
239+
const listCalls = request.mock.calls.filter(([method]) => method === "sessions.list");
240+
expect(listCalls).toHaveLength(3);
241+
expect(listCalls[2]?.[1]).toMatchObject({
242+
agentId: "main",
243+
limit: 1,
244+
includeGlobal: true,
245+
includeUnknown: true,
246+
configuredAgentsOnly: true,
247+
includeDerivedTitles: true,
248+
});
249+
expect(listCalls[2]?.[1]).not.toHaveProperty("append");
250+
expect(listCalls[2]?.[1]).not.toHaveProperty("offset");
251+
sessions.dispose();
252+
});
253+
121254
it("publishes terminal run state to shared session subscribers", async () => {
122255
const key = "agent:main:main";
123256
const request = vi.fn(async (method: string) => {

‎ui/src/lib/sessions/index.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,14 @@ export function createSessionCapability(gateway: SessionGateway): SessionCapabil
759759
}
760760
return null;
761761
}
762-
await refresh({ agentId: options.agentId, force: true });
762+
const patchRefreshOptions: SessionListOptions = { ...lastListOptions };
763+
delete patchRefreshOptions.append;
764+
delete patchRefreshOptions.offset;
765+
await refresh({
766+
...patchRefreshOptions,
767+
agentId: options.agentId ?? patchRefreshOptions.agentId,
768+
force: true,
769+
});
763770
if (hasModelPatch) {
764771
setModelOverride(key, patchParams.model);
765772
}

0 commit comments

Comments
 (0)