Skip to content

convex-hosting 0.15.0: serve from the assets in the pushed code, no query per request; routeAll takes one object - #139

Merged
nicu-chiciuc merged 20 commits into
mainfrom
nicu-manifest-serving
Nov 10, 2026
Merged

nicu-chiciuc merged 20 commits into
mainfrom
nicu-manifest-serving

Conversation

@nicu-chiciuc

@nicu-chiciuc nicu-chiciuc commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Every request to a hosted site ran two functions: the app's HTTP action, then the component's route query, 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 for wrangler 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 .wasm as base64), so the manifest is base64, decoded once per request with Convex's native Uint8Array.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.

  • route is 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: routeAll takes one object, every input named.

    import { assets } from "../.convex-hosting/version.js";
    
    routeAll({ http, component: components.hosting, assets, worker: server });

    A files-only site leaves worker out. The names follow Cloudflare: assets is a Worker's static assets (the assets setting, the ASSETS binding); site was the setting of Workers Sites, which Cloudflare deprecated for Static Assets. worker is the Worker script (has_user_worker, run_worker_first). The file stays version.js: it holds one version, Cloudflare's unit of a deploy, and apps already name it in CI scripts and test mocks. It exports only assets: the tab-reload query reads assets.versionId in place of the versionId export. An old call or import fails the push, since Convex's push stops on a type error.

  • The package entry exports only routeAll, RouteAllOptions and Assets.

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.

Case 0.14.0: functions / billed this PR static-hosting 0.2.1
page 2 / 3 1 / 2 2 / 3
asset 2 / 3 1 / 2 2 / 3
rendered 2 / 2 1 / 1 cannot render

Billed adds the download of a stored body. Convex's source records a storage call for both a storage URL fetch and ctx.storage.get in 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.

Files Time per request Module Memory of the action's 64 MB
10,000 4.2 ms 0.9 MB
100,000 7.5 ms 8.9 MB about 7 MB

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

  • Cloudflare's 196 conformance cases and its handler tests run on the in-memory path; its integration fixtures run against a local Convex deployment through the real CLI, with no expected failure.
  • A fast-check property: for any set of paths, Unicode included, with storage keys of any length, every path that the CLI wrote is found by Cloudflare's reader with its own URL, type and ETag, and any other path is not found.
  • Overlapping deploys, on the real component and serving code (src/client/overlap.test.ts): after every event (an upload, a push, a mark request arriving, its markLive running, each collect call), 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 and collect run 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.
  • That test found one losing order: the newer upload's mark request still running while the older upload is pushed and marked. So the mark carries the time its request arrived, and markLive refuses it when another version went live after that.

