Skip to content

fix(chat): guard history restore races - #1917

Merged
zhangmo8 merged 1 commit into
devfrom
fix/chat-history-restore-race
Jul 10, 2026
Merged

fix(chat): guard history restore races#1917
zhangmo8 merged 1 commit into
devfrom
fix/chat-history-restore-race

Conversation

@zhangmo8

@zhangmo8 zhangmo8 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • prevent an in-flight older-history load from compensating the scroll position after a session switch
  • invalidate completions using both the active session ID and restore request ID across asynchronous boundaries
  • add a regression test for switching sessions while older history is still loading

Validation

  • pnpm exec vitest --config vitest.config.renderer.ts test/renderer/components/ChatPage.test.ts --run
  • pnpm run i18n
  • pnpm run typecheck:web
  • git diff --check origin/dev...HEAD

UI layout

No visual layout changes.

Before
[Session A: history load pending] --resolves after--> [Session B scroll position overwritten]

After
[Session A: history load pending] --resolves after--> [Session B unchanged]

Summary by CodeRabbit

  • Bug Fixes

    • Improved chat history loading when switching sessions, preventing stale scroll adjustments from moving the conversation unexpectedly.
    • Preserved the current scroll position while deferred messages and session data finish loading.
  • Tests

    • Added coverage for session switching during deferred history loading.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d08507a3-b493-4579-90cd-15f45b8e2db6

📥 Commits

Reviewing files that changed from the base of the PR and between 65bd1d6 and c2c63a0.

📒 Files selected for processing (2)
  • src/renderer/src/pages/ChatPage.vue
  • test/renderer/components/ChatPage.test.ts

📝 Walkthrough

Walkthrough

loadOlderMessagesAtTop now ignores stale asynchronous history loads when the session or restore request changes. A regression test verifies that switching sessions leaves the existing scroll position unchanged until the new session load completes.

Changes

Chat history session safety

Layer / File(s) Summary
Guard history scroll compensation
src/renderer/src/pages/ChatPage.vue, test/renderer/components/ChatPage.test.ts
loadOlderMessagesAtTop checks session and restore request identity before and after asynchronous work, with a test covering session switching during deferred history loading.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: fixing chat history restore race conditions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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/chat-history-restore-race

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.

@zhangmo8
zhangmo8 merged commit 49546ea into dev Jul 10, 2026
2 checks passed
@zhangmo8
zhangmo8 deleted the fix/chat-history-restore-race branch July 10, 2026 06:01
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