@devries-cameron20 / t3code-1 / commits / ab06e2a265
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(clients): attachment sizes just under 1 MB no longer read "1024 KB" (#29165)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Alex Southwell committed Nov 3, 2026 at 01:34 UTC ab06e2a265db928902daffe33f5fdb3904a67fdc
2 files changed +19 -4
packages/client-runtime/src/state/attachments.test.ts
+16 -1
@@ -9,7 +9,11 @@ import * as Effect from "effect/Effect";
9 import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
10
11 import type { AtomCommand } from "./runtime.ts";
12 -import { runAttachmentUploadCycle, verifyPersistedAttachmentUpload } from "./attachments.ts";
12 +import {
13 + formatAttachmentSize,
14 + runAttachmentUploadCycle,
15 + verifyPersistedAttachmentUpload,
16 +} from "./attachments.ts";
17
18 const environmentId = EnvironmentId.make("environment-1");
19 const registry = {} as AtomRegistry.AtomRegistry;
@@ -129,3 +133,14 @@ describe("verifyPersistedAttachmentUpload", () => {
133 expect(lookups).toBe(2);
134 });
135 });
136 +
137 +describe("formatAttachmentSize", () => {
138 + it.each([
139 + [1_047_552, "1023 KB"],
140 + [1_047_553, "1.0 MB"],
141 + [1_048_575, "1.0 MB"],
142 + [1_048_576, "1.0 MB"],
143 + ])("formats %d bytes as %s", (sizeBytes, label) => {
144 + expect(formatAttachmentSize(sizeBytes)).toBe(label);
145 + });
146 +});
packages/client-runtime/src/state/attachments.ts
+3 -3
@@ -194,9 +194,9 @@ export function clampFileAttachmentUploadBytes(advertisedMaxUploadBytes: number)
194 }
195
196 export function formatAttachmentSize(sizeBytes: number): string {
197 - return sizeBytes >= 1024 * 1024
198 - ? `${(sizeBytes / (1024 * 1024)).toFixed(1)} MB`
199 - : `${Math.max(1, Math.ceil(sizeBytes / 1024))} KB`;
197 + const kilobytes = Math.max(1, Math.ceil(sizeBytes / 1024));
198 + // Pick the unit after rounding, so 1023.5 KB reads "1.0 MB", not "1024 KB".
199 + return kilobytes >= 1024 ? `${(sizeBytes / (1024 * 1024)).toFixed(1)} MB` : `${kilobytes} KB`;
200 }
201
202 export function fileAttachmentTooLargeMessage(name: string, maxUploadBytes: number): string {