Repository navigation
Commit a8261ce
fix(service-storage)!: every upload bound resolves by one precedence, and unset never means unlimited (#33883)
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill names the storage upload bound,
the storage plugin's options or `max_upload_mb`
## 维护者速读
- 改了什么:存储的上传上限改为三个 Limits 键共用的同一条优先级(已保存的设置 > 宿主选项 > 清单默认值 > 内置默认 100
MB),新增宿主选项 `maxUploadMb`(数字或显式的 `'unlimited'`),「未设置」不再等于「不限」。
- 为什么改:规则要求每个上传入口在任何组合下都有上限;不限只能由宿主以 `maxUploadMb: 'unlimited'`
明确选择,并在启动时以 warn 宣告;宿主传错值则拒绝启动。
- 风险与回滚:上述组合(以及已保存但无效的 `max_upload_mb`)的上传从不限变为 100
MB(BREAKING,changeset 与 README 里有「Who moves」与逐行修复,含 DevPlugin 的具体步骤);默认
`os serve`(绑定设置、未保存)本来就是 100 MB,不变。回滚即还原本 PR。
-
先看:`packages/services/service-storage/src/storage-limits.ts`(`pickLayer`
与 `resolveStorageLimits`
的上传层、`parseHostMaxUploadMb`),`storage-service-plugin.ts`(构造函数校验与启动行钩子),`mount-storage-routes.ts`。
- 两分钟验证:`pnpm --filter @objectstack/service-storage exec vitest run
--maxWorkers=2 src/storage-limits.test.ts`,预期 43 个测试全绿。
- 需要你做的:无,席位落地
## What changes
Every storage upload bound now resolves by one precedence, the same for
all three storage Limits keys (`presigned_ttl`, `session_ttl`,
`max_upload_mb`): **saved setting > host option > manifest default >
built-in default**. Unset never means unlimited.
- **Built-in default.** `DEFAULT_MAX_UPLOAD_MB = 100`
(`storage-limits.ts`), held equal to the settings manifest's declared
`max_upload_mb` default by a drift pin.
- **Host option.** `maxUploadMb` on the `StorageServicePlugin`
constructor, on `MountStorageRoutesOptions` and on
`StorageRoutesOptions`: the host layer, through the same `pickLayer` the
TTLs use. It takes a positive number of MB, or `'unlimited'`. Anything
else throws `InvalidMaxUploadMbError` at construction or mount
(`parseHostMaxUploadMb`).
- **Failure paths.** A settings read that fails, and a saved value that
is present but invalid (dropped by `readStorageLimits`), fall to the
host option or else the built-in default.
- **Coverage.** The bound applies wherever `maxUploadBytes` is read: the
byte doors (chunk `PUT`, presigned local raw `PUT`, upload-link `PUT`
and its several-file form), the declared-size doors (presign, chunked
start), and the server-side verbs (`field-file-service.ts`,
`file-attachment-service.ts`, `record-file-access.ts`), which now take
the plugin's host option as `hostMaxUploadMb`.
- **Boot line.** Each host door says once the bound in force and the
layer it came from: the plugin (a `kernel:ready` hook registered after
the settings binding, through its logger), `mountStorageRoutes` and
`registerStorageRoutes` (through the `logger` they are given,
`announceUploadBound`). It is a `warn` when there is no bound, which
only an explicit host `'unlimited'` reaches, and that `warn` is said on
`console.warn` when the door was given no logger.
- **Host bound edges.** A host number must floor to a finite bound of at
least one byte: a number too small to bound one byte, or too large to be
a finite byte bound, is refused like any other malformed value. The file
verbs (`FieldFileService`, `FileAttachmentService`, `RecordFileAccess`)
judge a host bound handed to them at construction too.
- **Entry exports.** `HostMaxUploadMb` (type) and
`InvalidMaxUploadMbError` are exported from the package entry, so a host
can type the option and recognise the refusal by class.
- The upload refusal's message also names the host option, for hosts
with no storage settings.
- Docs: the service-storage README Limits section and the error
catalog's `PAYLOAD_TOO_LARGE` entry state the rule. The stale comment in
`request-body-limit-upload-doors.dogfood.test.ts` now names the built-in
bound.
- Test wiring: `@objectstack/service-settings` joins service-storage's
devDependencies and its vitest source aliases, so the drift pin reads
the manifest from source.
**BREAKING, who moves:** a DevPlugin-composed server; `--preset minimal`
with storage; `mountStorageRoutes` hosts over a bare adapter or an
unbound plugin; `bindToSettings: false` embedders; settings-bound hosts
during a settings fault; a host whose saved or env-sourced
`max_upload_mb` is present but not a positive number. Each moves from no
bound to 100 MB. Remedies: a host that constructs the plugin passes
`maxUploadMb: 500` or `maxUploadMb: 'unlimited'`; a DevPlugin-composed
server turns DevPlugin's storage toggle off and mounts the plugin itself
(`new DevPlugin({ services: { storage: false }, extraPlugins: [new
StorageServicePlugin({ maxUploadMb: 500 })] })`, or the instance in the
stack's `plugins`); a host with an invalid saved value corrects it,
because the saved layer cannot spell "no bound", and to accept any size
removes it and passes the host's `'unlimited'`. The settings manifest's
default value is unchanged.
## Tests
`packages/services/service-storage/src/storage-limits.test.ts` §5 and
`record-file-access.integration.test.ts`:
- **Rule pins.** Each unset path resolves to 100 MB: resolution with no
snapshot; a plugin with no settings service; a settings read that fails;
a dropped saved value; `mountStorageRoutes` over a bare adapter and over
an unbound plugin's service; `bindToSettings: false`. The host option
overrides the manifest default, on the plugin and on
`mountStorageRoutes`. An explicit `'unlimited'` is honoured and
announced at `warn`: by the plugin, by the mount with a logger and with
none (on `console.warn`), and by `registerStorageRoutes` with a logger
and with none; a bounded mount or registration with no logger writes
nothing to `console.warn`, and a bounded registration names its bound
and layer to its logger. A malformed host option (`0`, `-1`, `NaN`,
`Infinity`, `1e-9`, `Number.MAX_VALUE`, `'100'`, `'Unlimited'`,
`'none'`, `null`, `true`, `{}`) refuses the plugin, the mount and the
route registrar, with no route registered, and the file verbs refuse one
handed to them; a bound of exactly one byte (`1 / MiB`) constructs and
resolves to 1 byte. A saved setting still wins over a host
`'unlimited'`. The drift pin.
- **Door pins** (no settings bound). A declared 101 MB body is refused
unread, and an undeclared one is read under the built-in bound and
refused, at the local raw `PUT`, the chunk `PUT`, the upload-link `PUT`
and its several-file form. A presign and a chunked start for 101 MB are
refused. A 101 MB file inside a several-file form within its form limit
is refused by the link verb, with the link unspent. `field-files` and
`file-attachments` refuse a 101 MB file before the engine is reached.
- **Controls.** Exactly 100 MB is accepted. A settings-bound plugin with
nothing saved holds the declared 100 MB, 3600 s and 86400 s, as before
(the default `os serve` composition). The host's explicit `'unlimited'`
states no bound and relays a host size refusal in its own words. Under
`'unlimited'` the server verbs pass the size verdict.
- **Flipped controls.** The no-settings, `bindToSettings: false` and
"states no bound" controls now assert the built-in bound. The two "a
host size refusal is not the door's own" cases moved to the explicit
`'unlimited'` mount, which is the only no-bound path left.
## Acceptance notes
- `mountStorageRoutes`' `maxUploadMb` bounds that mount's doors. The
server-side verbs on the kernel take the storage plugin's own
`maxUploadMb`. A host that passes a larger bound to the mount than to
the plugin gets the tighter of the two on the upload-link spend, which
is judged again in the verb.
- The released 18.5.0 changelog note "with `max_upload_mb` unset a byte
door states no bound" no longer holds. The new changeset says so; the
released entry is not edited.
- Importer packages' suites (cli, runtime, mailbox, organizations,
plugin-dev and others) were not re-run locally. No test outside this
package sends more than 100 MB through a storage door (grep of the test
tree), and CI runs them.
## Verification
<details><summary>Package test and typecheck, head 667098e</summary>
```
pnpm --filter @objectstack/service-storage exec vitest run --maxWorkers=2
Test Files 86 passed (86)
Tests 1672 passed | 1 skipped (1673)
pnpm --filter @objectstack/service-storage typecheck
check:test-typecheck: OK — 0 file(s) / 0 error(s)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Ablation 1: the built-in layer resolved to no bound,
then restored</summary>
`node scripts/ablation-replace.mjs` on `storage-limits.ts`, anchor hit 1
-> 0, replacement 0 -> 1, run of `storage-limits.test.ts` and
`record-file-access.integration.test.ts` (head 92e01a9):
```
Tests 18 failed | 113 passed (131)
ablation-replace: ok restored: blob == HEAD (c44e644) and `git diff HEAD` is empty
```
</details>
<details><summary>Ablation 2: the no-logger announcement removed, then
restored</summary>
`node scripts/ablation-replace.mjs` on `storage-limits.ts`
(`announceUploadBound` says nothing without a logger), anchor hit 1 ->
0, run of `storage-limits.test.ts` (head 667098e):
```
× mountStorageRoutes with no logger still announces 'unlimited' at warn, on console
× registerStorageRoutes announces the bound in force: 'unlimited' at warn, with a logger or, without one, on console
Tests 2 failed | 41 passed (43)
ablation-replace: ok restored: blob == HEAD (9ffe93f) and `git diff HEAD` is empty
```
</details>
<details><summary>Derived gate families, head 667098e</summary>
`node scripts/pm/dispatch-gates.mjs --commands`: 121 derived, 121 run
(`--ran`: 121 accounted for). 118 exit 0, including
`check-adr-0087-registration --base origin/main`,
`check-changeset-no-major`, `check-empty-changeset`,
`check:changeset-fixed`, `check:cross-package-test-inputs`,
`check:test-source-alias`, `check:doc-authoring`, `check:i18n` and
`check:nul-bytes`. The derivation warned that the tree is 21 commits
behind `origin/main`, with 6 derivation inputs changed in that range;
main was not merged, because there is no conflict and no main-caused
red.
NOT MEASURED, left to CI: `@objectstack/spec check:skill-examples` and
`check:dual-build-cjs-loads` (exit 3, PREREQUISITE NOT MET: a
whole-workspace build), and `check:type-check-debt` (exit 124: the local
600 s timeout expired while its closure build waited for the verify lock
behind the dogfood battery). CI's Type Check lanes cover all three.
</details>
<details><summary>Dogfood battery, final head 667098e</summary>
```
pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' build && pnpm --filter @objectstack/dogfood test
os-verify-lock: VERDICT command-exit 0 · held the lock 2163s
Test Files 467 passed | 3 skipped (470)
Tests 3959 passed | 42 skipped (4001)
```
The first head (14805de) gave the same counts: 467 passed | 3 skipped
files, 3959 passed | 42 skipped tests.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_
<!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6f9a2e8 commit a8261ce
17 files changed
Lines changed: 976 additions & 90 deletions
File tree
- .changeset
- content/docs/api
- packages
- qa/dogfood/test
- services/service-storage
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
611 | 611 | | |
612 | 612 | | |
613 | 613 | | |
614 | | - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
615 | 617 | | |
616 | 618 | | |
617 | 619 | | |
618 | | - | |
| 620 | + | |
| 621 | + | |
619 | 622 | | |
620 | 623 | | |
621 | 624 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
124 | 150 | | |
125 | 151 | | |
126 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
178 | 186 | | |
179 | 187 | | |
180 | 188 | | |
181 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
182 | 193 | | |
183 | 194 | | |
184 | 195 | | |
| |||
190 | 201 | | |
191 | 202 | | |
192 | 203 | | |
193 | | - | |
| 204 | + | |
194 | 205 | | |
195 | 206 | | |
196 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
143 | 151 | | |
144 | 152 | | |
145 | 153 | | |
| |||
315 | 323 | | |
316 | 324 | | |
317 | 325 | | |
| 326 | + | |
| 327 | + | |
318 | 328 | | |
319 | 329 | | |
320 | 330 | | |
321 | 331 | | |
322 | 332 | | |
323 | 333 | | |
324 | 334 | | |
| 335 | + | |
325 | 336 | | |
326 | 337 | | |
327 | 338 | | |
| |||
594 | 605 | | |
595 | 606 | | |
596 | 607 | | |
597 | | - | |
| 608 | + | |
598 | 609 | | |
599 | 610 | | |
600 | 611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
| |||
0 commit comments