fix(plugins): export real tool args when payload.args is a CopyOnWriteDict - #5911
Open
Sanjays2402 wants to merge 1 commit into
Open
fix(plugins): export real tool args when payload.args is a CopyOnWriteDict#5911Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
…eDict
ToolsTelemetryExporter serialized payload.args directly with orjson.
orjson reads a dict subclass's internal C-level storage rather than its
Python-level accessors, so a cpex CopyOnWriteDict (whose real contents
live behind overridden methods, with an empty backing shell) serialized
to "{}". Every tool.pre_invoke span exported an empty
tool.invocation.args even when the tool was called with real arguments.
Converting to a plain dict before dumping restores the real arguments and
is a no-op for the plain-dict case.
Adds a regression test in the plugin's existing test module asserting the
exported args for a CopyOnWriteDict payload.
Signed-off-by: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com>
Sanjays2402
requested review from
Lang-Akshay,
brian-hussey,
crivetimihai,
ja8zyjits and
msureshkumar88
as code owners
July 26, 2026 03:10
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.
Closes #5699
📌 Summary
ToolsTelemetryExporteralways exportedtool.invocation.argsas{}on thetool.pre_invokespan, even when the tool was invoked with real arguments, so tool telemetry lost all input data.🔁 Reproduction Steps
Issue #5699. Offline reproduction of the root cause:
🐞 Root Cause
tool_pre_invokepassespayload.argsstraight toorjson.dumps(plugins/tools_telemetry_exporter/telemetry_exporter.py:171). When the plugin framework hands over acpex.framework.memory.CopyOnWriteDict, orjson serializes adictsubclass by reading its internal C-level storage and bypasses the Python-level overrides the copy-on-write wrapper relies on. The backing shell is empty, so the export is{}whilerepr()and normal access show the real arguments.💡 Fix Description
Convert to a plain
dictbefore dumping. One line, no behaviour change for the plain-dictcase (nested values are already plain containers).📏 Reviewability
triage🧪 Verification
New
test_pre_invoke_exports_copy_on_write_argsin the plugin's existing test module. Verified fail-without-fix / pass-with-fix by stashing the source change:pytest tests/unit/mcpgateway/plugins/plugins/tools_telemetry_exporter/-k copy_on_writeruff check,ruff format --checkon both changed files📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)