Deduplicate tool names with empty results in call summary#550
Open
PratikDhanave wants to merge 2 commits into
Open
Deduplicate tool names with empty results in call summary#550PratikDhanave wants to merge 2 commits into
PratikDhanave wants to merge 2 commits into
Conversation
DefaultToolCallFormatter listed each tool name once by checking the groupedResults map, but that map is only populated for non-empty results. Repeated calls to the same tool whose results were empty (an empty-string result or an orphaned call with no matching result) never registered a name in the map, so each call re-appended the name and the summary emitted duplicate 'name:' lines. Track seen names in a dedicated set so deduplication is independent of whether a result is present.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a bug in the compaction tool-call summary formatter where repeated tool calls with empty/absent results could cause the same tool name to be emitted multiple times, despite the formatter’s intended deduplication behavior.
Changes:
- Deduplicate tool names using a dedicated
seenNamesset, independent of whether any non-empty results were recorded. - Add a regression test ensuring repeated tool calls with empty results only emit the tool name once.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| agent/compaction/toolresult.go | Uses a separate seenNames map to ensure tool-name deduplication works even when results are empty/missing. |
| agent/compaction/compaction_test.go | Adds a targeted test covering the empty-result deduplication regression case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
When
ToolResultStrategycollapses an old tool-call group,DefaultToolCallFormatterlists each distinct tool name once. The deduplication guard keyed off thegroupedResultsmap:But
groupedResultsis only written when a result is non-empty. So repeated calls to the same tool whose results are empty — an empty-string result, or an orphaned call with no matching result content — never register the name in the map, and each call re-appends the name toorderedNames. The summary then emits the samename:line twice:This directly contradicts the formatter’s stated design (the doc comment promises "deduplication ... for repeated tool names"). Empty/absent results are realistic for tool-heavy conversations — e.g. parallel calls to a fire-and-forget tool (
notify,log) that returns an empty string — which is exactly the input this formatter receives when collapsing old groups.Fix
Track seen names in a dedicated set so deduplication is independent of whether a result is present:
Test
TestDefaultToolCallFormatter_DedupsRepeatedNamesWithEmptyResultsformats a group with two parallel calls to the same tool, both with empty results, and asserts the name is listed once. It fails on the old code ("[Tool Calls]\nnotify:\nnotify:") and passes with the fix.