Skip to content

fix: generate SDK UUIDs as v7#237

Draft
marandaneto wants to merge 2 commits into
mainfrom
fix/use-uuid-v7
Draft

fix: generate SDK UUIDs as v7#237
marandaneto wants to merge 2 commits into
mainfrom
fix/use-uuid-v7

Conversation

@marandaneto

@marandaneto marandaneto commented Jun 19, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

SDK-generated IDs should be UUID v7 so event UUIDs, personless distinct IDs, and default AI trace IDs are time-ordered instead of random UUID v4 values.

This adds an internal UUID v7 helper that uses Guid.CreateVersion7() when the runtime provides it, with a fallback generator for older runtimes/target frameworks. The helper is used for runtime SDK-generated IDs in PostHog and PostHog.AI.

💚 How did you test it?

  • dotnet test tests/UnitTests/UnitTests.csproj --filter "FullyQualifiedName~CapturedEventTests|FullyQualifiedName~PostHogContextTests"
  • dotnet test tests/PostHog.AI.Tests/PostHog.AI.Tests.csproj --filter "FullyQualifiedName~PostHogOpenAIHandlerTests.SendAsyncCapturesEventOnSuccess"
  • dotnet build src/PostHog/PostHog.csproj --no-restore
  • dotnet build src/PostHog.AI/PostHog.AI.csproj --no-restore
  • dotnet test PostHog.sln
  • dotnet test
  • dotnet format --verify-no-changes

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented by the worker agent using repository-local inspection and .NET CLI validation. Follow-up review feedback added runtime use of Guid.CreateVersion7() when available plus deterministic fallback monotonicity coverage.

@marandaneto marandaneto self-assigned this Jun 19, 2026
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-06-19 11:43:40 UTC
Duration: 630ms

⚠️ Some Tests Failed

2/16 tests passed, 14 failed


Feature_Flags Tests

⚠️ 2/16 tests passed, 14 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 44ms
Request Payload.Flags Request Uses V2 Query Param 22ms
Request Payload.Flags Request Hits Flags Path Not Decide 5ms
Request Payload.Flags Request Omits Authorization Header 5ms
Request Payload.Token In Flags Body Matches Init 5ms
Request Payload.Groups Round Trip 5ms
Request Payload.Groups Default To Empty Object 5ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 5ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 5ms
Request Payload.Disable Geoip Omitted Defaults To False 4ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 5ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 184ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 7ms
Request Lifecycle.Mock Response Value Is Returned To Caller 5ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 5ms

Failures

request_payload.request_with_person_properties_device_id

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_uses_v2_query_param

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_hits_flags_path_not_decide

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_omits_authorization_header

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.token_in_flags_body_matches_init

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.groups_round_trip

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.groups_default_to_empty_object

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.disable_geoip_false_propagates_as_geoip_disable_false

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.disable_geoip_omitted_defaults_to_false

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flag_keys_to_evaluate_contains_only_requested_key

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_lifecycle.two_flag_calls_produce_two_remote_requests

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_lifecycle.mock_response_value_is_returned_to_caller

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

side_effect_events.get_feature_flag_captures_feature_flag_called_event

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/PostHog/Library/UuidV7.cs:48-58
**Monotonicity not covered by any test**

The `IncrementRandom` counter is the whole reason this file exists rather than a simple `Guid.NewGuid()` wrapper — it ensures UUIDs generated in the same millisecond are still lexicographically ordered. But there is no test that actually exercises this path. A test that generates two UUIDs in rapid succession (spinning in a tight loop until two share the same millisecond) and then asserts `string.Compare(first, second) < 0` would give real confidence that the increment logic is correct. Without it, a future refactor of `IncrementRandom` could silently break the ordering guarantee and the existing test suite would not catch it.

Reviews (1): Last reviewed commit: "fix: generate SDK UUIDs as v7" | Re-trigger Greptile

Comment thread src/PostHog/Library/UuidV7.cs
Comment thread src/PostHog/Library/UuidV7.cs
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.

1 participant