Skip to content

🐛 fix: fixed compressed group message & open the switch config to control compression config enabled#11901

Merged
ONLY-yours merged 4 commits into
mainfrom
fix/fixedCompressedGroupMessage
Jan 27, 2026
Merged

🐛 fix: fixed compressed group message & open the switch config to control compression config enabled#11901
ONLY-yours merged 4 commits into
mainfrom
fix/fixedCompressedGroupMessage

Conversation

@ONLY-yours

@ONLY-yours ONLY-yours commented Jan 27, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

🔀 Description of Change

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

📸 Screenshots / Videos

Before After
... ...

📝 Additional Information

Summary by Sourcery

Make context compression behavior configurable and fix handling of compressed group messages when determining the last message ID.

New Features:

  • Add a user-facing switch to enable or disable automatic context compression per chat configuration.

Bug Fixes:

  • Ensure compressed group messages return their underlying last message ID instead of the group ID when resolving the last message.

Enhancements:

  • Introduce an optional context compression enable flag in the general agent configuration and thread it through agent runtime creation.
  • Update locale strings to document and describe the context compression setting in the model settings UI.

Tests:

  • Add a selector test case verifying last message resolution for compressed group messages.

@vercel

vercel Bot commented Jan 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
lobehub Ready Ready Preview, Comment Jan 27, 2026 0:53am

Request Review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@sourcery-ai

sourcery-ai Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a user-configurable switch to enable/disable context compression, wires this flag through the agent runtime, and fixes how compressed group messages expose their last message ID in selectors and tests.

Sequence diagram for context compression toggle affecting chat execution

sequenceDiagram
  actor User
  participant Controls as ChatInputControls
  participant Store as ChatStore
  participant Runtime as AgentRuntimeService
  participant Exec as StreamingExecutor
  participant Agent as GeneralChatAgent

  User->>Controls: Toggle enableContextCompression
  Controls->>Store: Update chatConfig.enableContextCompression

  User->>Controls: Send message
  Controls->>Store: Dispatch streamingExecutor

  Store->>Exec: streamingExecutor(agentConfigData, modelRuntimeConfig)
  Exec->>Agent: new GeneralChatAgent({
  Exec->>Agent:  compressionConfig.enabled = agentConfigData.chatConfig.enableContextCompression ?? true
  Exec->>Agent: })

  User->>Runtime: Start server-side chat (if applicable)
  Runtime->>Agent: new GeneralChatAgent({
  Runtime->>Agent:  compressionConfig.enabled = metadata.agentConfig.chatConfig.enableContextCompression ?? true
  Runtime->>Agent: })

  Agent->>Agent: phase init/user_input
  Agent->>Agent: compressionEnabled = config.compressionConfig.enabled ?? true
  Agent->>Agent: if compressionEnabled then shouldCompress(messages)
  Agent-->>Store: AgentInstruction compress_context (only if needsCompression)
  Agent-->>Store: Normal LLM call if no compression or disabled
Loading

Class diagram for updated GeneralChatAgent compression configuration

classDiagram
  class GeneralChatAgent {
    - GeneralAgentConfig config
    + constructor(config: GeneralAgentConfig)
    + handlePhaseInit(state: any, context: any): any
    + findExistingSummary(messages: any[]): any
  }

  class GeneralAgentConfig {
    + any agentConfig
    + CompressionConfig compressionConfig
    + ModelRuntimeConfig modelRuntimeConfig
    + string operationId
    + string userId
  }

  class CompressionConfig {
    + boolean enabled
    + number maxWindowToken
  }

  class ModelRuntimeConfig {
    + string model
    + string provider
    + CompressionModelConfig compressionModel
  }

  class CompressionModelConfig {
    + string model
    + string provider
  }

  class AgentRuntimeService {
    - Map~string, StepLifecycleCallbacks~ stepCallbacks
    + createAgent(operationId: string, metadata: any): GeneralChatAgent
    + baseURL(): string
  }

  class StreamingExecutor {
    + executeStreaming(agentConfigData: any, modelRuntimeConfig: ModelRuntimeConfig, messageKey: string, parentMessageId: string): void
  }

  GeneralChatAgent --> GeneralAgentConfig : uses
  GeneralAgentConfig --> CompressionConfig : has
  GeneralAgentConfig --> ModelRuntimeConfig : has
  ModelRuntimeConfig --> CompressionModelConfig : has
  AgentRuntimeService --> GeneralChatAgent : instantiates
  StreamingExecutor --> GeneralChatAgent : instantiates
Loading

Flow diagram for updated findLastMessageIdRecursive with compressedGroup handling

flowchart TD
  A[Start findLastMessageIdRecursive] --> B{node is undefined?}
  B -->|yes| Z[Return undefined]
  B -->|no| C{node has children?}
  C -->|yes| D[Get last child]
  D --> E[Recurse on last child]
  E --> Z
  C -->|no| F{node has tools?}
  F -->|yes| G[Get last tool]
  G --> H[Return last tool result_msg_id]
  H --> Z
  F -->|no| I{node.role is compressedGroup and node.lastMessageId exists?}
  I -->|yes| J[Return node.lastMessageId]
  J --> Z
  I -->|no| K[Return node.id]
  K --> Z
Loading

File-Level Changes

Change Details Files
Gate context compression on a configurable flag in the general chat agent and runtime wiring.
  • Introduce an enabled flag in compressionConfig with default true behavior in GeneralChatAgent before running compression checks.
  • Only call shouldCompress and emit compress_context instructions when compression is enabled.
  • Extend GeneralAgentConfig.compressionConfig to include an optional enabled flag and clarify documentation comments.
  • Pass enableContextCompression from agent metadata/chat config into GeneralChatAgent via AgentRuntimeService.
  • Ensure streamingExecutor also constructs GeneralChatAgent with compressionConfig.enabled derived from chatConfig.enableContextCompression.
