Skip to content

refactor(sidebar): move the sidebar's time rules into shared pure reducers - #29943

Merged
Jinwoo-H merged 2 commits into
mainfrom
jinwoo/sidebar-temporal-reducers
Oct 17, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
jinwoo/sidebar-temporal-reducers

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​123 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​119
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​118 $\color{#cf222e}{\Huge{\mathbf{−}}}$​37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81

ELI5

The sidebar has a few rules that depend on time: wait three seconds before re-sorting after activity, keep Smart sort on the saved order until the first live signal, and keep a just-slept workspace visible briefly. Today those rules are tangled up with the window's timers and React code. This PR pulls the rules out into small plain functions that take the current time as an input. The window still runs them exactly as before, so nothing looks different.

What Changed

Before and after for the user: no change.

Mechanism:

  • src/shared/sidebar-list/sort-settle.ts (new): reduceSortSettle(state, event, now) returns the next state, including the settle deadline, and whether to settle now. Events are a store write or the deadline firing. The rules are the same as before: a bump restarts the three-second window, adds and removes settle at once (compared against the row count at the last bump), Manual and a mode switch settle at once, and a write that lands settled clears the deadline.
  • src/renderer/src/store/settled-sort-epoch.ts: now a thin driver. It turns each store write into an event, holds the one timer that follows the reducer's deadline, and writes settledSortEpoch.
  • src/shared/sidebar-list/smart-sort-phase.ts (new): names Smart's cold and live phases, and when ranks follow the saved order. use-sort-order.ts uses these instead of inline checks. The latch is still a ref in the hook, so it still resets when the list unmounts.
  • sleeping-sweep-retention.ts moved unchanged from the renderer to src/shared/sidebar-list/. Its hook already drove it with a timer.
  • The "Recent" create grace was already a shared function that takes now, so it stays where it is.

Why

A later PR will run these decisions once in the background process and publish the results, so a phone and the desktop show the same order. That needs the rules to be pure functions with no clock, timers or React inside. Moving them now, while the window still drives them, keeps that later PR small and makes this one easy to check: same rules, new home.

The Smart comparator and its attention scoring stay in the renderer for now. Moving them pulls in five renderer modules and about a hundred import sites, and it would collide with the parallel text-order change to the same comparator. They can move in the PR that first runs them in the background process.

Linked Issue

N/A, part of the sidebar list refactor that started with #29906.

Visual Proof

N/A. This is a refactor with no visible or interaction change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New tests with an explicit clock: a settle burst restarting its window, adds and removes settling at once, Manual and mode switch, a settled write clearing the deadline, the Smart phases, the latch holding after its signal ends and resetting on unmount, and the exact create-grace boundary. I checked that the latch test fails when the latch is broken. The existing sidebar tests, the golden list fixtures and the store settle tests pass unchanged (804 test files under src/shared/sidebar-list, src/shared/workspace-view, src/renderer/src/store, src/renderer/src/components/sidebar). pnpm tc and the changed-code quality gate pass.

Review

A separate review found no behaviour change. Applied from it: the reducer now owns the Manual and mode-switch rule instead of getting a ready-made flag, and the write event type no longer allows a bump without a row count.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer only, with pure shared code. No wire, SSH, mobile or platform impact.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ebe47bef-9f42-4a5a-b14e-e3e5968a6e5e
📥 Commits

Reviewing files that changed from the base of the PR and between 633df3a and c61e8af.

📒 Files selected for processing: 14
  • src/renderer/src/components/sidebar/hide-sleeping-transient-pty-gap.test.ts
  • src/renderer/src/components/sidebar/worktree-list/listing/use-sleeping-sweep-retention.ts
  • src/renderer/src/components/sidebar/worktree-list/listing/use-sort-order.test.tsx
  • src/renderer/src/components/sidebar/worktree-list/listing/use-sort-order.ts
  • src/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees-retention.test.tsx
  • src/renderer/src/store/settled-sort-epoch.test.ts
  • src/renderer/src/store/settled-sort-epoch.ts
  • src/shared/sidebar-list/sleeping-sweep-retention.test.ts
  • src/shared/sidebar-list/sleeping-sweep-retention.ts
  • src/shared/sidebar-list/smart-sort-phase.test.ts
  • src/shared/sidebar-list/smart-sort-phase.ts
  • src/shared/sidebar-list/sort-settle.test.ts
  • src/shared/sidebar-list/sort-settle.ts
  • src/shared/workspace-view/workspace-row-filters.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📝 Walkthrough

The change adds shared helpers for Smart sort phases and sort-settle state. The worktree sort hook and renderer store use those helpers. Tests cover Smart ordering, settle events, and the create-grace boundary. Sidebar retention imports now use the shared sidebar-list module path.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to c61e8

No merge-blocking sidebar behavior issue is established; this change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: moving sidebar time-dependent rules into shared pure reducers.
Description check Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked refactor context, testing, scope, and checklist status. Visual proof is correc…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked refactor context, testing, scope, and checklist status. Visual proof is correctly marked N/A for a refactor with no visible change.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H
Jinwoo-H merged commit 7bf3e15 into main Oct 17, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant