refactor(clients): share thread list v2 sort in client-runtime - #5144
refactor(clients): share thread list v2 sort in client-runtime#5144t3dotgg wants to merge 1 commit into
Conversation
Web and mobile each carried their own copy of the v2 active-list priority derivation and settled-tail ordering, and mobile's settled tail ignored settledAt entirely, so the two clients could disagree on order. The priority rule (threadListV2Priority) and the settled sort (sortSettledThreadsForListV2 + resolveSettledTimestamp) now live in @t3tools/client-runtime/state/thread-sort next to sortThreadsForListV2. Priority derives only from server-backed state (wokeAt, settledOverride), so every client and device renders the same order by construction. Mobile's settled rows also adopt the shared timestamp resolver for their time label so label and order can't disagree. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 816ff2d This PR consolidates duplicate thread sorting logic from web and mobile apps into the shared client-runtime package. The sorting behavior is preserved, with one intentional improvement: mobile's settled thread timestamps now align with their sort order. Tests are comprehensive and moved to the shared package. You can customize Macroscope's approvability policy. Learn more. |
Stacked on #4745.
Web and mobile each carried their own copy of the thread list v2 ordering rules: the active-list priority callback was duplicated at both call sites, and the settled tails used different comparators — mobile sorted by
latestUserMessageAt ?? updatedAtand ignoredsettledAtentirely, so an explicitly settled thread could land in a different position on each client.This moves the ordering rules into
@t3tools/client-runtime/state/thread-sort, next to the already-sharedsortThreadsForListV2:threadListV2Priority— the woke / un-settled / default ranking, derived only from server-backed state (wokeAt,settledOverride), so every client and device computes the same order by construction.resolveSettledTimestamp+sortSettledThreadsForListV2— moved from web'sSidebar.logic.ts; settled rows order by when the work ended (settledAt, else last activity). Mobile's settled tail now uses it too, and its slim-row time label reads from the same resolver so label and order can't disagree.Both clients delete their local copies; web's settled-sort tests moved to the shared package with the code.
Verification:
vp test run packages/client-runtime apps/mobile apps/web/src/components(1764 tests)vp run --filter @t3tools/{client-runtime,web,mobile} typecheckMade with Claude Fable 5 using Claude Code.
Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Note
Low Risk
Refactor of list ordering and display timestamps with parity tests; no auth or persistence changes. Mobile settled order may shift for threads where explicit settle time differed from last activity.
Overview
Unifies thread list v2 ordering in
@t3tools/client-runtime/state/thread-sortso web and mobile no longer maintain separate comparators.Adds
threadListV2Priority(woke → keep-active → default, from server-backedwokeAtandsettledOverride),resolveSettledTimestamp, andsortSettledThreadsForListV2(most recently “finished” first). Web and mobile partition/sort through these helpers instead of inline callbacks and web-onlySidebar.logicsettled sort.Mobile behavior change: the settled tail previously ordered by
latestUserMessageAt/updatedAtand ignoredsettledAt; it now matches web. Slim settled rows showresolveSettledTimestampso the time label matches sort order.Removes duplicated settled-sort code and tests from
Sidebar.logic; coverage lives inthreadSort.test.ts.Reviewed by Cursor Bugbot for commit 816ff2d. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Share thread list v2 sort logic in
client-runtimeacross web and mobileresolveSettledTimestamp,sortSettledThreadsForListV2, andthreadListV2Priorityintopackages/client-runtime/src/state/threadSort.ts, removing duplicated implementations fromapps/web/src/components/Sidebar.logic.ts.settledAt, else last activity including turn completion timestamps), with stable id tiebreaking, in both the web sidebar and mobile thread list.threadListV2Priorityfunction, with wake threads ranked above manual keep-active pins; wake tracking changes from aSetto aMapofkey->wokeAtin both consumers.resolveSettledTimestampto match the sort key.latestTurn.requestedAt/startedAt/completedAt), which may reorder threads that previously sorted bylatestUserMessageAtorupdatedAt.Macroscope summarized 816ff2d.