From 33eb9e9ad98346e2b43afed9fa0bd51355e61834 Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Fri, 24 Apr 2026 14:32:24 -0500 Subject: [PATCH] =?UTF-8?q?fix(platform):=20address=20review=20=E2=80=94?= =?UTF-8?q?=20format=5Fbytes=20rollup,=20storage=20bar=20visibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename _format_bytes → format_bytes (public API, used cross-module) - Add unit boundary rollup (1024 KB → 1.0 MB) matching frontend formatBytes - Show WorkspaceStorageSection even when token limits are null - Move import to top level in routes.py Co-Authored-By: Claude Opus 4.6 (1M context) --- .../backend/api/features/workspace/routes.py | 6 +++--- .../backend/backend/util/workspace.py | 21 +++++++++++-------- .../UsageLimits/UsagePanelContent.tsx | 7 ++++++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/autogpt_platform/backend/backend/api/features/workspace/routes.py b/autogpt_platform/backend/backend/api/features/workspace/routes.py index 05fcfa4387..528b23f74d 100644 --- a/autogpt_platform/backend/backend/api/features/workspace/routes.py +++ b/autogpt_platform/backend/backend/api/features/workspace/routes.py @@ -27,7 +27,7 @@ from backend.data.workspace import ( soft_delete_workspace_file, ) from backend.util.settings import Config -from backend.util.workspace import WorkspaceManager, _format_bytes +from backend.util.workspace import WorkspaceManager, format_bytes from backend.util.workspace_storage import get_workspace_storage @@ -286,8 +286,8 @@ async def upload_file( status_code=413, detail=( f"Storage limit exceeded. " - f"You've used {_format_bytes(new_total)} of your " - f"{_format_bytes(storage_limit_bytes)} quota. " + f"You've used {format_bytes(new_total)} of your " + f"{format_bytes(storage_limit_bytes)} quota. " f"Delete some files or upgrade your plan for more storage." ), ) diff --git a/autogpt_platform/backend/backend/util/workspace.py b/autogpt_platform/backend/backend/util/workspace.py index e19be10a47..e39d51905f 100644 --- a/autogpt_platform/backend/backend/util/workspace.py +++ b/autogpt_platform/backend/backend/util/workspace.py @@ -21,15 +21,18 @@ from backend.util.virus_scanner import scan_content_safe from backend.util.workspace_storage import compute_file_checksum, get_workspace_storage -def _format_bytes(n: int) -> str: +def format_bytes(n: int) -> str: """Format bytes as a human-readable string (e.g. 250 MB, 1.0 GB).""" - if n < 1024: + KB, MB, GB = 1024, 1024**2, 1024**3 + if n < KB: return f"{n} B" - if n < 1024 * 1024: - return f"{n / 1024:.0f} KB" - if n < 1024 * 1024 * 1024: - return f"{n / (1024 * 1024):.0f} MB" - return f"{n / (1024 * 1024 * 1024):.1f} GB" + if n < MB: + kb = round(n / KB) + return f"{n / MB:.1f} MB" if kb >= 1024 else f"{kb} KB" + if n < GB: + mb = round(n / MB) + return f"{n / GB:.1f} GB" if mb >= 1024 else f"{mb} MB" + return f"{n / GB:.1f} GB" logger = logging.getLogger(__name__) @@ -225,8 +228,8 @@ class WorkspaceManager: if storage_limit > 0 and projected_usage > storage_limit: raise ValueError( f"Storage limit exceeded. " - f"You've used {_format_bytes(current_usage)} of your " - f"{_format_bytes(storage_limit)} quota. " + f"You've used {format_bytes(current_usage)} of your " + f"{format_bytes(storage_limit)} quota. " f"Delete some files or upgrade your plan for more storage." ) if storage_limit > 0 and projected_usage / storage_limit >= 0.8: diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx index 8ffba42c0c..543e7e98c8 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx @@ -166,7 +166,12 @@ export function UsagePanelContent({ if (!daily && !weekly) { return ( -
No usage limits configured
+
+
+ No usage limits configured +
+ +
); }