[Feature Proposal] Add persistent unique identity for shapes
Search before asking
- [x] I have searched the X-AnyLabeling issues and found no similar feature requests.
Description
Problem
Shape array indexes are not stable after sorting, insertion, deletion, copy/paste, editing, or reloading a JSON file.
Fields such as group_id describe relationships between shapes, but do not
identify an individual shape. This makes it difficult for downstream systems
to track the same object over time.
Proposal
Add a persistent field named xanylabeling_shape_id to every shape in the
annotation JSON.
The ID should:
- remain unchanged after editing, saving, reloading, and undo/redo;
- be preserved when an existing valid ID is found;
- be generated for missing IDs;
- repair invalid or duplicated IDs;
- be unique within the same annotation JSON file;
- apply to rectangles, polygons, points, lines, masks, rotated boxes, and other shape types;
- be stored as the first JSON property for readability and stable diffs.
The migration must not remove or modify unrelated fields such as
group_id, description, flags, attributes, kie_linking, or
difficult.
This field is intended to provide stable object identity for downstream features and tools.
Use case
Use cases
-
Track the same annotation object after editing, sorting, deletion, or reloading.
-
Support downstream object management using:
(project_id, image_id, xanylabeling_shape_id) -
Connect behavior analytics, quality inspection, review queues, and virtual review workflows to a stable shape identity.
-
Support cross-image object operations without relying on the shape array index.
-
Migrate historical JSON files that do not contain shape IDs.
-
Preserve object identity when labels or other annotation attributes are changed.
Additional
Additional information
- Proposed field name:
xanylabeling_shape_id - Proposed format: 32-character lowercase hexadecimal UUID4 value
- If a generated ID collides with an existing ID, retry up to 1024 times
- Existing valid IDs must be preserved
- Missing, invalid, or duplicated IDs should be repaired
- Loading an old JSON may repair IDs in memory without immediately writing the file
- A separate project-level migration action can write IDs back to JSON files
- Migration should only modify the ID field and its key position
- Geometry, labels, and unrelated fields must remain unchanged
- External export formats do not necessarily need to expose this private field
Design Document
Detailed design document:
Persistent Shape Identity Project Design
Are you willing to submit a PR?
- [x] Yes I'd like to help by submitting a PR!