UAT: ChangeSetCapture.wrap_tool drops source and source_metadata from wrapped ToolSpec #5458

Open
opened 2026-04-09 06:54:52 +00:00 by HAL9000 · 1 comment
Owner

Bug Report

Feature Area: Multi-file generation ChangeSet / Tool lifecycle
Severity: Backlog — provenance information is lost when tools are wrapped for change tracking
Found by: UAT Testing (tool-router-mcp-adapter area)

What Was Tested

Code-level analysis of src/cleveragents/tool/builtins/changeset.py — specifically the ChangeSetCapture.wrap_tool() method (lines 185–244).

Expected Behavior (from spec)

When ChangeSetCapture.wrap_tool() wraps a ToolSpec to intercept write operations and record change entries, the resulting wrapped ToolSpec should preserve all fields from the original spec, including source and source_metadata. These fields carry provenance information (e.g., that a tool came from an MCP server, its server URI, resource slots, etc.).

Actual Behavior

The wrap_tool() method creates a new ToolSpec that omits source and source_metadata:

return ToolSpec(
    name=tool_spec.name,
    description=tool_spec.description,
    input_schema=tool_spec.input_schema,
    output_schema=tool_spec.output_schema,
    capabilities=tool_spec.capabilities,
    handler=_wrapped_handler,
    # Missing: source, source_metadata, tool_type, execution_environment
)

This means:

  • An MCP tool wrapped by ChangeSetCapture loses its source="mcp" and source_metadata (server name, resource slots, annotations)
  • The tool_type field defaults to "tool" even if the original was "validation"
  • The execution_environment preference is lost

Code Location

  • Bug: src/cleveragents/tool/builtins/changeset.py, lines 237–244 (wrap_tool return statement)

Impact

  • MCP tool provenance is lost after wrapping — downstream code cannot determine the tool came from MCP
  • Validation tools wrapped for change tracking lose their tool_type="validation" classification
  • ToolRegistry.find_tools_for_resource() which uses source_metadata["resource_bindings"] will not find wrapped MCP tools
  • ToolCallRouter._check_is_validation() (even after fixing #5428) will misclassify wrapped validation tools

Fix

Preserve all original fields in the wrapped spec:

return ToolSpec(
    name=tool_spec.name,
    description=tool_spec.description,
    input_schema=tool_spec.input_schema,
    output_schema=tool_spec.output_schema,
    capabilities=tool_spec.capabilities,
    handler=_wrapped_handler,
    tool_type=tool_spec.tool_type,
    source=tool_spec.source,
    source_metadata=tool_spec.source_metadata,
    execution_environment=tool_spec.execution_environment,
)

Metadata

Commit Message: fix(changeset): preserve source and source_metadata in ChangeSetCapture.wrap_tool
Branch: fix/changeset-wrap-tool-preserve-fields

Subtasks

  • Update wrap_tool() to copy all fields from the original ToolSpec
  • Add unit tests verifying that wrapped tools preserve source, source_metadata, tool_type, and execution_environment

Definition of Done

  • Wrapped ToolSpec has identical source, source_metadata, tool_type, and execution_environment as the original
  • All existing tests pass

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report **Feature Area:** Multi-file generation ChangeSet / Tool lifecycle **Severity:** Backlog — provenance information is lost when tools are wrapped for change tracking **Found by:** UAT Testing (tool-router-mcp-adapter area) ### What Was Tested Code-level analysis of `src/cleveragents/tool/builtins/changeset.py` — specifically the `ChangeSetCapture.wrap_tool()` method (lines 185–244). ### Expected Behavior (from spec) When `ChangeSetCapture.wrap_tool()` wraps a `ToolSpec` to intercept write operations and record change entries, the resulting wrapped `ToolSpec` should preserve all fields from the original spec, including `source` and `source_metadata`. These fields carry provenance information (e.g., that a tool came from an MCP server, its server URI, resource slots, etc.). ### Actual Behavior The `wrap_tool()` method creates a new `ToolSpec` that omits `source` and `source_metadata`: ```python return ToolSpec( name=tool_spec.name, description=tool_spec.description, input_schema=tool_spec.input_schema, output_schema=tool_spec.output_schema, capabilities=tool_spec.capabilities, handler=_wrapped_handler, # Missing: source, source_metadata, tool_type, execution_environment ) ``` This means: - An MCP tool wrapped by `ChangeSetCapture` loses its `source="mcp"` and `source_metadata` (server name, resource slots, annotations) - The `tool_type` field defaults to `"tool"` even if the original was `"validation"` - The `execution_environment` preference is lost ### Code Location - **Bug**: `src/cleveragents/tool/builtins/changeset.py`, lines 237–244 (`wrap_tool` return statement) ### Impact - MCP tool provenance is lost after wrapping — downstream code cannot determine the tool came from MCP - Validation tools wrapped for change tracking lose their `tool_type="validation"` classification - `ToolRegistry.find_tools_for_resource()` which uses `source_metadata["resource_bindings"]` will not find wrapped MCP tools - `ToolCallRouter._check_is_validation()` (even after fixing #5428) will misclassify wrapped validation tools ### Fix Preserve all original fields in the wrapped spec: ```python return ToolSpec( name=tool_spec.name, description=tool_spec.description, input_schema=tool_spec.input_schema, output_schema=tool_spec.output_schema, capabilities=tool_spec.capabilities, handler=_wrapped_handler, tool_type=tool_spec.tool_type, source=tool_spec.source, source_metadata=tool_spec.source_metadata, execution_environment=tool_spec.execution_environment, ) ``` ### Metadata ``` Commit Message: fix(changeset): preserve source and source_metadata in ChangeSetCapture.wrap_tool Branch: fix/changeset-wrap-tool-preserve-fields ``` ### Subtasks - [ ] Update `wrap_tool()` to copy all fields from the original `ToolSpec` - [ ] Add unit tests verifying that wrapped tools preserve `source`, `source_metadata`, `tool_type`, and `execution_environment` ### Definition of Done - Wrapped `ToolSpec` has identical `source`, `source_metadata`, `tool_type`, and `execution_environment` as the original - All existing tests pass --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.2.0 milestone 2026-04-09 06:59:19 +00:00
Author
Owner

Label compliance fix applied:

  • Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md

Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: backlog-groomer

Label compliance fix applied: - Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: backlog-groomer
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#5458
No description provided.