packages/agent-runtime/src/agents/GeneralChatAgent.ts
packages/agent-runtime/src/types/generalAgent.ts
src/server/services/agentRuntime/AgentRuntimeService.ts
src/store/chat/slices/aiChat/actions/streamingExecutor.ts
Expose a UI control and localization strings for enabling/disabling context compression.
  • Add a new switch form item under chat model settings to toggle chatConfig.enableContextCompression.
  • Wire the switch into the form as a boolean checked value named chatConfig.enableContextCompression.
  • Add i18n keys and copy describing automatic context compression behavior and label text for the setting in default locale and language-specific setting files.
src/features/ChatInput/ActionBar/Params/Controls.tsx
src/locales/default/setting.ts
locales/en-US/setting.json
locales/zh-CN/setting.json
Fix findLastMessageId behavior for compressed group messages and add coverage.
  • Update findLastMessageIdRecursive to prefer compressedGroup.lastMessageId over the group’s own ID when the node role is compressedGroup.
  • Adjust the priority comment in findLastMessageIdRecursive to document the new behavior order (children > tools > compressedGroup.lastMessageId > self).
  • Add a unit test ensuring displayMessageSelectors.findLastMessageId returns lastMessageId for a compressed group message instead of the group ID.
src/store/chat/slices/message/selectors/displayMessage.ts
src/store/chat/slices/message/selectors/displayMessage.test.ts
Minor cleanup in agent runtime base URL getter.
  • Normalize baseURL getter formatting while preserving existing environment-based base URL resolution behavior.
src/server/services/agentRuntime/AgentRuntimeService.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gru-agent

gru-agent Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

TestGru Assignment

Summary

Link CommitId Status Reason
Detail 42efa2f ✅ Finished

History Assignment

Files

File Pull Request
src/store/chat/slices/aiChat/actions/streamingExecutor.ts ❌ Failed (I failed to setup the environment.)
src/store/chat/slices/message/selectors/displayMessage.ts ❌ Failed (I failed to setup the environment.)
src/server/services/agentRuntime/AgentRuntimeService.ts ❌ Failed (I failed to setup the environment.)
packages/agent-runtime/src/agents/GeneralChatAgent.ts ❌ Failed (I failed to setup the environment.)

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

@sourcery-ai sourcery-ai 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.

Hey - I've left some high level feedback:

  • In findLastMessageIdRecursive, the 'compressedGroup' branch relies on 'lastMessageId' in node with an any cast; consider extending the UIChatMessage type (or introducing a dedicated CompressedGroupMessage type) so the field is type-safe instead of using runtime checks and as any.
  • The defaulting logic for compressionConfig.enabled (e.g., in GeneralChatAgent, AgentRuntimeService, and streamingExecutor) is duplicated and all default to true; consider centralizing this defaulting in one place to avoid drift and make behavior easier to reason about.
  • In the new compressed-group selector test, compressedGroupMessage is cast from unknown as UIChatMessage; tightening the test helper typings (or defining a proper factory for this message shape) would improve type safety and catch future shape mismatches earlier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `findLastMessageIdRecursive`, the `'compressedGroup'` branch relies on `'lastMessageId' in node` with an `any` cast; consider extending the `UIChatMessage` type (or introducing a dedicated `CompressedGroupMessage` type) so the field is type-safe instead of using runtime checks and `as any`.
- The defaulting logic for `compressionConfig.enabled` (e.g., in `GeneralChatAgent`, `AgentRuntimeService`, and `streamingExecutor`) is duplicated and all default to `true`; consider centralizing this defaulting in one place to avoid drift and make behavior easier to reason about.
- In the new compressed-group selector test, `compressedGroupMessage` is cast from `unknown as UIChatMessage`; tightening the test helper typings (or defining a proper factory for this message shape) would improve type safety and catch future shape mismatches earlier.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ONLY-yours ONLY-yours merged commit dc51838 into main Jan 27, 2026
32 of 33 checks passed
@ONLY-yours ONLY-yours deleted the fix/fixedCompressedGroupMessage branch January 27, 2026 12:56
@lobehubbot

lobehubbot commented Jan 27, 2026

Copy link
Copy Markdown
Member

❤️ Great PR @ONLY-yours ❤️

The growth of the project is inseparable from user feedback and contribution, thanks for your contribution! If you are interested in the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.


This comment was translated by Claude.

Original Content

❤️ Great PR @ONLY-yours ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

lobehubbot pushed a commit that referenced this pull request Jan 27, 2026
### [Version 2.0.3](v2.0.2...v2.0.3)
<sup>Released on **2026-01-27**</sup>

#### 🐛 Bug Fixes

- **misc**: Fixed compressed group message & open the switch config to control compression config enabled, fixed the onboarding crash problem.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Fixed compressed group message & open the switch config to control compression config enabled, closes [#11901](#11901) ([dc51838](dc51838))
* **misc**: Fixed the onboarding crash problem, closes [#11905](#11905) ([439e4ee](439e4ee))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot

Copy link
Copy Markdown
Member

🎉 This PR is included in version 2.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@TonyGeez

TonyGeez commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

It would make sense to set auto-compression to disabled by default and have an option to reverse the compression.

It auto-compressed without being aware, at 12k token using an 1m context model...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants