From e05c34e76a545c417b41428acef29691a112d38c Mon Sep 17 00:00:00 2001 From: Toran Bruce Richards Date: Mon, 16 Jun 2025 09:01:10 +0100 Subject: [PATCH] fix(platform/backend): skip invalid graphs when listing in block menu (#10159) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Background & Summary of Changes If a user has a single invalid Agent in their Library (i.e one with a Block which doesn't exist) currently the Blocks menu does not return any Agent results. Valid agents should still load even when some stored graphs are malformed. Graphs which are malformed should just be skipped rather than breaking the entire process, this PR implements that fix, unblocking users with a malformed Agent in their Library (me!). ## Testing I have tested this PR in the dev deployment (where I have this issue on my account) and have confirmed that Agents now show up in the list: | Before this Change | After this Change | | ------------------ | ----------------- | | ![Before change screenshot](https://github.com/user-attachments/assets/9263da25-ff4a-4dfa-bd96-19dfd689ddac) | ![After change screenshot](https://github.com/user-attachments/assets/86219055-b97b-456c-a270-80d729c909da) | ## Changes 🏗️ - Validate each graph’s serialization in get_graphs and skip any that raise an exception - Added error logging for invalid graphs ## Checklist 📋 For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] poetry run format - [ ] poetry run test For configuration changes: - [x] .env.example is updated or already compatible with my changes - [x] docker-compose.yml is updated or already compatible with my changes - [x] I have included a list of my configuration changes in the PR description (under Changes) Fixes [OPEN-2461: Loading a Library Agent with an invalid block causes all Library Agent Loading to fail in Builder Blocks Menu](https://linear.app/autogpt/issue/OPEN-2461/loading-a-library-agent-with-an-invalid-block-causes-all-library-agent) --- autogpt_platform/backend/backend/data/graph.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.py index c556ba0450..7733ec3518 100644 --- a/autogpt_platform/backend/backend/data/graph.py +++ b/autogpt_platform/backend/backend/data/graph.py @@ -655,7 +655,10 @@ async def get_graphs( graph_models = [] for graph in graphs: try: - graph_models.append(GraphModel.from_db(graph)) + graph_model = GraphModel.from_db(graph) + # Trigger serialization to validate that the graph is well formed. + graph_model.model_dump() + graph_models.append(graph_model) except Exception as e: logger.error(f"Error processing graph {graph.id}: {e}") continue