Skip to content

Commit 6d72b36

Browse files
committed
fix(chat): keep the working row stable while sessions start
1 parent fba3c7c commit 6d72b36

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎apps/mobile/src/features/threads/thread-feed-live-follow.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ describe("resolveThreadFeedSubmissionAnchor", () => {
3030
).toBe("first-message");
3131
});
3232

33+
it("preserves the first-message anchor after its outbox entry drains", () => {
34+
expect(
35+
resolveThreadFeedSubmissionAnchor({
36+
currentAnchorMessageId: "first-message",
37+
submittedMessageId: "second-message",
38+
hasStartedTurn: false,
39+
hasUserMessage: false,
40+
queuedMessageCount: 0,
41+
}),
42+
).toBe("first-message");
43+
});
44+
3345
it("does not anchor a follow-up after a user message appears", () => {
3446
expect(
3547
resolveThreadFeedSubmissionAnchor({

‎apps/mobile/src/features/threads/thread-feed-live-follow.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export function resolveThreadFeedSubmissionAnchor<AnchorId>(input: {
2323
return null;
2424
}
2525

26-
return input.queuedMessageCount > 0 ? input.currentAnchorMessageId : input.submittedMessageId;
26+
if (input.currentAnchorMessageId !== null) {
27+
return input.currentAnchorMessageId;
28+
}
29+
30+
return input.queuedMessageCount > 0 ? null : input.submittedMessageId;
2731
}
2832

2933
export function resolveThreadFeedLiveFollow(

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,29 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
638638
).toBe(false);
639639
});
640640

641+
it("keeps a follow-up active while its provider session is starting", () => {
642+
const localDispatch = createLocalDispatchSnapshot(
643+
makeThread({ latestTurn: completedTurn, session: readySession }),
644+
);
645+
646+
expect(
647+
hasServerAcknowledgedLocalDispatch({
648+
localDispatch,
649+
phase: "connecting",
650+
latestTurn: completedTurn,
651+
latestUserMessageId: MessageId.make("message-followup"),
652+
session: {
653+
...readySession,
654+
status: "starting",
655+
updatedAt: "2026-03-29T00:01:00.000Z",
656+
},
657+
hasPendingApproval: false,
658+
hasPendingUserInput: false,
659+
threadError: null,
660+
}),
661+
).toBe(false);
662+
});
663+
641664
it("acknowledges a settled newer turn", () => {
642665
const localDispatch = createLocalDispatchSnapshot(
643666
makeThread({ latestTurn: completedTurn, session: readySession }),

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ export function hasServerAcknowledgedLocalDispatch(input: {
601601
if (input.hasPendingApproval || input.hasPendingUserInput || Boolean(input.threadError)) {
602602
return true;
603603
}
604+
if (input.phase === "connecting") {
605+
return false;
606+
}
604607

605608
const latestTurn = input.latestTurn ?? null;
606609
const session = input.session ?? null;

0 commit comments

Comments
 (0)