Skip to content

Preserve MCP tool error outcomes#2135

Closed
xeophon wants to merge 1 commit into
PrimeIntellect-ai:agent/fix-mcp-session-lifecyclefrom
xeophon:agent/preserve-mcp-tool-errors
Closed

Preserve MCP tool error outcomes#2135
xeophon wants to merge 1 commit into
PrimeIntellect-ai:agent/fix-mcp-session-lifecyclefrom
xeophon:agent/preserve-mcp-tool-errors

Conversation

@xeophon

@xeophon xeophon commented Jul 26, 2026

Copy link
Copy Markdown
Member

Overview

Preserves MCP tool-declared outcome semantics across harness execution, typed messages, traces, replay, and provider conversion.

This PR is stacked on #2134, which owns the shared null/bash MCP client and its session lifecycle and replay-safety behavior.

Details

MCP CallToolResult contains both model-visible content and an isError outcome. The shared MCP client now returns both values, and the harness program carries the outcome into ToolMessage.is_error.

The typed outcome participates in graph identity and trace serialization, so success and failure results with identical content remain distinguishable after persistence and resume.

For chat-compatible providers, the localhost harness handoff uses a private marker that is removed before the provider request while adding a readable failure label to the model-visible content. Anthropic-native tool_result.is_error maps directly into the same typed representation.

Note

Preserve MCP tool error outcomes through the verifier pipeline

  • Adds is_error field to ToolMessage in types.py and propagates it from call_mcp through the bash/null harness programs and into parsed messages.
  • Introduces _vf_is_error as an internal wire flag in chat.py; when serializing for external consumption the flag is replaced with a "Tool execution failed:\n" content prefix, while internal paths (harness launch) preserve the machine-readable flag via include_internal=True.
  • The Anthropic dialect in anthropic.py reads is_error from tool_result blocks, and message_hash in graph.py incorporates error vs. success into the digest so error and success tool messages hash differently.
  • ChatDialect.apply_overrides rewrites messages containing _vf_is_error to error-prefixed content before forwarding upstream.
  • Behavioral Change: tool messages that were previously indistinguishable from successful ones now carry a visible error prefix when sent to upstream models, and produce different cache keys.

Macroscope summarized 1e47ec2.

@xeophon
xeophon force-pushed the agent/preserve-mcp-tool-errors branch from 0a85961 to a88d1c2 Compare July 26, 2026 11:31

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a88d1c2. Configure here.

Comment thread verifiers/v1/harnesses/bash/program.py
@xeophon
xeophon force-pushed the agent/preserve-mcp-tool-errors branch from 2e08cf1 to 1e47ec2 Compare July 26, 2026 15:40
@xeophon
xeophon changed the base branch from main to agent/fix-mcp-session-lifecycle July 26, 2026 15:41

xeophon commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

Superseded by #2138, which carries the same head commit and is linked natively above #2134 in GitHub stack 2139. Closing this fork-head PR because GitHub native stacks require same-repository branches.

@xeophon xeophon closed this Jul 26, 2026
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.

1 participant