Skip to content

Conversation

@danielaskdd
Copy link
Collaborator

@danielaskdd danielaskdd commented Oct 26, 2025

Refactor: Enhanced Entity Merging with Chunk Tracking

Overview

This PR refactors entity merging operations with chunk tracking information handling, and significant improvements concurrency data integrity. The changes replace global locking with fine-grained entity-specific locks and add comprehensive chunk tracking support throughout the merge process.

Key Improvements

📊 Chunk Tracking Integration

  • Complete tracking support: Entity merge operations now properly update chunk tracking data
  • Relation chunk merging: Preserves and merges chunk tracking information for relationships
  • Entity chunk merging: Maintains chunk associations during entity consolidation
  • Cleanup synchronization: Properly removes old chunk tracking records during entity/relation deletion

🔧 Merge Logic Enhancements

  • Unified attribute merging: Refactored with a consistent _merge_entity_attribute() function
  • New merge strategy: Added join_unique_comma strategy for better attribute combination
  • Relation completeness: Fixed bug where target entity relationships were being lost
  • Deduplication fix: Corrected relation deduplication logic to prevent data loss
  • Undirected graph support: Normalized entity ordering for consistent graph representation

🔒 Concurrency & Performance

  • Fine-grained keyed locking: Replaced global graph database lock with entity/relation-specific locks
  • Multi-entity lock support: Properly handles locking multiple entities when needed
  • Deadlock prevention: Implements sorted lock key generation to prevent concurrent operation conflicts
  • Better throughput: Allows concurrent operations on different entities without blocking

✏️ Enhanced Entity Editing

  • Merge Support with Entity Renaming: Enable renaming of entities during merge operations, even when the target entity already exists.
  • Operation Summary: Entity edit return detailed operation status including merge results, partial success handling, and error information. This allows the frontend to respond more intelligently to different outcomes like partial success (update OK, merge failed) or complete failures.
  • Graceful Fallback: When merge fails, non-name updates are preserved with clear status reporting

🎨 Frontend Enhancements

  • Merge Dialog: New UI component for entity merging with source/target selection
  • Property Edit Dialog: Enhanced property editing with entity_type field support
  • Search History Sync: Improved search history management across operations
  • Internationalization: Updated translations for all supported languages (en, zh, zh_TW, ar, fr)
  • Entity Type Editing: Enable modification of the entity_type field

Migration Notes

  • The merge_strategy parameter is now deprecated (no action required)
  • Existing merge operations will work seamlessly with improved safety
  • No breaking changes to public APIs

Testing Recommendations

  • Test entity merging with multiple scenarios (2 entities, 3+ entities, existing target)
  • Test concurrent edit/merge operations to validate locking mechanism
  • Test partial operation scenarios (successful update but failed merge)
  • Verify entity merge operations in concurrent scenarios
  • Verify chunk tracking integrity after merge operations
  • Verify relationship deduplication during merge
  • Validate relationship completeness after entity consolidation

* Include target entity in collection
* Merge all relevant relationships
* Prevent relationship loss
* Fix merge completeness
• Update GRAPH_FIELD_SEP comment clarity
• Deprecate merge_strategy parameter
• Unify entity/relation merge logic
• Add join_unique_comma strategy
- Pass chunk storages to merge function
- Merge relation chunk tracking data
- Merge entity chunk tracking data
- Delete old chunk tracking records
- Persist chunk storage updates
• Use entity/relation-specific locks
• Lock multiple entities when needed
@danielaskdd
Copy link
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

• Extract internal implementation helpers
• Add allow_merge parameter to aedit_entity
• Support merging when renaming to existing name
• Improve code reusability and modularity
• Maintain backward compatibility
- **API:** The `graph/entity/edit` endpoint now returns a detailed `operation_summary` for better client-side handling of update, rename, and merge outcomes.
- **Web UI:** Added an "auto-merge on rename" option. The UI now gracefully handles merge success, partial failures (update OK, merge fail), and other errors with specific user feedback.
- Add is_renaming condition check
- Ensure updates when entity renamed
- Extract MergeDialog to separate component
- Update search history on entity rename
- Add dropdown refresh trigger mechanism
- Sync query label with entity changes
- Force graph re-render after updates
@danielaskdd danielaskdd merged commit af6aff3 into HKUDS:main Oct 27, 2025
1 check passed
@danielaskdd danielaskdd deleted the merge-entity branch October 27, 2025 18:46
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.

1 participant