Compare all identity fields in function call/result equality#532
Open
PratikDhanave wants to merge 2 commits into
Open
Compare all identity fields in function call/result equality#532PratikDhanave wants to merge 2 commits into
PratikDhanave wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
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
contentEqualto compareFunctionCallContent.Error,FunctionCallContent.InformationalOnly, andFunctionResultContent.Error. - Add a small
errorsEqualhelper that compareserrorvalues by their message string. - Expand the existing
TestMessageIndexUpdate_MatchesKnownContentTypestable 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.
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.
Problem
contentEqual(agent/compaction/equality.go) is a structural-equality predicate, and every arm compares all the fields that distinguish two content values —TextReasoningContentcomparesProtectedData,ErrorContentcomparesMessage/ErrorCode/Details,DataContentcompares all three fields, etc.The function-content arms were the exception, ignoring fields the types actually carry:
The most consequential omission is
FunctionResultContent.Error— the field that distinguishes a failed tool call from a successful one. Two results with the sameCallIDandResultbut differentErrorcompared equal.MessageIndex.Updateuses this predicate to decide whether the previously-processed prefix is unchanged (the early-return atindex.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
errorsEqualhelper, matching howFunctionCallContent/FunctionResultContentalready serialize theirErrorfield to and from JSON (Goerrorvalues aren't generally==-comparable).Test
Extends the existing
TestMessageIndexUpdate_MatchesKnownContentTypestable (black-box, inequality_test.go) with the previously-uncovered fields: aFunctionCallContentdiffering only inInformationalOnly, one differing only inError, and aFunctionResultContentdiffering only inError— each expected not to match. All three fail onmain(got true want false) and pass with the fix; the existing rows are unchanged.