Skip to content

Commit 3ceec80

Browse files
committed
Merge branch 'dev' into kpczerwinski/secrt-1726-move-completion-backend
2 parents 05866d0 + 3b34c04 commit 3ceec80

File tree

47 files changed

+479
-1171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+479
-1171
lines changed

autogpt_platform/backend/.env.default

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,6 @@ POSTMARK_WEBHOOK_TOKEN=
134134
# Error Tracking
135135
SENTRY_DSN=
136136

137-
# Cloudflare Turnstile (CAPTCHA) Configuration
138-
# Get these from the Cloudflare Turnstile dashboard: https://dash.cloudflare.com/?to=/:account/turnstile
139-
# This is the backend secret key
140-
TURNSTILE_SECRET_KEY=
141-
# This is the verify URL
142-
TURNSTILE_VERIFY_URL=https://challenges.cloudflare.com/turnstile/v0/siteverify
143-
144137
# Feature Flags
145138
LAUNCH_DARKLY_SDK_KEY=
146139

autogpt_platform/backend/backend/executor/scheduler.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import threading
5+
import uuid
56
from enum import Enum
67
from typing import Optional
78
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
@@ -37,7 +38,9 @@
3738
from backend.util.clients import get_scheduler_client
3839
from backend.util.cloud_storage import cleanup_expired_files_async
3940
from backend.util.exceptions import (
41+
GraphNotFoundError,
4042
GraphNotInLibraryError,
43+
GraphValidationError,
4144
NotAuthorizedError,
4245
NotFoundError,
4346
)
@@ -162,14 +165,12 @@ async def _execute_graph(**kwargs):
162165
f"Graph execution {graph_exec.id} took {elapsed:.2f}s to create/publish - "
163166
f"this is unusually slow and may indicate resource contention"
164167
)
168+
except GraphNotFoundError as e:
169+
await _handle_graph_not_available(e, args, start_time)
165170
except GraphNotInLibraryError as e:
166-
elapsed = asyncio.get_event_loop().time() - start_time
167-
logger.warning(
168-
f"Scheduled execution blocked for deleted/archived graph {args.graph_id} "
169-
f"(user {args.user_id}) after {elapsed:.2f}s: {e}"
170-
)
171-
# Clean up orphaned schedules for this graph
172-
await _cleanup_orphaned_schedules_for_graph(args.graph_id, args.user_id)
171+
await _handle_graph_not_available(e, args, start_time)
172+
except GraphValidationError:
173+
await _handle_graph_validation_error(args)
173174
except Exception as e:
174175
elapsed = asyncio.get_event_loop().time() - start_time
175176
logger.error(
@@ -178,6 +179,34 @@ async def _execute_graph(**kwargs):
178179
)
179180

180181

