fix(traces): normalize tool_use arguments JSON to fix span dedup - #2013
Merged
Merged
Conversation
The spanToKey function used raw arguments strings for tool_use span comparison. Request body arguments (compact JSON from client) and response body arguments (re-serialized by stream aggregation) had different whitespace formatting, causing identical tool calls to produce different keys and fail deduplication. Added normalizeJSON to re-parse and re-serialize arguments before key generation, eliminating formatting differences.
Contributor
Greptile SummaryThis PR normalizes tool-use trace keys to reduce duplicate spans. The main changes are:
Confidence Score: 5/5This looks safe to merge after considering a small trace-deduplication edge case.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(traces): normalize tool_use argument..." | Re-trigger Greptile |
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.
问题
追踪页面中,连续工具调用的
tool_usespan 出现重复显示。例如:bash工具调用、工具结果、write工具调用write工具调用、工具结果、edit工具调用其中
write工具调用在两个段里都出现了。根因
spanToKey函数生成去重 key 时,直接使用tool_usespan 的原始 arguments 字符串。但同一个 tool call 的 arguments 在两个地方的 JSON 格式不同:{"command":"pwd"}{"command": "pwd"}Go 的
json.Marshal在冒号后加空格,与客户端的紧凑 JSON 不一致。导致同一个 tool call 生成了不同的 key,去重失败。修复
在
spanToKey的tool_use分支,对 arguments 调用normalizeJSON(解析再重新序列化),消除 JSON 格式差异。