Remove orphaned tool calls before compaction#5059
Merged
Conversation
- Add fix_conversation to handle agent_visible vs user_visible messages separately - Update fix_lead_trail to have more specific error message for trailing assistant messages - Add two new tests for handling pending tool requests in last assistant message - Conversation fixes now only apply to agent_visible messages, preserving non-visible ones
DOsinga
approved these changes
Oct 11, 2025
crates/goose/src/conversation/mod.rs
Outdated
| let messages = conversation.messages().clone(); | ||
| let (messages, issues) = fix_messages(messages); | ||
| (Conversation::new_unvalidated(messages), issues) | ||
| let all_messages = conversation.messages().clone(); |
Collaborator
There was a problem hiding this comment.
I dont think you need to clone here
crates/goose/src/conversation/mod.rs
Outdated
| /// messages should always be from the user. | ||
| /// | ||
| /// This function handles agent_visible and non-visible messages separately to ensure | ||
| /// that only agent-visible messages are fixed, while preserving non-visible messages. |
Collaborator
There was a problem hiding this comment.
here and below, let's cut these comments down
| } | ||
| } | ||
|
|
||
| #[test] |
Collaborator
There was a problem hiding this comment.
these tests don't test the new functionality, replace them with something that does
crates/goose/src/conversation/mod.rs
Outdated
| messages.pop(); | ||
| issues.push("Removed trailing assistant message".to_string()); | ||
| issues | ||
| .push("Removed trailing assistant message with pending tool requests".to_string()); |
crates/goose/src/conversation/mod.rs
Outdated
| final_messages.extend(fixed_visible); | ||
|
|
||
| // Sort by timestamp to maintain order | ||
| final_messages.sort_by_key(|m| m.created); |
Collaborator
There was a problem hiding this comment.
this seems scary; if we weren't sorted by created (and we don't always set these I think), we might now have broken the conversation. use a shadow map to keep order
| } else { | ||
| non_visible_messages.push(msg); | ||
| } | ||
| } |
katzdave
added a commit
that referenced
this pull request
Oct 15, 2025
* 'main' of github.com:block/goose: (49 commits) fixing video embed (#5171) chore: clean up random unused files (#5166) fix: adjust download_cli.sh to tolerate no OS variable (#5169) mcp tutorial page for firecrawl (#5152) Remove orphaned tool calls before compaction (#5059) feat: add copy as markdown button to documentation pages (#5158) chore: include vendored node executable (#5160) remove extra whitespace from message (#5159) Clear deeplinks after use (#5128) Revert "Fix gpt-5 input context limit (#4619)" (#5135) fix: missing cmake and protobuf for windows build, deduplicate sh/pws… (#5028) Fix bedrock tool input schema (#5064) Add self-test recipe for goose validation (#5111) fix: modifies openai request logic for reasoning models (#4221) (#4294) Fix race condition threat when set_param and set_secret of c… (#5109) Clean room implementation of the chat process (#5079) Bump rmcp (#5096) set version in an env variable for testing (#5100) fix : enhance fuzzy file search in goose desktop (#5071) Make async (#5126) ...
lifeizhou-ap
added a commit
that referenced
this pull request
Oct 15, 2025
* main: fix: include apple silicon build of the desktop app in build artifacts (#5174) fixing video embed (#5171) chore: clean up random unused files (#5166) fix: adjust download_cli.sh to tolerate no OS variable (#5169) mcp tutorial page for firecrawl (#5152) Remove orphaned tool calls before compaction (#5059) feat: add copy as markdown button to documentation pages (#5158) chore: include vendored node executable (#5160) remove extra whitespace from message (#5159) Clear deeplinks after use (#5128) Revert "Fix gpt-5 input context limit (#4619)" (#5135) fix: missing cmake and protobuf for windows build, deduplicate sh/pws… (#5028)
tlongwell-block
added a commit
that referenced
this pull request
Oct 15, 2025
…utonomous * origin/main: feat: add Daily Standup Report Generator recipe (#5123) (#5131) Sort providers in alphabetical vs random (#5090) Declarative providers (#5084) adding youtube link to firecrawl mcp tutorial, merge after 9am Eastern Oct 15 (#5173) Ollama integration: modified default model + added models (#5153) Fix codex subagent configuration in documentation (#5180) fix: include apple silicon build of the desktop app in build artifacts (#5174) fixing video embed (#5171) chore: clean up random unused files (#5166) fix: adjust download_cli.sh to tolerate no OS variable (#5169) mcp tutorial page for firecrawl (#5152) Remove orphaned tool calls before compaction (#5059) feat: add copy as markdown button to documentation pages (#5158) chore: include vendored node executable (#5160) remove extra whitespace from message (#5159)
wpfleger96
added a commit
to wpfleger96/goose
that referenced
this pull request
Oct 15, 2025
* main: (55 commits) [docs] Add Blog Post: "Designing AI for Users, Not Just LLMs" (block#5190) docs: update cognee, jetbrains, mbot extensions config (block#5172) Minimally disable subagents when not in autonomous model (block#5149) Fix provider sort (block#5188) blog: Getting Started with Goose on Windows (block#5156) feat: add CI/CD Pipeline recipe (block#5183) feat: add Daily Standup Report Generator recipe (block#5123) (block#5131) Sort providers in alphabetical vs random (block#5090) Declarative providers (block#5084) adding youtube link to firecrawl mcp tutorial, merge after 9am Eastern Oct 15 (block#5173) Ollama integration: modified default model + added models (block#5153) Fix codex subagent configuration in documentation (block#5180) fix: include apple silicon build of the desktop app in build artifacts (block#5174) fixing video embed (block#5171) chore: clean up random unused files (block#5166) fix: adjust download_cli.sh to tolerate no OS variable (block#5169) mcp tutorial page for firecrawl (block#5152) Remove orphaned tool calls before compaction (block#5059) feat: add copy as markdown button to documentation pages (block#5158) chore: include vendored node executable (block#5160) ...
michaelneale
added a commit
that referenced
this pull request
Oct 16, 2025
* main: (35 commits) fix: include apple silicon build of the desktop app in build artifacts (#5174) fixing video embed (#5171) chore: clean up random unused files (#5166) fix: adjust download_cli.sh to tolerate no OS variable (#5169) mcp tutorial page for firecrawl (#5152) Remove orphaned tool calls before compaction (#5059) feat: add copy as markdown button to documentation pages (#5158) chore: include vendored node executable (#5160) remove extra whitespace from message (#5159) Clear deeplinks after use (#5128) Revert "Fix gpt-5 input context limit (#4619)" (#5135) fix: missing cmake and protobuf for windows build, deduplicate sh/pws… (#5028) Fix bedrock tool input schema (#5064) Add self-test recipe for goose validation (#5111) fix: modifies openai request logic for reasoning models (#4221) (#4294) Fix race condition threat when set_param and set_secret of c… (#5109) Clean room implementation of the chat process (#5079) Bump rmcp (#5096) set version in an env variable for testing (#5100) fix : enhance fuzzy file search in goose desktop (#5071) ...
Merged
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
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.
Remove orphaned tool calls before compaction. Also add in fix_conversation to catch other potential conversation errors.
This PR is based on #4968 but adapted for the main branch.
Changes
fix_conversationto handle agent_visible and non-visible messages separatelyfix_lead_trailto have a more specific error message for trailing assistant messages with pending tool requeststest_last_assistant_message_with_pending_tool_requestandtest_last_assistant_message_with_multiple_pending_tool_requestsTesting