fix: generate SDK UUIDs as v7#237
Conversation
posthog-dotnet Compliance ReportDate: 2026-06-19 11:43:40 UTC
|
| 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'
Prompt To Fix All With AIFix 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 |
💡 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 inPostHogandPostHog.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-restoredotnet build src/PostHog.AI/PostHog.AI.csproj --no-restoredotnet test PostHog.slndotnet testdotnet format --verify-no-changes📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented by the
workeragent using repository-local inspection and .NET CLI validation. Follow-up review feedback added runtime use ofGuid.CreateVersion7()when available plus deterministic fallback monotonicity coverage.