From 5b73bed325725084bfd824e3c557c30d87785f0e Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Thu, 9 Apr 2026 17:08:49 +0800 Subject: [PATCH 1/2] optimize ConversationStateService --- .../Conversations/Services/ConversationStateService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 455a23a02..70b75b6ca 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -38,6 +38,7 @@ public class ConversationStateService : IConversationStateService /// States in the previous rounds of conversation /// private ConversationState _historyStates; + private bool _isReadOnly; public ConversationStateService( IServiceProvider services, @@ -153,7 +154,8 @@ public IConversationStateService SetState(string name, T value, bool isNeedVe public async Task> Load(string conversationId, bool isReadOnly = false) { - _conversationId = !isReadOnly ? conversationId : null; + _isReadOnly = isReadOnly; + _conversationId = conversationId; Reset(); var endNodes = new Dictionary(); @@ -232,7 +234,7 @@ public async Task> Load(string conversationId, bool i public async Task Save() { - if (_conversationId == null || _sidecar?.IsEnabled == true) + if (_conversationId == null || _sidecar?.IsEnabled == true || _isReadOnly == true) { return; } From c591732a65e01bf2ac5b921a087c913492981fdf Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Thu, 9 Apr 2026 17:15:36 +0800 Subject: [PATCH 2/2] simplify state Save --- .../Conversations/Services/ConversationStateService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 70b75b6ca..a58b83947 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -234,7 +234,7 @@ public async Task> Load(string conversationId, bool i public async Task Save() { - if (_conversationId == null || _sidecar?.IsEnabled == true || _isReadOnly == true) + if (_conversationId == null || _sidecar?.IsEnabled == true || _isReadOnly) { return; }