Skip to content

fix(console): preserve chat messages when updateSession is called#1481

Open
leoleils wants to merge 3 commits intoagentscope-ai:mainfrom
leoleils:bugfix/chat-session-messages-lost
Open

fix(console): preserve chat messages when updateSession is called#1481
leoleils wants to merge 3 commits intoagentscope-ai:mainfrom
leoleils:bugfix/chat-session-messages-lost

Conversation

@leoleils
Copy link

Problem

When switching pages (e.g. to MCP or Model settings) during an LLM streaming response or tool call, chat messages in the current session are lost and cannot be recovered even after refreshing.

Root Cause

SessionApi.updateSession (in console/src/pages/Chat/sessionApi/index.ts) had session.messages = [] on its first line, which forcefully cleared the messages array on every call. When the UI called updateSession to sync session metadata during streaming, the empty messages array overwrote the existing messages in sessionList via the spread operator { ...this.sessionList[index], ...session }.

Fix

  • Removed session.messages = []
  • Used destructuring const { messages, ...metadataUpdate } = session to exclude the messages field from the merge, so updateSession only touches metadata (name, realId resolution, etc.)
  • All other logic (realId resolution, fallback refresh, return value) remains unchanged

Tests

Added property-based tests (vitest + fast-check):

  • Bug condition test: confirms messages are preserved after updateSession
  • Preservation tests: verifies metadata update, realId resolution, fallback refresh, and return value behavior remain unchanged

Remove the erroneous session.messages = [] assignment in
SessionApi.updateSession that cleared existing messages on every
metadata update. Use destructuring to exclude the messages field
from the spread merge, ensuring only metadata is updated while
chat history is preserved.

Add vitest + fast-check property-based tests to verify the fix
and prevent regression.
@github-actions github-actions bot added the first-time-contributor PR created by a first time contributor label Mar 14, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the chat session management where chat messages were inadvertently cleared when updateSession was invoked. The fix ensures that message data is preserved during session metadata updates, preventing data loss in the UI. Additionally, comprehensive property-based tests have been introduced to validate the fix and maintain the integrity of other session management functionalities.

Highlights

  • Bug Fix: Chat Message Preservation: Resolved an issue where chat messages were lost when updateSession was called, particularly during LLM streaming or tool calls, due to an erroneous session.messages = [] assignment.
  • Refactored Session Update Logic: Modified the updateSession method to use object destructuring (const { messages, ...metadataUpdate } = session) to ensure only session metadata is updated, leaving the messages array untouched.
  • Introduced Property-Based Testing: Added comprehensive property-based tests using vitest and fast-check to validate the bug fix and confirm that other expected behaviors of updateSession (metadata updates, realId resolution, fallback refresh, return value) remain unchanged.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • console/package-lock.json
    • Added fast-check and vitest dependencies, along with their transitive dependencies.
    • Removed some nested fdir, picomatch, and tinyglobby entries from node_modules/@typescript-eslint/typescript-estree/node_modules and node_modules/vite/node_modules.
    • Removed pathe and tinyexec from node_modules/mermaid/node_modules.
    • Added new top-level fdir, pathe, picomatch, tinyexec, tinyrainbow, obug, siginfo, stackback, std-env, why-is-node-running, expect-type, magic-string, pure-rand, chai, assertion-error, and @vitest/* packages.
  • console/package.json
    • Added fast-check and vitest as dev dependencies.
  • console/src/pages/Chat/sessionApi/index.ts
    • Refactored updateSession to prevent clearing chat messages by destructuring the session object and only merging metadata.
    • Updated the tempId assignment to use the destructured metadataUpdate.id.
  • console/src/pages/Chat/sessionApi/sessionApi.test.ts
    • Added new test file containing property-based tests for SessionApi.updateSession to verify message preservation and other functionalities.
  • console/vitest.config.ts
    • Added new Vitest configuration file for running tests, including path aliases and test environment settings.
Activity
  • The pull request introduces a fix for a known bug where chat messages were lost during session updates.
  • New testing infrastructure (vitest, fast-check) has been set up to ensure the robustness of the fix and prevent regressions.
  • The changes include both bug resolution and the addition of comprehensive tests, indicating a thorough approach to quality assurance.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug that caused chat messages to be lost when updating a session. The approach of using object destructuring to separate metadata from messages is clean and effective. The addition of property-based tests using vitest and fast-check is a great improvement, ensuring the fix is robust and preventing future regressions. I have one suggestion to enhance type safety in the implementation.

leoleils and others added 2 commits March 15, 2026 12:49
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time-contributor PR created by a first time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant