Skip to content

Commit 20c30c7

Browse files
rustyconoverclaude
andcommitted
deps: pin vgi-rpc 3a8d584 (advertised upload size never exceeds the fetch cap)
vgi-rpc 3a8d584 makes make_wsgi_app always advertise VGI-Max-Upload-Bytes when it vends upload URLs, defaulting to and capped by the server's inbound fetch cap, and adds VGI_RPC_MAX_FETCH_BYTES (default 256 MiB, raised to VGI_RPC_MAX_UPLOAD_BYTES when larger). This fixes the staging failure where a worker advertising 1 GiB refused a 300 MB upload after it was sent. vgi serve already goes through external_config_from_env + make_wsgi_app, so it gets the invariant; its docstrings now say so. The HTTP test fixture's --max-upload-bytes now raises the S3/demo-storage fetch cap to match, the same rule as the env var. Tests: the 1 GiB staging config yields a 1 GiB fetch cap, an unset upload cap advertises the fetch cap, and contradictory caps stop startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d75a44b commit 20c30c7

6 files changed

Lines changed: 96 additions & 19 deletions

File tree

‎CLAUDE.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ vgi-client --input data.parquet --function sum_all_columns --worker vgi-fixture-
329329
| `VGI_STORAGE_EXTERNALIZE` | `1` wraps any storage backend (e.g. SQLite) in `ExternalizingStorage`; needs `VGI_BLOB_VENDOR_URL`. cloudflare-do is always wrapped |
330330
| `VGI_STORAGE_EXTERNALIZE_BYTES` | Storage values at or over this size go to the blob vendor (default 524288; max 1048576 on cloudflare-do). Alias: `VGI_CF_DO_EXTERNALIZE_BYTES` |
331331
| `VGI_RPC_MAX_REQUEST_BYTES` | `vgi-serve --http` (and `vgi-fixture-http` with the vendor): advertised and enforced request cap; clients upload larger requests via the vendor's upload URLs |
332-
| `VGI_RPC_EXTERNALIZE_THRESHOLD_BYTES` / `VGI_RPC_EXTERNAL_COMPRESSION` / `VGI_RPC_MAX_UPLOAD_BYTES` | With the vendor: result externalization threshold (default 1 MiB), its compression, and the advertised upload size |
332+
| `VGI_RPC_EXTERNALIZE_THRESHOLD_BYTES` / `VGI_RPC_EXTERNAL_COMPRESSION` / `VGI_RPC_MAX_UPLOAD_BYTES` | With the vendor: result externalization threshold (default 1 MiB), its compression, and the advertised upload size (unset: the inbound fetch cap) |
333+
| `VGI_RPC_MAX_FETCH_BYTES` | With the vendor: largest request fetched from an inbound upload pointer. Default 256 MiB, raised to `VGI_RPC_MAX_UPLOAD_BYTES` when that is larger; an upload cap above an explicit fetch cap fails startup. vgi-rpc never advertises an upload size above it |
333334

334335
### Worker Debug Mode
335336

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ vgi-fixtures = { workspace = true }
291291
# (VGI-Upload-URL-Support: 2), which is unreleased on vgi-rpc-python's
292292
# protocol-3.4 branch. Replace this pin with a `vgi-rpc>=<release>` floor
293293
# when that release ships.
294-
vgi-rpc = { git = "https://github.com/Query-farm/vgi-rpc-python", rev = "f0fb6754ae5b70900ba21629a1e2d48eb2182774" }
294+
vgi-rpc = { git = "https://github.com/Query-farm/vgi-rpc-python", rev = "3a8d584fbc56f02329d8790fbc29104b91b40516" }
295295

296296
[dependency-groups]
297297
dev = ["lxml>=6.0.2", "pytest-timeout>=2.4.0", "vgi-fixtures"]

‎tests/test_serve_blob_vendor.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import subprocess
1414
import sys
1515
from collections.abc import Iterator
16+
from typing import Protocol
1617
from urllib.parse import urlsplit
1718

1819
import pyarrow as pa
@@ -32,6 +33,15 @@ def vendor() -> Iterator[FakeVendorServer]:
3233
yield server
3334

3435

