-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: synchronize local message state after conversation compaction #5315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This fixes a critical bug where message visibility metadata was not properly synchronized between client and server after compaction, causing repeated compaction failures. The Problem: When the server performs conversation compaction, it sends an UpdateConversation event with the compacted messages where old messages are marked agentVisible=false. However, the streaming handlers in both useChatStream.ts and useMessageStream.ts were updating React state but NOT updating the local currentMessages variable that accumulates subsequent message events. This caused: 1. Server compacts 400 messages → sends 10 messages (old ones agentVisible=false) 2. Client updates React state ✓ 3. Local currentMessages still has 400 messages with agentVisible=true ✗ 4. New messages get appended to the stale 400-message array 5. React state gets overwritten with incorrect metadata 6. Next request sends 400+ messages marked agentVisible=true 7. Server tries to compact again but context is too large → fails The Fix: Synchronize the local currentMessages variable when UpdateConversation event is received, ensuring subsequent messages are appended to the compacted conversation with correct visibility metadata. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Collaborator
Author
|
OK my agent was a little eager, needs some more testing. |
DOsinga
approved these changes
Oct 22, 2025
Collaborator
DOsinga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunate but true!
katzdave
added a commit
that referenced
this pull request
Oct 22, 2025
* 'main' of github.com:block/goose: Fix gemini again (#5308) fix: synchronize local message state after conversation compaction (#5315) docs: replace broken links with working links (#5266) Add Web Accessibility Auditor recipe to cookbook (#5318) To do mcp tutorial (#5317) workflows: add a manual trigger option to pr-smoke-test (#5302) documenting `goose recipe list` command (#5278)
michaelneale
added a commit
that referenced
this pull request
Oct 24, 2025
* main: (77 commits) Fix legacy import (#5343) Unify loading goose messages and usechatstream determines chat state (#5306) Docs: goose session export and goose session import (#5267) Create recipe dir on save (#5337) docs: Update Discord link (#5335) [recipe workflow]: Fix `Invalid revision range` error (#5334) Add tech-article-explainer recipe (#5333) doc: added beta banner for old blog post (#5332) feat: add code refactor recipe (#5320) Security audit recipe (#5319) feat: add generate commit message recipe (#5326) fix: remove dependency on gsap library (#5330) feat: dynamically load ollama models (#5309) fix: skip temperature for goose-gpt-5 model (#5311) Replace compaction notifications with system notifications (#5218) Diagnostics (#5323) Fix gemini again (#5308) fix: synchronize local message state after conversation compaction (#5315) docs: replace broken links with working links (#5266) Add Web Accessibility Auditor recipe to cookbook (#5318) ...
BlairAllan
pushed a commit
to BlairAllan/goose
that referenced
this pull request
Oct 25, 2025
…lock#5315) Co-authored-by: Claude <[email protected]> Signed-off-by: Blair Allan <[email protected]>
BlairAllan
pushed a commit
to BlairAllan/goose
that referenced
this pull request
Nov 29, 2025
…lock#5315) Co-authored-by: Claude <[email protected]> Signed-off-by: Blair Allan <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a critical bug where message visibility metadata was not properly synchronized between client and server after compaction, causing repeated compaction failures and context overflow issues.
The Problem
When the server performs conversation compaction:
UpdateConversationevent with 10 messages (old ones markedagentVisible=false)currentMessagesvariable still has 400 messages withagentVisible=true✗agentVisible=trueThis created a persistent mismatch between client and server state where the client thought all 400 messages were visible to the agent, while the server had correctly marked most as
agentVisible=false.The Fix
Synchronize the local
currentMessagesvariable whenUpdateConversationevent is received in both streaming handlers:useChatStream.ts: AddedcurrentMessages = event.conversationto sync local variable with compacted stateuseMessageStream.ts: AddedcurrentMessages = parsedEvent.conversationto sync local variable with compacted stateThis ensures that subsequent messages are appended to the compacted conversation with correct visibility metadata, not the stale 400-message array.
Testing
Impact