Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: route the six file-size toasts through formatBytes (#3869)

[._.]/ Adam Eivy1b7ab6868e6d
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 74060938d4..018a8257fa 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -45,3 +45,4 @@
- Agents run on an API provider (LM Studio, raw OpenAI/Anthropic — anything with no native filesystem tools) now receive the per-directory `CLAUDE.md` files too, not just the global and repo-root ones. Those agents read nothing off disk on their own, so a convention that lived in `server/CLAUDE.md` or `client/src/CLAUDE.md` reached them as a pointer with no contents — which is how relocating a backup rsync-exclude rule out of the root file silently removed a data-loss guard from that whole class of agent. Nested files are now discovered under the workspace and spliced in after the root one, each labeled with its repo-relative path, bounded to 10 files and 5 levels deep and skipping vendored, generated, and runtime trees.
- The Node version PortOS requires is now written down in exactly one place and checked before anything slow runs. The floor was copied into five sites that could drift apart — both setup scripts, `.nvmrc`, the CI workflows and the README — while the install path the README actually documents (`npm run setup`, `npm start`) checked none of them, so an unsupported Node installed happily for several minutes and then failed inside Vite with an error that never named the cause. `scripts/checkNodeVersion.js` now owns the number (22.12), runs first in the root `setup`, `start` and `dev` scripts so an old Node fails in the first second, and a drift test holds the other sites to it — the shell gates and the README to the floor exactly, `.nvmrc` and CI to at-or-above it, since running CI on 24 while supporting 22.12 is a preference rather than a mistake. All four `package.json` files now declare `engines` as well.
- The Pipeline's Reverse Outline map now keeps the selected scene in the URL (`?scene=<id>`) instead of component state, so the open scene detail survives a reload and can be linked to or shared. A stale id — after regenerating the outline, say — falls back to the "click a marker" placeholder rather than a blank card, and regenerating clears the selection outright.
+- The six "file too large" toasts — album covers, artist portraits, tracks, author headshots, reference audio and OpenClaw attachments — now render their size cap through the shared `formatBytes` helper instead of each dividing by 1024 twice and gluing on "MB". The rendered text gains a space before the unit (`12 MB` rather than `12MB`), which is what the rest of PortOS already shows and what the reference-audio toast already read.
diff --git a/client/src/components/music/AlbumsManager.jsx b/client/src/components/music/AlbumsManager.jsx
index c8472ed74b..96e272c3ec 100644
--- a/client/src/components/music/AlbumsManager.jsx
+++ b/client/src/components/music/AlbumsManager.jsx
@@ -20,7 +20,7 @@ import useMediaJobProgress from '../../hooks/useMediaJobProgress';
import { useConfirmDelete } from '../../hooks/useConfirmDelete';
import { DEFAULT_NEGATIVE_PROMPT } from '../../lib/imageGenDefaults';
import { readFileAsBase64 } from '../../utils/fileUpload';
-import { formatTimecode } from '../../utils/formatters';
+import { formatBytes, formatTimecode } from '../../utils/formatters';
import ArtistPicker from './ArtistPicker';
import {
listAlbums, createAlbum, updateAlbum, deleteAlbum,
@@ -168,7 +168,7 @@ export default function AlbumsManager() {
const file = e.target.files?.[0];
if (!file) return;
if (!file.type.startsWith('image/')) { toast.error('Please choose an image file'); return; }
- if (file.size > COVER_MAX_BYTES) { toast.error(`Image exceeds ${Math.round(COVER_MAX_BYTES / 1024 / 1024)}MB`); return; }
+ if (file.size > COVER_MAX_BYTES) { toast.error(`Image exceeds ${formatBytes(COVER_MAX_BYTES, 0)}`); return; }
// Capture the album-switch generation counter (bumped by selectAlbum/
// startCreate) so a slow read+upload that finishes after the user moved to a
// different album doesn't write this cover onto the wrong album's form.
diff --git a/client/src/components/music/ArtistsManager.jsx b/client/src/components/music/ArtistsManager.jsx
index 8cd5901fd4..aaa3871f6c 100644
--- a/client/src/components/music/ArtistsManager.jsx
+++ b/client/src/components/music/ArtistsManager.jsx
@@ -19,6 +19,7 @@ import useMediaJobProgress from '../../hooks/useMediaJobProgress';
import { useConfirmDelete } from '../../hooks/useConfirmDelete';
import { DEFAULT_NEGATIVE_PROMPT } from '../../lib/imageGenDefaults';
import { readFileAsBase64 } from '../../utils/fileUpload';
+import { formatBytes } from '../../utils/formatters';
import {
listArtists, createArtist, updateArtist, deleteArtist, uploadGalleryImage, generateImage,
ARTIST_NAME_MAX, ARTIST_GENRE_MAX, ARTIST_BIO_MAX, ARTIST_MUSICAL_STYLE_MAX,
@@ -138,7 +139,7 @@ export default function ArtistsManager() {
if (!file) return;
if (!file.type.startsWith('image/')) { toast.error('Please choose an image file'); return; }
if (file.size > PORTRAIT_MAX_BYTES) {
- toast.error(`Image exceeds ${Math.round(PORTRAIT_MAX_BYTES / 1024 / 1024)}MB`);
+ toast.error(`Image exceeds ${formatBytes(PORTRAIT_MAX_BYTES, 0)}`);
return;
}
setUploadingPortrait(true);
diff --git a/client/src/components/music/TracksManager.jsx b/client/src/components/music/TracksManager.jsx
index b332ef3e7e..890721aa3d 100644
--- a/client/src/components/music/TracksManager.jsx
+++ b/client/src/components/music/TracksManager.jsx
@@ -20,7 +20,7 @@ import toast from '../ui/Toast';
import FilePickerButton from '../ui/FilePickerButton';
import ConfirmButtonPair from '../ui/ConfirmButtonPair';
import { useConfirmDelete } from '../../hooks/useConfirmDelete';
-import { formatTimecode } from '../../utils/formatters';
+import { formatBytes, formatTimecode } from '../../utils/formatters';
import ArtistPicker from './ArtistPicker';
import MusicGenPanel from './MusicGenPanel';
import ChiptunePanel from './ChiptunePanel';
@@ -231,7 +231,7 @@ export default function TracksManager() {
const handleAudioFile = async (e) => {
const file = e.target.files?.[0];
if (!file || !requireSaved()) return;
- if (file.size > AUDIO_MAX_BYTES) { toast.error(`Audio exceeds ${Math.round(AUDIO_MAX_BYTES / 1024 / 1024)}MB`); return; }
+ if (file.size > AUDIO_MAX_BYTES) { toast.error(`Audio exceeds ${formatBytes(AUDIO_MAX_BYTES, 0)}`); return; }
const targetId = persisted.id; // server write targets THIS track
setUploading(true);
const fd = new FormData();
diff --git a/client/src/components/songs/ReferenceAnalysis.jsx b/client/src/components/songs/ReferenceAnalysis.jsx
index dec5cbfd76..6de34a16c2 100644
--- a/client/src/components/songs/ReferenceAnalysis.jsx
+++ b/client/src/components/songs/ReferenceAnalysis.jsx
@@ -44,6 +44,7 @@ import { startMemoRecording, arrayBufferToBase64 } from '../../lib/audioRecorder
import { proposeSegmentScore, proposeStackedSegmentScore, diffScoreBars, PITCH_CLASS_NAMES } from '../../lib/referenceAnalysis';
import { scoreHasMusic, parseScore } from '../../lib/scoreNotation';
import { harmonyPartLabel } from '../../lib/songCraft';
+import { formatBytes } from '../../utils/formatters';
import { MUSCRIPTOR_MODELS, DEFAULT_MUSCRIPTOR_MODEL } from '../../lib/muscriptorModels.js';
// Client-side guard for the base64-JSON upload path: the server body limit is
@@ -142,7 +143,7 @@ export function ReferenceAudioAttach({ reference, onUpdate }) {
const file = e.target.files?.[0];
if (!file) return;
if (file.size > MAX_AUDIO_BYTES) {
- toast.error(`Audio file too large (max ${Math.round(MAX_AUDIO_BYTES / 1024 / 1024)} MB)`);
+ toast.error(`Audio file too large (max ${formatBytes(MAX_AUDIO_BYTES, 0)})`);
return;
}
const bytes = await file.arrayBuffer();
diff --git a/client/src/hooks/useOpenClawAttachments.js b/client/src/hooks/useOpenClawAttachments.js
index 4c3eb9914e..86b2fa5ccf 100644
--- a/client/src/hooks/useOpenClawAttachments.js
+++ b/client/src/hooks/useOpenClawAttachments.js
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { readFileAsBase64 } from '../utils/fileUpload';
+import { formatBytes } from '../utils/formatters';
const MAX_ATTACHMENTS = 8;
// Matches server-side ATTACHMENT_BASE64_MAX_CHARS (13,333,333 chars). Base64 expands raw bytes
@@ -104,7 +105,7 @@ export function useOpenClawAttachments({ sending, onError = () => {} } = {}) {
if (tooLargeFile) {
onError(
- `"${tooLargeFile.name}" is too large. Maximum attachment size is ${Math.round(MAX_ATTACHMENT_FILE_SIZE / (1024 * 1024))}MB.`
+ `"${tooLargeFile.name}" is too large. Maximum attachment size is ${formatBytes(MAX_ATTACHMENT_FILE_SIZE, 0)}.`
);
return;
}
diff --git a/client/src/hooks/useOpenClawAttachments.test.jsx b/client/src/hooks/useOpenClawAttachments.test.jsx
new file mode 100644
index 0000000000..ec20707b9b
--- /dev/null
+++ b/client/src/hooks/useOpenClawAttachments.test.jsx
@@ -0,0 +1,44 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { renderHook, act } from '@testing-library/react';
+import { useOpenClawAttachments } from './useOpenClawAttachments';
+
+vi.mock('../utils/fileUpload', () => ({
+ readFileAsBase64: vi.fn(async () => 'ZmFrZQ==')
+}));
+
+function fakeFile({ name, size, type = 'image/png' }) {
+ return { name, size, type, lastModified: 0 };
+}
+
+describe('useOpenClawAttachments oversize rejection', () => {
+ beforeEach(() => {
+ // jsdom does not implement the object-URL APIs the hook uses for image previews.
+ URL.createObjectURL = vi.fn(() => 'blob:preview');
+ URL.revokeObjectURL = vi.fn();
+ });
+
+ it('reports the size cap using the canonical formatBytes output', async () => {
+ const onError = vi.fn();
+ const { result } = renderHook(() => useOpenClawAttachments({ sending: false, onError }));
+
+ await act(async () => {
+ await result.current.appendFiles([fakeFile({ name: 'huge.png', size: 20 * 1024 * 1024 })]);
+ });
+
+ // 9,999,999-byte cap → "10 MB" via formatBytes(bytes, 0), not a hand-rolled "10MB".
+ expect(onError).toHaveBeenCalledWith('"huge.png" is too large. Maximum attachment size is 10 MB.');
+ expect(result.current.attachments).toEqual([]);
+ });
+
+ it('accepts a file under the cap', async () => {
+ const onError = vi.fn();
+ const { result } = renderHook(() => useOpenClawAttachments({ sending: false, onError }));
+
+ await act(async () => {
+ await result.current.appendFiles([fakeFile({ name: 'small.png', size: 1024 })]);
+ });
+
+ expect(result.current.attachments).toHaveLength(1);
+ expect(onError).toHaveBeenLastCalledWith('');
+ });
+});
diff --git a/client/src/pages/Authors.jsx b/client/src/pages/Authors.jsx
index 782d8a6634..2363943b09 100644
--- a/client/src/pages/Authors.jsx
+++ b/client/src/pages/Authors.jsx
@@ -20,6 +20,7 @@ import GalleryImagePicker from '../components/imageGen/GalleryImagePicker';
import useMediaJobProgress from '../hooks/useMediaJobProgress';
import { DEFAULT_NEGATIVE_PROMPT } from '../lib/imageGenDefaults';
import { readFileAsBase64 } from '../utils/fileUpload';
+import { formatBytes } from '../utils/formatters';
import {
listAuthors, createAuthor, updateAuthor, deleteAuthor, uploadGalleryImage, generateImage,
AUTHOR_NAME_MAX, AUTHOR_WRITING_STYLE_MAX, AUTHOR_BIO_MAX,
@@ -155,7 +156,7 @@ export default function Authors() {
if (!file) return;
if (!file.type.startsWith('image/')) { toast.error('Please choose an image file'); return; }
if (file.size > HEADSHOT_MAX_BYTES) {
- toast.error(`Image exceeds ${Math.round(HEADSHOT_MAX_BYTES / 1024 / 1024)}MB`);
+ toast.error(`Image exceeds ${formatBytes(HEADSHOT_MAX_BYTES, 0)}`);
return;
}
setUploadingHeadshot(true);
diff --git a/client/src/utils/formatters.test.js b/client/src/utils/formatters.test.js
index 4c3c3a03d7..f400ffd80b 100644
--- a/client/src/utils/formatters.test.js
+++ b/client/src/utils/formatters.test.js
@@ -2,9 +2,22 @@ import { describe, it, expect } from 'vitest';
import {
formatContextLength, formatDurationMin, formatDurationMs, formatEventDateTime, timeAgo,
formatCooldown, parseSizeGb, recommendedRamGb, parseTimeoutMs, formatDurationSec, middleTruncate,
- formatWeight, formatPercent, formatUsd,
+ formatWeight, formatPercent, formatUsd, formatBytes,
} from './formatters.js';
+describe('formatBytes', () => {
+ it('renders whole-MB file-size caps with no decimals at decimals=0', () => {
+ // The shape the "file too large" toasts depend on (issue #3869).
+ expect(formatBytes(12 * 1024 * 1024, 0)).toBe('12 MB');
+ expect(formatBytes(35 * 1024 * 1024, 0)).toBe('35 MB');
+ expect(formatBytes(50 * 1024 * 1024, 0)).toBe('50 MB');
+ });
+
+ it('rounds a non-round cap to the nearest whole unit at decimals=0', () => {
+ expect(formatBytes(9_999_999, 0)).toBe('10 MB');
+ });
+});
+
describe('formatWeight', () => {
it('rounds unit-conversion float noise to one decimal', () => {
expect(formatWeight(170.35000000000002)).toBe('170.4 lbs');