36+
class _Echo(Protocol):
37+
def echo(self, value: int) -> int: ...
38+
39+
40+
class _EchoImpl:
41+
def echo(self, value: int) -> int:
42+
return value
43+
44+
3545
def test_nothing_configured() -> None:
3646
"""No vendor and no request cap: everything off, as before."""
3747
cfg = resolve_blob_vendor_http_config({})
@@ -73,9 +83,44 @@ def test_vendor_configured(vendor: FakeVendorServer) -> None:
7383
assert cfg.external_location.storage is cfg.upload_url_provider
7484
assert cfg.external_location.externalize_threshold_bytes == 2048
7585
assert cfg.max_upload_bytes == 1073741824
86+
# The inbound fetch cap follows the advertised upload size (a 300 MB
87+
# upload used to be refused after upload by the 256 MiB default).
88+
assert cfg.external_location.fetch_config.max_fetch_bytes == 1073741824
7689
assert cfg.max_request_bytes == 65536
7790

7891

92+
def test_vendor_upload_cap_defaults_to_fetch_cap(vendor: FakeVendorServer) -> None:
93+
"""Unset VGI_RPC_MAX_UPLOAD_BYTES: vgi-rpc advertises the fetch cap, so a client is never surprised after upload."""
94+
import falcon.testing
95+
from vgi_rpc.http import make_wsgi_app
96+
from vgi_rpc.rpc import RpcServer
97+
98+
cfg = resolve_blob_vendor_http_config(
99+
{"VGI_BLOB_VENDOR_URL": vendor.url, "VGI_CF_DO_TOKEN": "test-token", "VGI_RPC_MAX_FETCH_BYTES": "536870912"}
100+
)
101+
assert cfg.max_upload_bytes is None
102+
assert cfg.external_location is not None
103+
assert cfg.external_location.fetch_config.max_fetch_bytes == 536870912
104+
server = RpcServer(_Echo, _EchoImpl(), external_location=cfg.external_location)
105+
app = make_wsgi_app(
106+
server, token_key=b"k" * 32, upload_url_provider=cfg.upload_url_provider, max_upload_bytes=cfg.max_upload_bytes
107+
)
108+
assert falcon.testing.TestClient(app).simulate_get("/health").headers["VGI-Max-Upload-Bytes"] == "536870912"
109+
110+
111+
def test_vendor_contradictory_caps_stop_startup(vendor: FakeVendorServer) -> None:
112+
"""VGI_RPC_MAX_UPLOAD_BYTES above an explicit VGI_RPC_MAX_FETCH_BYTES is a startup error."""
113+
with pytest.raises(ValueError, match="exceeds VGI_RPC_MAX_FETCH_BYTES"):
114+
resolve_blob_vendor_http_config(
115+
{
116+
"VGI_BLOB_VENDOR_URL": vendor.url,
117+
"VGI_CF_DO_TOKEN": "test-token",
118+
"VGI_RPC_MAX_UPLOAD_BYTES": "1073741824",
119+
"VGI_RPC_MAX_FETCH_BYTES": "268435456",
120+
}
121+
)
122+
123+
79124
def test_vendor_without_token(vendor: FakeVendorServer) -> None:
80125
"""A vendor URL with no token stops startup."""
81126
with pytest.raises(ValueError, match="VGI_BLOB_VENDOR_TOKEN"):

‎uv.lock‎

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vgi/_test_fixtures/http_server.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from datetime import UTC, datetime, timedelta
2323
from typing import TYPE_CHECKING, Any
2424

25+
from vgi_rpc.external_fetch import DEFAULT_MAX_FETCH_BYTES, FetchConfig
26+
2527
from vgi._test_fixtures.accumulate.worker import AccumulateWorker
2628
from vgi._test_fixtures.projection_repro.worker import ProjReproWorker
2729
from vgi._test_fixtures.schema_reconcile.worker import SchemaReconcileWorker
@@ -121,6 +123,24 @@ def generate_upload_url(self, size: int, sha256_hex: str) -> UploadUrl:
121123
)
122124

123125

