Skip to content

feat(session): persist sidebar group mode preference#1434

Merged
zerob13 merged 2 commits intodevfrom
feat/default_sort_by_project
Apr 7, 2026
Merged

feat(session): persist sidebar group mode preference#1434
zerob13 merged 2 commits intodevfrom
feat/default_sort_by_project

Conversation

@zerob13
Copy link
Copy Markdown
Collaborator

@zerob13 zerob13 commented Apr 7, 2026

Summary by CodeRabbit

  • New Features

    • Sidebar grouping preference is now persisted and restored across sessions.
  • Changes

    • Default sidebar grouping mode changed from 'time' to 'project'.
    • Grouping preference is loaded before sessions are shown to ensure consistent grouping.
  • Bug Fixes

    • Invalid or failed preference loads now fall back to 'project' to avoid inconsistent state.
  • Tests

    • Added tests for persistence, rollback on save failure, concurrent toggles, and path-label behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

📝 Walkthrough
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding persistence for the sidebar group mode preference, which is confirmed by the file-level summaries showing added preference storage and async loading/toggling logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/default_sort_by_project

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
test/renderer/stores/sessionStore.test.ts (1)

231-252: Add an overlapping-toggle regression test.

These cases only exercise one in-flight toggleGroupMode(). They will still pass if two back-to-back toggles persist out of order, so the main async race in the new store logic is currently untested.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/renderer/stores/sessionStore.test.ts` around lines 231 - 252, Add a
regression test that simulates overlapping in-flight toggles to cover the async
race in toggleGroupMode: use setupStore to get { store, configPresenter,
settings } (or with failSetSetting: true for failure case), call await
store.fetchSessions(), then trigger two back-to-back store.toggleGroupMode()
calls without awaiting the first (e.g., start first toggle and immediately start
second) to ensure persistence ordering is respected; assert final
store.groupMode.value is the expected final mode, assert
configPresenter.setSetting was called with SIDEBAR_GROUP_MODE_KEY and the
correct values in order (and in the failure case that the store rolls back to
the previous mode and setSetting was still invoked with the attempted value).
Ensure the test references toggleGroupMode, fetchSessions, setupStore,
configPresenter.setSetting, and SIDEBAR_GROUP_MODE_KEY so it exercises the
overlapping-toggle race.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/renderer/src/stores/ui/session.ts`:
- Around line 170-172: Concurrent toggles call setSetting(...) simultaneously;
create a serialized write chain (e.g., add a new module-level Promise variable
like groupModeWritePromise) and modify toggleGroupMode to: increment
groupModeUpdateVersion, capture that version in a local variable, append the new
write to groupModeWritePromise = (groupModeWritePromise ??
Promise.resolve()).then(async () => { await setSetting('sidebar_group_mode',
groupMode.value); if (localVersion !== groupModeUpdateVersion) return; }) so
writes run sequentially and only the last captured version is allowed to "win";
apply the same promise-chain+version-guard pattern to the other block that
performs setSetting (the code referenced around the second occurrence) to ensure
the last toggle persists.
- Around line 48-49: The groupByProject() logic uses dir.split('/').pop() which
fails on Windows backslashes; update the label extraction to be
separator-agnostic by using Node's path.basename(dir) (ensure you import path
from 'path') or, if you prefer no import, replace the split with a regex split
like dir.split(/[\\/]/).pop() and keep the '__no_project__' special-case (e.g.,
label: dir === '__no_project__' ? 'common.project.none' : (path.basename(dir) or
(dir.split(/[\\/]/).pop() ?? dir))). Ensure the change is applied where dir is
used to build the label in groupByProject().

---

Nitpick comments:
In `@test/renderer/stores/sessionStore.test.ts`:
- Around line 231-252: Add a regression test that simulates overlapping
in-flight toggles to cover the async race in toggleGroupMode: use setupStore to
get { store, configPresenter, settings } (or with failSetSetting: true for
failure case), call await store.fetchSessions(), then trigger two back-to-back
store.toggleGroupMode() calls without awaiting the first (e.g., start first
toggle and immediately start second) to ensure persistence ordering is
respected; assert final store.groupMode.value is the expected final mode, assert
configPresenter.setSetting was called with SIDEBAR_GROUP_MODE_KEY and the
correct values in order (and in the failure case that the store rolls back to
the previous mode and setSetting was still invoked with the attempted value).
Ensure the test references toggleGroupMode, fetchSessions, setupStore,
configPresenter.setSetting, and SIDEBAR_GROUP_MODE_KEY so it exercises the
overlapping-toggle race.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ae17a85e-324b-4098-8443-a3254b47503b

📥 Commits

Reviewing files that changed from the base of the PR and between 82a69d9 and f65455f.

