Skip to content

Conversation

@lifeizhou-ap
Copy link
Collaborator

@lifeizhou-ap lifeizhou-ap commented Jan 7, 2026

Summary

Root Cause
When the route llm_search tool was called, it return the empty content in the call_tool_result payload, and saved into session.

payload:

[{"type":"toolResponse","id":"tooluse_EhzKFCKORv6dLIKcEtOKxQ","toolResult":{"status":"success","value":{"content":[],"isError":false}}}]

When loading the session and deserialized call_tool_result via rmcp, it returns error as the call_tool_result because of result.content.is_empty() && result.structured_content.is_none(). This is based on the mcp standard that it should either have at least one content or structured_content.

Fix

  • Validated call_tool_result and set it to errorData if it is invalid. This will avoid set invalid call_tool_result in the message and session
  • Added debug the tool result data when deserialising tool_result fails to make it easy to debug.

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

Unit test and manual testing

Related Issues

#6345

@lifeizhou-ap lifeizhou-ap marked this pull request as ready for review January 7, 2026 10:25
Copilot AI review requested due to automatic review settings January 7, 2026 10:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses an issue where invalid CallToolResult objects with empty content were being saved to sessions, causing deserialization failures when loading. The fix adds validation to convert invalid tool results into error responses and improves debugging with additional logging.

Key changes:

  • Added validate() function to detect invalid CallToolResult objects and convert them to errors before saving
  • Enhanced deserialization error handling with debug logging that includes the original data
  • Applied validation in the agent tool execution flow to prevent invalid results from being stored

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/goose/src/conversation/tool_result_serde.rs Added validation function and debug logging for deserialization failures; includes comprehensive test coverage
crates/goose/src/conversation/mod.rs Changed module visibility from private to public to expose validation function
crates/goose/src/agents/agent.rs Integrated validation into tool result processing pipeline

Comment on lines +157 to +177
Ok(call_tool_result) => match serde_json::to_string(call_tool_result) {
Ok(json_str) => match serde_json::from_str::<CallToolResult>(&json_str) {
Ok(_) => result,
Err(e) => {
tracing::error!("CallToolResult failed validation by deserialization: {}. Original data: {}", e, json_str);
Err(ErrorData {
code: ErrorCode::INTERNAL_ERROR,
message: Cow::from(format!("Tool result validation failed: {}", e)),
data: None,
})
}
},
Err(e) => {
tracing::error!("CallToolResult failed serialization: {}", e);
Err(ErrorData {
code: ErrorCode::INTERNAL_ERROR,
message: Cow::from(format!("Tool result serialization failed: {}", e)),
data: None,
})
}
},
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

This validation performs an unnecessary serialize->deserialize round-trip. Since CallToolResult is from the rmcp crate which performs validation during deserialization, you can validate directly by checking if content is empty and structured_content is None, matching the MCP standard constraint mentioned in the PR description.