182+
async def _handle_graph_validation_error(args: "GraphExecutionJobArgs") -> None:
183+
logger.error(
184+
f"Scheduled Graph {args.graph_id} failed validation. Unscheduling graph"
185+
)
186+
if args.schedule_id:
187+
scheduler_client = get_scheduler_client()
188+
await scheduler_client.delete_schedule(
189+
schedule_id=args.schedule_id,
190+
user_id=args.user_id,
191+
)
192+
else:
193+
logger.error(
194+
f"Unable to unschedule graph: {args.graph_id} as this is an old job with no associated schedule_id please remove manually"
195+
)
196+
197+
198+
async def _handle_graph_not_available(
199+
e: Exception, args: "GraphExecutionJobArgs", start_time: float
200+
) -> None:
201+
elapsed = asyncio.get_event_loop().time() - start_time
202+
logger.warning(
203+
f"Scheduled execution blocked for deleted/archived graph {args.graph_id} "
204+
f"(user {args.user_id}) after {elapsed:.2f}s: {e}"
205+
)
206+
# Clean up orphaned schedules for this graph
207+
await _cleanup_orphaned_schedules_for_graph(args.graph_id, args.user_id)
208+
209+
181210
async def _cleanup_orphaned_schedules_for_graph(graph_id: str, user_id: str) -> None:
182211
"""
183212
Clean up orphaned schedules for a specific graph when execution fails with GraphNotAccessibleError.
@@ -222,9 +251,11 @@ class Jobstores(Enum):
222251

223252

224253
class GraphExecutionJobArgs(BaseModel):
254+
schedule_id: str | None = None
225255
user_id: str
226256
graph_id: str
227257
graph_version: int
258+
agent_name: str | None = None
228259
cron: str
229260
input_data: BlockInput
230261
input_credentials: dict[str, CredentialsMetaInput] = Field(default_factory=dict)
@@ -470,11 +501,14 @@ def add_graph_execution_schedule(
470501
logger.info(
471502
f"Scheduling job for user {user_id} with timezone {user_timezone} (cron: {cron})"
472503
)
504+
schedule_id = str(uuid.uuid4())
473505

474506
job_args = GraphExecutionJobArgs(
507+
schedule_id=schedule_id,
475508
user_id=user_id,
476509
graph_id=graph_id,
477510
graph_version=graph_version,
511+
agent_name=name,
478512
cron=cron,
479513
input_data=input_data,
480514
input_credentials=input_credentials,
@@ -486,6 +520,7 @@ def add_graph_execution_schedule(
486520
trigger=CronTrigger.from_crontab(cron, timezone=user_timezone),
487521
jobstore=Jobstores.EXECUTION.value,
488522
replace_existing=True,
523+
id=schedule_id,
489524
)
490525
logger.info(
491526
f"Added job {job.id} with cron schedule '{cron}' in timezone {user_timezone}, input data: {input_data}"

autogpt_platform/backend/backend/executor/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
get_database_manager_async_client,
4343
get_integration_credentials_store,
4444
)
45-
from backend.util.exceptions import GraphValidationError, NotFoundError
45+
from backend.util.exceptions import (
46+
GraphNotFoundError,
47+
GraphValidationError,
48+
NotFoundError,
49+
)
4650
from backend.util.logging import TruncatedLogger, is_structured_logging_enabled
4751
from backend.util.settings import Config
4852
from backend.util.type import convert
@@ -516,7 +520,7 @@ async def validate_and_construct_node_execution_input(
516520
skip_access_check=True,
517521
)
518522
if not graph:
519-
raise NotFoundError(f"Graph #{graph_id} not found.")
523+
raise GraphNotFoundError(f"Graph #{graph_id} not found.")
520524

521525
# Validate that the user has permission to execute this graph
522526
# This checks both library membership and execution permissions,

autogpt_platform/backend/backend/server/rest_api.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import backend.server.v2.otto.routes
3636
import backend.server.v2.store.model
3737
import backend.server.v2.store.routes
38-
import backend.server.v2.turnstile.routes
3938
import backend.util.service
4039
import backend.util.settings
4140
from backend.blocks.llm import LlmModel
@@ -281,11 +280,6 @@ async def validation_error_handler(
281280
app.include_router(
282281
backend.server.v2.otto.routes.router, tags=["v2", "otto"], prefix="/api/otto"
283282
)
284-
app.include_router(
285-
backend.server.v2.turnstile.routes.router,
286-
tags=["v2", "turnstile"],
287-
prefix="/api/turnstile",
288-
)
289283

290284
app.include_router(
291285
backend.server.routers.postmark.postmark.router,

autogpt_platform/backend/backend/server/v2/turnstile/__init__.py

Whitespace-only changes.

autogpt_platform/backend/backend/server/v2/turnstile/models.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

autogpt_platform/backend/backend/server/v2/turnstile/routes.py

Lines changed: 0 additions & 112 deletions
This file was deleted.

autogpt_platform/backend/backend/server/v2/turnstile/routes_test.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

autogpt_platform/backend/backend/util/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class NotFoundError(ValueError):
3838
"""The requested record was not found, resulting in an error condition"""
3939

4040

41+
class GraphNotFoundError(ValueError):
42+
"""The requested Agent Graph was not found, resulting in an error condition"""
43+
44+
4145
class NeedConfirmation(Exception):
4246
"""The user must explicitly confirm that they want to proceed"""
4347

autogpt_platform/backend/backend/util/settings.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,6 @@ class Secrets(UpdateTrackingModel["Secrets"], BaseSettings):
537537
description="The secret key to use for the unsubscribe user by token",
538538
)
539539

540-
# Cloudflare Turnstile credentials
541-
turnstile_secret_key: str = Field(
542-
default="",
543-
description="Cloudflare Turnstile backend secret key",
544-
)
545-
turnstile_verify_url: str = Field(
546-
default="https://challenges.cloudflare.com/turnstile/v0/siteverify",
547-
description="Cloudflare Turnstile verify URL",
548-
)
549-
550540
# OAuth server credentials for integrations
551541
# --8<-- [start:OAuthServerCredentialsExample]
552542
github_client_id: str = Field(default="", description="GitHub OAuth client ID")

0 commit comments

Comments
 (0)