The best way to control Claude Code, Codex and more from any computer or phone
fix(client-runtime): last user message sort ignores agent-posted messages (#33873)
Julius Marminge committed
Nov 12, 2026 at 16:05 UTC
c1b42c17dc1466aba893ef180b23a8413a132ea9
3 files changed
+34
-8
packages/client-runtime/src/state/threadSearch.ts
+1
-8
@@ -246,14 +246,7 @@ function buildThreadSearchSubject(
246
projectTitle: string | null | undefined,
247
environmentLabel: string | null | undefined,
248
): ThreadSearchSubject {
249
- // What the user wrote, not agent wakes or task notices in the user role. A
250
- // thread the user never wrote in counts from its creation; an older server
251
- // omits the field, so the latest user-role message stands in.
252
- const authored = thread.latestUserAuthoredMessageAt;
253
- const activityAt =
254
- authored === undefined
255
- ? getThreadSortTimestamp(thread, "updated_at")
256
- : Date.parse(authored ?? thread.createdAt);
249
+ const activityAt = getThreadSortTimestamp(thread, "updated_at");
250
const localOpenedAt = localThreadOpens.get(`${thread.environmentId}:${thread.id}`) ?? 0;
251
return {
252
id: thread.id,
packages/client-runtime/src/state/threadSort.test.ts
+20
@@ -172,6 +172,26 @@ describe("sortThreads", () => {
172
173
expect(sorted.map((thread) => thread.id)).toEqual(["thread-1", "thread-2"]);
174
});
175
+
176
+ it("orders last user message by what the user wrote, not agent messages in the user role", () => {
177
+ const sorted = sortThreads(
178
+ [
179
+ makeThread({
180
+ id: "agent-posted",
181
+ latestUserAuthoredMessageAt: "2026-03-09T10:00:00.000Z",
182
+ latestUserMessageAt: "2026-03-09T10:30:00.000Z",
183
+ }),
184
+ makeThread({
185
+ id: "user-wrote",
186
+ latestUserAuthoredMessageAt: "2026-03-09T10:10:00.000Z",
187
+ latestUserMessageAt: "2026-03-09T10:10:00.000Z",
188
+ }),
189
+ ],
190
+ "updated_at",
191
+ );
192
+
193
+ expect(sorted.map((thread) => thread.id)).toEqual(["user-wrote", "agent-posted"]);
194
+ });
195
});
196
197
describe("planPinnedReorder with hidden rows", () => {
packages/client-runtime/src/state/threadSort.ts
+13
@@ -6,6 +6,7 @@ export interface ThreadSortInput {
6
readonly createdAt: string;
7
readonly updatedAt: string;
8
readonly latestUserMessageAt?: string | null;
9
+ readonly latestUserAuthoredMessageAt?: string | null;
10
readonly messages?: ReadonlyArray<{
11
readonly createdAt: string;
12
readonly role: string;
@@ -80,6 +81,18 @@ function getFirstSortableTimestamp(...values: Array<string | null | undefined>):
81
}
82
83
function getLatestUserMessageTimestamp(thread: ThreadSortInput): number {
84
+ // Agents also post in the user role; only what the user wrote counts. A thread
85
+ // the user never wrote in counts from its creation; older servers omit the field.
86
+ if (thread.latestUserAuthoredMessageAt !== undefined) {
87
+ return (
88
+ getFirstSortableTimestamp(
89
+ thread.latestUserAuthoredMessageAt,
90
+ thread.createdAt,
91
+ thread.updatedAt,
92
+ ) ?? Number.NEGATIVE_INFINITY
93
+ );
94
+ }
95
+
96
if (thread.latestUserMessageAt) {
97
const latestUserMessageTimestamp = toSortableTimestamp(thread.latestUserMessageAt);
98
if (latestUserMessageTimestamp !== null) {