Skip to content

fix: implement __eq__ and __ne__ for CopyOnWriteDict#55

Merged
terylt merged 4 commits into
mainfrom
fix/copyonwritedict-equality-bug
May 29, 2026
Merged

fix: implement __eq__ and __ne__ for CopyOnWriteDict#55
terylt merged 4 commits into
mainfrom
fix/copyonwritedict-equality-bug

Conversation

@prakhar-singh1928
Copy link
Copy Markdown
Contributor

@prakhar-singh1928 prakhar-singh1928 commented May 28, 2026

fix: implement eq and ne for CopyOnWriteDict

Fixes equality comparison bug where CopyOnWriteDict compared equal to {} even when containing data from its wrapped original mapping. This caused apply_policy() to incorrectly drop valid payload modifications when plugins removed all arguments.

Summary

CopyOnWriteDict now compares equality using its materialized logical mapping instead of the empty backing dict storage. This preserves valid hook payload updates when a plugin transforms populated args into an empty {} payload.

Closes: #54

Changes

  • Add eq() to CopyOnWriteDict so equality compares logical mapping contents rather than backing storage
  • Add ne() for consistent inequality behavior
  • Explicitly mark CopyOnWriteDict as unhashable with hash = None ( for lint issues)
  • Add equality and regression coverage in tests/unit/cpex/framework/test_memory.py
  • Add apply_policy() regression coverage in tests/unit/cpex/framework/test_policies.py
  • Add executor-path regression coverage for the tool_pre_invoke empty-args flow in tests/unit/cpex/framework/test_policies.py

Checks

  • PR-scoped lint issues addressed
  • make lint passes
  • make test passes
  • CHANGELOG updated (if user-facing)

Notes (optional)

Copy link
Copy Markdown
Contributor

@vishu-bh vishu-bh left a comment

Choose a reason for hiding this comment

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

Thanks @prakhar-singh1928!

Fixes CopyOnWriteDict equality to compare the materialized mapping instead of the empty underlying dict storage. That preserves valid plugin payload modifications, including the WXO case where wxo_* args are stripped and the resulting args become {}.

The added regression tests cover direct equality, policy application, and the tool_pre_invoke executor path.

LGTM ☘️

Copy link
Copy Markdown
Contributor

@terylt terylt left a comment

Choose a reason for hiding this comment

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

LGTM

@terylt terylt force-pushed the fix/copyonwritedict-equality-bug branch from 2fee074 to 94f736a Compare May 29, 2026 13:01
prakhar-singh1928 and others added 4 commits May 29, 2026 07:07
Fixes equality comparison bug where CopyOnWriteDict compared equal to {}
even when containing data. This caused apply_policy() to incorrectly drop
valid payload modifications when plugins removed all arguments.

Changes:
- Add __eq__ and __ne__ methods to CopyOnWriteDict
- Add 13 comprehensive equality unit tests
- Add policy regression tests for empty args scenario
- Add end-to-end integration tests

Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
- Restored missing 'assert a not in keys' in test_iteration_order_with_deletions
- Added fast-path length check in CopyOnWriteDict.__eq__() for better performance
- Performance optimization is safe: if lengths differ, mappings cannot be equal

Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
@terylt terylt force-pushed the fix/copyonwritedict-equality-bug branch from 94f736a to 307b1e8 Compare May 29, 2026 13:10
@terylt terylt merged commit 8f3738b into main May 29, 2026
21 checks passed
@terylt terylt deleted the fix/copyonwritedict-equality-bug branch May 29, 2026 13:18
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.

[BUG]: CopyOnWriteDict equality causes empty hook arg modifications to be dropped

3 participants