Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public async Task<IEnumerable<VectorCollectionConfig>> GetKnowledgeCollectionCon
return configs;
}

#if !DEBUG
[SharpCache(10)]
#endif
public async Task<VectorCollectionConfig> GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider)
{
var configs = await GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter
Expand All @@ -121,7 +123,7 @@ public async Task<VectorCollectionConfig> GetKnowledgeCollectionConfig(string co
});
return configs?.FirstOrDefault();
}
#endregion
#endregion


#region Documents
Expand Down
51 changes: 26 additions & 25 deletions src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,6 @@ public MembaseGraphDb(

private const int RetryCount = 3;

private AsyncPolicy BuildRetryPolicy()
{
var settings = _services.GetRequiredService<MembaseSettings>();
var timeoutSeconds = (double)settings.TimeoutSecond / RetryCount;

var timeoutPolicy = Policy.TimeoutAsync(TimeSpan.FromSeconds(timeoutSeconds));

var retryPolicy = Policy
.Handle<HttpRequestException>()
.Or<TaskCanceledException>()
.Or<TimeoutRejectedException>()
.Or<ApiException>(ex => ex.StatusCode == HttpStatusCode.ServiceUnavailable)
.WaitAndRetryAsync(
retryCount: RetryCount,
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
onRetry: (ex, timespan, retryAttempt, _) =>
{
_logger.LogWarning(ex,
"CypherQueryAsync retry {RetryAttempt}/{MaxRetries} after {Delay}s. Exception: {Message}",
retryAttempt, RetryCount, timespan.TotalSeconds, ex.Message);
});

return Policy.WrapAsync(retryPolicy, timeoutPolicy);
}

public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryExecuteOptions? options = null)
{
if (string.IsNullOrEmpty(options?.GraphId))
Expand Down Expand Up @@ -87,4 +62,30 @@ public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryEx
throw;
}
}


private AsyncPolicy BuildRetryPolicy()
{
var settings = _services.GetRequiredService<MembaseSettings>();
var timeoutSeconds = (double)settings.TimeoutSecond / RetryCount;

var timeoutPolicy = Policy.TimeoutAsync(TimeSpan.FromSeconds(timeoutSeconds));

var retryPolicy = Policy
.Handle<HttpRequestException>()
.Or<TaskCanceledException>()
.Or<TimeoutRejectedException>()
.Or<ApiException>(ex => ex.StatusCode == HttpStatusCode.ServiceUnavailable)
.WaitAndRetryAsync(
retryCount: RetryCount,
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
onRetry: (ex, timespan, retryAttempt, _) =>
{
_logger.LogWarning(ex,
"CypherQueryAsync retry {RetryAttempt}/{MaxRetries} after {Delay}s. Exception: {Message}",
retryAttempt, RetryCount, timespan.TotalSeconds, ex.Message);
});
Comment on lines +84 to +87
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Logs raw ex.message 📘 Rule violation ⛨ Security

The retry logger records the raw exception message (ex.Message), which may include sensitive
user/provider content or internal configuration details depending on the thrown exception. This
violates the requirement to avoid logging sensitive content and to keep logs minimal/structured.
Agent Prompt
## Issue description
The retry log includes `ex.Message`, which may contain sensitive user/provider payloads or internal configuration details.

## Issue Context
Compliance requires logs to exclude sensitive content and avoid exposing internal configuration values; logs should prefer minimal, structured metadata.

## Fix Focus Areas
- src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.cs[84-87]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


return Policy.WrapAsync(retryPolicy, timeoutPolicy);
}
}
4 changes: 0 additions & 4 deletions src/Plugins/BotSharp.Plugin.Membase/Services/DemoRuleGraph.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using BotSharp.Abstraction.Graph;
using BotSharp.Abstraction.Graph.Models;
using BotSharp.Abstraction.Rules;
using BotSharp.Abstraction.Rules.Models;
using BotSharp.Abstraction.Rules.Options;
using BotSharp.Abstraction.Utilities;
using Microsoft.Extensions.Logging;
using System.Text.Json;

namespace BotSharp.Plugin.Membase.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using BotSharp.Abstraction.Graph.Models;

namespace BotSharp.Plugin.Membase.Settings;

public class MembaseSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public async Task<IEnumerable<VectorCollectionConfig>> GetKnowledgeCollectionCon
});
}

#if !DEBUG
[SharpCache(10)]
#endif
public async Task<VectorCollectionConfig> GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider)
{
var configs = await GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter
Expand Down
Loading