AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): exclude disabled blocks from chat search and indexing (#11854)
Swifty2134d777bef6
diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/find_block.py b/autogpt_platform/backend/backend/api/features/chat/tools/find_block.pyindex a5e66f0a1c..7ca85961f9 100644--- a/autogpt_platform/backend/backend/api/features/chat/tools/find_block.py+++ b/autogpt_platform/backend/backend/api/features/chat/tools/find_block.py@@ -107,7 +107,8 @@ class FindBlockTool(BaseTool):block_id = result["content_id"]block = get_block(block_id)- if block:+ # Skip disabled blocks+ if block and not block.disabled:# Get input/output schemasinput_schema = {}output_schema = {}diff --git a/autogpt_platform/backend/backend/api/features/store/content_handlers.py b/autogpt_platform/backend/backend/api/features/store/content_handlers.pyindex 1560db421c..cbbdcfbebf 100644--- a/autogpt_platform/backend/backend/api/features/store/content_handlers.py+++ b/autogpt_platform/backend/backend/api/features/store/content_handlers.py@@ -188,6 +188,10 @@ class BlockHandler(ContentHandler):try:block_instance = block_cls()+ # Skip disabled blocks - they shouldn't be indexed+ if block_instance.disabled:+ continue+# Build searchable text from block metadataparts = []if hasattr(block_instance, "name") and block_instance.name:@@ -248,12 +252,19 @@ class BlockHandler(ContentHandler):from backend.data.block import get_blocksall_blocks = get_blocks()- total_blocks = len(all_blocks)++ # Filter out disabled blocks - they're not indexed+ enabled_block_ids = [+ block_id+ for block_id, block_cls in all_blocks.items()+ if not block_cls().disabled+ ]+ total_blocks = len(enabled_block_ids)if total_blocks == 0:return {"total": 0, "with_embeddings": 0, "without_embeddings": 0}- block_ids = list(all_blocks.keys())+ block_ids = enabled_block_idsplaceholders = ",".join([f"${i+1}" for i in range(len(block_ids))])embedded_result = await query_raw_with_schema(diff --git a/autogpt_platform/backend/backend/api/features/store/content_handlers_test.py b/autogpt_platform/backend/backend/api/features/store/content_handlers_test.pyindex 28bc88e270..fee879fae0 100644--- a/autogpt_platform/backend/backend/api/features/store/content_handlers_test.py+++ b/autogpt_platform/backend/backend/api/features/store/content_handlers_test.py@@ -81,6 +81,7 @@ async def test_block_handler_get_missing_items(mocker):mock_block_instance.name = "Calculator Block"mock_block_instance.description = "Performs calculations"mock_block_instance.categories = [MagicMock(value="MATH")]+ mock_block_instance.disabled = Falsemock_block_instance.input_schema.model_json_schema.return_value = {"properties": {"expression": {"description": "Math expression to evaluate"}}}@@ -116,11 +117,18 @@ async def test_block_handler_get_stats(mocker):"""Test BlockHandler returns correct stats."""handler = BlockHandler()- # Mock get_blocks+ # Mock get_blocks - each block class returns an instance with disabled=False+ def make_mock_block_class():+ mock_class = MagicMock()+ mock_instance = MagicMock()+ mock_instance.disabled = False+ mock_class.return_value = mock_instance+ return mock_class+mock_blocks = {- "block-1": MagicMock(),- "block-2": MagicMock(),- "block-3": MagicMock(),+ "block-1": make_mock_block_class(),+ "block-2": make_mock_block_class(),+ "block-3": make_mock_block_class(),}# Mock embedded count query (2 blocks have embeddings)@@ -309,6 +317,7 @@ async def test_block_handler_handles_missing_attributes():mock_block_class = MagicMock()mock_block_instance = MagicMock()mock_block_instance.name = "Minimal Block"+ mock_block_instance.disabled = False# No description, categories, or schemadel mock_block_instance.descriptiondel mock_block_instance.categories@@ -342,6 +351,7 @@ async def test_block_handler_skips_failed_blocks():good_instance.name = "Good Block"good_instance.description = "Works fine"good_instance.categories = []+ good_instance.disabled = Falsegood_block.return_value = good_instancebad_block = MagicMock()