Skip to content

Commit 6737fb8

Browse files
matt2eclaude
andcommitted
fix(messages): keep message link authors named, local and retryable
Addresses the review of 1c81e00. A link's author never shows as a key fragment. A profile with no name (nameIsFallback) keeps the channel label even when the identity names view hands back its fragment, while an agent's library name still names it. The unit fixture now resolves through the app's own names view and agent directory, which return that fragment. A link in a channel whose membership is still cached waits for the relay to confirm it before reading. A deleted or unavailable message keeps the channel label and is remembered for the session, so virtualized remounts do not read it again. Any other failed read is retried when the live stream connects again, the session's own retry signal, or once every link to that message has unmounted; it never retries in a loop. A message its channel's timeline already holds takes its author from that row, without borrowing a reader. A workflow's message reads "Workflow in #<channel>", the name its row header shows, in both the visible label and the accessible name. Replies held only by an open thread panel still take the exact read: reaching them needs a lookup in the FOUNDATION relay session, which is left for explicit guidance. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 1c81e00 commit 6737fb8

3 files changed

Lines changed: 260 additions & 78 deletions

File tree

‎docs/plugin-architecture.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,16 +1443,18 @@ formatting, escaped pasted wrappers are normalized outside code, and paired `<
14431443
autolink wrappers are hidden in display. Buzz links use known channel names with corresponding icons, falling back
14441444
to Channel, Message or Thread when that name is unavailable in the current community;
14451445
the full destination remains on the anchor. A raw message or thread link in a listed
1446-
channel reads as “<author> in #<channel>” once its author has a name; DMs, Solo chats,
1447-
authored labels and drafts keep the channel name. Buzz activation stays inside the host,
1446+
channel reads as “<author> in #<channel>” once its author has a name, and a workflow’s
1447+
as “Workflow in #<channel>”; DMs, Solo chats, authored labels and drafts keep the channel
1448+
name, as do deleted or unavailable messages. Buzz activation stays inside the host,
14481449
including modifier/middle clicks, even when the optional Links plugin is disabled.
14491450
Unsupported Buzz formats remain plain text. The host-matched author preview exports `LinkRenderer`; older hosts do not
14501451
provide `registerLink`.
14511452

14521453
Message hover/focus previews are host-owned. The entire card is a keyboard-accessible
14531454
link to the same destination, routed through the same host navigation handler. Opening a preview allocates the current
14541455
session's bounded thread reader; closing disposes it. A live message link borrows
1455-
the same reader only until it learns its author. The reader supplies verified
1456+
the same reader only until it learns its author, and not when its channel’s timeline
1457+
already holds the message. The reader supplies verified
14561458
message content, author and timestamp and preserves edit/deletion/access handling.
14571459
Previewing never acknowledges reading or switches community. The host offers a
14581460
resolved label to the bundled presentation via `LinkLabelContext`, and whether

‎src/features/conversation/linked-message.test.tsx‎

Lines changed: 166 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { act, cleanup, render, screen } from "@testing-library/react";
33
import { afterEach, expect, it, vi } from "vitest";
44
import { LinkLabel } from "../../bundled/links/InlineLink";
5+
import { bindNames } from "../identity-names/service";
6+
import { createAgentDirectory } from "../identity-names/testing";
57
import type { ChannelMessage, Profile } from "../relay/contracts";
68
import type { RelaySession } from "../relay/session";
79
import type { ThreadSnapshot, ThreadView } from "../relay/threads";
@@ -45,14 +47,19 @@ const ready = (target: ChannelMessage): Partial<ThreadSnapshot> => ({
4547
targetStatus: "ready",
4648
});
4749

48-
/** Exact readers the test settles by hand; `open` counts undisposed ones. */
50+
type Channel = {
51+
id: string;
52+
name: string;
53+
channelType?: string;
54+
cached?: true;
55+
};
56+
/** Exact readers the test settles by hand; `open` counts undisposed ones.
57+
* Names resolve through the app's own names view and agent directory. */
4958
function fixture({
50-
channels = [{ id: "design", name: "design" }] as {
51-
id: string;
52-
name: string;
53-
channelType?: string;
54-
}[],
59+
channels = [{ id: "design", name: "design" }] as Channel[],
5560
profiles = new Map<string, Profile>([[alice, { name: "Alice" }]]),
61+
agents = [] as { pubkey: string; name: string }[],
62+
shown = [] as ChannelMessage[],
5663
capacity = Number.POSITIVE_INFINITY,
5764
} = {}) {
5865
const views: {
@@ -90,21 +97,51 @@ function fixture({
9097
},
9198
};
9299
});
100+
const changed = (listeners: Set<() => void>) => () =>
101+
act(async () => {
102+
for (const listener of listeners) listener();
103+
});
104+
const subscriber = (listeners: Set<() => void>) => (listener: () => void) => {
105+
listeners.add(listener);
106+
return () => void listeners.delete(listener);
107+
};
93108
const profileListeners = new Set<() => void>();
94-
const list = { status: "ready", channels };
109+
const listListeners = new Set<() => void>();
110+
const liveListeners = new Set<() => void>();
111+
let list = { status: "ready", channels };
112+
let live = { status: "connected" };
95113
const ensure = vi.fn(async () => {});
114+
const profileQueries = {
115+
snapshot: () => profiles,
116+
subscribe: subscriber(profileListeners),
117+
ensure,
118+
};
119+
const library = { status: "ready", definitions: [], identities: agents };
120+
const names = bindNames(
121+
{
122+
profiles: profileQueries,
123+
agentLibrary: {
124+
snapshot: () => library,
125+
subscribe: () => () => {},
126+
refresh: async () => {},
127+
retain: () => () => {},
128+
},
129+
},
130+
{ snapshot: () => [createAgentDirectory()], subscribe: () => () => {} },
131+
);
96132
const session = {
97133
unread: {},
98134
thread,
99-
profiles: {
100-
snapshot: () => profiles,
101-
subscribe(listener: () => void) {
102-
profileListeners.add(listener);
103-
return () => void profileListeners.delete(listener);
104-
},
105-
ensure,
135+
names,
136+
profiles: profileQueries,
137+
channels: {
138+
list: () => list,
139+
subscribeList: subscriber(listListeners),
140+
window: (channelId: string) => ({
141+
rows: shown.filter((row) => row.channelId === channelId),
142+
}),
106143
},
107-
channels: { list: () => list, subscribeList: () => () => {} },
144+
live: { snapshot: () => live, subscribe: subscriber(liveListeners) },
108145
media: () => undefined,
109146
} as unknown as RelaySession;
110147
return {
@@ -115,9 +152,15 @@ function fixture({
115152
open: () => views.filter((view) => !view.disposed),
116153
async setProfiles(next: Map<string, Profile>) {
117154
profiles = next;
118-
await act(async () => {
119-
for (const listener of profileListeners) listener();
120-
});
155+
await changed(profileListeners)();
156+
},
157+
async setChannels(next: Channel[]) {
158+
list = { status: "ready", channels: next };
159+
await changed(listListeners)();
160+
},
161+
async setLive(status: string) {
162+
live = { status };
163+
await changed(liveListeners)();
121164
},
122165
};
123166
}
@@ -168,8 +211,9 @@ it("names the linked message's author and channel once its exact reader settles"
168211
expect(app.ensure).toHaveBeenCalledWith([alice], "background");
169212
});
170213

171-
it("names a reply's author with the thread icon and a workflow by its owner", async () => {
214+
it("names a reply's author with the thread icon and a workflow as its row header does", async () => {
172215
const app = fixture();
216+
const relay = "c".repeat(64);
173217
render(
174218
<>
175219
{link(app.session, href(id(1), id(9)))}
@@ -179,50 +223,137 @@ it("names a reply's author with the thread icon and a workflow by its owner", as
179223
await started();
180224
await app.views[0]?.publish(ready(message(id(1), { threadRootId: id(9) })));
181225
await app.views[1]?.publish(
182-
ready(message(id(2), { authorId: "c".repeat(64), workflowOwnerId: alice })),
226+
ready(message(id(2), { authorId: relay, workflowOwnerId: alice })),
183227
);
184228
const reply = screen.getByRole("link", { name: "Alice in #design" });
185229
expect(reply.querySelector('[data-link-kind="thread"] svg')).not.toBeNull();
186-
expect(
187-
screen.getByRole("link", { name: "Workflow · owned by Alice in #design" }),
188-
).toBeTruthy();
230+
// The owner did not send it, so only the workflow is named.
231+
const workflow = screen.getByRole("link", { name: "Workflow in #design" });
232+
expect(workflow.textContent).toBe("Workflow in #design");
233+
expect(app.ensure).not.toHaveBeenCalledWith([relay], "background");
189234
});
190235

191-
it("keeps the channel label while the author has no name, and names them once loaded", async () => {
236+
it("never names an author by a key fragment, and names them once their profile does", async () => {
237+
const agent = "d".repeat(64);
238+
const unnamed = (key: string): Profile => ({
239+
name: key.slice(0, 10),
240+
nameIsFallback: true,
241+
});
192242
const app = fixture({
193243
profiles: new Map([
194-
[alice, { name: alice.slice(0, 10), nameIsFallback: true }],
244+
[alice, unnamed(alice)],
245+
[agent, unnamed(agent)],
195246
]),
247+
agents: [{ pubkey: agent, name: "Builder" }],
196248
});
197-
render(link(app.session, href(id(1))));
249+
// The app's names view hands back the fragment for a profile with no name.
250+
expect(app.session.names.resolve(alice)).toBe(alice.slice(0, 10));
251+
render(
252+
<>
253+
{link(app.session, href(id(1)))}
254+
{link(app.session, href(id(2)))}
255+
</>,
256+
);
198257
await started();
199258
await app.views[0]?.publish(ready(message(id(1))));
259+
await app.views[1]?.publish(ready(message(id(2), { authorId: agent })));
200260
expect(screen.getByRole("link", { name: "design" }).textContent).toBe(
201261
"design",
202262
);
203-
await app.setProfiles(new Map([[alice, { name: "Alice" }]]));
263+
// An agent's library name is a name even while its profile has none.
264+
expect(screen.getByRole("link", { name: "Builder in #design" })).toBeTruthy();
265+
await app.setProfiles(
266+
new Map([
267+
[alice, { name: "Alice" }],
268+
[agent, unnamed(agent)],
269+
]),
270+
);
204271
expect(screen.getByRole("link", { name: "Alice in #design" })).toBeTruthy();
205272
});
206273

207-
it("keeps the channel label when the message is unavailable or no reader is free", async () => {
208-
const unavailable = fixture();
209-
const view = render(link(unavailable.session, href(id(1))));
274+
it("takes the author from the channel's loaded timeline without reading", async () => {
275+
const app = fixture({ shown: [message(id(1))] });
276+
render(
277+
<>
278+
{link(app.session, href(id(1)))}
279+
{link(app.session, href(id(2)))}
280+
</>,
281+
);
210282
await started();
211-
await unavailable.views[0]?.publish({
212-
status: "idle",
283+
expect(screen.getByRole("link", { name: "Alice in #design" })).toBeTruthy();
284+
// Only the message no timeline holds is read.
285+
expect(app.thread).toHaveBeenCalledOnce();
286+
expect(app.thread).toHaveBeenCalledWith("design", id(2), { exact: true });
287+
});
288+
289+
it("waits for the relay to confirm a cached channel before reading", async () => {
290+
const app = fixture({
291+
channels: [{ id: "design", name: "design", cached: true }],
292+
});
293+
render(link(app.session, href(id(1))));
294+
await started();
295+
expect(app.thread).not.toHaveBeenCalled();
296+
expect(screen.getByRole("link", { name: "design" })).toBeTruthy();
297+
await app.setChannels([{ id: "design", name: "design" }]);
298+
await started();
299+
expect(app.thread).toHaveBeenCalledOnce();
300+
await app.views[0]?.publish(ready(message(id(1))));
301+
expect(screen.getByRole("link", { name: "Alice in #design" })).toBeTruthy();
302+
});
303+
304+
it("keeps the channel label for an unavailable message and never reads it again", async () => {
305+
const app = fixture();
306+
const view = render(link(app.session, href(id(1))));
307+
await started();
308+
await app.views[0]?.publish({
309+
status: "ready",
310+
canLoadMore: false,
213311
targetStatus: "unavailable",
214-
error: "Message unavailable",
215312
});
216313
expect(screen.getByRole("link", { name: "design" })).toBeTruthy();
217-
expect(unavailable.open()).toHaveLength(0);
314+
expect(app.open()).toHaveLength(0);
315+
// A virtualized remount, or the stream reconnecting, does not re-read it.
218316
view.unmount();
317+
render(link(app.session, href(id(1))));
318+
await started();
319+
await app.setLive("retrying");
320+
await app.setLive("connected");
321+
expect(app.thread).toHaveBeenCalledOnce();
322+
expect(screen.getByRole("link", { name: "design" })).toBeTruthy();
323+
});
324+
325+
it("retries a failed lookup once the live stream reconnects, never in a loop", async () => {
326+
const app = fixture();
327+
render(link(app.session, href(id(1))));
328+
await started();
329+
await app.views[0]?.publish({
330+
status: "error",
331+
targetStatus: "error",
332+
error: "Relay unavailable",
333+
});
334+
await started();
335+
expect(app.thread).toHaveBeenCalledOnce();
336+
expect(app.open()).toHaveLength(0);
337+
// The stream staying up is no news; connecting again is.
338+
await app.setLive("connected");
339+
expect(app.thread).toHaveBeenCalledOnce();
340+
await app.setLive("retrying");
341+
await app.setLive("connected");
342+
expect(app.thread).toHaveBeenCalledTimes(2);
343+
await app.views[1]?.publish(ready(message(id(1))));
344+
expect(screen.getByRole("link", { name: "Alice in #design" })).toBeTruthy();
345+
cleanup();
346+
// No free reader fails the same way, without retrying until then.
219347
const full = fixture({ capacity: 0 });
220348
render(link(full.session, href(id(1))));
221349
await started();
222350
await started();
223-
// A failed lookup waits for a later mount instead of retrying in a loop.
224351
expect(full.thread).toHaveBeenCalledOnce();
225352
expect(screen.getByRole("link", { name: "design" })).toBeTruthy();
353+
await full.setLive("retrying");
354+
await full.setLive("connected");
355+
await started();
356+
expect(full.thread).toHaveBeenCalledTimes(2);
226357
});
227358

228359
it("reads nothing for authored labels, drafts, unlisted channels, DMs or Solo chats", async () => {

0 commit comments

Comments
 (0)