Skip to content

Commit 82a4171

Browse files
tulsi-builderBasilBotclaude
committed
fix(agents): open a transcript its lookup finds after the profile shows
Working now asks the agent's Activity for the conversation's transcript, but it opened only when the session was known on the first render. A session the lookup finds a moment later, such as the one session a Solo chat, DM or channel-scoped agent keeps for its channel, settled the request and showed the overview instead, so the click rarely reached the transcript. Keep the request pending while the session is still being looked up and open the transcript once found. A click or key press before then cancels it, so a late result never takes the reader's focus. Co-authored-by: BasilBot <399581b6165ab01343e3a1324774b1024d76942aea563468f93c975e5ee5193c@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: tulsi <[email protected]>
1 parent 1da0dc8 commit 82a4171

6 files changed

Lines changed: 141 additions & 17 deletions

File tree

‎src/bundled/claude-code/tabs.test.tsx‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,38 @@ it("opens the conversation's transcript when opened from its activity, once", as
455455
expect(screen.queryByText("Two files.")).toBeNull();
456456
});
457457

458+
it("opens a channel's session transcript when opened from one of its threads' activity", async () => {
459+
// A Solo chat, DM or channel-scoped agent keeps one session per channel, so
460+
// the thread's own lookup finds it only after the profile is shown.
461+
localStorage.setItem(
462+
"buzz.claude-code.sessions.v1",
463+
JSON.stringify({
464+
[agent().key]: { channel: { id: "kept", seen: 0, at: 2 } },
465+
}),
466+
);
467+
const transcript = JSON.stringify({
468+
type: "assistant",
469+
uuid: "u1",
470+
timestamp: "2026-10-09T10:00:05Z",
471+
message: { content: [{ type: "text", text: "Two files." }] },
472+
});
473+
const Activity = tab(
474+
installed({ files: { "./-Users-me--buzz/kept.jsonl": transcript } }).type,
475+
1,
476+
);
477+
const done = vi.fn();
478+
render(
479+
<Activity
480+
agent={agent()}
481+
save={vi.fn()}
482+
conversation={{ channelId: "channel", rootId: "e".repeat(64) }}
483+
initialTranscript={{ opening: 1, done }}
484+
/>,
485+
);
486+
expect(await screen.findByText("Two files.")).toBeVisible();
487+
expect(done).toHaveBeenCalledTimes(1);
488+
});
489+
458490
it("shows the transcript and that sessions may be missing when some history cannot be read", async () => {
459491
localStorage.setItem(
460492
"buzz.claude-code.sessions.v1",

‎src/bundled/claude-code/tabs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ export function createTabs({
742742
const { open, show, back } = useOpenTranscript(
743743
conversation,
744744
label,
745-
initialTranscript && { initial: here, ...initialTranscript },
745+
initialTranscript && { initial: here, searching, ...initialTranscript },
746746
close,
747747
);
748748
return (

‎src/bundled/codex/tabs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ export function createTabs(
844844
const { open, show, back } = useOpenTranscript(
845845
conversation,
846846
label,
847-
initialTranscript && { initial: here, ...initialTranscript },
847+
initialTranscript && { initial: here, searching, ...initialTranscript },
848848
close,
849849
);
850850
const saved = new Set(conversations.map((row) => row.key));

‎src/bundled/goose/tabs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ export function createTabs({
869869
const { open, show, back } = useOpenTranscript(
870870
conversation,
871871
label,
872-
initialTranscript && { initial: here, ...initialTranscript },
872+
initialTranscript && { initial: here, searching, ...initialTranscript },
873873
close,
874874
);
875875
const rows = (recent.value ?? [])

‎src/features/agents/OpenedConversation.test.tsx‎

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,87 @@ it("keeps the reader's choice when the opened conversation's lookup finishes lat
3535
expect(result.current.open).toBe(recent);
3636
});
3737

38-
it("never opens a transcript found only after the conversation was shown", async () => {
38+
it("opens a transcript its lookup finds after the conversation was shown, once", async () => {
39+
let resolve: (row: Row) => void = () => {};
40+
const lookup = new Promise<Row>((done) => {
41+
resolve = done;
42+
});
3943
const done = vi.fn();
4044
const { result } = renderHook(() => {
41-
const { session } = useOpenedSession<Row>(
45+
const { session, searching } = useOpenedSession<Row>(
4246
[recent],
4347
conversation,
44-
async () => found,
48+
() => lookup,
49+
);
50+
return useOpenTranscript<Row>(conversation, (row) => row.key, {
51+
initial: session,
52+
searching,
53+
opening: 1,
54+
done,
55+
});
56+
});
57+
try {
58+
expect(result.current.open).toBeUndefined();
59+
expect(done).not.toHaveBeenCalled();
60+
} finally {
61+
await act(async () => resolve(found));
62+
}
63+
expect(result.current.open).toEqual(found);
64+
expect(done).toHaveBeenCalledTimes(1);
65+
act(() => result.current.back());
66+
expect(result.current.open).toBeUndefined();
67+
});
68+
69+
it("keeps the overview when the reader types or clicks before the lookup finishes", async () => {
70+
for (const input of ["keydown", "pointerdown"] as const) {
71+
let resolve: (row: Row) => void = () => {};
72+
const lookup = new Promise<Row>((done) => {
73+
resolve = done;
74+
});
75+
const done = vi.fn();
76+
const { result, unmount } = renderHook(() => {
77+
const { session, searching } = useOpenedSession<Row>(
78+
[recent],
79+
conversation,
80+
() => lookup,
81+
);
82+
return useOpenTranscript<Row>(conversation, (row) => row.key, {
83+
initial: session,
84+
searching,
85+
opening: 1,
86+
done,
87+
});
88+
});
89+
try {
90+
act(() => void document.body.dispatchEvent(new Event(input)));
91+
expect(done).toHaveBeenCalledTimes(1);
92+
} finally {
93+
await act(async () => resolve(found));
94+
}
95+
expect(result.current.open).toBeUndefined();
96+
expect(done).toHaveBeenCalledTimes(1);
97+
unmount();
98+
}
99+
});
100+
101+
it("settles without opening when the lookup finds no session", async () => {
102+
const done = vi.fn();
103+
const { result } = renderHook(() => {
104+
const { session, searching } = useOpenedSession<Row>(
105+
[recent],
106+
conversation,
107+
async () => undefined,
45108
);
46109
return useOpenTranscript<Row>(conversation, (row) => row.key, {
47110
initial: session,
111+
searching,
48112
opening: 1,
49113
done,
50114
});
51115
});
52116
await act(async () => {});
53117
expect(result.current.open).toBeUndefined();
54-
expect(done).toHaveBeenCalled();
118+
expect(done).toHaveBeenCalledTimes(1);
55119
});
56120

57121
it("opens the known conversation's transcript once, not again after Back", () => {

‎src/features/agents/OpenedConversation.tsx‎

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,22 @@ export function useOpenedSession<T extends Saved>(
101101
/** The transcript a type's tab shows over itself as a panel subview, titled
102102
* `title(row)`. It closes when the profile is retargeted to another
103103
* conversation, and viewing it again brings its tab back in a tabbed host.
104-
* `request` asks for the conversation's transcript first. It opens by itself
105-
* only if already known when the conversation is shown, since one found later
106-
* must not take the reader's focus; `request.done` reports that it was offered.
107-
* A new `request.opening` asks again, even for the conversation already shown.
108-
* Closing that tab calls `close`, since it was all that was asked for, unless
109-
* the host is only clearing the profile's own detail tabs. */
104+
* `request` asks for the conversation's transcript first. While its session
105+
* is still `searching`, the transcript opens once found, unless the reader
106+
* clicks or types first, so a late result never takes their focus;
107+
* `request.done` reports that it was offered. A new `request.opening` asks
108+
* again, even for the conversation already shown. Closing that tab calls
109+
* `close`, since it was all that was asked for, unless the host is only
110+
* clearing the profile's own detail tabs. */
110111
export function useOpenTranscript<T>(
111112
conversation: AgentConversation | undefined,
112113
title: (row: T) => string,
113-
request?: { initial: T | undefined; opening: number; done(): void },
114+
request?: {
115+
initial: T | undefined;
116+
searching?: boolean | undefined;
117+
opening: number;
118+
done(): void;
119+
},
114120
close?: () => void,
115121
) {
116122
const place = conversation
@@ -127,6 +133,8 @@ export function useOpenTranscript<T>(
127133
const [offered, setOffered] = useState<{ place: string; opening?: number }>({
128134
place: "",
129135
});
136+
// The place whose asked-for session is still being looked up.
137+
const [waiting, setWaiting] = useState<string>();
130138
const moved = offered.place !== place;
131139
if (moved || (opening !== undefined && opening !== offered.opening)) {
132140
setOffered({ place, ...(opening !== undefined && { opening }) });
@@ -135,19 +143,39 @@ export function useOpenTranscript<T>(
135143
? { place, row: request.initial, initial: true as const }
136144
: undefined;
137145
if (moved || asked) setShown(asked);
146+
setWaiting(!asked && place && request?.searching ? place : undefined);
147+
} else if (waiting !== undefined) {
148+
if (waiting !== place || !request) setWaiting(undefined);
149+
else if (request.initial !== undefined) {
150+
setWaiting(undefined);
151+
setShown({ place, row: request.initial, initial: true });
152+
} else if (!request.searching) setWaiting(undefined);
138153
}
154+
const pending = !!place && waiting === place;
155+
// The reader's own click or key press wins over a lookup still finishing.
156+
useEffect(() => {
157+
if (!pending) return;
158+
const cancel = () => setWaiting(undefined);
159+
const events = ["pointerdown", "keydown"] as const;
160+
for (const type of events) document.addEventListener(type, cancel, true);
161+
return () => {
162+
for (const type of events)
163+
document.removeEventListener(type, cancel, true);
164+
};
165+
}, [pending]);
139166
const tabs = usePanelTabHost();
140167
// A transcript already open in its tab is brought forward when asked again.
141-
// biome-ignore lint/correctness/useExhaustiveDependencies: once per opening.
168+
// biome-ignore lint/correctness/useExhaustiveDependencies: once per opening, after its lookup.
142169
useEffect(() => {
143-
if (!request) return;
170+
if (!request || pending) return;
144171
if (tabs && shown?.initial && shown.place === place)
145172
tabs.activate(tabs.owner, title(shown.row));
146173
request.done();
147-
}, [opening]);
174+
}, [opening, pending]);
148175
return {
149176
open: shown?.place === place ? shown.row : undefined,
150177
show(row: T) {
178+
setWaiting(undefined);
151179
setShown({ place, row });
152180
tabs?.activate(tabs.owner, title(row));
153181
},

0 commit comments

Comments
 (0)