mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(block): Avoid infinite loop execution on AddToListBlock self-loop (#9629)
### Changes 🏗️ <img width="757" alt="image" src="https://github.com/user-attachments/assets/909aab58-24c7-42ec-9580-ac3e9f32057e" /> Since a self-loop is now allowed for AddToListBlock, providing an entry pin using a static output will cause infinite execution. This PR change avoid such scenario to be allowed. ### 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: <!-- Put your test plan here: --> - [x] Described above
This commit is contained in:
@@ -468,11 +468,27 @@ class AddToListBlock(Block):
|
||||
|
||||
@classmethod
|
||||
def get_missing_links(cls, data: BlockInput, links: List["Link"]) -> set[str]:
|
||||
# If `list` self-loop present, the `entry` pin can't be static.
|
||||
list_self_loop_present = any(
|
||||
link.sink_name == "list" and link.sink_id == link.source_id
|
||||
for link in links
|
||||
)
|
||||
entry_static_output_present = any(
|
||||
link.sink_name == "entry" and link.is_static for link in links
|
||||
)
|
||||
if list_self_loop_present and entry_static_output_present:
|
||||
raise ValueError(
|
||||
"The `entry` pin can't have static output from `AgentInput` or "
|
||||
"`StoreValue` block as long as the `list` pin has a self-loop."
|
||||
"This will cause an infinite execution loop."
|
||||
)
|
||||
|
||||
return super().get_missing_links(
|
||||
data,
|
||||
[
|
||||
link
|
||||
for link in links
|
||||
# Allow execution with `list` pin self-loop
|
||||
if link.sink_name != "list" or link.sink_id != link.source_id
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user