Skip to content

Commit b244726

Browse files
authored
fix(backend): Include webhook block executions in GraphExecution queries (#9984)
- Resolves #9752 - Follow-up fix to #9940 ### Changes 🏗️ - `GRAPH_EXECUTION_INCLUDE` -> `graph_execution_include(include_block_ids)` - Add `get_io_block_ids()` and `get_webhook_block_ids()` to `backend.data.blocks` ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [ ] I have tested my changes according to the test plan: - [ ] Payload for webhook-triggered runs is shown on `/library/agents/[id]`
1 parent 3471781 commit b244726

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

autogpt_platform/backend/backend/data/block.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import inspect
23
from abc import ABC, abstractmethod
34
from enum import Enum
@@ -8,6 +9,7 @@
89
Generator,
910
Generic,
1011
Optional,
12+
Sequence,
1113
Type,
1214
TypeVar,
1315
cast,
@@ -523,3 +525,21 @@ async def initialize_blocks() -> None:
523525
def get_block(block_id: str) -> Block[BlockSchema, BlockSchema] | None:
524526
cls = get_blocks().get(block_id)
525527
return cls() if cls else None
528+
529+
530+
@functools.cache
531+
def get_webhook_block_ids() -> Sequence[str]:
532+
return [
533+
id
534+
for id, B in get_blocks().items()
535+
if B().block_type in (BlockType.WEBHOOK, BlockType.WEBHOOK_MANUAL)
536+
]
537+
538+
539+
@functools.cache
540+
def get_io_block_ids() -> Sequence[str]:
541+
return [
542+
id
543+
for id, B in get_blocks().items()
544+
if B().block_type in (BlockType.INPUT, BlockType.OUTPUT)
545+
]

autogpt_platform/backend/backend/data/execution.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,19 @@
3838
from backend.util import type as type_utils
3939
from backend.util.settings import Config
4040

41-
from .block import BlockInput, BlockType, CompletedBlockOutput, get_block
41+
from .block import (
42+
BlockInput,
43+
BlockType,
44+
CompletedBlockOutput,
45+
get_block,
46+
get_io_block_ids,
47+
get_webhook_block_ids,
48+
)
4249
from .db import BaseDbModel
4350
from .includes import (
4451
EXECUTION_RESULT_INCLUDE,
45-
GRAPH_EXECUTION_INCLUDE,
4652
GRAPH_EXECUTION_INCLUDE_WITH_NODES,
53+
graph_execution_include,
4754
)
4855
from .model import CredentialsMetaInput, GraphExecutionStats, NodeExecutionStats
4956
from .queue import AsyncRedisEventBus, RedisEventBus
@@ -411,7 +418,9 @@ async def get_graph_execution(
411418
include=(
412419
GRAPH_EXECUTION_INCLUDE_WITH_NODES
413420
if include_node_executions
414-
else GRAPH_EXECUTION_INCLUDE
421+
else graph_execution_include(
422+
[*get_io_block_ids(), *get_webhook_block_ids()]
423+
)
415424
),
416425
)
417426
if not execution:
@@ -568,7 +577,9 @@ async def update_graph_execution_start_time(
568577
"executionStatus": ExecutionStatus.RUNNING,
569578
"startedAt": datetime.now(tz=timezone.utc),
570579
},
571-
include=GRAPH_EXECUTION_INCLUDE,
580+
include=graph_execution_include(
581+
[*get_io_block_ids(), *get_webhook_block_ids()]
582+
),
572583
)
573584
return GraphExecution.from_db(res) if res else None
574585

@@ -603,7 +614,9 @@ async def update_graph_execution_stats(
603614

604615
graph_exec = await AgentGraphExecution.prisma().find_unique_or_raise(
605616
where={"id": graph_exec_id},
606-
include=GRAPH_EXECUTION_INCLUDE,
617+
include=graph_execution_include(
618+
[*get_io_block_ids(), *get_webhook_block_ids()]
619+
),
607620
)
608621
return GraphExecution.from_db(graph_exec)
609622

autogpt_platform/backend/backend/data/includes.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from typing import cast
1+
from typing import Sequence, cast
22

33
import prisma.enums
44
import prisma.types
55

6-
from backend.blocks.io import IO_BLOCK_IDs
7-
86
AGENT_NODE_INCLUDE: prisma.types.AgentNodeInclude = {
97
"Input": True,
108
"Output": True,
@@ -42,18 +40,26 @@
4240
}
4341
}
4442

45-
GRAPH_EXECUTION_INCLUDE: prisma.types.AgentGraphExecutionInclude = {
46-
"NodeExecutions": {
47-
**cast(
48-
prisma.types.FindManyAgentNodeExecutionArgsFromAgentGraphExecution,
49-
GRAPH_EXECUTION_INCLUDE_WITH_NODES["NodeExecutions"],
50-
),
51-
"where": {
52-
"Node": {"is": {"AgentBlock": {"is": {"id": {"in": IO_BLOCK_IDs}}}}},
53-
"NOT": [{"executionStatus": prisma.enums.AgentExecutionStatus.INCOMPLETE}],
54-
},
43+
44+
def graph_execution_include(
45+
include_block_ids: Sequence[str],
46+
) -> prisma.types.AgentGraphExecutionInclude:
47+
return {
48+
"NodeExecutions": {
49+
**cast(
50+
prisma.types.FindManyAgentNodeExecutionArgsFromAgentGraphExecution,
51+
GRAPH_EXECUTION_INCLUDE_WITH_NODES["NodeExecutions"], # type: ignore
52+
),
53+
"where": {
54+
"Node": {
55+
"is": {"AgentBlock": {"is": {"id": {"in": include_block_ids}}}}
56+
},
57+
"NOT": [
58+
{"executionStatus": prisma.enums.AgentExecutionStatus.INCOMPLETE}
59+
],
60+
},
61+
}
5562
}
56-
}
5763

5864

5965
INTEGRATION_WEBHOOK_INCLUDE: prisma.types.IntegrationWebhookInclude = {

0 commit comments

Comments
 (0)