Fix GetExecutorName to handle agent names with underscores

Split on last underscore instead of first, and validate that the
suffix is a 32-char hex string (sanitized GUID) before stripping it.
This prevents truncation of agent names like 'my_agent' when the
executor ID is 'my_agent_<guid>'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Shyju Krishnankutty
2026-03-03 19:57:43 -08:00
Unverified
parent 41d5c6ea47
commit f59eba4926
2 changed files with 48 additions and 2 deletions
@@ -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<char> suffix = executorId.AsSpan(separatorIndex + 1);
if (IsGuidSuffix(suffix))
{
return executorId[..separatorIndex];
}
}
return executorId;
}
/// <summary>
/// Checks whether the given span looks like a sanitized GUID (32 hex characters).
/// </summary>
private static bool IsGuidSuffix(ReadOnlySpan<char> 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)
@@ -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("")]