Skip to content

Commit df3e34c

Browse files
committed
fix(contracts): read large file attachments from newer clients
1 parent b2b43be commit df3e34c

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

‎packages/contracts/src/orchestration.test.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
ThreadTurnStartRequestedPayload,
3636
SnapShotAccessibility,
3737
isProviderSendTurnSupportedImageMimeType,
38-
PROVIDER_SEND_TURN_MAX_FILE_BYTES,
3938
} from "./orchestration.ts";
4039
import { ProviderInstanceId } from "./providerInstance.ts";
4140

@@ -358,9 +357,6 @@ it.effect("tolerates attachment types from newer builds when decoding messages",
358357
}),
359358
);
360359

361-
// The tolerant member must not catch malformed known attachments: a file over
362-
// the size cap or an image with a bad mime has to fail its own schema, not
363-
// slide through the open one with those constraints unchecked.
364360
it.effect("rejects malformed known attachment types instead of tolerating them", () =>
365361
Effect.gen(function* () {
366362
const base = {
@@ -380,10 +376,11 @@ it.effect("rejects malformed known attachment types instead of tolerating them",
380376
updatedAt: "2026-01-01T00:00:00.000Z",
381377
});
382378

383-
const oversizedFile = yield* Effect.exit(
384-
decode({ ...base, type: "file", sizeBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES + 1 }),
385-
);
386-
assert.strictEqual(Exit.isFailure(oversizedFile), true);
379+
const largeFile = yield* decode({ ...base, type: "file", sizeBytes: 75_000_000 });
380+
assert.strictEqual(largeFile.attachments?.[0]?.sizeBytes, 75_000_000);
381+
382+
const emptyFile = yield* Effect.exit(decode({ ...base, type: "file", sizeBytes: 0 }));
383+
assert.strictEqual(Exit.isFailure(emptyFile), true);
387384

388385
const badMimeImage = yield* Effect.exit(
389386
decode({ ...base, type: "image", mimeType: "application/pdf", sizeBytes: 12 }),

‎packages/contracts/src/orchestration.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,7 @@ export const ChatFileAttachment = Schema.Struct({
318318
id: ChatAttachmentId,
319319
name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
320320
mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100)),
321-
sizeBytes: NonNegativeInt.check(
322-
Schema.isGreaterThanOrEqualTo(1),
323-
Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_FILE_BYTES),
324-
),
321+
sizeBytes: NonNegativeInt.check(Schema.isGreaterThanOrEqualTo(1)),
325322
/** Clipboard text folded by a client. Providers keep these path-only so the
326323
agent can inspect the file selectively instead of eagerly spending the
327324
same context the fold is intended to preserve. */

0 commit comments

Comments
 (0)