📒 Files selected for processing (2)
  • src/renderer/src/stores/ui/session.ts
  • test/renderer/stores/sessionStore.test.ts

Comment on lines +170 to +172
let groupModeLoadPromise: Promise<void> | null = null
let hasLoadedGroupMode = false
let groupModeUpdateVersion = 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Serialize the preference writes so the last toggle wins.

groupModeUpdateVersion only guards the in-memory rollback. Two quick toggleGroupMode() calls still issue concurrent setSetting(...) writes, so the slower first write can finish last and leave sidebar_group_mode persisted with the wrong value even though groupMode.value already reflects the newer mode.

Also applies to: 428-442

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/src/stores/ui/session.ts` around lines 170 - 172, Concurrent
toggles call setSetting(...) simultaneously; create a serialized write chain
(e.g., add a new module-level Promise variable like groupModeWritePromise) and
modify toggleGroupMode to: increment groupModeUpdateVersion, capture that
version in a local variable, append the new write to groupModeWritePromise =
(groupModeWritePromise ?? Promise.resolve()).then(async () => { await
setSetting('sidebar_group_mode', groupMode.value); if (localVersion !==
groupModeUpdateVersion) return; }) so writes run sequentially and only the last
captured version is allowed to "win"; apply the same promise-chain+version-guard
pattern to the other block that performs setSetting (the code referenced around
the second occurrence) to ensure the last toggle persists.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/renderer/src/stores/ui/session.ts`:
- Around line 193-205: The store currently treats
configPresenter.getSetting/setSetting as throwing, but the real presenter API is
synchronous/non-throwing (getSetting returns T|undefined, setSetting returns
void and logs errors), so update the store to match that contract: remove
try/catch rollback paths in loadGroupModePreference and in toggleGroupMode
(referencing loadGroupModePreference, groupModeUpdateVersion, groupMode,
DEFAULT_GROUP_MODE, toggleGroupMode, and configPresenter.getSetting/setSetting),
treat missing savedGroupMode as undefined and fall back to DEFAULT_GROUP_MODE,
and remove test-only behaviors (failSetSetting) that expect thrown errors —
instead adapt tests to the non-throwing behavior or add an explicit
error-returning presenter if you want to test rollback semantics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 216813cb-e7f9-4487-9b1e-de275bbd8f2b

📥 Commits

Reviewing files that changed from the base of the PR and between f65455f and d26893c.

📒 Files selected for processing (2)
  • src/renderer/src/stores/ui/session.ts
  • test/renderer/stores/sessionStore.test.ts

Comment on lines +193 to +205
const loadGroupModePreference = async (): Promise<void> => {
const loadVersion = groupModeUpdateVersion

try {
const savedGroupMode = await configPresenter.getSetting<GroupMode>(SIDEBAR_GROUP_MODE_KEY)
if (groupModeUpdateVersion === loadVersion) {
groupMode.value = normalizeGroupMode(savedGroupMode)
}
} catch (error) {
if (groupModeUpdateVersion === loadVersion) {
groupMode.value = DEFAULT_GROUP_MODE
}
console.warn('[sessionStore] Failed to load sidebar group mode:', error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

These rollback/error paths don't match the real configPresenter contract.

src/shared/types/presenters/legacy.presenters.d.ts defines getSetting() as T | undefined and setSetting() as void, and src/main/presenter/configPresenter/index.ts catches/logs its own exceptions. In production, Lines 201-205 and Lines 440-445 will not see rejected calls here. The risky part is the save path: if persistence fails, toggleGroupMode() keeps the optimistic UI state instead of rolling back, and the new failSetSetting tests only pass because the mock throws in a way the real presenter does not. Please either surface failures from the presenter explicitly or simplify this store/tests to the current sync, non-throwing API.

Also applies to: 434-445

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/src/stores/ui/session.ts` around lines 193 - 205, The store
currently treats configPresenter.getSetting/setSetting as throwing, but the real
presenter API is synchronous/non-throwing (getSetting returns T|undefined,
setSetting returns void and logs errors), so update the store to match that
contract: remove try/catch rollback paths in loadGroupModePreference and in
toggleGroupMode (referencing loadGroupModePreference, groupModeUpdateVersion,
groupMode, DEFAULT_GROUP_MODE, toggleGroupMode, and
configPresenter.getSetting/setSetting), treat missing savedGroupMode as
undefined and fall back to DEFAULT_GROUP_MODE, and remove test-only behaviors
(failSetSetting) that expect thrown errors — instead adapt tests to the
non-throwing behavior or add an explicit error-returning presenter if you want
to test rollback semantics.

@zerob13 zerob13 merged commit 624cefc into dev Apr 7, 2026
3 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