-
Notifications
You must be signed in to change notification settings - Fork 620
Fix keyset pagination with monotonic UUIDv7-like task IDs #1215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+247
−25
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0e085be
Initial plan
Copilot f32e1e1
Fix sporadic test failure by using monotonically increasing task IDs
Copilot b699d69
Fix keyset pagination by sorting before applying cursor filter
Copilot fba8ccf
Refactor keyset pagination code styling per review feedback
Copilot 0fd7769
Add TimeProvider support and test for identical timestamp handling
Copilot b8fa0d8
Revert TimeProvider NuGet dependency, use conditional compilation for…
Copilot 1213ce8
Add comment explaining CS0436 suppression for linked InMemoryMcpTaskS…
Copilot a80c8b4
Use conditional namespace to avoid CS0436 type conflicts
Copilot 32dbb40
Use monotonic UUID v7 for task IDs with polyfill for older targets
Copilot fdd7e85
Move UUID v7 polyfill to Common/Polyfills/System/GuidPolyfills.cs
Copilot 4053b29
Revert ListTasksAsync changes, use monotonic GUID with TimeProvider s…
Copilot a637ea2
Move UUID v7 generation logic back to GuidPolyfills class
Copilot 8ef5371
Simplify pagination cursor to use only TaskId since UUID v7 is monoto…
Copilot ef86c4d
Rename polyfill to CreateVersion7(DateTimeOffset) to match .NET 9 API
Copilot 676aecb
Revert to CreateMonotonicUuid name and document why CreateVersion7 ca…
Copilot 0877589
Refactor GuidPolyfills to GuidHelpers with simplified monotonic counter
Copilot 7ea4064
Simplify GUID creation using unsafe pointer manipulation
Copilot e17be78
Fix test project duplicate compile for GuidHelpers.cs on net472
Copilot a9f8a4d
Scope unsafe block to only the pointer manipulation lines
Copilot 446477d
Clarify comment that this is UUIDv7-like format, not RFC-compliant
Copilot 0854883
Move AllowUnsafeBlocks to specific project csproj files
Copilot fe42850
Use two longs (ticks + counter) for monotonic ID generation instead o…
Copilot 5dc6a21
Rename GuidHelpers to IdHelpers since it no longer generates GUIDs
Copilot 14d0d82
Update src/ModelContextProtocol.Core/ModelContextProtocol.Core.csproj
stephentoub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using System.Threading; | ||
|
|
||
| namespace System; | ||
|
|
||
| /// <summary> | ||
| /// Provides helper methods for monotonic ID generation. | ||
| /// </summary> | ||
| internal static class IdHelpers | ||
| { | ||
| private static long s_counter; | ||
|
|
||
| /// <summary> | ||
| /// Creates a strictly monotonically increasing identifier string using 64-bit timestamp ticks | ||
| /// and a 64-bit counter, formatted as a 32-character hexadecimal string (GUID-like). | ||
| /// </summary> | ||
| /// <param name="timestamp">The timestamp to embed in the identifier.</param> | ||
| /// <returns>A new strictly monotonically increasing identifier string.</returns> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// This method creates a 128-bit identifier composed of two 64-bit values: | ||
| /// - High 64 bits: <see cref="DateTimeOffset.Ticks"/> from the timestamp | ||
| /// - Low 64 bits: A globally monotonically increasing counter | ||
| /// </para> | ||
| /// <para> | ||
| /// The resulting string is strictly monotonically increasing when compared lexicographically, | ||
| /// which is required for keyset pagination to work correctly. Unlike <c>Guid.CreateVersion7</c>, | ||
| /// which uses random bits for intra-millisecond uniqueness, this implementation guarantees | ||
| /// strict ordering for all identifiers regardless of when they were created. | ||
| /// </para> | ||
| /// </remarks> | ||
| public static string CreateMonotonicId(DateTimeOffset timestamp) | ||
| { | ||
| long ticks = timestamp.UtcTicks; | ||
| long counter = Interlocked.Increment(ref s_counter); | ||
|
|
||
| // Format as 32-character hex string (16 bytes = 128 bits) | ||
| // High 64 bits: timestamp ticks, Low 64 bits: counter | ||
| return $"{ticks:x16}{counter:x16}"; | ||
stephentoub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.