Skip to content

Commit 7fc68b4

Browse files
sergiiopmclaude
andcommitted
fix(client-runtime): keep inbox return order after a reload
With the Working section on, the send sort only knew about returns seen since the page loaded, so a reload could reorder the inbox. Use the finished run's stored time as the return, only when the Working section is on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 792c673 commit 7fc68b4

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎packages/client-runtime/src/state/threadInbox.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,31 @@ describe("sortInboxThreadsBySend", () => {
306306
).map((entry) => entry.id),
307307
).toEqual(["returned", "unsettled", "sent"]);
308308
});
309+
310+
it("keeps a finished run's return after a reload, only with the Working section", () => {
311+
const returnedEarlier = inboxThread("returned-earlier", {
312+
latestUserAuthoredMessageAt: "2026-06-01T01:00:00.000Z",
313+
latestRun: {
314+
runId: RunId.make("run:done"),
315+
status: "completed" as const,
316+
requestedAt: "2026-06-01T01:00:00.000Z",
317+
startedAt: "2026-06-01T01:00:00.000Z",
318+
completedAt: "2026-06-01T03:00:00.000Z",
319+
assistantMessageId: null,
320+
},
321+
});
322+
const sentLater = inboxThread("sent-later", {
323+
latestUserAuthoredMessageAt: "2026-06-01T02:00:00.000Z",
324+
});
325+
// A fresh page has no observed returns yet.
326+
expect(
327+
sortInboxThreadsBySend([sentLater, returnedEarlier], () => undefined).map(
328+
(entry) => entry.id,
329+
),
330+
).toEqual(["returned-earlier", "sent-later"]);
331+
expect(sortInboxThreadsBySend([sentLater, returnedEarlier]).map((entry) => entry.id)).toEqual([
332+
"sent-later",
333+
"returned-earlier",
334+
]);
335+
});
309336
});

‎packages/client-runtime/src/state/threadInbox.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type InboxSendSortInput = InboxThreadInput &
6060
/**
6161
* Newest first by the last message the user sent. Agent activity never moves
6262
* a row; creating, un-settling, or (with the Working section) a return does.
63+
* Pass `observedReturnAt` only with the Working section on.
6364
*/
6465
export function sortInboxThreadsBySend<T extends InboxSendSortInput>(
6566
threads: readonly T[],
@@ -76,6 +77,10 @@ export function sortInboxThreadsBySend<T extends InboxSendSortInput>(
7677
? thread.latestUserMessageAt
7778
: thread.latestUserAuthoredMessageAt) ?? undefined,
7879
) ?? 0,
80+
// With the Working section, a finished run is a return; the stored time survives reloads.
81+
observedReturnAt === undefined
82+
? 0
83+
: (toSortableTimestamp(thread.latestRun?.completedAt ?? undefined) ?? 0),
7984
observedReturnAt?.(thread) ?? 0,
8085
),
8186
]),

0 commit comments

Comments
 (0)