-
Notifications
You must be signed in to change notification settings - Fork 16
fix: sidebar session staleness and sort ordering #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mattleaverton
merged 5 commits into
danshapiro:main
from
mattleaverton:fix/sidebar-session-staleness
Mar 31, 2026
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
33003ac
fix: sync WebSocket patches to all session windows, not just active s…
mattleaverton c76b4c3
fix: use max(ratchetedActivity, serverTimestamp) for activity sort
mattleaverton 2391ad2
fix: remove ratchetedActivity from sidebar sort
mattleaverton 1c5c551
fix: skip error dispatch when preserveLoadingState is true
mattleaverton ff20cbd
fix: restore ratchetedActivity sort and rename sort mode labels
mattleaverton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Fix Sidebar Session Staleness | ||
|
|
||
| ## Goal | ||
|
|
||
| The sidebar session list goes stale and never recovers. Fresh data arrives from the server every few seconds (confirmed: 200 OK, 50 items), gets committed to Redux (`resultVersion` incrementing), but the sidebar renders old data. Fix the root causes so the sidebar always reflects current server state. | ||
|
|
||
| ## Root Causes (confirmed via live profiling on localhost:3347) | ||
|
|
||
| ### 1. Window/top-level state divergence (primary cause) | ||
|
|
||
| `sidebarSelectors.ts:38` reads `sessions.windows.sidebar.projects`, falling back to `sessions.projects`. WebSocket patches update `sessions.projects` (top-level) and sync only to the **active** surface via `syncActiveWindowFromTopLevel()`. When sidebar isn't active, its window state goes stale — and the selector always picks the stale window data over the fresh top-level data because it exists. | ||
|
|
||
| Key locations: | ||
| - `src/store/selectors/sidebarSelectors.ts:38` — selector reads stale window state | ||
| - `src/store/sessionsSlice.ts:152` — `syncActiveWindowFromTopLevel()` only syncs active surface | ||
| - `src/store/sessionsSlice.ts:243-245, 263-265` — commit guards skip sync when not active | ||
| - `src/store/sessionsThunks.ts:609-614` — `queueActiveSessionWindowRefresh()` only refreshes active surface | ||
|
|
||
| ### 2. Silent error swallowing in refresh path | ||
|
|
||
| `refreshVisibleSessionWindowSilently()` (sessionsThunks.ts:420-427) catches all errors and just sets `loading: false`. No retry, no error state surfaced, no logging. If a refresh fails, sidebar stays stale forever. | ||
|
|
||
| ### 3. Zero observability | ||
|
|
||
| `sessionsThunks.ts` has zero `console.log`, `console.warn`, or `console.error` calls. The entire refresh coordination system (generation checks, identity matching, commit/discard decisions) is completely silent. Makes debugging impossible. | ||
|
|
||
| ## Approach | ||
|
|
||
| Fix the selector to always use fresh data, add recovery mechanisms for failed refreshes, and add logging so these issues are visible in the future. Verify with a running server using Chrome browser automation. | ||
|
|
||
| ## Verification Criteria | ||
|
|
||
| 1. **Sidebar stays fresh**: With a running dev server, create new Claude sessions and verify they appear in the sidebar within seconds — not just in Redux state, but in the rendered DOM. | ||
| 2. **Surface switching doesn't cause staleness**: Switch between sidebar and history surfaces, verify sidebar data stays current after switching back. | ||
| 3. **Error recovery**: Simulate a failed fetch (e.g., kill server briefly), verify sidebar recovers on next successful fetch rather than staying stale forever. | ||
| 4. **Logging exists**: Key decision points in the refresh flow (commit, discard, error, retry) emit debug-level log messages. | ||
| 5. **All existing tests pass**: `npm run check` green. | ||
| 6. **No regressions in history view**: History surface still works correctly since it shares the same window system. |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
refreshVisibleSessionWindowSilentlyruns withpreserveLoadingState: true(the search/requested-vs-visible drift path), this newsetSessionWindowErrordispatch clearsloadingKindin the reducer even though the foreground request is still loading. That breaks the contract ofpreserveLoadingStateand can hide the active search/loading indicator while the in-flight visible fetch is still running, which is especially reproducible when the background refresh fails transiently during a query transition.Useful? React with 👍 / 👎.