Skip to content

Commit bf4ec4b

Browse files
fix(ui): disambiguate multi-account session labels (#124228)
* fix(ui): disambiguate multi-account session labels Parse the optional account segment on per-account-channel-peer DM and group keys so Control UI no longer falls through to the raw routing key. Append a non-default account as " · accountId" on label, displayName, and fallback so two Alice rows from different Telegram accounts stay distinguishable. Signed-off-by: Sebastien Tardif <[email protected]> * fix(ui): take the session account from the gateway row The display resolver was reading the account out of the session key and inferring it from label text. That missed the shipped `dm` spelling of direct keys, invented an account-qualified group shape no key builder emits, and treated any name ending in "(<account>)" as already disambiguated. The Gateway already projects the canonical `accountId` onto every session row from the delivery route, so display consumes that and parses the key only for panes rendered before their row arrives. Key parsing now covers both `direct` and the pre-#11881 `dm` spelling, group keys go back to their canonical account-less shape, and the account suffix is applied at a single point instead of five. `resolveChannelSessionInfo` classifies `dm` keys as channel sessions and no longer reads a peer kind sitting in the channel slot as a channel. * fix(ui): stop inferring session identity from rendered text Three related text-inference defects in the same display neighborhood: The account suffix was skipped when the resolved name already ended in " · <account>". That reads rendered output as if it were a fact, and it cannot tell an account apart from a user label that happens to look like one. The suffix is now appended from the recorded account alone. The string it was defending against came from the sidebar rename dialog, which pre-filled with the resolved display name. Submitting persisted a derived string as a real user label, which then outranked every later derivation. Sidebar rows now carry the stored label alongside the resolved one, and rename edits that, matching the Sessions page. Channel classification accepted an account segment before any peer kind, so `agent:<x>:<channel>:<account>:group:<id>` was filed under a channel even though accounts qualify direct chats only and the canonical route parser rejects the shape. The grammar now allows an account only before `direct`/`dm`. Resolver tests now prove the row projection is authoritative rather than duplicating an account the key already carries: one case where only the projection supplies it, and one where the two disagree. * ci: retrigger after check-lint shard cancel Signed-off-by: Sebastien Tardif <[email protected]> * test(ui): prove rename opens on the stored label The existing sidebar rename coverage uses a row that already has a stored label, so it passes whether rename pre-fills the stored label or the resolved display name. It could not catch the round-trip this branch repaired. Adds a browser case on a displayName-only row with a projected account: the sidebar shows "Alice · cards" and the rename field opens blank. On the parent commit the field opens holding "Alice · cards", which is the string that used to become a real user label on submit. * fix(ui): do not double-append a stored account suffix A persisted label that already ends in " · accountId" must stay as-is so "Alice · cards" does not become "Alice · cards · cards". Signed-off-by: Sebastien Tardif <[email protected]> * docs(ui): name the producer the account suffix check defends The comment above withAccountDisambiguator claimed the rendered name is never inspected, which the suffix check contradicts. State the real contract instead: the account itself still comes only from the recorded value, and the endsWith check is idempotence against the chat pane's inline rename, which seeds its input with the rendered title and persists a partial edit verbatim. --------- Signed-off-by: Sebastien Tardif <[email protected]> Co-authored-by: vyctorbrzezowski <[email protected]>
1 parent 5014839 commit bf4ec4b

6 files changed

Lines changed: 294 additions & 30 deletions

‎ui/src/components/app-sidebar-session-navigation-logic.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export function buildSidebarSessionNavigationState(input: {
207207
// The sidebar's zone structure already says what forked from what;
208208
// a "Subagent:" prefix on named threads is noise (other surfaces keep it).
209209
label: resolveSessionDisplayName(row.key, row, { includeSubagentPrefix: false }),
210+
userLabel: row.label,
210211
subtitle: resolveSessionWorkSubtitle(row),
211212
href: sessionNavigationTarget({
212213
face: resolveSessionPreferredFace(row),

‎ui/src/components/app-sidebar-session-types.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export type SidebarRecentSession = {
6161
createdActor?: SessionCreatedActor;
6262
archivedBy?: SessionCreatedActor;
6363
label: string;
64+
/**
65+
* Stored user label, undecorated. `label` above is the resolved display name
66+
* and can carry a derived account or channel; rename edits this one so a
67+
* derived string never lands back in persisted state.
68+
*/
69+
userLabel?: string;
6470
/** Compact repo/branch/node line for work sessions. */
6571
subtitle?: string;
6672
href: string;

‎ui/src/components/session-organizer-controller.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
12
import type { ReactiveControllerHost } from "lit";
23
import type { FsListDirResult } from "../../../packages/gateway-protocol/src/index.js";
34
import {
@@ -419,7 +420,10 @@ export class SessionOrganizerController {
419420
const nextLabel =
420421
(await showInputDialog?.({
421422
title: t("sessionsView.renameSessionPrompt"),
422-
defaultValue: session.label,
423+
// The stored label, not the resolved display name: pre-filling the
424+
// derived string persists it on submit and it then outranks every
425+
// later derivation. Matches the Sessions page rename.
426+
defaultValue: normalizeOptionalString(session.userLabel) ?? "",
423427
})) ?? null;
424428
if (nextLabel === null) {
425429
return;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { expect, it } from "vitest";
2+
import {
3+
captureUiProof,
4+
controlUiSessionUrl,
5+
createSessionManagementE2eSuite,
6+
installMockGateway,
7+
sessionRow,
8+
sessionsListResponse,
9+
trimmedTextContents,
10+
} from "./session-management.test-support.ts";
11+
12+
const suite = createSessionManagementE2eSuite();
13+
14+
/**
15+
* An ordinary Gateway direct-chat row: an origin-derived `displayName`, no user
16+
* label, and the `accountId` the Gateway projects from the canonical route
17+
* (src/gateway/session-classification.ts). Without both traits this would
18+
* exercise the label branch instead of the shipped one.
19+
*/
20+
function gatewayDirectRow(key: string, updatedAt: number, accountId?: string) {
21+
return { ...sessionRow(key, "Alice", updatedAt), accountId, label: undefined };
22+
}
23+
24+
suite.define(() => {
25+
it("disambiguates same-name sessions from different Telegram accounts in the sidebar", async () => {
26+
const defaultKey = "agent:main:telegram:direct:42";
27+
const cardsKey = "agent:main:telegram:cards:direct:42";
28+
const context = await suite.browser.newContext({
29+
colorScheme: "dark",
30+
locale: "en-US",
31+
serviceWorkers: "block",
32+
viewport: { height: 900, width: 1280 },
33+
});
34+
const page = await context.newPage();
35+
await installMockGateway(page, {
36+
methodResponses: {
37+
"sessions.list": sessionsListResponse([
38+
gatewayDirectRow(defaultKey, 2),
39+
gatewayDirectRow(cardsKey, 1, "cards"),
40+
]),
41+
},
42+
sessionKey: defaultKey,
43+
});
44+
45+
try {
46+
await page.goto(controlUiSessionUrl(suite.server.baseUrl, defaultKey));
47+
const defaultRow = page.locator(`[data-session-key="${defaultKey}"]`);
48+
const cardsRow = page.locator(`[data-session-key="${cardsKey}"]`);
49+
await defaultRow.waitFor({ state: "visible", timeout: 10_000 });
50+
await cardsRow.waitFor({ state: "visible" });
51+
await expect
52+
.poll(() => trimmedTextContents(defaultRow.locator(".sidebar-recent-session__name")))
53+
.toEqual(["Alice"]);
54+
await expect
55+
.poll(() => trimmedTextContents(cardsRow.locator(".sidebar-recent-session__name")))
56+
.toEqual(["Alice · cards"]);
57+
await captureUiProof(page, "telegram-account-session-labels.png");
58+
} finally {
59+
await context.close();
60+
}
61+
});
62+
63+
it("opens rename on the stored label, not the account-decorated name", async () => {
64+
const cardsKey = "agent:main:telegram:cards:direct:42";
65+
const context = await suite.browser.newContext({
66+
locale: "en-US",
67+
serviceWorkers: "block",
68+
viewport: { height: 900, width: 1280 },
69+
});
70+
const page = await context.newPage();
71+
await installMockGateway(page, {
72+
methodResponses: {
73+
"sessions.list": sessionsListResponse([gatewayDirectRow(cardsKey, Date.now(), "cards")]),
74+
},
75+
sessionKey: cardsKey,
76+
});
77+
78+
try {
79+
await page.goto(`${suite.server.baseUrl}chat`);
80+
const row = page.locator(`[data-session-key="${cardsKey}"]`);
81+
await row.waitFor({ state: "visible", timeout: 10_000 });
82+
// The row itself carries the account discriminator, so a rename field that
83+
// echoed the rendered name would look plausible while persisting it.
84+
await expect
85+
.poll(() => trimmedTextContents(row.locator(".sidebar-recent-session__name")))
86+
.toEqual(["Alice · cards"]);
87+
88+
await row.hover();
89+
await row.getByRole("button", { name: "Open session menu" }).click();
90+
await page.getByRole("menuitem", { name: "Rename…" }).click();
91+
const field = page
92+
.locator('openclaw-modal-dialog[label="Rename session"]')
93+
.getByRole("textbox", { name: "Rename session" });
94+
await field.waitFor({ state: "visible" });
95+
// This row has no stored label, so the field starts empty. Submitting the
96+
// decorated name here is what used to freeze it into persisted state.
97+
expect(await field.inputValue()).toBe("");
98+
} finally {
99+
await context.close();
100+
}
101+
});
102+
});

‎ui/src/lib/session-display.test.ts‎

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,96 @@ describe("resolveSessionDisplayName", () => {
3838
expect(resolveSessionDisplayName("agent:main:imessage:direct:+4912")).toBe("iMessage · +4912");
3939
});
4040

41+
// Rows are shaped like the Gateway projection: displayName plus the
42+
// accountId it derives from the canonical route, no user label.
43+
it.each([
44+
{
45+
name: "an account-less direct row keeps its plain name",
46+
key: "agent:main:telegram:direct:42",
47+
row: { displayName: "Alice" },
48+
expected: "Alice",
49+
},
50+
{
51+
name: "an account-qualified direct row names its account",
52+
key: "agent:main:telegram:cards:direct:42",
53+
row: { accountId: "cards", displayName: "Alice" },
54+
expected: "Alice · cards",
55+
},
56+
{
57+
name: "a shipped dm-spelled row names its account",
58+
key: "agent:main:telegram:cards:dm:42",
59+
row: { accountId: "cards", displayName: "Alice" },
60+
expected: "Alice · cards",
61+
},
62+
{
63+
name: "an unnamed shipped dm row reads as a friendly peer plus account",
64+
key: "agent:main:telegram:cards:dm:491234567890",
65+
row: { accountId: "cards" },
66+
expected: "Telegram · …567890 · cards",
67+
},
68+
{
69+
name: "the default account adds no discriminator",
70+
key: "agent:main:telegram:default:direct:42",
71+
row: { accountId: "default", displayName: "Alice" },
72+
expected: "Alice",
73+
},
74+
{
75+
name: "a human label that merely looks account-shaped still gets a discriminator",
76+
key: "agent:main:telegram:work:direct:42",
77+
row: { accountId: "work", label: "Alice (work)" },
78+
expected: "Alice (work) · work",
79+
},
80+
{
81+
name: "a stored label that already ends in the account suffix is left alone",
82+
key: "agent:main:telegram:cards:direct:42",
83+
row: { accountId: "cards", label: "Alice · cards" },
84+
expected: "Alice · cards",
85+
},
86+
{
87+
name: "a canonical group key is unchanged",
88+
key: "agent:main:telegram:group:-1001234567890",
89+
row: undefined,
90+
expected: "Telegram Group",
91+
},
92+
{
93+
name: "an account-looking group key is not read as an account-qualified group",
94+
key: "agent:main:dm:account:group:room",
95+
row: undefined,
96+
expected: "dm:account:group:room",
97+
},
98+
])("$name", ({ key, row, expected }) => {
99+
expect(resolveSessionDisplayName(key, row)).toBe(expected);
100+
});
101+
102+
it("reads the account off the key only until the gateway row arrives", () => {
103+
expect(resolveSessionDisplayName("agent:main:telegram:cards:direct:42")).toBe(
104+
"Telegram · 42 · cards",
105+
);
106+
expect(resolveSessionDisplayName("agent:main:signal:work:dm:+4912")).toBe(
107+
"Signal · +4912 · work",
108+
);
109+
expect(resolveSessionDisplayName("agent:main:telegram:default:direct:42")).toBe(
110+
"Telegram · 42",
111+
);
112+
});
113+
114+
it("takes the account from the gateway row, not the key", () => {
115+
// Only the projection carries account identity here; the key has none.
116+
expect(
117+
resolveSessionDisplayName("agent:main:telegram:direct:42", {
118+
accountId: "cards",
119+
displayName: "Alice",
120+
}),
121+
).toBe("Alice · cards");
122+
// When the two disagree, the route the Gateway parsed wins over the guess.
123+
expect(
124+
resolveSessionDisplayName("agent:main:telegram:cards:direct:42", {
125+
accountId: "ops",
126+
displayName: "Alice",
127+
}),
128+
).toBe("Alice · ops");
129+
});
130+
41131
it("does not split UTF-16 surrogate pairs when shortening peer ids", () => {
42132
expect(resolveSessionDisplayName("agent:main:telegram:direct:12345😀67890")).toBe(
43133
"Telegram · …67890",
@@ -177,10 +267,30 @@ describe("resolveChannelSessionInfo", () => {
177267
channel: "telegram",
178268
channelSession: true,
179269
});
180-
expect(resolveChannelSessionInfo("agent:main:slack:acct-1:channel:C1")).toEqual({
270+
expect(resolveChannelSessionInfo("agent:main:slack:channel:C1")).toEqual({
181271
channel: "slack",
182272
channelSession: true,
183273
});
274+
// Shipped pre-#11881 keys spell direct chats `dm`; they are still channel sessions.
275+
expect(resolveChannelSessionInfo("agent:main:telegram:cards:dm:42")).toEqual({
276+
channel: "telegram",
277+
channelSession: true,
278+
});
279+
expect(resolveChannelSessionInfo("agent:main:dm:+123", "whatsapp")).toEqual({
280+
channel: "whatsapp",
281+
channelSession: true,
282+
});
283+
// Accounts qualify direct chats only, so these key shapes name no channel
284+
// and must not be filed under one the canonical parser would reject.
285+
expect(resolveChannelSessionInfo("agent:main:telegram:work:group:room")).toEqual({
286+
channelSession: false,
287+
});
288+
expect(resolveChannelSessionInfo("agent:main:slack:acct-1:channel:C1")).toEqual({
289+
channelSession: false,
290+
});
291+
expect(resolveChannelSessionInfo("agent:main:dm:account:group:room")).toEqual({
292+
channelSession: false,
293+
});
184294
// dmScope per-peer keys have no channel segment; the row channel wins.
185295
expect(resolveChannelSessionInfo("agent:main:direct:+123", "whatsapp")).toEqual({
186296
channel: "whatsapp",

0 commit comments

Comments
 (0)