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

address review: enforce attachment data/url mutual exclusivity, move size check inside setAttachments updater

[._.]/ Adam Eivyb1b7fdaa278d
diff --git a/client/src/pages/OpenClaw.jsx b/client/src/pages/OpenClaw.jsx
index 8a3f1e989d..b2a6b5f0b4 100644
--- a/client/src/pages/OpenClaw.jsx
+++ b/client/src/pages/OpenClaw.jsx
@@ -343,22 +343,16 @@ export default function OpenClaw() {
try {
const next = await filesToAttachments(limitedFiles);
-
- const existingBase64Chars = attachments.reduce((sum, a) => sum + (typeof a.data === 'string' ? a.data.length : 0), 0);
const newBase64Chars = next.reduce((sum, a) => sum + (typeof a.data === 'string' ? a.data.length : 0), 0);
- if (existingBase64Chars + newBase64Chars > MAX_ATTACHMENTS_TOTAL_BASE64_CHARS) {
- next.forEach(a => { if (a.previewUrl) URL.revokeObjectURL(a.previewUrl); });
- const totalMB = Math.round((existingBase64Chars + newBase64Chars) * 0.75 / (1024 * 1024));
- setMessagesError(`Combined attachments exceed the 50MB encoded total limit (~${totalMB}MB decoded).`);
- return;
- }
setAttachments(current => {
- // Re-check limits against actual current state to prevent race conditions if
- // appendFiles is called concurrently before the previous async read resolves.
+ // All limit checks use `current` (live state) to avoid stale-closure races
+ // when appendFiles is called concurrently before the previous async read resolves.
const currentBase64Chars = current.reduce((sum, a) => sum + (typeof a.data === 'string' ? a.data.length : 0), 0);
if (currentBase64Chars + newBase64Chars > MAX_ATTACHMENTS_TOTAL_BASE64_CHARS) {
next.forEach(a => { if (a.previewUrl) URL.revokeObjectURL(a.previewUrl); });
+ const totalMB = Math.round((currentBase64Chars + newBase64Chars) * 0.75 / (1024 * 1024));
+ setMessagesError(`Combined attachments exceed the 50MB encoded total limit (~${totalMB}MB decoded).`);
return current;
}
const currentCount = Array.isArray(current) ? current.length : 0;
@@ -369,9 +363,9 @@ export default function OpenClaw() {
}
const accepted = next.slice(0, remaining);
next.slice(remaining).forEach(a => { if (a.previewUrl) URL.revokeObjectURL(a.previewUrl); });
+ setMessagesError('');
return [...current, ...accepted];
});
- setMessagesError('');
} catch (err) {
setMessagesError(err.message || 'Failed to prepare attachment');
}
diff --git a/server/routes/openclaw.js b/server/routes/openclaw.js
index f3b7eace1a..7b0ab50302 100644
--- a/server/routes/openclaw.js
+++ b/server/routes/openclaw.js
@@ -41,6 +41,13 @@ const attachmentSchema = z.object({
});
}
+ if (hasData && hasUrl) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: 'Attachment must include either base64 data or url, not both.'
+ });
+ }
+
if (value.sourceType === 'base64' && !hasData) {
ctx.addIssue({
code: z.ZodIssueCode.custom,