Skip to content

refactor(adapters): use Web Crypto randomUUID instead of node:crypto (2/2)#19504

Closed
ediskandarov wants to merge 1 commit into
mastra-ai:mainfrom
ediskandarov:refactor/web-crypto-randomuuid-adapters
Closed

refactor(adapters): use Web Crypto randomUUID instead of node:crypto (2/2)#19504
ediskandarov wants to merge 1 commit into
mastra-ai:mainfrom
ediskandarov:refactor/web-crypto-randomuuid-adapters

Conversation

@ediskandarov

@ediskandarov ediskandarov commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Part 2 of 2 of the repo-wide UUID unification (split from #19502, which exceeded the 150-file review limit; part 1 covers packages/*). This part covers stores/*, agent-sdks/*, pubsub/*, mastracode/, workflows/inngest, voice/*, signals/github, server-adapters/nestjs, and observability/ — 83 files.

Same mechanical change and rationale as part 1: drop randomUUID from node:crypto/crypto imports and call the identical Web Crypto global, removing an unnecessary Node-only module dependency that breaks bundling for V8-isolate runtimes (Convex default runtime, Cloudflare Workers without nodejs_compat). Follows the @mastra/convex fix in #19498.

One non-trivial spot: the datasets storage domains in stores/mongodb, stores/mysql, and stores/spanner passed randomUUID as a function reference to planDatasetItemBatch; those now pass () => crypto.randomUUID().

Related issue(s)

Fixes #19501

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Code refactoring
  • Performance improvement
  • Test update

Testing

  • Zero leftover runtime randomUUID-from-crypto imports in the covered directories (repo-wide grep).
  • pnpm turbo build for @mastra/mongodb, @mastra/mysql, @mastra/spanner, @mastra/openai and their dependency graphs: clean (this caught and verified the function-reference fix above).
  • Deterministic test UUIDs unaffected: @internal/test-utils/setup stubs the global crypto.randomUUID.
  • Changeset patch-bumps the 25 published packages touched here.

AI disclosure

Implemented with Claude Code (Fable 5) as a reviewed codemod; human-reviewed.

🤖 Generated with Claude Code

ELI5

We replaced Node-specific UUID generation with the browser-compatible Web Crypto version across the codebase. This helps the same code run in edge environments like Cloudflare Workers and Convex without extra Node compatibility settings.

Summary

  • Updated UUID generation across storage, SDKs, workflows, voice, pubsub, signals, adapters, Mastra Code, and observability to use crypto.randomUUID().
  • Updated MongoDB, MySQL, and Spanner dataset batching to receive UUID generators.
  • Preserved deterministic UUID stubs in tests and other node:crypto APIs.
  • Added validation to prevent covered directories from reintroducing randomUUID imports.
  • Added patch changesets for 25 published packages.

Part 2/2 of the repo-wide unification (stores/, agent-sdks/, pubsub/,
mastracode/, workflows/, voice/, signals/, server-adapters/,
observability/). Same mechanical change as part 1: drop randomUUID
from node:crypto imports and call the identical Web Crypto global,
removing an unnecessary Node-only module dependency that breaks
V8-isolate bundling.

Fixes mastra-ai#19501

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 002b9a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 38 packages
Name Type
@mastra/acp Patch
@mastra/claude Patch
@mastra/cloudflare Patch
@mastra/cloudflare-d1 Patch
@mastra/code-sdk Patch
@mastra/couchbase Patch
@mastra/cursor Patch
@mastra/github-signals Patch
@mastra/inngest Patch
@mastra/libsql Patch
@mastra/mongodb Patch
@mastra/mssql Patch
@mastra/mysql Patch
@mastra/nestjs Patch
@mastra/observability Patch
@mastra/openai Patch
@mastra/pg Patch
@mastra/google-cloud-pubsub Patch
@mastra/redis-streams Patch
@mastra/spanner Patch
@mastra/upstash Patch
@mastra/vectorize Patch
@mastra/voice-aws-nova-sonic Patch
@mastra/voice-google-gemini-live Patch
mastracode Patch
@mastra/opencode Patch
@mastra/longmemeval Patch
@mastra/braintrust Patch
@mastra/datadog Patch
@mastra/laminar Patch
@mastra/langfuse Patch
@mastra/langsmith Patch
@mastra/otel-bridge Patch
@mastra/otel-exporter Patch
@mastra/posthog Patch
@mastra/sentry Patch
@mastra/arize Patch
@mastra/arthur Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

@ediskandarov is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

@dane-ai-mastra

Copy link
Copy Markdown
Contributor

PR triage

Linked issue check passed (#19501).

Mastra uses CodeRabbit for automated code reviews. Please address all feedback from CodeRabbit by either making changes to your PR or leaving a comment explaining why you disagree with the feedback. Since CodeRabbit is an AI, it may occasionally provide incorrect feedback.


PR complexity score

Factor Value Score impact
Files changed 84 +60
Lines changed 1363 +60
Author merged PRs 3 -3
Test files changed Yes -10
Final score 107

Applied label: complexity: critical


Changed test gate

Changed Test Gate is pending. The Changed Test Gate / changed-tests check will update the test label when it completes.

@coderabbitai

coderabbitai Bot commented Jul 15, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 35dcc9b1-8300-4c12-84a4-4b2c3a6ec26f

📥 Commits

Reviewing files that changed from the base of the PR and between bd2f1d2 and 002b9a3.

📒 Files selected for processing (84)
  • .changeset/web-crypto-uuid-adapters.md
  • agent-sdks/acp/src/agent.ts
  • agent-sdks/claude/src/index.ts
  • agent-sdks/claude/src/utils.ts
  • agent-sdks/cursor/src/index.ts
  • agent-sdks/cursor/src/utils.ts
  • agent-sdks/openai/src/index.ts
  • agent-sdks/openai/src/utils.ts
  • mastracode/sdk/src/acp/server.ts
  • mastracode/sdk/src/analytics.ts
  • mastracode/tui/src/tui/goal-manager.ts
  • mastracode/tui/src/tui/mastra-tui.ts
  • observability/mastra/src/processor-tracing.test.ts
  • pubsub/google-cloud-pubsub/src/agentic-loop-pubsub.test.ts
  • pubsub/redis-streams/src/agentic-loop-pubsub.test.ts
  • pubsub/redis-streams/src/connection-and-cleanup.test.ts
  • pubsub/redis-streams/src/index.ts
  • pubsub/redis-streams/src/pubsub.test.ts
  • pubsub/redis-streams/test-fixtures/agent-thread-worker.entry.ts
  • server-adapters/nestjs/src/services/shutdown.service.ts
  • signals/github/src/index.ts
  • stores/_test-utils/src/domains/agents/data.ts
  • stores/_test-utils/src/domains/agents/index.ts
  • stores/_test-utils/src/domains/background-tasks/data.ts
  • stores/_test-utils/src/domains/channels/data.ts
  • stores/_test-utils/src/domains/datasets/data.ts
  • stores/_test-utils/src/domains/experiments/data.ts
  • stores/_test-utils/src/domains/favorites/data.ts
  • stores/_test-utils/src/domains/memory/data.ts
  • stores/_test-utils/src/domains/memory/messages-update.ts
  • stores/_test-utils/src/domains/memory/observational-memory.ts
  • stores/_test-utils/src/domains/memory/resources.ts
  • stores/_test-utils/src/domains/memory/threads.ts
  • stores/_test-utils/src/domains/observability/data.ts
  • stores/_test-utils/src/domains/schedules/data.ts
  • stores/_test-utils/src/domains/scores/data.ts
  • stores/_test-utils/src/domains/scores/index.ts
  • stores/_test-utils/src/domains/tool-provider-connections/data.ts
  • stores/_test-utils/src/domains/workflows/data.ts
  • stores/_test-utils/src/domains/workflows/index.ts
  • stores/cloudflare-d1/src/storage/rest-api.test.ts
  • stores/cloudflare-d1/src/storage/test-utils.ts
  • stores/cloudflare/src/kv/storage/test-utils.ts
  • stores/couchbase/src/vector/index.integration.test.ts
  • stores/libsql/src/storage/domains/memory/index.ts
  • stores/libsql/src/storage/domains/notifications/index.ts
  • stores/mongodb/src/storage/domains/agents/index.ts
  • stores/mongodb/src/storage/domains/datasets/index.ts
  • stores/mongodb/src/storage/domains/experiments/index.ts
  • stores/mongodb/src/storage/domains/mcp-clients/index.ts
  • stores/mongodb/src/storage/domains/mcp-servers/index.ts
  • stores/mongodb/src/storage/domains/memory/index.ts
  • stores/mongodb/src/storage/domains/notifications/index.ts
  • stores/mongodb/src/storage/domains/prompt-blocks/index.ts
  • stores/mongodb/src/storage/domains/scorer-definitions/index.ts
  • stores/mongodb/src/storage/domains/scores/index.ts
  • stores/mongodb/src/storage/domains/skills/index.ts
  • stores/mongodb/src/storage/domains/workspaces/index.ts
  • stores/mssql/src/storage/domains/agents/index.ts
  • stores/mssql/src/storage/domains/scores/index.ts
  • stores/mysql/src/storage/domains/datasets/index.ts
  • stores/mysql/src/storage/domains/experiments/index.ts
  • stores/mysql/src/storage/domains/memory/index.ts
  • stores/mysql/src/storage/domains/schedules/index.ts
  • stores/pg/src/storage/domains/memory/index.ts
  • stores/pg/src/storage/domains/notifications/index.ts
  • stores/pg/src/storage/domains/observability/v-next/integration.test.ts
  • stores/pg/src/storage/domains/observability/v-next/retention.test.ts
  • stores/pg/src/storage/index.vnext.test.ts
  • stores/redis/src/storage/index.test.ts
  • stores/spanner/src/storage/domains/datasets/index.ts
  • stores/spanner/src/storage/domains/experiments/index.ts
  • stores/spanner/src/storage/domains/observability/metrics.ts
  • stores/spanner/src/storage/domains/schedules/index.ts
  • stores/spanner/src/storage/domains/scores/index.ts
  • stores/spanner/src/storage/index.test.ts
  • stores/upstash/src/storage/index.test.ts
  • stores/upstash/src/vector/index.ts
  • stores/vectorize/src/vector/index.test.ts
  • voice/aws-nova-sonic/src/index.ts
  • voice/google-gemini-live-api/src/index.ts
  • workflows/_test-utils/src/domains/streaming.ts
  • workflows/inngest/src/execution-engine.ts
  • workflows/inngest/src/workflow.ts

Walkthrough

Changes

Web Crypto UUID migration

Layer / File(s) Summary
Runtime adapters and integrations
agent-sdks/*, mastracode/*, pubsub/*, voice/*, workflows/inngest/*
Replaces node:crypto randomUUID imports with crypto.randomUUID() across runtime ID-generation paths.
Shared test fixtures and workflow tests
stores/_test-utils/*, workflows/_test-utils/*, observability/*
Updates generated fixture, stream, memory, score, observability, and workflow test identifiers to use Web Crypto UUID generation.
Storage and vector adapters
stores/{cloudflare,libsql,mongodb,mysql,pg,spanner,upstash,redis}/*
Updates generated storage, dataset, memory, notification, score, version, trace, and vector identifiers while preserving existing control flow.
Release metadata
.changeset/web-crypto-uuid-adapters.md
Adds patch releases and documents the UUID generation change.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

Suggested labels: tests: no tests added

Suggested reviewers: devin-ai-integration[bot], lekoarts, wardpeet, abhiaiyer91, tylerbarnes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR standardizes UUID generation and removes node:crypto randomUUID imports, but it does not show the required regression guard. Add a lint or test guard that blocks new node:crypto randomUUID imports so the repo-wide convention cannot regress.
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is descriptive and clearly matches the Web Crypto UUID refactor.
Out of Scope Changes check ✅ Passed All shown edits are directly tied to the UUID refactor, tests, or release metadata, with no unrelated changes introduced.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@ediskandarov

Copy link
Copy Markdown
Contributor Author

Closing: pivoting to package-scoped PRs per review feedback. Will re-submit per package after the @mastra/core slice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: critical Critical-complexity PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify on Web Crypto crypto.randomUUID and drop node:crypto imports of randomUUID

1 participant