126+
def _upload_fetch_config(max_upload_bytes: int) -> FetchConfig:
127+
"""Inbound fetch config able to fetch back the uploads this server advertises.
128+
129+
``make_wsgi_app`` refuses a ``max_upload_bytes`` above the server's fetch
130+
cap (an upload it would then refuse to fetch), so ``--max-upload-bytes``
131+
raises the cap from its 256 MiB default, as ``VGI_RPC_MAX_UPLOAD_BYTES``
132+
does for the blob vendor.
133+
134+
Args:
135+
max_upload_bytes: The advertised upload cap.
136+
137+
Returns:
138+
A fetch config whose ``max_fetch_bytes`` is at least *max_upload_bytes*.
139+
140+
"""
141+
return FetchConfig(max_fetch_bytes=max(DEFAULT_MAX_FETCH_BYTES, max_upload_bytes))
142+
143+
124144
def main() -> None:
125145
"""Run the fixture worker as an HTTP server.
126146
@@ -176,7 +196,10 @@ def _run(
176196
max_upload_bytes: int = typer.Option(
177197
4 * 1024 * 1024,
178198
"--max-upload-bytes",
179-
help="Advertise max direct HTTP upload bytes for server-vended upload URLs",
199+
help=(
200+
"Advertise max direct HTTP upload bytes for server-vended upload URLs; with "
201+
"--s3-bucket/--demo-storage the inbound fetch cap is raised to match"
202+
),
180203
),
181204
externalize_compression: str = typer.Option(
182205
"none",
@@ -289,6 +312,7 @@ def _make_compression() -> Compression | None:
289312
storage=storage,
290313
externalize_threshold_bytes=externalize_threshold_bytes,
291314
compression=compression,
315+
fetch_config=_upload_fetch_config(max_upload_bytes),
292316
**_s3_kwargs,
293317
)
294318
upload_url_provider = storage
@@ -307,6 +331,7 @@ def _make_compression() -> Compression | None:
307331
storage=demo_blob_storage,
308332
externalize_threshold_bytes=externalize_threshold_bytes,
309333
compression=compression,
334+
fetch_config=_upload_fetch_config(max_upload_bytes),
310335
url_validator=localhost_only_validator,
311336
)
312337
upload_url_provider = demo_blob_storage

‎vgi/serve.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ class BlobVendorHttpConfig:
212212
upload_url_provider: The vendor, vending pre-signed upload URLs so
213213
clients can send requests over ``max_request_bytes``; ``None``
214214
without the vendor.
215-
max_upload_bytes: ``VGI_RPC_MAX_UPLOAD_BYTES`` (advertised only).
215+
max_upload_bytes: ``VGI_RPC_MAX_UPLOAD_BYTES``, or ``None``.
216+
``make_wsgi_app`` advertises ``None`` as the inbound fetch cap
217+
(``VGI_RPC_MAX_FETCH_BYTES``, default 256 MiB, raised to this
218+
value when it is larger), so the advertised upload size never
219+
exceeds what the worker will fetch back.
216220
max_request_bytes: ``VGI_RPC_MAX_REQUEST_BYTES`` -- advertised and
217221
enforced. Clients (the DuckDB extension) only take the upload-URL
218222
path for a request larger than this, so set it with the vendor.
@@ -232,7 +236,8 @@ def resolve_blob_vendor_http_config(env: Mapping[str, str] | None = None) -> Blo
232236
``VGI_CF_DO_TOKEN``) turns on result externalization
233237
(``VGI_RPC_EXTERNALIZE_THRESHOLD_BYTES``, default 1 MiB;
234238
``VGI_RPC_EXTERNAL_COMPRESSION``) and client upload URLs
235-
(``VGI_RPC_MAX_UPLOAD_BYTES``). ``VGI_RPC_MAX_REQUEST_BYTES`` is read
239+
(``VGI_RPC_MAX_UPLOAD_BYTES``; the inbound fetch cap follows it, or
240+
``VGI_RPC_MAX_FETCH_BYTES`` sets it). ``VGI_RPC_MAX_REQUEST_BYTES`` is read
236241
either way: it is an explicit operator setting. In Orchard hosted mode it
237242
defaults to ``HOSTED_DEFAULT_MAX_REQUEST_BYTES`` (32 MiB), because the
238243
HTTP server buffers that much before authentication runs.
@@ -244,8 +249,9 @@ def resolve_blob_vendor_http_config(env: Mapping[str, str] | None = None) -> Blo
244249
The settings; all ``None`` when nothing is configured.
245250
246251
Raises:
247-
ValueError: A variable is set but malformed, or the vendor URL is set
248-
without a token.
252+
ValueError: A variable is set but malformed, the vendor URL is set
253+
without a token, or ``VGI_RPC_MAX_UPLOAD_BYTES`` exceeds an
254+
explicit ``VGI_RPC_MAX_FETCH_BYTES``.
249255
250256
"""
251257
environ = os.environ if env is None else env

0 commit comments

Comments
 (0)