Skip to content

Commit 667098e

Browse files
committed
fix(service-storage): every host door announces an explicit unlimited upload bound; the host bound is a finite whole-byte bound
Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
1 parent 14805de commit 667098e

11 files changed

Lines changed: 163 additions & 29 deletions

‎.changeset/storage-upload-bound-built-in-default.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@ Metadata-protocol: none
1717
- **Host option.** `maxUploadMb` on the `StorageServicePlugin` constructor, on `mountStorageRoutes` and on `registerStorageRoutes` is the host layer, exactly like `presignedTtl` and `sessionTtl`. It takes a positive number of MB, or `'unlimited'` for no bound. Any other value (`0`, a negative or non-finite number, a numeric string, any other string) refuses construction or the mount.
1818
- **Failure paths.** A settings read that fails, and a saved value that is present but not a positive number, take the host option or else the built-in default, never no bound.
1919
- **Coverage.** The bound applies wherever an upload is judged: the byte doors (the chunk `PUT`, the presigned local raw `PUT`, the upload-link `PUT` and its several-file form), the declared-size doors (presign, chunked start), and the server-side file verbs (`field-files`, `file-attachments` and the upload link's several-file spend).
20-
- **Boot line.** One line at boot names the bound in force and the layer it came from. With an explicit `'unlimited'` it is a `warn`.
20+
- **Boot line.** Each host door says, once at boot or mount, the bound in force and the layer it came from: the plugin through its logger, `mountStorageRoutes` and `registerStorageRoutes` through the `logger` they are given. With an explicit `'unlimited'` the line is a `warn`, and it is said even when no logger was passed, on `console.warn`.
2121

2222
**Who moves.** Each of these moves from no upload bound to 100 MB:
2323

2424
- a DevPlugin-composed server;
2525
- `--preset minimal` with storage;
2626
- a `mountStorageRoutes` host over a bare adapter or over a plugin bound to no settings;
2727
- an embedder that passes `bindToSettings: false`;
28-
- a settings-bound host while its settings read fails.
28+
- a settings-bound host while its settings read fails;
29+
- a host whose saved or env-sourced `max_upload_mb` is present but not a positive number (it was dropped, and nothing stood in its place).
2930

30-
The remedy for each is one host option: `new StorageServicePlugin({ maxUploadMb: 500 })` for another bound, or `maxUploadMb: 'unlimited'` to keep accepting uploads of any size (boot then says so at `warn`). Pass the same option to `mountStorageRoutes` for that mount's doors.
31+
Remedies:
32+
33+
- **A host that constructs the plugin** (`bindToSettings: false` embedders, `--preset minimal`, settings-fault hosts): one option, `new StorageServicePlugin({ maxUploadMb: 500 })` for another bound, or `maxUploadMb: 'unlimited'` to keep accepting uploads of any size (boot then says so at `warn`). A `mountStorageRoutes` or `registerStorageRoutes` host passes the same option for that mount's doors.
34+
- **A DevPlugin-composed server**: DevPlugin constructs the storage plugin with no options, so turn its storage toggle off and mount the plugin yourself: `new DevPlugin({ services: { storage: false }, extraPlugins: [new StorageServicePlugin({ maxUploadMb: 500 })] })`, or list the `StorageServicePlugin` instance in the stack's own `plugins`, where an explicit instance wins.
35+
- **A host with an invalid saved value**: correct the saved `max_upload_mb` (Setup's File Storage settings, or the env override) to a positive number. The saved layer cannot spell "no bound"; to accept any size, remove the saved value and pass the host option `maxUploadMb: 'unlimited'`.
3136

3237
**Unchanged.** A settings-bound host with nothing saved, which is the default `os serve`, already enforced the manifest's 100 MB and still does. A saved `max_upload_mb` still wins over every host option. The 18.5.0 note "with `max_upload_mb` unset a byte door states no bound and reads the whole body" no longer holds: with `max_upload_mb` unset a byte door states the host's bound or else the built-in 100 MB, and it states no bound only under an explicit host `'unlimited'`.

‎content/docs/api/error-catalog.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,13 @@ The standard catalog names no `413` member.
612612
declared `size`), the chunked-upload start (the declared `totalSize`), the local adapter's raw
613613
upload (the body) and the chunk door (the bytes the upload already holds plus the chunk) refuse
614614
it before anything is stored. The message names the size, the limit and the setting. With no
615-
storage settings bound, the bound is the storage plugin's `maxUploadMb` option, else the built-in
616-
100 MB: an upload bound is never unset.
615+
saved value, the bound is the storage plugin's `maxUploadMb` option, then the setting's declared
616+
default, then the built-in 100 MB: an upload bound is never unset.
617617
- **An import over its route's row ceiling** — 5,000 rows on the synchronous route, 50,000 on the
618618
job route ([size limits](/docs/data-modeling/import-mappings#size-limits)).
619619

620-
**Fix:** Raise the setting (or, with no storage settings bound, the host's `maxUploadMb`) or send a
621-
smaller file; split the import across requests. Resending
620+
**Fix:** Raise the setting (or, with nothing saved, the host's `maxUploadMb`) or send a smaller
621+
file; split the import across requests. Resending
622622
the same request cannot succeed.
623623
**Retry:** `no_retry`
624624

‎packages/services/service-storage/README.md‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,20 @@ new StorageServicePlugin({ maxUploadMb: 500 }); // the host's bound, in
132132
new StorageServicePlugin({ maxUploadMb: 'unlimited' }); // no bound, announced at warn on boot
133133
```
134134

135-
Anything else (`0`, a negative or non-finite number, a numeric string, any
136-
other string) refuses construction. One line at boot names the bound in force
137-
and the layer it came from. On the S3 adapter a presigned upload is judged by
135+
Anything else (`0`, a negative or non-finite number, a number too small to
136+
bound one byte, a numeric string, any other string) refuses construction. Each
137+
host door — the plugin, `mountStorageRoutes`, `registerStorageRoutes` — says once
138+
the bound in force and the layer it came from; an explicit `'unlimited'` is said
139+
at `warn`, on `console.warn` when the door was given no logger.
140+
141+
Who moved from no bound to 100 MB, and the remedy:
142+
143+
| Host | Remedy |
144+
|:---|:---|
145+
| Constructs the plugin with no settings bound (`bindToSettings: false`, `--preset minimal`), or its settings read fails | `maxUploadMb: 500` or `'unlimited'` on the plugin |
146+
| `mountStorageRoutes` / `registerStorageRoutes` over a bare adapter or an unbound plugin | the same option on that call |
147+
| DevPlugin-composed server (DevPlugin builds the plugin with no options) | `new DevPlugin({ services: { storage: false }, extraPlugins: [new StorageServicePlugin({ maxUploadMb: 500 })] })`, or list the instance in the stack's `plugins` |
148+
| A saved or env-sourced `max_upload_mb` that is not a positive number | correct the saved value; the saved layer cannot spell "no bound", so to accept any size remove it and pass `maxUploadMb: 'unlimited'` | On the S3 adapter a presigned upload is judged by
138149
its declared size — the bytes go straight to the bucket.
139150

140151
## REST API Endpoints

‎packages/services/service-storage/src/field-file-service.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
// The upload doors' own size verdict and refusal, asked here rather than
2525
// restated.
2626
import {
27+
parseHostMaxUploadMb,
2728
resolveStorageLimits,
2829
uploadSizeRefusal,
2930
UPLOAD_TOO_LARGE_CODE,
@@ -185,7 +186,10 @@ function isSlot(owner: FieldFileSlot | null, slot: FieldFileSlot): boolean {
185186
}
186187

187188
export class FieldFileService implements IFieldFileService {
188-
constructor(private readonly deps: FieldFileServiceDeps) {}
189+
constructor(private readonly deps: FieldFileServiceDeps) {
190+
// The host bound is judged where the verb is built, as at every host door.
191+
parseHostMaxUploadMb(deps.hostMaxUploadMb, 'FieldFileService');
192+
}
189193

190194
async storeFile(input: StoreFieldFileInput): Promise<StoredFieldFile> {
191195
const request = validateStoreInput(input);

‎packages/services/service-storage/src/file-attachment-service.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { createWallOrganizationResolver } from './backfill-sys-file-organization
3535
// The upload doors' own size verdict and refusal, asked here rather than
3636
// restated.
3737
import {
38+
parseHostMaxUploadMb,
3839
resolveStorageLimits,
3940
uploadSizeRefusal,
4041
UPLOAD_TOO_LARGE_CODE,
@@ -322,6 +323,8 @@ export class FileAttachmentService
322323
private readonly recordFiles: RecordFileAccess | null;
323324

324325
constructor(private readonly deps: FileAttachmentServiceDeps) {
326+
// The host bound is judged where the verb is built, as at every host door.
327+
parseHostMaxUploadMb(deps.hostMaxUploadMb, 'FileAttachmentService');
325328
const bound = deps.recordFiles;
326329
this.recordFiles = bound
327330
? new RecordFileAccess({

‎packages/services/service-storage/src/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export type {
2525
// group as last read. Types only — the reading and the resolution stay inside
2626
// the package, so the precedence has one definition.
2727
export type { StorageLimitsSnapshot, StorageLimitReading } from './storage-limits.js';
28+
// The host's upload bound (`maxUploadMb` on the plugin, `mountStorageRoutes` and
29+
// `registerStorageRoutes`): its type, so a host can type the option, and the
30+
// refusal a malformed one boots into, so a host can recognise it by class.
31+
export type { HostMaxUploadMb } from './storage-limits.js';
32+
export { InvalidMaxUploadMbError } from './storage-limits.js';
2833
// [#15169] The host door: the storage routes composed from a kernel and
2934
// mounted on an HTTP surface the host owns — for kernels with no `http-server`
3035
// service (cloud's per-environment tenant kernels). Published as ONE entry

‎packages/services/service-storage/src/mount-storage-routes.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
import type { IHttpServer, IDataEngine, IStorageService } from '@objectstack/spec/contracts';
5959
import {
6060
parseHostMaxUploadMb,
61+
announceUploadBound,
6162
resolveStorageLimits,
62-
uploadBoundBootLine,
6363
type HostMaxUploadMb,
6464
type StorageLimitsSnapshot,
6565
} from './storage-limits.js';
@@ -106,7 +106,11 @@ export interface MountStorageRoutesOptions {
106106
maxUploadMb?: HostMaxUploadMb;
107107
/** TTL of the signed URL minted on a GATED download. @default 300 */
108108
downloadTtl?: number;
109-
/** Receives the door's one-time notices (the upload bound in force, open upload mode, unbound gates). */
109+
/**
110+
* Receives the door's one-time notices (the upload bound in force, open
111+
* upload mode, unbound gates). Without one, an explicit `maxUploadMb:
112+
* 'unlimited'` is still announced, on `console.warn`.
113+
*/
110114
logger?: { info(msg: string): void; warn(msg: string): void };
111115
}
112116

@@ -169,15 +173,15 @@ export function mountStorageRoutes(
169173

170174
// The upload bound this mount's doors meet now, and the layer it came from:
171175
// the kernel has bootstrapped, so a bound plugin's settings are read.
176+
// No bound is said at `warn` whether or not the host passed a logger.
172177
const carrier = storage as { getLimitsSnapshot?: () => StorageLimitsSnapshot | undefined };
173-
const bound = uploadBoundBootLine(
178+
announceUploadBound(
174179
'mountStorageRoutes',
175180
resolveStorageLimits(typeof carrier.getLimitsSnapshot === 'function' ? carrier.getLimitsSnapshot() : undefined, {
176181
maxUploadMb,
177182
}),
183+
opts.logger,
178184
);
179-
if (bound.level === 'warn') opts.logger?.warn(bound.message);
180-
else opts.logger?.info(bound.message);
181185

182186
const unbound: string[] = [];
183187
if (!report.sessionResolver) {

‎packages/services/service-storage/src/record-file-access.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
// The upload doors' own size verdict and refusal, asked here rather than
3737
// restated.
3838
import {
39+
parseHostMaxUploadMb,
3940
resolveStorageLimits,
4041
uploadSizeRefusal,
4142
UPLOAD_TOO_LARGE_CODE,
@@ -764,7 +765,10 @@ function describe(file: FileRecord): Pick<RecordFileEntry, 'fileId' | 'name' | '
764765
}
765766

766767
export class RecordFileAccess implements ICallerRecordFileService, UploadLinkDoor {
767-
constructor(private readonly deps: RecordFileAccessDeps) {}
768+
constructor(private readonly deps: RecordFileAccessDeps) {
769+
// The host bound is judged where the verb is built, as at every host door.
770+
parseHostMaxUploadMb(deps.hostMaxUploadMb, 'RecordFileAccess');
771+
}
768772

769773
private now(): number {
770774
return this.deps.now ? this.deps.now() : Date.now();

‎packages/services/service-storage/src/storage-limits.test.ts‎

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,38 @@ describe('the upload bound resolves by one precedence — saved > host > manifes
10051005
});
10061006

10071007
describe('no limit is an explicit host choice, honoured and announced', () => {
1008+
it('mountStorageRoutes with no logger still announces \'unlimited\' at warn, on console', async () => {
1009+
const kernel = new ObjectKernel({ skipSystemValidation: true, gracefulShutdown: false } as never);
1010+
kernel.registerService('storage', new LocalStorageAdapter({ rootDir: await tmpRoot(), signingSecret: 'test-secret-bound' }));
1011+
const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => {});
1012+
mountStorageRoutes(routeCollector().http, kernel, { basePath: BASE, maxUploadMb: 'unlimited' });
1013+
expect(consoleWarn.mock.calls.filter(([m]) => String(m).includes('UNLIMITED'))).toHaveLength(1);
1014+
// CONTROL — a bounded mount with no logger says nothing on console.warn.
1015+
consoleWarn.mockClear();
1016+
mountStorageRoutes(routeCollector().http, kernel, { basePath: BASE });
1017+
expect(consoleWarn).not.toHaveBeenCalled();
1018+
});
1019+
1020+
it('registerStorageRoutes announces the bound in force: \'unlimited\' at warn, with a logger or, without one, on console', async () => {
1021+
const adapter = new LocalStorageAdapter({ rootDir: await tmpRoot(), signingSecret: 'test-secret-bound' });
1022+
const warns: string[] = [];
1023+
const infos: string[] = [];
1024+
const logger = { info: (m: string) => { infos.push(m); }, warn: (m: string) => { warns.push(m); } };
1025+
registerStorageRoutes(routeCollector().http, adapter, new StorageMetadataStore(null), { maxUploadMb: 'unlimited', logger });
1026+
expect(warns.filter((m) => m.includes('UNLIMITED'))).toHaveLength(1);
1027+
1028+
const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => {});
1029+
registerStorageRoutes(routeCollector().http, adapter, new StorageMetadataStore(null), { maxUploadMb: 'unlimited' });
1030+
expect(consoleWarn.mock.calls.filter(([m]) => String(m).includes('UNLIMITED'))).toHaveLength(1);
1031+
1032+
// CONTROL — a bounded registration names its bound and layer to the logger, and nothing goes to console.warn.
1033+
consoleWarn.mockClear();
1034+
registerStorageRoutes(routeCollector().http, adapter, new StorageMetadataStore(null), { logger });
1035+
registerStorageRoutes(routeCollector().http, adapter, new StorageMetadataStore(null));
1036+
expect(infos.find((m) => m.includes(`(${BUILT_IN} bytes)`))).toContain('built-in default');
1037+
expect(consoleWarn).not.toHaveBeenCalled();
1038+
});
1039+
10081040
it('the plugin: maxUploadMb \'unlimited\' accepts any size, and boot says so at warn', async () => {
10091041
const { routes, warns, infos } = await bootPlugin(null, { maxUploadMb: 'unlimited' });
10101042
expect((await call(routes, 'POST', `${BASE}/upload/presigned`, {
@@ -1034,7 +1066,10 @@ describe('the upload bound resolves by one precedence — saved > host > manifes
10341066
});
10351067

10361068
it('a malformed host option refuses the boot — the plugin, the host mount and the route registrar alike', async () => {
1037-
const malformed: unknown[] = [0, -1, Number.NaN, Number.POSITIVE_INFINITY, '100', 'Unlimited', 'none', null, true, {}];
1069+
// The numeric arm's two edges: too small to bound one byte, and too large to be a finite byte bound.
1070+
const malformed: unknown[] = [
1071+
0, -1, Number.NaN, Number.POSITIVE_INFINITY, 1e-9, Number.MAX_VALUE, '100', 'Unlimited', 'none', null, true, {},
1072+
];
10381073
const kernel = new ObjectKernel({ skipSystemValidation: true, gracefulShutdown: false } as never);
10391074
kernel.registerService('storage', new LocalStorageAdapter({ rootDir: await tmpRoot(), signingSecret: 'test-secret-bound' }));
10401075
for (const bad of malformed) {
@@ -1051,8 +1086,22 @@ describe('the upload bound resolves by one precedence — saved > host > manifes
10511086
).toThrow(InvalidMaxUploadMbError);
10521087
expect(direct.routes.size).toBe(0);
10531088
}
1054-
// CONTROL — the two well-formed spellings construct.
1089+
// The file verbs judge a host bound handed to them directly, too.
1090+
for (const bad of [0, 1e-9, Number.MAX_VALUE, '100']) {
1091+
const deps = {
1092+
getEngine: () => null,
1093+
getStorage: () => null,
1094+
getLimitsSnapshot: () => undefined,
1095+
hostMaxUploadMb: bad as never,
1096+
logger: { warn: () => {}, info: () => {}, error: () => {}, debug: () => {} } as never,
1097+
};
1098+
expect(() => new FieldFileService(deps as never), String(bad)).toThrow(InvalidMaxUploadMbError);
1099+
expect(() => new FileAttachmentService(deps as never), String(bad)).toThrow(InvalidMaxUploadMbError);
1100+
}
1101+
// CONTROL — the well-formed spellings construct, down to a bound of exactly one byte.
10551102
expect(() => new StorageServicePlugin({ maxUploadMb: 0.5 })).not.toThrow();
1103+
expect(() => new StorageServicePlugin({ maxUploadMb: 1 / MIB })).not.toThrow();
1104+
expect(resolveStorageLimits(undefined, { maxUploadMb: 1 / MIB }).maxUploadBytes).toBe(1);
10561105
expect(() => new StorageServicePlugin({ maxUploadMb: 'unlimited' })).not.toThrow();
10571106
});
10581107
});

0 commit comments

Comments
 (0)