Skip to content

Commit e8375ce

Browse files
committed
docs(site/src): name what applies an edit response and why a send applies its whole batch
1 parent 26fd057 commit e8375ce

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎site/src/api/queries/chats.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ describe("mutation invalidation scope", () => {
19011901
).toEqual([4, 3, 2, 1]);
19021902
});
19031903

1904-
it("editChatMessage leaves the messages cache to the chat page", async () => {
1904+
it("editChatMessage does not write its response to the messages cache", async () => {
19051905
const queryClient = createTestQueryClient();
19061906
const chatId = "chat-1";
19071907
queryClient.setQueryData<InfMessages>(chatMessagesKey(chatId), {

‎site/src/api/queries/chats.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,8 +2475,8 @@ type EditChatMessageMutationArgs = {
24752475
req: TypesGen.EditChatMessageRequest;
24762476
};
24772477

2478-
// The chat page applies the edit's messages, after checking that the stream
2479-
// has not already moved past them.
2478+
// useChatStore's applyEditResponse writes the edit's messages, unless the
2479+
// stream has moved past them.
24802480
export const editChatMessage = (queryClient: QueryClient, chatId: string) => ({
24812481
mutationFn: ({ messageId, req }: EditChatMessageMutationArgs) =>
24822482
API.experimental.editChatMessage(chatId, messageId, req),

‎site/src/pages/AgentsPage/components/ChatConversation/submitChatTurn.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ export async function submitChatTurn(
406406
// instead, the WebSocket event overrides this optimistic value.
407407
store.setChatStatus("running");
408408
}
409-
// Apply the full batch because a queued send can insert a promoted
410-
// head below the highest cached ID, which a reconnect would skip.
409+
// Apply every inserted message, not only response.message: a send can also
410+
// insert cancellations and a promoted queue head, whose lower IDs an
411+
// after_id reconnect would skip.
411412
const insertedMessages =
412413
response.messages ?? (response.message ? [response.message] : []);
413414
if (insertedMessages.length > 0) {

0 commit comments

Comments
 (0)