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 @@ -20,17 +20,9 @@ public GraphKnowledgeService(

public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryOptions? options = null)
{
try
{
var db = GetGraphDb(options?.Provider);
var result = await db.ExecuteQueryAsync(query, options);
return result;
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error when searching graph knowledge (Query: {query}).");
return new GraphQueryResult();
}
var db = GetGraphDb(options?.Provider);
var result = await db.ExecuteQueryAsync(query, options);
return result;
Comment on lines +23 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

Action required

1. Removed query error fallback 📘 Rule violation ⛯ Reliability

ExecuteQueryAsync no longer catches provider failures, so exceptions can bubble to callers with no
safe fallback result. This violates the requirement to return a safe fallback with clear logging at
provider boundaries.
Agent Prompt
## Issue description
`GraphKnowledgeService.ExecuteQueryAsync` removed its try/catch and now lets provider/storage errors escape without returning a safe fallback or logging, violating the boundary guard/fallback requirement.

## Issue Context
This method is a provider/storage boundary (calls `GetGraphDb(...).ExecuteQueryAsync(...)`). The previous implementation returned a safe fallback `GraphQueryResult` and logged an error; the PR removed that behavior.

## Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.cs[23-25]

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

Comment on lines +23 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

Action required

3. Null graph db dereference 🐞 Bug ⛯ Reliability

GraphKnowledgeService.ExecuteQueryAsync can dereference a null IGraphDb when GetGraphDb returns null
(no registered provider match), causing a NullReferenceException that now propagates to callers.
This will break /knowledge/graph/search and any other callers because there is no controller- or
middleware-level exception handling in production.
Agent Prompt
### Issue description
`GraphKnowledgeService.ExecuteQueryAsync` calls `db.ExecuteQueryAsync(...)` without verifying that `GetGraphDb(...)` actually found a provider, which can produce a `NullReferenceException`.

### Issue Context
`GetGraphDb` uses `FirstOrDefault` and can return null when configuration requests an unregistered provider.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.cs[21-35]
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[208-224]
- src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs[231-262]

### Implementation notes
- Add a null check after `GetGraphDb(...)`.
- Prefer preserving previous behavior (return empty `GraphQueryResult` and log) unless the API contract is explicitly changing; if changing to “throw”, add controller-level handling or a global exception handler middleware to return a controlled error response.

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

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryEx
{
var argLogs = args.Select(x => (new KeyValue(x.Key, x.Value.ConvertToString(BotSharpOptions.defaultJsonOptions))).ToString());
_logger.LogError(ex, $"Error when executing query in {Provider} graph db. (Query: {query}), (Argments: \r\n{string.Join("\r\n", argLogs)})");
return new();
throw;
Copy link
Contributor

Choose a reason for hiding this comment

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

Action required

2. Rethrow breaks safe fallback 📘 Rule violation ⛯ Reliability

The graph DB implementation now rethrows exceptions instead of returning a safe fallback result,
increasing the likelihood of runtime failures propagating across the provider boundary. This
violates the requirement for safe fallback behavior with clear logging at provider/storage
boundaries.
Agent Prompt
## Issue description
`MembaseGraphDb.ExecuteQueryAsync` now rethrows exceptions from the provider boundary instead of returning a safe fallback result.

## Issue Context
The catch block already logs the error; rethrowing defeats the safe fallback requirement and can cause upstream failures.

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

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

}
}
}
Loading