Skip to content

Compare all identity fields in function call/result equality#532

Open
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanave:fix-compaction-function-equality
Open

Compare all identity fields in function call/result equality#532
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanave:fix-compaction-function-equality

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

Problem

contentEqual (agent/compaction/equality.go) is a structural-equality predicate, and every arm compares all the fields that distinguish two content values — TextReasoningContent compares ProtectedData, ErrorContent compares Message/ErrorCode/Details, DataContent compares all three fields, etc.

The function-content arms were the exception, ignoring fields the types actually carry:

case *message.FunctionCallContent:
    // drops Error and InformationalOnly
    return l.CallID == r.CallID && l.Name == r.Name && l.Arguments == r.Arguments
case *message.FunctionResultContent:
    // drops Error
    return l.CallID == r.CallID && reflect.DeepEqual(l.Result, r.Result)

The most consequential omission is FunctionResultContent.Error — the field that distinguishes a failed tool call from a successful one. Two results with the same CallID and Result but different Error compared equal.

MessageIndex.Update uses this predicate to decide whether the previously-processed prefix is unchanged (the early-return at index.go:81). So a tool result that flips between failure and success at the conversation tail can be treated as already-processed and skipped during re-indexing.

Fix

Compare the missing fields. Errors are compared by message string via a small errorsEqual helper, matching how FunctionCallContent/FunctionResultContent already serialize their Error field to and from JSON (Go error values aren't generally ==-comparable).

Test

Extends the existing TestMessageIndexUpdate_MatchesKnownContentTypes table (black-box, in equality_test.go) with the previously-uncovered fields: a FunctionCallContent differing only in InformationalOnly, one differing only in Error, and a FunctionResultContent differing only in Error — each expected not to match. All three fail on main (got true want false) and pass with the fix; the existing rows are unchanged.

contentEqual is a structural-equality predicate: every content arm
compares all of the fields that distinguish two values (e.g.
TextReasoningContent compares ProtectedData, ErrorContent compares
Message/ErrorCode/Details). The FunctionCallContent and
FunctionResultContent arms were the exception — they ignored fields the
types carry:

- FunctionResultContent dropped Error, so a failed tool result and an
  otherwise-identical successful one compared equal.
- FunctionCallContent dropped Error and InformationalOnly.

Because MessageIndex.Update uses this predicate to decide whether the
processed prefix is unchanged, a result that flipped between failure and
success at the conversation tail could be treated as already processed
and skipped during re-indexing.

Compare the missing fields (errors by message string, matching how
function content serializes its Error to JSON). Extends the existing
content-type equality table test with the previously-uncovered fields.
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 17, 2026 20:38
Copilot AI review requested due to automatic review settings July 17, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a correctness gap in agent/compaction’s structural content equality so that tool/function call and result content comparisons account for all identity-defining fields, preventing MessageIndex.Update from incorrectly treating changed tool outcomes as unchanged.

Changes:

  • Extend contentEqual to compare FunctionCallContent.Error, FunctionCallContent.InformationalOnly, and FunctionResultContent.Error.
  • Add a small errorsEqual helper that compares error values by their message string.
  • Expand the existing TestMessageIndexUpdate_MatchesKnownContentTypes table to cover the newly-compared fields.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
agent/compaction/equality.go Makes function call/result structural equality include previously-ignored fields (notably Error).
agent/compaction/equality_test.go Adds regression tests ensuring changes in InformationalOnly / Error prevent equality matches.

💡 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