Skip to content

Commit a68180e

Browse files
committed
fix(ui): keep agent-scoped composer models fresh across pane switches
1 parent 709c0f5 commit a68180e

2 files changed

Lines changed: 35 additions & 19 deletions

File tree

‎ui/src/e2e/chat-composer-redesign.e2e.test.ts‎

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ describeControlUiE2e("Control UI chat composer redesign", () => {
112112

113113
try {
114114
await page.goto(`${server.baseUrl}chat`);
115-
await gateway.waitForRequest("chat.metadata");
116-
expect(await gateway.getRequests("models.list")).toHaveLength(0);
115+
await gateway.waitForRequest("chat.startup");
117116

118117
const composer = page.locator(".agent-chat__input");
119118
const composerShell = page.locator(".agent-chat__composer-shell");
@@ -133,6 +132,8 @@ describeControlUiE2e("Control UI chat composer redesign", () => {
133132
const voice = page.getByRole("button", { name: "Start voice input" });
134133

135134
await expect.poll(() => model.isVisible()).toBe(true);
135+
expect(await gateway.getRequests("chat.metadata")).toHaveLength(0);
136+
expect(await gateway.getRequests("models.list")).toHaveLength(0);
136137
await expect.poll(() => contextUsage.isVisible()).toBe(true);
137138
await expect.poll(() => usage.isVisible()).toBe(false);
138139
await expect.poll(() => settings.isVisible()).toBe(true);
@@ -705,17 +706,10 @@ describeControlUiE2e("Control UI chat composer redesign", () => {
705706

706707
try {
707708
await page.goto(controlUiSessionUrl(server.baseUrl, "agent:work:main"));
708-
await expect
709-
.poll(
710-
async () => {
711-
const requests = await gateway.getRequests("chat.metadata");
712-
return requests.some(
713-
(request) => (request.params as { agentId?: string } | undefined)?.agentId === "work",
714-
);
715-
},
716-
{ timeout: 10_000 },
717-
)
718-
.toBe(true);
709+
await gateway.waitForRequest("chat.startup");
710+
// The initial work-agent catalog is complete in chat.startup, so only the
711+
// later switch to the other agent should require chat.metadata.
712+
expect(await gateway.getRequests("chat.metadata")).toHaveLength(0);
719713

720714
const composer = page.locator(".agent-chat__input");
721715
await expect
@@ -729,23 +723,28 @@ describeControlUiE2e("Control UI chat composer redesign", () => {
729723
await expect
730724
.poll(async () => {
731725
const requests = await gateway.getRequests("chat.metadata");
732-
return requests.some(
726+
return requests.filter(
733727
(request) => (request.params as { agentId?: string } | undefined)?.agentId === "other",
734-
);
728+
).length;
735729
})
736-
.toBe(true);
730+
.toBe(1);
737731
await expect
738732
.poll(() => composer.locator('[data-chat-model-option="anthropic/other-model"]').count())
739733
.toBe(1);
740734
await expect
741735
.poll(() => composer.locator('[data-chat-model-option="openai/work-model"]').count())
742736
.toBe(0);
737+
const metadataRequests = await gateway.getRequests("chat.metadata");
738+
expect(metadataRequests).toHaveLength(1);
739+
expect((metadataRequests[0]?.params as { agentId?: string } | undefined)?.agentId).toBe(
740+
"other",
741+
);
743742
} finally {
744743
await context.close();
745744
}
746745
});
747746

748-
it("keeps startup models when the metadata refresh fails", async () => {
747+
it("keeps startup models when an explicit metadata refresh fails", async () => {
749748
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
750749
const page = await context.newPage();
751750
const gateway = await installMockGateway(page, {
@@ -755,12 +754,23 @@ describeControlUiE2e("Control UI chat composer redesign", () => {
755754

756755
try {
757756
await page.goto(`${server.baseUrl}chat`);
757+
await gateway.waitForRequest("chat.startup");
758+
const composer = page.locator(".agent-chat__input");
759+
await expect
760+
.poll(() => composer.locator('[data-chat-model-provider-group="openai"]').textContent())
761+
.toContain("GPT-5.5");
762+
expect(await gateway.getRequests("chat.metadata")).toHaveLength(0);
763+
764+
// Startup metadata now owns the initial catalog, so there is no unconditional
765+
// parallel refresh. Exercise the same-agent pane refresh path explicitly.
766+
await page.locator("openclaw-chat-pane").evaluate((pane) => {
767+
(pane as HTMLElement & { sessionKey: string }).sessionKey = "agent:main:refreshed";
768+
});
758769
await gateway.waitForRequest("chat.metadata");
759770
await gateway.rejectDeferred("chat.metadata", {
760771
code: "UNAVAILABLE",
761772
message: "metadata unavailable",
762773
});
763-
const composer = page.locator(".agent-chat__input");
764774
await expect
765775
.poll(() => composer.locator('[data-chat-model-provider-group="openai"]').textContent())
766776
.toContain("GPT-5.5");

‎ui/src/pages/chat/chat-pane-session.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export abstract class ChatPaneSession extends ChatPaneSuggestions {
182182
this.cancelHeaderRename();
183183
this.resetOlderMessagesViewport();
184184
const catalogKey = parseCatalogSessionKey(nextSessionKey);
185+
const previousAgentId = resolveChatAgentId(state);
185186
const previousSessionsResult = state.sessionsResult;
186187
const nextSessionRow = state.sessionsResult?.sessions.find((row) => row.key === nextSessionKey);
187188
const nextSessionLabel = resolveSessionDisplayName(nextSessionKey, nextSessionRow);
@@ -241,7 +242,12 @@ export abstract class ChatPaneSession extends ChatPaneSuggestions {
241242
}
242243
void state.loadAssistantIdentity();
243244
void refreshChatAvatar(state).finally(() => this.requestUpdate());
244-
void refreshChatMetadata(state).finally(() => state.requestUpdate?.());
245+
const nextAgentId = resolveChatAgentId(state);
246+
// Agent-scoped catalogs remain valid across same-agent sessions. Cross-agent
247+
// failures must clear instead of retaining models owned by the previous agent.
248+
void refreshChatMetadata(state, {
249+
preserveModelCatalogOnFallback: Boolean(previousAgentId && previousAgentId === nextAgentId),
250+
}).finally(() => state.requestUpdate?.());
245251
const subscriptionSync = syncSelectedSessionMessageSubscription(state);
246252
const composerStorageError = state.chatError === CHAT_COMPOSER_DRAFT_STORAGE_ERROR;
247253
const historyLoad = loadChatHistory(state, { deferBranches: true });

0 commit comments

Comments
 (0)