{"record":{"id":"21b5c1ca6293aefc","repo":"Tencent/WeKnora","slug":"no-effective-agent-knowledge-scope-is-available","errorCode":null,"errorMessage":"no effective Agent knowledge scope is available","messagePattern":"no effective Agent knowledge scope is available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/database_query.go","lineNumber":255,"sourceCode":"\n\tlogger.Infof(ctx, \"[Tool][DatabaseQuery] Execute completed successfully: %d rows returned\", len(results))\n\treturn &types.ToolResult{\n\t\tSuccess: true,\n\t\tOutput:  output,\n\t\tData: map[string]interface{}{\n\t\t\t\"columns\":      columns,\n\t\t\t\"rows\":         results,\n\t\t\t\"row_count\":    len(results),\n\t\t\t\"display_type\": \"database_query\",\n\t\t},\n\t}, nil\n}\n\n// validateAndSecureSQL validates the SQL query and injects tenant_id conditions\nfunc (t *DatabaseQueryTool) validateAndSecureSQL(sqlQuery string, tenantID uint64) (string, error) {\n\tsearchScopes := searchScopesFromTargets(t.searchTargets)\n\tif len(searchScopes) == 0 {\n\t\treturn \"\", fmt.Errorf(\"no effective Agent knowledge scope is available\")\n\t}\n\tsecuredSQL, validationResult, err := utils.ValidateAndSecureSQL(\n\t\tsqlQuery,\n\t\tutils.WithSecurityDefaults(tenantID),\n\t\tutils.WithSoftDeleteFilter(\"knowledge_bases\", \"knowledges\", \"chunks\"),\n\t\tutils.WithHiddenKBFilter(),\n\t\tutils.WithChunkEnabledFilter(),\n\t\tutils.WithInjectionRiskCheck(),\n\t\tutils.WithSearchScopes(searchScopes),\n\t)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif !validationResult.Valid {\n\t\tvar errMsgs []string\n\t\tfor _, valErr := range validationResult.Errors {\n\t\t\terrMsgs = append(errMsgs, fmt.Sprintf(\"%s: %s\", valErr.Type, valErr.Message))","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/database_query.go#L237-L273","documentation":"validateAndSecureSQL derives zero search scopes from the tool's search targets: the Agent execution carries no effective knowledge scope, so SQL cannot be constrained to tenant/KB boundaries and the query is refused as a security precondition failure.","triggerScenarios":"Thrown at internal/agent/tools/database_query.go:255 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Configure search targets on the Agent so at least one knowledge base scope exists","Verify the caller propagated tenant and scope context into the tool","Refuse to run unrestricted queries rather than bypassing scope injection"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}