Repository navigation
convex-hosting 0.15.0: serve from the assets in the pushed code, no query per request; routeAll takes one object - #139
Conversation
…, with no query per request The deploy writes each path's content hash, content type, and stored file into .convex-hosting/version.js, in the layout of Cloudflare's asset manifest, and the HTTP action runs Cloudflare's handler against them. The route query is gone, so a page, a miss, a redirect, a 304, and a session refresh cost one function call instead of two, and a file two instead of three. After the push, deploy sends one request with the version's mark token, and the code that answers marks its version live. A first install pushes twice.
…ead over stored files - The mark request follows no redirect, which would carry the token to another origin. - npx convex run output may pass Node's 1 MiB default, so the buffer is 64 MiB; a test reads 2,500 storage URLs in two pages. - The key width of the storage URLs is a loop: a spread passes one argument per stored file. - docs/deploy.md describes the mark and the second push of a first install.
Workers Paid allows 100,000 static asset files per version (20,000 on Free). The CLI already refused a file above Cloudflare's 25 MiB; it now refuses a site above Cloudflare's file count, the most that the site's files were measured with in the pushed code.
A k6 run per case at a fixed arrival rate against each target's own Convex cloud project, with a unique query string per request so no cache answers, every response checked, and the deployment's function logs grouped by request. Results of 2026-11-04 (400 files, two rounds at 25/s, one at 100/s): this branch runs one function per request where 0.14.0 and static-hosting run two; with the billed download of a stored body, a file costs 2 calls in place of 3 and a rendered page 1 in place of 2.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
convex-hosting-hello-world-assets-only | edd691c | Nov 10 2026, 09:55 PM |
|
Preview |
commit: |
Convex's default convex/tsconfig.json sets allowJs, so tsc reads .convex-hosting/version.js itself and inferred html_handling: string, which is not a Site: the second push of a first install failed its typecheck (the preview jobs of hello-world-assets-only and tanstack-spa). The file now carries /** @type {import("@samebase/convex-hosting").Site} */. The fixtures' helper wrote convex/http.ts with routeAll(..., versionId), so every request answered 500 for a site of another format. It passes the site now; all 7 fixtures pass against local deployments.
|
Preview |
|
Preview |
routeAll({ http, component, assets, worker }) names every input. The
generated module exports assets, Cloudflare's name for a Worker's static
assets, in place of site, the setting of the deprecated Workers Sites.
The file stays version.js. answer moves to its own module, so the
package entry exports only routeAll and its types.
Vendor asset-worker/src/assets-manifest.ts and search the manifest with its binarySearch, on the manifest decoded once per request with Convex's native Uint8Array.fromBase64. The CLI encodes the manifest as Miniflare does, in src/cli/manifest.ts. The content hash covers the bytes and the content type, as Cloudflare's covers the bytes and the extension, so it is the ETag. The storage URLs are a plain array. Measured on a cloud deployment against 3.8 ms for an empty action: 4.2 ms per request at 10,000 files, 12.4 ms at 100,000.
The mark request to the served code is the only proof of which code serves, and it keeps overlapping deploys from deleting anything, so the CLI's own markLive call of the last commits is reverted, and routeAll takes the component again. The storage URL keys and the property test stay. versionId is no longer its own export: the tab-reload query reads assets.versionId.
…ing code The version that serves keeps its entries and its files in every order of two deploys' steps, and of three with each mark run as it arrives, but for one order, now stated in the design: the newer upload's mark is still running while the older upload is pushed and marked. The same run with the mark sent from the CLI, the rejected design, deletes the entries of the version that serves with no request still running.
When a file step of the first mark's collect runs after the second mark's collect deleted the entries, it deletes a day-old file that only the serving version had. Run on the real component; the test runs each collect to its end, and says so.
Two deploys overlapped; the newer upload's mark request was still running while the older upload was pushed and marked. The late mark made the newer version live, and collect deleted the entries of the version that served. markLive now takes the time the request reached the serving code and answers superseded when another version went live after it. overlap.test.ts now picks when every collect call runs: every order of two deploys' steps and collect calls, every order of three deploys' steps, and random orders of three with their collect calls. With the rule removed, the first reports 10 losses and the random one fails within 50 runs.
…entence that restates the overlap test
Every request to a hosted site ran two functions: the app's HTTP action, then the component's
routequery, because an HTTP action reads the database only through a query. This PR ships the version's assets with the pushed code, so the action answers without a query.What changes
The deploy writes the version's assets into
.convex-hosting/version.js: Cloudflare's asset manifest (a 40-byte entry per path, sorted by path hash), encoded as Miniflare encodes it forwrangler dev, and searched with Cloudflare's own reader (asset-worker/src/assets-manifest.ts, vendored). The content hash covers the bytes and the content type, as Cloudflare's covers the bytes and the extension, and is the ETag. The tail, which Cloudflare leaves zero, holds the indexes of the storage URL and the content type. Convex modules carry no binary data (its own bundler embeds.wasmas base64), so the manifest is base64, decoded once per request with Convex's nativeUint8Array.fromBase64.The storage URLs are one string. They differ only in a 36-character key, so the start and the end they share are written once and the keys are joined at a fixed width. Convex evaluates the module for every request, and an array of 100,000 strings cost 5 ms and 9 MB more than that one string.
routeis deleted. The action runs Cloudflare's handler in memory, then downloads a file's bytes from its storage URL as before. The storage URLs are read at upload time with an inline query in the component, which also works while the deployed component is still 0.14.Marking a version live. Convex runs the HTTP module fresh for every request (measured: a module-level counter read 1 on every request), so "mark once" cannot live in the action. After the push, the CLI sends one request with the version's mark token, and the code that answers marks its own version, so a mark proves which code serves and overlapping deploys delete nothing. Ordinary requests call no function.
A first install pushes twice: once to install the component, once after the upload.
A version file uploaded to another deployment (production's, pushed to development by a running
npx convex dev) answers 404 naming that deployment.The CLI refuses more than 100,000 files, Cloudflare's limit per Worker version on the Paid plan.
Breaking:
routeAlltakes one object, every input named.A files-only site leaves
workerout. The names follow Cloudflare:assetsis a Worker's static assets (theassetssetting, theASSETSbinding);sitewas the setting of Workers Sites, which Cloudflare deprecated for Static Assets.workeris the Worker script (has_user_worker,run_worker_first). The file staysversion.js: it holds one version, Cloudflare's unit of a deploy, and apps already name it in CI scripts and test mocks. It exports onlyassets: the tab-reload query readsassets.versionIdin place of theversionIdexport. An old call or import fails the push, since Convex's push stops on a type error.The package entry exports only
routeAll,RouteAllOptionsandAssets.Calls per request
Measured with the benchmark on
nicu-hosting-bench, which moved out of this PR: the deployment's own logs, grouped by request, every request logged.Billed adds the download of a stored body. Convex's source records a storage call for both a storage URL fetch and
ctx.storage.getin an action, so the same one is added to every target.Cost of the assets in the module
Measured on a cloud deployment on 2026-11-10, median of 40 requests, from the deployment's logs. An empty action takes 3.8 ms.
Shapes measured and not used, at 100,000 files: an array of full storage URLs, 12.4 ms and about 16 MB; four sorted plain arrays with no binary manifest, 19.3 ms and about 21 MB; a plain object keyed by path, 184.7 ms and about 31 MB.
Tests
src/client/overlap.test.ts): after every event (an upload, a push, a mark request arriving, itsmarkLiverunning, eachcollectcall), the version that serves must still have its entries and its stored files. It runs every order of two deploys (221 runs), every order of three deploys' steps with each mark andcollectrun at once (280), and 300 random orders of three. None loses anything. The same run with the mark sent from the CLI, the design this PR rejects, does.markLiverefuses it when another version went live after that.Before merging
@samebase/convex-hosting0.15.0 to npm (release.ymlon push tomain).routeAllcall and itsversion.jsimports when it upgrades (the tab-reload query too), and a test that mocks the version module mocksassets.collectcall that runs past the day.app.useremoved and pushed) still passes the CLI's install probe but has no functions, so the deploy fails with "Could not find function". 0.14.0 does the same.npx convex runcalls (each its own process) plus the uploads, four at a time. Serving does not grow. That is the upload path; a follow-up, needed before 100,000 files deploy in Wrangler's minutes.