Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(platform): resolve 5 production Sentry alerts (#12496)

Zamil Majdy1ebcf856697b
diff --git a/autogpt_platform/backend/backend/api/features/v1.py b/autogpt_platform/backend/backend/api/features/v1.py
index a7fc2fa69c..510ad636cf 100644
--- a/autogpt_platform/backend/backend/api/features/v1.py
+++ b/autogpt_platform/backend/backend/api/features/v1.py
@@ -592,6 +592,11 @@ async def fulfill_checkout(user_id: Annotated[str, Security(get_user_id)]):
async def configure_user_auto_top_up(
request: AutoTopUpConfig, user_id: Annotated[str, Security(get_user_id)]
) -> str:
+ """Configure auto top-up settings and perform an immediate top-up if needed.
+
+ Raises HTTPException(422) if the request parameters are invalid or if
+ the credit top-up fails.
+ """
if request.threshold < 0:
raise HTTPException(status_code=422, detail="Threshold must be greater than 0")
if request.amount < 500 and request.amount != 0:
@@ -606,10 +611,20 @@ async def configure_user_auto_top_up(
user_credit_model = await get_user_credit_model(user_id)
current_balance = await user_credit_model.get_credits(user_id)
- if current_balance < request.threshold:
- await user_credit_model.top_up_credits(user_id, request.amount)
- else:
- await user_credit_model.top_up_credits(user_id, 0)
+ try:
+ if current_balance < request.threshold:
+ await user_credit_model.top_up_credits(user_id, request.amount)
+ else:
+ await user_credit_model.top_up_credits(user_id, 0)
+ except ValueError as e:
+ known_messages = (
+ "must not be negative",
+ "already exists for user",
+ "No payment method found",
+ )
+ if any(msg in str(e) for msg in known_messages):
+ raise HTTPException(status_code=422, detail=str(e))
+ raise
await set_auto_top_up(
user_id, AutoTopUpConfig(threshold=request.threshold, amount=request.amount)
diff --git a/autogpt_platform/backend/backend/api/features/workspace/routes.py b/autogpt_platform/backend/backend/api/features/workspace/routes.py
index 54b3e1802e..8ca339edbd 100644
--- a/autogpt_platform/backend/backend/api/features/workspace/routes.py
+++ b/autogpt_platform/backend/backend/api/features/workspace/routes.py
@@ -188,6 +188,7 @@ async def upload_file(
user_id: Annotated[str, fastapi.Security(get_user_id)],
file: UploadFile,
session_id: str | None = Query(default=None),
+ overwrite: bool = Query(default=False),
) -> UploadFileResponse:
"""
Upload a file to the user's workspace.
@@ -248,7 +249,9 @@ async def upload_file(
# Write file via WorkspaceManager
manager = WorkspaceManager(user_id, workspace.id, session_id)
try:
- workspace_file = await manager.write_file(content, filename)
+ workspace_file = await manager.write_file(
+ content, filename, overwrite=overwrite
+ )
except ValueError as e:
raise fastapi.HTTPException(status_code=409, detail=str(e)) from e
diff --git a/autogpt_platform/backend/backend/blocks/smart_decision_maker.py b/autogpt_platform/backend/backend/blocks/smart_decision_maker.py
index 7622d734cd..739999356d 100644
--- a/autogpt_platform/backend/backend/blocks/smart_decision_maker.py
+++ b/autogpt_platform/backend/backend/blocks/smart_decision_maker.py
@@ -934,7 +934,7 @@ class SmartDecisionMakerBlock(Block):
)
except Exception as e:
- logger.error(f"Tool execution with manager failed: {e}")
+ logger.warning(f"Tool execution with manager failed: {e}")
# Return error response
return _create_tool_response(
tool_call.id,
diff --git a/autogpt_platform/backend/backend/util/service.py b/autogpt_platform/backend/backend/util/service.py
index d1d7bb9027..24d7d12022 100644
--- a/autogpt_platform/backend/backend/util/service.py
+++ b/autogpt_platform/backend/backend/util/service.py
@@ -704,8 +704,19 @@ def get_service_client(
return kwargs
def _get_return(self, expected_return: TypeAdapter | None, result: Any) -> Any:
+ """Validate and coerce the RPC result to the expected return type.
+
+ Falls back to the raw result with a warning if validation fails.
+ """
if expected_return:
- return expected_return.validate_python(result)
+ try:
+ return expected_return.validate_python(result)
+ except Exception as e:
+ logger.warning(
+ "RPC return type validation failed, using raw result: %s",
+ type(e).__name__,
+ )
+ return result
return result
def __getattr__(self, name: str) -> Callable[..., Any]:
diff --git a/autogpt_platform/backend/backend/util/type.py b/autogpt_platform/backend/backend/util/type.py
index f22ae5a4d6..ca49f61412 100644
--- a/autogpt_platform/backend/backend/util/type.py
+++ b/autogpt_platform/backend/backend/util/type.py
@@ -302,7 +302,14 @@ def _value_satisfies_type(value: Any, target: Any) -> bool:
# Simple type (e.g. str, int)
if isinstance(target, type):
- return isinstance(value, target)
+ try:
+ return isinstance(value, target)
+ except TypeError:
+ # TypedDict and some typing constructs don't support isinstance checks.
+ # For TypedDict, check if value is a dict with the required keys.
+ if isinstance(value, dict) and hasattr(target, "__required_keys__"):
+ return all(k in value for k in target.__required_keys__)
+ return False
return False
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers/renderers/MarkdownRenderer.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers/renderers/MarkdownRenderer.tsx
index d94966c6c8..b7f96d6c32 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers/renderers/MarkdownRenderer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers/renderers/MarkdownRenderer.tsx
@@ -169,7 +169,7 @@ function renderMarkdown(
[remarkMath, { singleDollarTextMath: false }], // Math support for LaTeX
]}
rehypePlugins={[
- rehypeKatex, // Render math with KaTeX
+ [rehypeKatex, { strict: false }], // Render math with KaTeX
rehypeHighlight, // Syntax highlighting for code blocks
rehypeSlug, // Add IDs to headings
[rehypeAutolinkHeadings, { behavior: "wrap" }], // Make headings clickable
diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.json
index 84c00cf5b1..14fa8e9971 100644
--- a/autogpt_platform/frontend/src/app/api/openapi.json
+++ b/autogpt_platform/frontend/src/app/api/openapi.json
@@ -1579,6 +1579,7 @@
"post": {
"tags": ["v1", "credits"],
"summary": "Configure auto top up",
+ "description": "Configure auto top-up settings and perform an immediate top-up if needed.\n\nRaises HTTPException(422) if the request parameters are invalid or if\nthe credit top-up fails.",
"operationId": "postV1Configure auto top up",
"requestBody": {
"content": {
@@ -6684,6 +6685,16 @@
"anyOf": [{ "type": "string" }, { "type": "null" }],
"title": "Session Id"
}
+ },
+ {
+ "name": "overwrite",
+ "in": "query",
+ "required": false,
+ "schema": {
+ "type": "boolean",
+ "default": false,
+ "title": "Overwrite"
+ }
}
],
"requestBody": {
diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/MarkdownRenderer.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/MarkdownRenderer.tsx
index 9815cea6ff..9217be1105 100644
--- a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/MarkdownRenderer.tsx
+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/MarkdownRenderer.tsx
@@ -169,7 +169,7 @@ function renderMarkdown(
[remarkMath, { singleDollarTextMath: false }], // Math support for LaTeX
]}
rehypePlugins={[
- rehypeKatex, // Render math with KaTeX
+ [rehypeKatex, { strict: false }], // Render math with KaTeX
rehypeHighlight, // Syntax highlighting for code blocks
rehypeSlug, // Add IDs to headings
[rehypeAutolinkHeadings, { behavior: "wrap" }], // Make headings clickable
diff --git a/autogpt_platform/frontend/src/lib/direct-upload.ts b/autogpt_platform/frontend/src/lib/direct-upload.ts
index 3b66ac58b8..22fd79f4a4 100644
--- a/autogpt_platform/frontend/src/lib/direct-upload.ts
+++ b/autogpt_platform/frontend/src/lib/direct-upload.ts
@@ -28,6 +28,7 @@ export async function uploadFileDirect(
if (sessionID) {
url.searchParams.set("session_id", sessionID);
}
+ url.searchParams.set("overwrite", "true");
const formData = new FormData();
formData.append("file", file);