🐛 fix: fixed compressed group message & open the switch config to control compression config enabled#11901
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Reviewer's GuideAdds 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 executionsequenceDiagram
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
Class diagram for updated GeneralChatAgent compression configurationclassDiagram
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
Flow diagram for updated findLastMessageIdRecursive with compressedGroup handlingflowchart 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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
TestGru AssignmentSummary
Files
Tip You can |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
findLastMessageIdRecursive, the'compressedGroup'branch relies on'lastMessageId' in nodewith ananycast; consider extending theUIChatMessagetype (or introducing a dedicatedCompressedGroupMessagetype) so the field is type-safe instead of using runtime checks andas any. - The defaulting logic for
compressionConfig.enabled(e.g., inGeneralChatAgent,AgentRuntimeService, andstreamingExecutor) is duplicated and all default totrue; consider centralizing this defaulting in one place to avoid drift and make behavior easier to reason about. - In the new compressed-group selector test,
compressedGroupMessageis cast fromunknown 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
❤️ 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.
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. |
### [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"> [](#readme-top) </div>
|
🎉 This PR is included in version 2.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
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... |
💻 Change Type
🔗 Related Issue
🔀 Description of Change
🧪 How to Test
📸 Screenshots / Videos
📝 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:
Bug Fixes:
Enhancements:
Tests: