Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(chat): keep queued old frames out of selected tails

Afloat252f97f72a19
diff --git a/src/state/message-history.ts b/src/state/message-history.ts
index b35f9fc36f..fffb356416 100644
--- a/src/state/message-history.ts
+++ b/src/state/message-history.ts
@@ -95,8 +95,8 @@ export function capHeldInBackground(state: AppState, action: Action): AppState {
export const shortHeld = <T extends { messages: Message[]; hasMore?: boolean }>(owner: T | undefined): owner is T =>
Boolean(owner?.hasMore) && owner!.messages.length < MESSAGE_PAGE_SIZE;
-/** A row from before a short tail, landing in a conversation nobody has on screen (a frame queued while the snapshot was
- * read): appended, it would read as the newest row. The page before the tail brings it in order when the tail opens.
+/** A row from before a short tail (a frame queued while the snapshot was read): appended, it would read as the newest
+ * row, even if the conversation opened while its older page was loading. That page brings it in order.
* Only a row that is older than the tail and continues a row the tail does not hold counts: a row continuing the held
* rows is new, whatever its time says. */
export function olderThanHeld(state: AppState, action: Action): boolean {
@@ -105,7 +105,7 @@ export function olderThanHeld(state: AppState, action: Action): boolean {
const first = owner?.messages[0], parentId = action.message.parentId;
if (!shortHeld(owner) || first === undefined || action.message.at >= first.at || typeof parentId !== "string") return false;
if ("activeLeafId" in owner && owner.activeLeafId === parentId) return false;
- return !shownThread(state, action.threadId) && !owner.messages.some((message) => message.id === action.message.id || message.id === parentId);
+ return !owner.messages.some((message) => message.id === action.message.id || message.id === parentId);
}
export function loadOlderPage(action: LoadOlderMessages, current: AppState, inFlight: Set<string>,
diff --git a/src/state/tail-review.test.ts b/src/state/tail-review.test.ts
index 1bbd17ed7e..080e670b7a 100644
--- a/src/state/tail-review.test.ts
+++ b/src/state/tail-review.test.ts
@@ -72,6 +72,21 @@ describe("review: a queued frame older than the snapshot's tail", () => {
});
});
+describe("a selected tail while its older page is still loading", () => {
+ it("does not append a queued historical frame after the newest reply", () => {
+ const rows = Array.from({ length: 31 }, (_, index) => ({ id: `r${index}`, at: index, parentId: index ? `r${index - 1}` : null,
+ role: index === 0 ? "user" : "bot", kind: "text", text: `r${index}` }) as Message);
+ const bot = { id: "b", threadId: "t", name: "B", messages: rows.slice(11), hasMore: true, activeLeafId: "r30", tasks: [] } as unknown as Bot;
+ let state: AppState = { ...initialState, bots: [bot], selectedId: "b", activeView: "chat", loadingOlder: { t: true } };
+ state = reducer(state, { type: "messageAdded", threadId: "t", message: rows[5]! });
+ expect(state.bots[0]!.messages.at(-1)?.id).toBe("r30");
+ expect(state.bots[0]!.activeLeafId).toBe("r30");
+ state = reducer(state, { type: "olderMessages", threadId: "t", generation: 0, before: "r11", messages: rows.slice(0, 11), hasMore: false });
+ expect(state.bots[0]!.messages).toEqual(rows);
+ expect(visibleMessages(state.bots[0]!)).toEqual(rows);
+ });
+});
+
describe("review: the Computer panel's recently changed files on a tailed bot (opened from the Team map, no chat drawn)", () => {
it("lists the same files as a whole page once the bot is selected and the page before its tail lands", async () => {
const rows: Row[] = [];