Before merging

  • Merging publishes @samebase/convex-hosting 0.15.0 to npm (release.yml on push to main).
  • Each app changes its routeAll call and its version.js imports when it upgrades (the tab-reload query too), and a test that mocks the version module mocks assets.
  • Stated, not fixed, both with overlapping deploys only (the precondition is one deploy at a time per deployment): the late-mark rule compares the HTTP action's clock with the mutation's, so it holds as far as the two agree; and an upload pushed just under a day later, after a newer version went live, is deleted as never live by a collect call that runs past the day.
  • Found, not fixed here: an unmounted component (its app.use removed 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.
  • Deploy time grows with file count: 10,000 files took 1,519 s, about 360 npx convex run calls (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.

…, 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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 4, 2026 00:31 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc had a problem deploying to hello-world-assets-only preview November 4, 2026 00:31 — with GitHub Actions Failure
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
convex-hosting-hello-world-assets-only edd691c Nov 10 2026, 09:55 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://nicu-manifest-serving-convex-hosting-tanstack-ssr-workers.pfp.workers.dev (commit edd691c)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://92dc5e9c-convex-hosting-tanstack-ssr-workers.pfp.workers.dev edd691c 2026-11-10T21:55:41.928Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c9f87820-convex-hosting-tanstack-ssr-workers.pfp.workers.dev ef74582 2026-11-10T19:11:09.049Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4dc74f84-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 2619476 2026-11-10T18:20:55.263Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://16d4451c-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 55f41d6 2026-11-10T17:39:35.578Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4ed75a9c-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 6254422 2026-11-10T15:53:16.044Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://2d6c4de8-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 52dc5b7 2026-11-10T14:56:36.011Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ee028e76-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 6ce0df7 2026-11-10T13:31:37.057Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://3b3392bf-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 6c2a31c 2026-11-10T13:07:05.423Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://2cfee26b-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 51d6f50 2026-11-04T01:02:10.077Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://54ea7480-convex-hosting-tanstack-ssr-workers.pfp.workers.dev 787b8b6 2026-11-04T00:32:25.412Z Visit the dashboard ↗

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Preview nicu-manifest-serving of examples/tanstack-ssr: https://quixotic-greyhound-33.convex.site
Deployment: https://quixotic-greyhound-33.convex.cloud
Dashboard: https://dashboard.convex.dev/d/quixotic-greyhound-33
Preview deleted when the pull request closed.

@pkg-pr-new

pkg-pr-new Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/@samebase/convex-auth-tanstack-start@139
pnpm add https://pkg.pr.new/@samebase/convex-hosting@139
pnpm add https://pkg.pr.new/@samebase/convex-hosting-tanstack-start@139

commit: edd691c

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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 4, 2026 01:01 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 4, 2026 01:01 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 4, 2026 01:01 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Preview nicu-manifest-serving of examples/hello-world-assets-only: https://dashing-chinchilla-705.convex.site
Deployment: https://dashing-chinchilla-705.convex.cloud
Dashboard: https://dashboard.convex.dev/d/dashing-chinchilla-705
Preview deleted when the pull request closed.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Preview nicu-manifest-serving of examples/tanstack-spa: https://tidy-bird-916.convex.site
Deployment: https://tidy-bird-916.convex.cloud
Dashboard: https://dashboard.convex.dev/d/tidy-bird-916
Preview deleted when the pull request closed.

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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 10, 2026 13:06 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 10, 2026 13:06 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 10, 2026 13:06 — with GitHub Actions Inactive
@nicu-chiciuc nicu-chiciuc changed the title convex-hosting 0.15.0: serve from the site's files in the pushed code, no query per request convex-hosting 0.15.0: serve from the assets in the pushed code, no query per request; routeAll takes one object Nov 10, 2026
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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 10, 2026 13:30 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 10, 2026 13:30 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 10, 2026 13:30 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc had a problem deploying to hello-world-assets-only preview November 10, 2026 14:55 — with GitHub Actions Failure
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 10, 2026 14:56 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 10, 2026 14:56 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 10, 2026 14:56 — with GitHub Actions Inactive
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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 10, 2026 15:52 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 10, 2026 15:52 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 10, 2026 15:52 — with GitHub Actions Inactive
…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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 10, 2026 17:38 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 10, 2026 17:38 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 10, 2026 17:38 — with GitHub Actions Inactive
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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 10, 2026 18:19 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 10, 2026 18:19 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 10, 2026 18:19 — with GitHub Actions Inactive
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.
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-spa preview November 10, 2026 19:10 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to tanstack-ssr preview November 10, 2026 19:10 — with GitHub Actions Inactive
@nicu-chiciuc
nicu-chiciuc temporarily deployed to hello-world-assets-only preview November 10, 2026 19:10 — with GitHub Actions Inactive

This branch was successfully deployed

3 active deployments
hello-world-assets-only preview — edd691c5 Deployed Nov 10, 2026 by nicu-chiciuc via preview (hello-world-assets-only, HELLO_WORLD_ASSETS_ONLY) #280
tanstack-spa preview — edd691c5 Deployed Nov 10, 2026 by nicu-chiciuc via preview (tanstack-spa, TANSTACK_SPA) #280
tanstack-ssr preview — edd691c5 Deployed Nov 10, 2026 by nicu-chiciuc via preview (tanstack-ssr, TANSTACK_SSR) #280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant