Skip to content

fix(sidebar): fix session list block (#1762)#1772

Merged
zhangmo8 merged 2 commits into
devfrom
fix/sidebar-history-pagination-stuck
Jun 16, 2026
Merged

fix(sidebar): fix session list block (#1762)#1772
zhangmo8 merged 2 commits into
devfrom
fix/sidebar-history-pagination-stuck

Conversation

@zhangmo8

@zhangmo8 zhangmo8 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

问题

Closes #1762

用户数据库中有 100+ 个 regular 会话(数据完整、schema 正常),但侧边栏只显示最近十几个,滚动到底部不触发"加载更多",搜索也找不到未加载的旧会话。

根因

两个相互叠加的缺陷:

  1. 页槽被子代理会话浪费:侧边栏分页请求 listLightweight 时传 includeSubagents: true,使一页 30 条混入 session_kind = 'subagent' 的会话;但显示层只渲染 regular 会话(isRegularSession),被子代理占用的名额直接消失,可见会话远少于 30。
  2. 首屏未填满视口 → 无滚动条 → 永不加载performSessionListScrollCheck 仅在 scroll 事件中触发。首屏 regular 会话太少时内容高度 < 容器高度,没有可滚动空间,scroll 永不触发,loadNextPage() 永远不被调用。

改动

  • T1 stores/ui/session.ts:首屏与翻页分页请求 includeSubagents: true → false,让后端按 WHERE session_kind='regular' 分页,页槽不再被子代理会话浪费。
  • T2 components/WindowSideBar.vue:新增 ensureSessionListFilled(),加载/过滤变化后检测 scrollHeight <= clientHeight && hasMore,未填满则循环 loadNextPage() 直到填满或无更多数据;带重入锁 + 50 轮上限 + "无新增即停"兜底。

主进程 4 处 includeSubagents: true.list()(agent 迁移/删除/级联删),与本修复无关,未改动。

行为对比

BEFORE                              AFTER
┌─ Sidebar ───────────┐            ┌─ Sidebar ───────────┐
│ Today               │            │ Today               │
│  · chat A           │            │  · chat A           │
│  · chat B           │            │  · chat B  ...      │
│ (十几条后停住)       │            │ Yesterday           │
│ [无滚动条]           │            │  · chat ...         │
│ [旧会话无法加载]      │   ──▶      │ Last 7 days         │
│                     │            │  · chat ...         │
│                     │            │ [可滚动, 持续加载]    │
└─────────────────────┘            │ [全部 regular 可见]  │
                                   └─────────────────────┘

测试

  • sessionStore.test.ts:+3 例(首屏/翻页 includeSubagents=false、cursor 推进与累积去重、hasMore=false 不再请求)
  • WindowSideBar.test.ts:+2 例(未填满视口持续加载至 hasMore=false、无更多数据不自动加载)
  • 相关套件 70 例全绿;format / lint / architecture guard / typecheck 通过

后续

侧边栏搜索接入后端 FTS(命中未加载的历史会话)按计划留作独立后续 PR,不阻塞本次根治。

SDD

docs/issues/sidebar-history-pagination-stuck/(spec / plan / tasks)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed sidebar history pagination getting stuck by excluding sub-agent sessions from pagination requests.
    • Added automatic session loading to fill the viewport when the session list is too short.
  • Documentation

    • Added implementation plan, technical specification, and task breakdown for the pagination fix.
  • Tests

    • Added test coverage for sidebar viewport auto-fill behavior and session pagination.

zhangmo8 added 2 commits June 16, 2026 12:40
侧边栏只展示 regular 会话,但分页请求携带 includeSubagents:true,
使一页 30 条结果混入子代理会话并被显示层过滤,导致可见会话远少于一页。
改为 includeSubagents:false,让后端按 session_kind='regular' 分页。

Refs #1762
首屏返回的 regular 会话过少时列表内容不足以撑出滚动条,scroll 事件
永不触发,loadNextPage 永远不会被调用。新增 ensureSessionListFilled,
加载/过滤变化后检测视口是否填满,未满且仍有更多数据则继续加载,
并以重入锁与轮数上限兜底。

Closes #1762
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR fixes sidebar history pagination getting stuck (issue #1762) by setting includeSubagents: false in both loadSessionPage calls so subagent sessions no longer consume pagination slots, and by adding an ensureSessionListFilled auto-fill loop in WindowSideBar.vue that proactively loads pages when the list is too short to trigger scroll-based pagination. New tests and issue documentation accompany both changes.

Changes

Sidebar History Pagination Fix

Layer / File(s) Summary
Exclude subagents from session store pagination
src/renderer/src/stores/ui/session.ts, test/renderer/stores/sessionStore.test.ts
Both the initial and next-page listLightweight calls now pass includeSubagents: false. Three new store tests confirm the flag is present on first load, preserved with the cursor on subsequent pages, and that no request is issued after hasMore is false.
Viewport auto-fill loop in WindowSideBar
src/renderer/src/components/WindowSideBar.vue, test/renderer/components/WindowSideBar.test.ts
Adds ensureSessionListFilled with an isFillingSessionList reentrancy guard and max-rounds cap. A watch on session length, hasMore, loading, and sidebarSelectedAgentId triggers the fill immediately. Tests extend the mock sessionStore with loadNextPage and assert fill-until-exhaustion and no-op-when-already-done behaviors.
Issue spec, plan, and task documents
docs/issues/sidebar-history-pagination-stuck/*
Adds spec.md (root-cause analysis, acceptance criteria), plan.md (implementation approach including optional backend FTS), and tasks.md (phased task checklist T1–T4).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hoppity-hop through the session list wide,
Sub-agents no longer shall sneak inside!
My ensureFilled loop keeps on turning the page,
No viewport goes empty — I've freed every cage.
The history loads, not a record is missed,
✨ The pagination bug? It no longer exists!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix(sidebar): fix session list block (#1762)' is related to the changeset but uses vague language ('block') and is somewhat redundant ('fix...fix'). While it references the issue number and general area, it lacks specificity about the actual changes (pagination fix and auto-fill mechanism). Consider a more specific title like 'fix(sidebar): fix pagination and auto-fill session list (#1762)' to better convey the actual changes being made.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR fully addresses issue #1762 by implementing both required fixes: excluding subagent sessions from pagination and auto-filling the viewport when initial load is incomplete.
Out of Scope Changes check ✅ Passed All changes directly support the stated objectives: documentation, pagination fix, viewport auto-fill logic, and comprehensive test coverage for the specific issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 fix/sidebar-history-pagination-stuck

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.

@zhangmo8 zhangmo8 changed the title fix(sidebar): 修复历史会话分页加载卡死 (#1762) fix(sidebar): fix session list block (#1762) Jun 16, 2026

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
docs/issues/sidebar-history-pagination-stuck/plan.md (1)

40-49: ⚡ Quick win

Split the sidebar FTS search work out of this pagination-fix issue.

T3 is a separate feature with its own backend/API surface, so keeping it in the same spec/plan/tasks makes this PR read as if it includes search work even though the current fix is about pagination and viewport auto-fill. Please move the FTS item to its own issue doc, or mark it explicitly out-of-scope here.

  • docs/issues/sidebar-history-pagination-stuck/plan.md#L40-L49: move T3 into a separate plan or mark it as future work only.
  • docs/issues/sidebar-history-pagination-stuck/spec.md#L34-L37: trim the user story to the pagination fix unless search is actually in scope.
  • docs/issues/sidebar-history-pagination-stuck/tasks.md#L21-L27: remove T3 from this task list or point it at the separate search issue.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/issues/sidebar-history-pagination-stuck/plan.md` around lines 40 - 49,
The sidebar FTS search enhancement (Change 3 / T3) is a separate feature that
should not be part of this pagination-fix issue. In
docs/issues/sidebar-history-pagination-stuck/plan.md lines 40-49, remove or mark
the FTS search work as explicitly out-of-scope future work rather than a
deliverable of this issue. In
docs/issues/sidebar-history-pagination-stuck/spec.md lines 34-37, trim the user
story to focus only on the pagination and viewport auto-fill fix, removing any
search-related requirements. In
docs/issues/sidebar-history-pagination-stuck/tasks.md lines 21-27, remove task
T3 from the task list entirely or replace it with a reference to a separate
search issue if one will be created, so this PR is clearly scoped to pagination
work only.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@docs/issues/sidebar-history-pagination-stuck/plan.md`:
- Around line 40-49: The sidebar FTS search enhancement (Change 3 / T3) is a
separate feature that should not be part of this pagination-fix issue. In
docs/issues/sidebar-history-pagination-stuck/plan.md lines 40-49, remove or mark
the FTS search work as explicitly out-of-scope future work rather than a
deliverable of this issue. In
docs/issues/sidebar-history-pagination-stuck/spec.md lines 34-37, trim the user
story to focus only on the pagination and viewport auto-fill fix, removing any
search-related requirements. In
docs/issues/sidebar-history-pagination-stuck/tasks.md lines 21-27, remove task
T3 from the task list entirely or replace it with a reference to a separate
search issue if one will be created, so this PR is clearly scoped to pagination
work only.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90ed45c1-2537-4bd8-adda-0708abee4a45

📥 Commits

Reviewing files that changed from the base of the PR and between 39bebe9 and c6f8d2f.

📒 Files selected for processing (7)
  • docs/issues/sidebar-history-pagination-stuck/plan.md
  • docs/issues/sidebar-history-pagination-stuck/spec.md
  • docs/issues/sidebar-history-pagination-stuck/tasks.md
  • src/renderer/src/components/WindowSideBar.vue
  • src/renderer/src/stores/ui/session.ts
  • test/renderer/components/WindowSideBar.test.ts
  • test/renderer/stores/sessionStore.test.ts

@zhangmo8 zhangmo8 merged commit c98213c into dev Jun 16, 2026
3 checks passed
@zhangmo8 zhangmo8 deleted the fix/sidebar-history-pagination-stuck branch June 16, 2026 04:48
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.

[BUG] 对话历史无法加载

1 participant