fix(sidebar): keep worktree row ordered after closing a chat - #65
Merged
Conversation
A worktree's collapsed sidebar row is positioned by its newest surviving chat — collapsing keeps the group at that chat's slot. Closing (archiving) the newest chat dropped it from the list, so the row fell back to an older sibling's timestamp and sank down the sidebar, even though closing a chat is itself a recent interaction. Record closing a chat as worktree activity in a persisted client store (`useUiStateStore.worktreeLastActivityAtByKey`, keyed by the same environment+worktree key the collapse uses) and fold that timestamp into the sidebar sort: each chat's effective sort time is the max of its own activity and its worktree's recorded activity. The row now keeps its place instead of sinking. Local (non-worktree) chats and callers that omit the map are unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the sidebar, a worktree's chats collapse into a single row positioned by the worktree's newest surviving chat (collapsing keeps the group at that chat's slot). Closing (archiving) the newest chat dropped it from the list, so the row fell back to an older sibling's timestamp and sank down the sidebar — even though closing a chat is itself a recent interaction. The bottom-right/ordering no longer reflected that the worktree was just touched.
Fix
Treat closing a chat as worktree activity and factor it into the sort:
worktreeLastActivityAtByKeytouseUiStateStore(localStorage-backed, sanitized on load likethreadLastVisitedAtById), keyed by the sameenvironmentId\0worktreePathkey the collapse uses. NewmarkWorktreeActivereducer advances the timestamp (never moves it backwards).WorktreeThreadTabs.closeTabrecords the interaction before archiving.sortThreadsForSidebarV2now takes the activity map and each chat's effective sort time ismax(own activity, worktree recorded activity), so the collapsed row keeps its place. Local (non-worktree) chats and callers that omit the map are unchanged.Tests
uiStateStore.test.ts:markWorktreeActivemonotonicity + guards; persistence/parse round-trip includes the new field.Sidebar.logic.test.ts: a surviving chat is lifted above a more-recently-active chat in another worktree once its worktree's close activity is recorded.Typecheck clean, targeted unit tests pass (132), lint clean for changed files.
🤖 Generated with Claude Code