Skip to content

fix: UUID generation fail in docker env#529

Merged
Shironex merged 1 commit intov0.12.0rcfrom
feature/v0.12.0rc-1768603410796-o2fn
Jan 17, 2026
Merged

fix: UUID generation fail in docker env#529
Shironex merged 1 commit intov0.12.0rcfrom
feature/v0.12.0rc-1768603410796-o2fn

Conversation

@Shironex
Copy link
Copy Markdown
Collaborator

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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 and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Shironex, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves an issue where UUID generation could fail in certain environments, specifically within Docker containers, by implementing a more resilient UUID generation strategy. It introduces a new, centralized utility function that intelligently selects the most appropriate and available method for creating UUIDs, complete with fallbacks. This ensures that unique identifiers are consistently and reliably generated, improving the application's stability and resolving issue #526.

Highlights

  • Robust UUID Generation: Introduced a new utility function, generateUUID, in apps/ui/src/lib/utils.ts to provide a more robust and compatible method for generating UUIDs.
  • Fallback Mechanism: The generateUUID function now includes a fallback mechanism, attempting to use crypto.randomUUID() first, then crypto.getRandomValues(), and finally Math.random() as a last resort, to ensure UUID generation works reliably across various environments, including Docker where crypto.randomUUID() might fail.
  • Consistent Application-Wide Usage: Replaced all direct calls to crypto.randomUUID() with the new generateUUID utility across multiple UI components, standardizing UUID creation throughout the application.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust generateUUID utility function to address failures of crypto.randomUUID in non-secure environments like Docker. The new function correctly falls back to crypto.getRandomValues and then to Math.random if necessary. The changes across the codebase consistently adopt this new utility. My review includes a minor refactoring suggestion for the generateUUID function to improve its structure and readability.

Comment thread apps/ui/src/lib/utils.ts
Comment on lines +137 to +161
// Use native randomUUID if available (secure contexts: HTTPS or localhost)
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
}

// Fallback using crypto.getRandomValues() (works in all modern browsers, including non-secure contexts)
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);

// Set version (4) and variant (RFC 4122) bits
bytes[6] = (bytes[6] & 0x0f) | 0x40; // Version 4
bytes[8] = (bytes[8] & 0x3f) | 0x80; // Variant RFC 4122

// Convert to hex string with proper UUID format
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
}

// Last resort fallback using Math.random() - less secure but ensures functionality
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
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.

medium

For better readability and to avoid redundant checks, you can group the crypto related logic under a single typeof crypto !== 'undefined' check. This makes the code slightly cleaner and more efficient by checking for the existence of the crypto object only once.

  if (typeof crypto !== 'undefined') {
    // Use native randomUUID if available (secure contexts: HTTPS or localhost)
    if (typeof crypto.randomUUID === 'function') {
      return crypto.randomUUID();
    }

    // Fallback using crypto.getRandomValues() (works in all modern browsers, including non-secure contexts)
    if (typeof crypto.getRandomValues === 'function') {
      const bytes = new Uint8Array(16);
      crypto.getRandomValues(bytes);

      // Set version (4) and variant (RFC 4122) bits
      bytes[6] = (bytes[6] & 0x0f) | 0x40; // Version 4
      bytes[8] = (bytes[8] & 0x3f) | 0x80; // Variant RFC 4122

      // Convert to hex string with proper UUID format
      const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
      return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
    }
  }

  // Last resort fallback using Math.random() - less secure but ensures functionality
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
    const r = (Math.random() * 16) | 0;
    const v = c === 'x' ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });

@Shironex Shironex added the Bug Something isn't working label Jan 16, 2026
@ruant
Copy link
Copy Markdown
Contributor

ruant commented Jan 17, 2026

LGTM, tested it and it works fine for me

@Shironex Shironex merged commit 93d73f6 into v0.12.0rc Jan 17, 2026
7 of 8 checks passed
@Shironex Shironex deleted the feature/v0.12.0rc-1768603410796-o2fn branch January 17, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants