Skip to content

Commit d42b6af

Browse files
t3dotggclaude
andcommitted
fix(server): guest images stay loadable after their reply leaves the window
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent eb111db commit d42b6af

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎apps/server/src/guest/GuestShareService.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,5 +971,18 @@ it.effect("serves an image on the host only when an agent reply the guest sees s
971971
],
972972
});
973973
assert.equal((yield* guestShares.media(session, unnamed)).mimeType, "image/png");
974+
975+
// Enough new rows push the first reply out of the window, but the open page still shows it.
976+
yield* eventSink.write({
977+
events: Array.from({ length: 600 }, (_, index) =>
978+
item(
979+
`item:filler-${index}`,
980+
index + 2,
981+
{ type: "assistant_message", text: "Working." },
982+
{ threadId: forkId, runId: forkRun.id },
983+
),
984+
),
985+
});
986+
assert.equal((yield* guestShares.media(session, shot)).mimeType, "image/png");
974987
}).pipe(Effect.scoped, Effect.provide(layerTest)),
975988
);

‎apps/server/src/guest/GuestShareService.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ const make = Effect.gen(function* () {
663663
return sources;
664664
};
665665

666-
// The replies in the rows the guest's stream opens with, so replies a fork inherits count too.
667-
// Read again only when the thread changes, not for every image the page loads.
666+
// The replies in the rows the guest's stream opens with, so replies a fork inherits count too,
667+
// plus those read before. Read again only when the thread changes, not for every image.
668668
const repliesByThread = new Map<
669669
ThreadId,
670670
{
@@ -681,12 +681,20 @@ const make = Effect.gen(function* () {
681681
rowLimit: SNAPSHOT_ROW_LIMIT,
682682
userTurnLimit: SNAPSHOT_USER_TURN_LIMIT,
683683
});
684-
// Only replies with image syntax can show an image; the rest are not kept.
685-
const replies = projection.visibleTurnItems.flatMap(({ item }) =>
686-
item.type === "assistant_message" && (item.text.includes("![") || /<img/i.test(item.text))
687-
? [item]
688-
: [],
684+
// Replies already read stay: an open guest page keeps rows that slide out of the window.
685+
const kept = new Map(
686+
(cached?.replies ?? []).map((reply) => [`${reply.threadId}\u0000${reply.id}`, reply]),
689687
);
688+
for (const { item } of projection.visibleTurnItems) {
689+
// Only replies with image syntax can show an image; the rest are not kept.
690+
if (
691+
item.type === "assistant_message" &&
692+
(item.text.includes("![") || /<img/i.test(item.text))
693+
) {
694+
kept.set(`${item.threadId}\u0000${item.id}`, item);
695+
}
696+
}
697+
const replies = [...kept.values()];
690698
repliesByThread.delete(threadId);
691699
repliesByThread.set(threadId, { sequence, replies });
692700
if (repliesByThread.size > SHARED_THREAD_REPLIES_LIMIT) {

0 commit comments

Comments
 (0)