Fix long time update AgentName

This commit is contained in:
2025-09-17 14:47:28 +07:00
parent cee3902a4d
commit 98fdfb9793
3 changed files with 51 additions and 7 deletions

View File

@@ -109,6 +109,20 @@ public class UserService : IUserService
{
account
};
// Initialize AgentGrain for new user (with empty agent name initially)
try
{
var agentGrain = _grainFactory.GetGrain<IAgentGrain>(user.Id);
await agentGrain.InitializeAsync(user.Id, string.Empty);
_logger.LogInformation("AgentGrain initialized for new user {UserId}", user.Id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to initialize AgentGrain for new user {UserId}", user.Id);
SentrySdk.CaptureException(ex);
// Don't throw here to avoid breaking the user creation process
}
}
return user;
@@ -165,17 +179,16 @@ public class UserService : IUserService
user.AgentName = agentName;
await _userRepository.SaveOrUpdateUserAsync(user);
// Initialize the AgentGrain for this user
// Update the AgentGrain with the new agent name (lightweight operation)
try
{
var agentGrain = _grainFactory.GetGrain<IAgentGrain>(user.Id);
await agentGrain.InitializeAsync(user.Id, agentName);
_logger.LogInformation("AgentGrain initialized for user {UserId} with agent name {AgentName}", user.Id,
agentName);
await agentGrain.UpdateAgentNameAsync(agentName);
_logger.LogInformation("AgentGrain updated for user {UserId} with agent name {AgentName}", user.Id, agentName);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to initialize AgentGrain for user {UserId} with agent name {AgentName}",
_logger.LogError(ex, "Failed to update AgentGrain for user {UserId} with agent name {AgentName}",
user.Id, agentName);
// Don't throw here to avoid breaking the user update process
}