fix(platform/backend): skip invalid graphs when listing in block menu (#10159)

<!-- Clearly explain the need for these changes: -->
## 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)
This commit is contained in:
Toran Bruce Richards
2025-06-16 09:01:10 +01:00
committed by GitHub
parent 1ff924e260
commit e05c34e76a

View File

@@ -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