Repository navigation
Add UUID v4 generation to UniqueIdGenerator - #9703
Conversation
…pers ArrowIOHelpers::generateUuidV4() constructed a fresh std::random_device and reseeded a local std::mt19937 on every call, which caused a rare but observed duplicate-UUID failure in ArrowIOHelpers_test on CI (weak random_device entropy on the runner produced two identical seeds across 1000 draws). UniqueIdGenerator already solves this correctly: a single process-wide RNG seeded once from high-resolution time mixed with the PID, accessed under an OpenMP critical section. Add getUUID(), which draws two 64-bit values from it to build a version-4 UUID, and have generateUuidV4() delegate to it instead of hand-rolling its own RNG.
|
@timosachsenberg The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-07-02 10:50:56.398812445 +0000
+++ AUTHORS.new 2026-07-02 10:51:01.788088237 +0000
@@ -25,6 +25,7 @@
- Chris Bielow
- Christian Ehrlich
- Christie Mathews
+ - Claude
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds ChangesUUID generation consolidation
Sequence Diagram(s)sequenceDiagram
participant ArrowIOHelpers
participant UniqueIdGenerator
participant Test
ArrowIOHelpers->>UniqueIdGenerator: getUUID()
UniqueIdGenerator->>UniqueIdGenerator: getUniqueId() x2
UniqueIdGenerator-->>ArrowIOHelpers: UUID string
Test->>UniqueIdGenerator: getUUID() repeated
Test->>Test: validate format and uniqueness
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/openms/source/CONCEPT/UniqueIdGenerator.cpp (1)
49-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
OpenMS::Byteinstead ofuint8_t.OpenMS defines
ByteinTypes.hspecifically to represent 8-bit byte data. Using the standarduint8_there deviates from the project's typed-primitives convention.♻️ Suggested change
- uint8_t bytes[16]; + Byte bytes[16];As per coding guidelines,
**/*.{h,hpp,cpp}: "Use OpenMS primitive types from OpenMS/CONCEPT/Types.h instead of standard C++ types".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/CONCEPT/UniqueIdGenerator.cpp` at line 49, Replace the local byte buffer in UniqueIdGenerator with the OpenMS primitive type from Types.h instead of the standard fixed-width integer. Update the declaration in UniqueIdGenerator so it uses OpenMS::Byte for the 16-byte array, keeping the rest of the UUID generation logic unchanged and aligned with the project’s typed-primitives convention.Source: Coding guidelines
src/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp (1)
73-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
TEST_TRUEinstead ofTEST_EQUAL(expr, true).Three assertions here compare a boolean expression against
trueusingTEST_EQUALinstead ofTEST_TRUE.✅ Suggested change
- TEST_EQUAL(u[8] == '-' && u[13] == '-' && u[18] == '-' && u[23] == '-', true) + TEST_TRUE(u[8] == '-' && u[13] == '-' && u[18] == '-' && u[23] == '-') // version nibble must be '4' (UUIDv4) TEST_EQUAL(u[14], '4') // variant nibble encodes the 10xx bits -> one of 8, 9, a, b const char var = u[19]; - TEST_EQUAL(var == '8' || var == '9' || var == 'a' || var == 'b' || - var == 'A' || var == 'B', true) + TEST_TRUE(var == '8' || var == '9' || var == 'a' || var == 'b' || + var == 'A' || var == 'B') ... - TEST_EQUAL(all_hex, true) + TEST_TRUE(all_hex)As per coding guidelines,
src/tests/class_tests/**/*_test.cpp: "PreferTEST_TRUE(expr)andTEST_FALSE(expr)overTEST_EQUAL(expr, true)andTEST_EQUAL(expr, false)for boolean assertions".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp` around lines 73 - 92, Replace the boolean assertions in UniqueIdGenerator_test with TEST_TRUE for the UUID format checks: the hyphen-position check, the variant nibble membership check, and the all_hex flag check currently use TEST_EQUAL(..., true). Update those assertions in the UniqueIdGenerator test case to follow the test convention and keep the same expressions, just switch to TEST_TRUE(expr) for each boolean condition.Source: Coding guidelines
src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h (1)
42-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDoc comment doesn't use
@brieftag.New public method documentation uses a plain
///two-line comment instead of the required@brieftag followed by a blank line and details. Note this matches the existing style of sibling methods in this class (getUniqueId(),setSeed(),getSeed()), so this is a pre-existing pattern being extended rather than a net-new deviation.📝 Suggested doc format
- /// Returns a new random UUID (version 4), formatted as the standard - /// 36-character string "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx". + /** + `@brief` Returns a new random UUID (version 4) + + Formatted as the standard 36-character string + "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx". + */ static std::string getUUID();As per coding guidelines,
**/*.h: "Add Doxygen documentation with@brieftag (required), followed by blank line and details".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h` around lines 42 - 45, The new public API documentation for getUUID() in UniqueIdGenerator.h should follow the class’s Doxygen style by using an `@brief` tag, then a blank line, then the detailed description. Update the comment on getUUID() to match the existing patterns used by getUniqueId(), setSeed(), and getSeed(), keeping the same wording but converting it to the required brief-plus-details format.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h`:
- Around line 42-45: The new public API documentation for getUUID() in
UniqueIdGenerator.h should follow the class’s Doxygen style by using an `@brief`
tag, then a blank line, then the detailed description. Update the comment on
getUUID() to match the existing patterns used by getUniqueId(), setSeed(), and
getSeed(), keeping the same wording but converting it to the required
brief-plus-details format.
In `@src/openms/source/CONCEPT/UniqueIdGenerator.cpp`:
- Line 49: Replace the local byte buffer in UniqueIdGenerator with the OpenMS
primitive type from Types.h instead of the standard fixed-width integer. Update
the declaration in UniqueIdGenerator so it uses OpenMS::Byte for the 16-byte
array, keeping the rest of the UUID generation logic unchanged and aligned with
the project’s typed-primitives convention.
In `@src/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp`:
- Around line 73-92: Replace the boolean assertions in UniqueIdGenerator_test
with TEST_TRUE for the UUID format checks: the hyphen-position check, the
variant nibble membership check, and the all_hex flag check currently use
TEST_EQUAL(..., true). Update those assertions in the UniqueIdGenerator test
case to follow the test convention and keep the same expressions, just switch to
TEST_TRUE(expr) for each boolean condition.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 47d4ec40-fef2-4b65-92f0-638f0151eead
📒 Files selected for processing (4)
src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.hsrc/openms/source/CONCEPT/UniqueIdGenerator.cppsrc/openms/source/FORMAT/ArrowIOHelpers.cppsrc/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp
Use OpenMS::Byte instead of uint8_t for the UUID byte buffer, switch boolean test assertions to TEST_TRUE per the test-suite convention, and format the getUUID() doc comment with the required @brief tag.
UniqueIdGenerator::getUUID() and the ArrowIOHelpers RNG fix landed without a CHANGELOG entry. Claude-Session: https://claude.ai/code/session_011wx1fg4dRyPtp75eUqYd7B Co-authored-by: Claude <[email protected]>
Description
This PR adds UUID v4 generation capability to the
UniqueIdGeneratorclass and refactors existing UUID generation code to use this new centralized implementation.Changes
New
getUUID()method: Added a static method toUniqueIdGeneratorthat generates RFC 4122 compliant UUID v4 strings in the standard 36-character format (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)getUniqueId()calls to obtain 128 bits of randomnessRefactored
ArrowIOHelpers: Replaced the localgenerateUuidV4()implementation with a call toUniqueIdGenerator::getUUID(), eliminating code duplication and ensuring consistent UUID generation across the codebaseComprehensive unit tests: Added tests validating:
Benefits
std::random_deviceper UUID call in ArrowIOHelpersChecklist
https://claude.ai/code/session_01EPSZbWojHGSiXY2EQ2v9hY
Summary by CodeRabbit
New Features
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxxformat.Tests