diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/WorkflowNamingHelper.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/WorkflowNamingHelper.cs index 26ee0803e4..0b657b3235 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/WorkflowNamingHelper.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/WorkflowNamingHelper.cs @@ -63,8 +63,38 @@ internal static class WorkflowNamingHelper { ArgumentException.ThrowIfNullOrEmpty(executorId); - int separatorIndex = executorId.IndexOf(ExecutorIdSuffixSeparator); - return separatorIndex > 0 ? executorId[..separatorIndex] : executorId; + int separatorIndex = executorId.LastIndexOf(ExecutorIdSuffixSeparator); + if (separatorIndex > 0) + { + ReadOnlySpan suffix = executorId.AsSpan(separatorIndex + 1); + if (IsGuidSuffix(suffix)) + { + return executorId[..separatorIndex]; + } + } + + return executorId; + } + + /// + /// Checks whether the given span looks like a sanitized GUID (32 hex characters). + /// + private static bool IsGuidSuffix(ReadOnlySpan value) + { + if (value.Length != 32) + { + return false; + } + + foreach (char c in value) + { + if (!char.IsAsciiHexDigit(c)) + { + return false; + } + } + + return true; } private static bool TryGetWorkflowName(string? orchestrationFunctionName, [NotNullWhen(true)] out string? workflowName) diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.UnitTests/Workflows/WorkflowNamingHelperTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.UnitTests/Workflows/WorkflowNamingHelperTests.cs index d2c54d24c3..780cf1275d 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.UnitTests/Workflows/WorkflowNamingHelperTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.UnitTests/Workflows/WorkflowNamingHelperTests.cs @@ -64,6 +64,22 @@ public sealed class WorkflowNamingHelperTests Assert.Equal("Physicist", result); } + [Fact] + public void GetExecutorName_NameWithUnderscoresAndGuidSuffix_ReturnsFullName() + { + string result = WorkflowNamingHelper.GetExecutorName("my_agent_8884e71021334ce49517fa2b17b1695b"); + + Assert.Equal("my_agent", result); + } + + [Fact] + public void GetExecutorName_NameWithUnderscoreButNoGuidSuffix_ReturnsSameName() + { + string result = WorkflowNamingHelper.GetExecutorName("my_custom_executor"); + + Assert.Equal("my_custom_executor", result); + } + [Theory] [InlineData(null)] [InlineData("")]