Suggested change
Ok(call_tool_result) => match serde_json::to_string(call_tool_result) {
Ok(json_str) => match serde_json::from_str::<CallToolResult>(&json_str) {
Ok(_) => result,
Err(e) => {
tracing::error!("CallToolResult failed validation by deserialization: {}. Original data: {}", e, json_str);
Err(ErrorData {
code: ErrorCode::INTERNAL_ERROR,
message: Cow::from(format!("Tool result validation failed: {}", e)),
data: None,
})
}
},
Err(e) => {
tracing::error!("CallToolResult failed serialization: {}", e);
Err(ErrorData {
code: ErrorCode::INTERNAL_ERROR,
message: Cow::from(format!("Tool result serialization failed: {}", e)),
data: None,
})
}
},
Ok(call_tool_result) => {
let has_empty_content = call_tool_result.content.is_empty();
let has_no_structured_content = call_tool_result.structured_content.is_none();
if has_empty_content && has_no_structured_content {
tracing::error!(
"CallToolResult failed validation: content must not be empty when structured_content is None"
);
Err(ErrorData {
code: ErrorCode::INTERNAL_ERROR,
message: Cow::from(
"Tool result validation failed: content must not be empty when structured_content is None",
),
data: None,
})
} else {
result
}
}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we could, but it introduced duplicated logic in goose and rmcp. So it would be good to reuse the deserialization function in rmcp to use it as source of truth

);
}
#[test]
fn test_validate_return_error_for_invalid_calltoolresult() {
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

Function name has grammatical error: should be "returns_error" not "return_error".

Suggested change
fn test_validate_return_error_for_invalid_calltoolresult() {
fn test_validate_returns_error_for_invalid_calltoolresult() {

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@michaelneale michaelneale left a comment

Choose a reason for hiding this comment

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

nice one - would be great if you could make this a branch and then it runs through the test_providers.sh end to end etc with live providers

@lifeizhou-ap
Copy link
Collaborator Author

nice one - would be great if you could make this a branch and then it runs through the test_providers.sh end to end etc with live providers

Thanks for the review! The empty content is only returned by router_llm_search tool and most of the tools return valid result . It is hard to create the test data for smoke test. Therefore we use unit test to test this scenario

@lifeizhou-ap lifeizhou-ap merged commit 093b076 into main Jan 8, 2026
20 checks passed
@lifeizhou-ap lifeizhou-ap deleted the lifei/fix-load-session-failure-due-to-invalid-call-tool-result branch January 8, 2026 22:36
michaelneale added a commit that referenced this pull request Jan 8, 2026
* main: (31 commits)
  added validation and debug for invalid call tool result (#6368)
  Update MCP apps tutorial: fix _meta structure and version prereq (#6404)
  Fixed fonts (#6389)
  Update confidence levels prompt injection detection to reduce false positive rates (#6390)
  Add ML-based prompt injection detection  (#5623)
  docs: update custom extensions tutorial (#6388)
  fix ResultsFormat error when loading old sessions (#6385)
  docs: add MCP Apps tutorial and documentation updates (#6384)
  changed z-index to make sure the search highlighter does not appear on modal overlay (#6386)
  Handling special claude model response in github copilot provider (#6369)
  fix: prevent duplicate rendering when tool returns both mcp-ui and mcp-apps resources (#6378)
  fix: update MCP Apps _meta.ui.resourceUri to use nested format (SEP-1865) (#6372)
  feat(providers): add streaming support for Google Gemini provider (#6191)
  Blog: edit links in mcp apps post (#6371)
  fix: prevent infinite loop of tool-input notifications in MCP Apps (#6374)
  fix: Show platform-specific keyboard shortcuts in UI (#6323)
  fix: we load extensions when agent starts so don't do it up front (#6350)
  docs: credit HumanLayer in RPI tutorial (#6365)
  Blog: Goose Lands MCP Apps (#6172)
  Claude 3.7 is out. we had some harcoded stuff (#6197)
  ...
wpfleger96 added a commit that referenced this pull request Jan 9, 2026
* main: (89 commits)
  fix(google): treat signed text as regular content in streaming (#6400)
  Add frameDomains and baseUriDomains CSP support for MCP Apps (#6399)
  fix(ci): add missing dependencies to openapi-schema-check job (#6367)
  feat: http proxy support
  Add support for changing working dir and extensions in same window/session (#6057)
  Sort keys in canonical models (#6403)
  added validation and debug for invalid call tool result (#6368)
  Update MCP apps tutorial: fix _meta structure and version prereq (#6404)
  Fixed fonts (#6389)
  Update confidence levels prompt injection detection to reduce false positive rates (#6390)
  Add ML-based prompt injection detection  (#5623)
  docs: update custom extensions tutorial (#6388)
  fix ResultsFormat error when loading old sessions (#6385)
  docs: add MCP Apps tutorial and documentation updates (#6384)
  changed z-index to make sure the search highlighter does not appear on modal overlay (#6386)
  Handling special claude model response in github copilot provider (#6369)
  fix: prevent duplicate rendering when tool returns both mcp-ui and mcp-apps resources (#6378)
  fix: update MCP Apps _meta.ui.resourceUri to use nested format (SEP-1865) (#6372)
  feat(providers): add streaming support for Google Gemini provider (#6191)
  Blog: edit links in mcp apps post (#6371)
  ...
wpfleger96 added a commit that referenced this pull request Jan 9, 2026
* main: (89 commits)
  fix(google): treat signed text as regular content in streaming (#6400)
  Add frameDomains and baseUriDomains CSP support for MCP Apps (#6399)
  fix(ci): add missing dependencies to openapi-schema-check job (#6367)
  feat: http proxy support
  Add support for changing working dir and extensions in same window/session (#6057)
  Sort keys in canonical models (#6403)
  added validation and debug for invalid call tool result (#6368)
  Update MCP apps tutorial: fix _meta structure and version prereq (#6404)
  Fixed fonts (#6389)
  Update confidence levels prompt injection detection to reduce false positive rates (#6390)
  Add ML-based prompt injection detection  (#5623)
  docs: update custom extensions tutorial (#6388)
  fix ResultsFormat error when loading old sessions (#6385)
  docs: add MCP Apps tutorial and documentation updates (#6384)
  changed z-index to make sure the search highlighter does not appear on modal overlay (#6386)
  Handling special claude model response in github copilot provider (#6369)
  fix: prevent duplicate rendering when tool returns both mcp-ui and mcp-apps resources (#6378)
  fix: update MCP Apps _meta.ui.resourceUri to use nested format (SEP-1865) (#6372)
  feat(providers): add streaming support for Google Gemini provider (#6191)
  Blog: edit links in mcp apps post (#6371)
  ...
fbalicchia pushed a commit to fbalicchia/goose that referenced this pull request Jan 13, 2026
@lifeizhou-ap
Copy link
Collaborator Author

Hi @alexhancock,

For the fix with the validation of CallToolResult, do you think it is worthwhile to fix in the rmcp? Either to check during CallToolResult serialization or in the constructor of CallToolResult. I feel check during serialization might be safer

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants