-
Notifications
You must be signed in to change notification settings - Fork 2k
.NET: Fix issue with resuming checkpoint after package version upgrade #6670
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
Open
peibekwe
wants to merge
2
commits into
main
Choose a base branch
from
peibekwe/durable-task-version-resume
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
39 changes: 39 additions & 0 deletions
39
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableTaskTypeResolver.cs
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,39 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Concurrent; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Agents.AI.Workflows.Checkpointing; | ||
|
|
||
| namespace Microsoft.Agents.AI.DurableTask.Workflows; | ||
|
|
||
| /// <summary> | ||
| /// Resolves persisted assembly-qualified type-name strings to a loaded <see cref="Type"/>, | ||
| /// tolerating differences in assembly version, culture, and public key token between the | ||
| /// persisted name and the currently loaded assemblies. Results are cached. | ||
| /// </summary> | ||
| internal static class DurableTaskTypeResolver | ||
| { | ||
| private static readonly ConcurrentDictionary<string, Type?> s_cache = new(); | ||
|
|
||
| /// <summary> | ||
| /// Resolves <paramref name="typeName"/> using a qualified <see cref="Type.GetType(string, bool)"/> | ||
| /// lookup, then a partial-name fallback that strips embedded version, culture, and public key | ||
| /// token qualifiers. | ||
| /// </summary> | ||
| [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access", Justification = "Workflow message and event types are registered at startup.")] | ||
| [UnconditionalSuppressMessage("Trimming", "IL2057:Unrecognized value passed to the parameter of method", Justification = "Workflow message and event types are registered at startup.")] | ||
| internal static Type? Resolve(string typeName) | ||
| => s_cache.GetOrAdd(typeName, static name => | ||
| { | ||
| Type? type = Type.GetType(name, throwOnError: false); | ||
| if (type is not null) | ||
| { | ||
| return type; | ||
| } | ||
|
|
||
| string normalized = TypeId.NormalizeTypeName(name); | ||
| return ReferenceEquals(normalized, name) | ||
| ? null | ||
| : Type.GetType(normalized, throwOnError: false); | ||
| }); | ||
|
peibekwe marked this conversation as resolved.
|
||
| } | ||
104 changes: 104 additions & 0 deletions
104
...Agents.AI.DurableTask.UnitTests/Workflows/DurableActivityExecutorResolveInputTypeTests.cs
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,104 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using Microsoft.Agents.AI.DurableTask.Workflows; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI.DurableTask.UnitTests.Workflows; | ||
|
|
||
| /// <summary> | ||
| /// Verifies that <see cref="DurableActivityExecutor.ResolveInputType(string?, ISet{Type})"/> | ||
| /// matches persisted assembly-qualified type-name strings against the executor's supported | ||
| /// input types even when the persisted name carries a different assembly version, culture, | ||
| /// or public key token than the loaded assemblies. | ||
| /// </summary> | ||
| public sealed class DurableActivityExecutorResolveInputTypeTests | ||
| { | ||
| [Fact] | ||
| public void ResolveInputType_NullInput_ReturnsFirstSupportedType() | ||
| { | ||
| Type result = DurableActivityExecutor.ResolveInputType(null, new HashSet<Type> { typeof(int) }); | ||
|
|
||
| Assert.Equal(typeof(int), result); | ||
| } | ||
|
peibekwe marked this conversation as resolved.
|
||
|
|
||
| [Fact] | ||
| public void ResolveInputType_EmptyInputAndNoSupportedTypes_FallsBackToString() | ||
| { | ||
| Type result = DurableActivityExecutor.ResolveInputType(string.Empty, new HashSet<Type>()); | ||
|
|
||
| Assert.Equal(typeof(string), result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ResolveInputType_LoadedAssemblyQualifiedName_ReturnsSupportedType() | ||
| { | ||
| Type supported = typeof(ChatMessage); | ||
| ISet<Type> supportedTypes = new HashSet<Type> { supported }; | ||
|
|
||
| Type result = DurableActivityExecutor.ResolveInputType(supported.AssemblyQualifiedName, supportedTypes); | ||
|
|
||
| Assert.Same(supported, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ResolveInputType_MutatedAssemblyVersion_ReturnsSupportedType() | ||
| { | ||
| Type supported = typeof(ChatMessage); | ||
| string simpleAssemblyName = supported.Assembly.GetName().Name!; | ||
| string mutated = $"{supported.FullName}, {simpleAssemblyName}, Version=99.0.0.0, Culture=neutral, PublicKeyToken=null"; | ||
| ISet<Type> supportedTypes = new HashSet<Type> { supported }; | ||
|
|
||
| Type result = DurableActivityExecutor.ResolveInputType(mutated, supportedTypes); | ||
|
|
||
| Assert.Same(supported, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ResolveInputType_MutatedGenericArgumentVersion_ReturnsSupportedType() | ||
| { | ||
| Type supported = typeof(List<ChatMessage>); | ||
| string outerSimple = supported.Assembly.GetName().Name!; | ||
| string innerSimple = typeof(ChatMessage).Assembly.GetName().Name!; | ||
| string mutated = | ||
| $"System.Collections.Generic.List`1[[Microsoft.Extensions.AI.ChatMessage, {innerSimple}, " + | ||
| "Version=99.0.0.0, Culture=neutral, PublicKeyToken=null]], " + | ||
| $"{outerSimple}, Version=99.0.0.0, Culture=neutral, PublicKeyToken=null"; | ||
| ISet<Type> supportedTypes = new HashSet<Type> { supported }; | ||
|
|
||
| Type result = DurableActivityExecutor.ResolveInputType(mutated, supportedTypes); | ||
|
|
||
| Assert.Same(supported, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ResolveInputType_ShortNameMatch_ReturnsSupportedType() | ||
| { | ||
| Type supported = typeof(ChatMessage); | ||
| ISet<Type> supportedTypes = new HashSet<Type> { supported }; | ||
|
|
||
| Type result = DurableActivityExecutor.ResolveInputType(supported.Name, supportedTypes); | ||
|
|
||
| Assert.Same(supported, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ResolveInputType_FullNameMatch_ReturnsSupportedType() | ||
| { | ||
| Type supported = typeof(ChatMessage); | ||
| ISet<Type> supportedTypes = new HashSet<Type> { supported }; | ||
|
|
||
| Type result = DurableActivityExecutor.ResolveInputType(supported.FullName, supportedTypes); | ||
|
|
||
| Assert.Same(supported, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ResolveInputType_StringFallback_ReturnsFirstSupportedTypeWhenStringUnsupported() | ||
| { | ||
| ISet<Type> supportedTypes = new HashSet<Type> { typeof(int) }; | ||
|
|
||
| Type result = DurableActivityExecutor.ResolveInputType(typeof(string).AssemblyQualifiedName, supportedTypes); | ||
|
|
||
| Assert.Equal(typeof(int), result); | ||
| } | ||
| } | ||
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
75 changes: 75 additions & 0 deletions
75
...tests/Microsoft.Agents.AI.DurableTask.UnitTests/Workflows/DurableTaskTypeResolverTests.cs
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,75 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using Microsoft.Agents.AI.DurableTask.Workflows; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI.DurableTask.UnitTests.Workflows; | ||
|
|
||
| /// <summary> | ||
| /// Verifies that <see cref="DurableTaskTypeResolver.Resolve(string)"/> resolves persisted | ||
| /// assembly-qualified type-name strings to a loaded <see cref="Type"/> across assembly | ||
| /// version, culture, and public key token mutations. | ||
| /// </summary> | ||
| public sealed class DurableTaskTypeResolverTests | ||
| { | ||
| [Fact] | ||
| public void Resolve_LoadedAssemblyQualifiedName_ReturnsLiveType() | ||
| { | ||
| Type live = typeof(List<ChatMessage>); | ||
| string aqn = live.AssemblyQualifiedName!; | ||
|
|
||
| Type? resolved = DurableTaskTypeResolver.Resolve(aqn); | ||
|
|
||
| Assert.Same(live, resolved); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Resolve_MutatedOuterAssemblyVersion_ReturnsLiveType() | ||
| { | ||
| Type live = typeof(ChatMessage); | ||
| string outerSimpleName = live.Assembly.GetName().Name!; | ||
| string mutated = $"{live.FullName}, {outerSimpleName}, Version=99.0.0.0, Culture=neutral, PublicKeyToken=null"; | ||
|
|
||
| Type? resolved = DurableTaskTypeResolver.Resolve(mutated); | ||
|
|
||
| Assert.Same(live, resolved); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Resolve_MutatedGenericArgumentVersion_ReturnsLiveType() | ||
| { | ||
| Type live = typeof(List<ChatMessage>); | ||
| string outerSimpleName = live.Assembly.GetName().Name!; | ||
| string innerSimpleName = typeof(ChatMessage).Assembly.GetName().Name!; | ||
| string mutated = | ||
| $"System.Collections.Generic.List`1[[Microsoft.Extensions.AI.ChatMessage, {innerSimpleName}, " + | ||
| "Version=99.0.0.0, Culture=neutral, PublicKeyToken=null]], " + | ||
| $"{outerSimpleName}, Version=99.0.0.0, Culture=neutral, PublicKeyToken=null"; | ||
|
|
||
| Type? resolved = DurableTaskTypeResolver.Resolve(mutated); | ||
|
|
||
| Assert.Same(live, resolved); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Resolve_UnknownType_ReturnsNull() | ||
| { | ||
| Type? resolved = DurableTaskTypeResolver.Resolve( | ||
| "Some.Unknown.Namespace.MissingType, Some.Unloaded.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); | ||
|
|
||
| Assert.Null(resolved); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Resolve_CachesResults() | ||
| { | ||
| Type live = typeof(ChatMessage); | ||
| string aqn = live.AssemblyQualifiedName!; | ||
|
|
||
| Type? first = DurableTaskTypeResolver.Resolve(aqn); | ||
| Type? second = DurableTaskTypeResolver.Resolve(aqn); | ||
|
|
||
| Assert.Same(first, second); | ||
| Assert.Same(live, second); | ||
| } | ||
| } |
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.