Skip to content

Deduplicate tool names with empty results in call summary#550

Open
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanave:fix-compaction-toolname-dedup-empty-results
Open

Deduplicate tool names with empty results in call summary#550
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanave:fix-compaction-toolname-dedup-empty-results

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

When ToolResultStrategy collapses an old tool-call group, DefaultToolCallFormatter lists each distinct tool name once. The deduplication guard keyed off the groupedResults map:

if _, ok := groupedResults[functionCall.name]; !ok {
    orderedNames = append(orderedNames, functionCall.name)
}
...
if result != "" {
    groupedResults[functionCall.name] = append(groupedResults[functionCall.name], result)
}

But groupedResults is 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 to orderedNames. The summary then emits the same name: line twice:

[Tool Calls]
notify:
notify:

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:

seenNames := make(map[string]bool)
...
if !seenNames[functionCall.name] {
    seenNames[functionCall.name] = true
    orderedNames = append(orderedNames, functionCall.name)
}

Test

TestDefaultToolCallFormatter_DedupsRepeatedNamesWithEmptyResults formats 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.

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.
Copilot AI review requested due to automatic review settings July 19, 2026 08:38
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 19, 2026 08:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 seenNames set, 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.

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.

2 participants