Skip to content

Add UUID v4 generation to UniqueIdGenerator - #9703

Merged
timosachsenberg merged 2 commits into
developfrom
claude/ci-failure-investigation-fax7re
Jul 2, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
claude/ci-failure-investigation-fax7re

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds UUID v4 generation capability to the UniqueIdGenerator class and refactors existing UUID generation code to use this new centralized implementation.

Changes

  • New getUUID() method: Added a static method to UniqueIdGenerator that generates RFC 4122 compliant UUID v4 strings in the standard 36-character format (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)

    • Leverages the existing seeded random number generator to avoid per-call entropy source dependency
    • Uses two consecutive getUniqueId() calls to obtain 128 bits of randomness
    • Sets version nibble to '4' and variant bits to '10' as per RFC 4122
  • Refactored ArrowIOHelpers: Replaced the local generateUuidV4() implementation with a call to UniqueIdGenerator::getUUID(), eliminating code duplication and ensuring consistent UUID generation across the codebase

  • Comprehensive unit tests: Added tests validating:

    • Correct UUID format (36 characters with hyphens at positions 8, 13, 18, 23)
    • Version nibble is '4'
    • Variant nibble is one of {8, 9, a, b, A, B}
    • All non-hyphen characters are valid hexadecimal digits
    • Uniqueness across 1000 consecutive generations

Benefits

  • Centralized UUID generation logic reduces maintenance burden
  • Consistent random seeding behavior across the application
  • Eliminates dependency on std::random_device per UUID call in ArrowIOHelpers
  • Provides a public API for UUID generation throughout OpenMS

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

https://claude.ai/code/session_01EPSZbWojHGSiXY2EQ2v9hY

Summary by CodeRabbit

  • New Features

    • Added a shared UUID generator that returns standard 36-character UUID v4 strings in xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx format.
    • Updated UUID creation in supported components to use the common generator for consistent formatting.
  • Tests

    • Added tests validating UUID string length and hyphen placement, correct v4 version and variant bits, hex-only characters, and uniqueness across 1000 generated values.

…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.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Claude

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

@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9268ecdb-b604-4f7d-9fd8-d4eb99c2d32f

📥 Commits

Reviewing files that changed from the base of the PR and between 74208a4 and 019ff4f.

📒 Files selected for processing (3)
  • src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h
  • src/openms/source/CONCEPT/UniqueIdGenerator.cpp
  • src/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h
  • src/openms/source/CONCEPT/UniqueIdGenerator.cpp
  • src/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp

📝 Walkthrough

Walkthrough

Adds UniqueIdGenerator::getUUID() for UUIDv4 strings, routes ArrowIOHelpers::generateUuidV4() through it, and adds tests that check UUID formatting and uniqueness.

Changes

UUID generation consolidation

Layer / File(s) Summary
UniqueIdGenerator getUUID implementation
src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h, src/openms/source/CONCEPT/UniqueIdGenerator.cpp
Adds the getUUID() declaration and implementation that builds a UUIDv4 string from two getUniqueId() values, sets version and variant bits, and formats the result as lowercase hex with hyphens.
ArrowIOHelpers delegation to getUUID
src/openms/source/FORMAT/ArrowIOHelpers.cpp
Replaces the local UUID construction logic in generateUuidV4() with UniqueIdGenerator::getUUID() and removes now-unused headers.
Tests for getUUID format and uniqueness
src/tests/class_tests/openms/source/UniqueIdGenerator_test.cpp
Adds a test section that checks UUID length, hyphen positions, version and variant nibbles, hex character validity, and uniqueness across 1000 generated values.

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
Loading

Possibly related PRs

  • OpenMS/OpenMS#9560: Touches the same UUID generation path in ArrowIOHelpers, with test coverage for generateUuidV4() format and uniqueness.

Poem

A rabbit hops with UUID in sight,
From one shared source, the bits align just right.
Hyphens, hex, and v4 glow,
Hop hop—unique strings go!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding UUID v4 generation to UniqueIdGenerator.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/ci-failure-investigation-fax7re

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
src/openms/source/CONCEPT/UniqueIdGenerator.cpp (1)

49-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use OpenMS::Byte instead of uint8_t.

OpenMS defines Byte in Types.h specifically to represent 8-bit byte data. Using the standard uint8_t here 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 win

Use TEST_TRUE instead of TEST_EQUAL(expr, true).

Three assertions here compare a boolean expression against true using TEST_EQUAL instead of TEST_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: "Prefer TEST_TRUE(expr) and TEST_FALSE(expr) over TEST_EQUAL(expr, true) and TEST_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 value

Doc comment doesn't use @brief tag.

New public method documentation uses a plain /// two-line comment instead of the required @brief tag 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 @brief tag (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

📥 Commits

Reviewing files that changed from the base of the PR and between d748be9 and 74208a4.

📒 Files selected for processing (4)
  • src/openms/include/OpenMS/CONCEPT/UniqueIdGenerator.h
  • src/openms/source/CONCEPT/UniqueIdGenerator.cpp
  • src/openms/source/FORMAT/ArrowIOHelpers.cpp
  • src/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.
@timosachsenberg
timosachsenberg merged commit 266ee85 into develop Jul 2, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the claude/ci-failure-investigation-fax7re branch July 2, 2026 14:24
timosachsenberg added a commit that referenced this pull request Jul 3, 2026
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]>
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.

2 participants