From 86fc20c66592659fad1b97ab36e17cb560880c64 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 01:42:20 +0200 Subject: [PATCH 01/20] convex-hosting 0.15.0: serve from the site's files in the pushed code, 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. --- README.md | 30 +- docs/design.md | 307 ++++++++++-------- docs/development.md | 5 +- docs/from-static-hosting.md | 22 +- docs/serving.md | 16 +- .../hello-world-assets-only/convex/http.ts | 4 +- examples/tanstack-spa/convex/http.ts | 4 +- examples/tanstack-ssr/convex/http.ts | 4 +- .../convex-hosting-tanstack-start/README.md | 2 +- packages/convex-hosting/CHANGELOG.md | 19 ++ packages/convex-hosting/package.json | 2 +- .../scripts/sync-workers-sdk.ts | 2 +- packages/convex-hosting/src/cli/convex.ts | 27 ++ packages/convex-hosting/src/cli/main.test.ts | 204 ++++++++++-- packages/convex-hosting/src/cli/main.ts | 188 ++++++++++- .../convex-hosting/src/cli/site-config.ts | 17 + .../convex-hosting/src/client/answer.test.ts | 234 +++++++++++++ .../convex-hosting/src/client/index.test.ts | 202 +++++++----- packages/convex-hosting/src/client/index.ts | 211 +++++++----- .../src/client/manifest.test.ts | 137 ++++++++ .../convex-hosting/src/client/manifest.ts | 267 +++++++++++++++ .../src/client/version-module.d.ts | 1 + .../src/component/_generated/component.ts | 22 +- .../src/component/conformance.test.ts | 84 ----- .../convex-hosting/src/component/lib.test.ts | 214 +----------- packages/convex-hosting/src/component/lib.ts | 180 ++-------- .../convex-hosting/src/component/schema.ts | 4 +- 27 files changed, 1574 insertions(+), 835 deletions(-) create mode 100644 packages/convex-hosting/src/cli/site-config.ts create mode 100644 packages/convex-hosting/src/client/answer.test.ts create mode 100644 packages/convex-hosting/src/client/manifest.test.ts create mode 100644 packages/convex-hosting/src/client/manifest.ts delete mode 100644 packages/convex-hosting/src/component/conformance.test.ts diff --git a/README.md b/README.md index 5dc65b1a..b1dafaa8 100644 --- a/README.md +++ b/README.md @@ -56,14 +56,14 @@ server build for every other request, as a Cloudflare Worker with static assets import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { versionId } from "../.convex-hosting/version.js"; +import { site } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; const http = httpRouter(); -routeAll(http, components.hosting, versionId, server); +routeAll(http, components.hosting, site, server); export default http; ``` @@ -106,10 +106,10 @@ wires both. ## Files only -A site without a server leaves the fourth argument out, -`routeAll(http, components.hosting, versionId)`, needs no adapter package, and deploys its build -directory: `--dist dist` after a `vite build`, or `--dist public` with no `--build` at all. A -single-page app adds `--not-found-handling single-page-application`. The +A site without a server leaves the fourth argument out, `routeAll(http, components.hosting, site)`, +needs no adapter package, and deploys its build directory: `--dist dist` after a `vite build`, or +`--dist public` with no `--build` at all. A single-page app adds +`--not-found-handling single-page-application`. The [tanstack-spa](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-spa) and [hello-world-assets-only](https://github.com/samebase/convex-hosting/tree/main/examples/hello-world-assets-only) examples are such sites. @@ -161,7 +161,7 @@ inside a Convex HTTP action, so `_headers`, `_redirects`, `.assetsignore`, `html `not_found_handling` mean what they mean on Cloudflare. This repository's CI runs Cloudflare's own tests against it: its -[196 cases](https://github.com/samebase/convex-hosting/blob/main/packages/convex-hosting/src/component/conformance.test.ts) +[196 cases](https://github.com/samebase/convex-hosting/blob/main/packages/convex-hosting/src/client/answer.test.ts) for `html_handling` and path encoding, and its [integration test](https://github.com/samebase/convex-hosting/tree/main/packages/convex-hosting/src/workers-sdk/fixtures/workers-with-assets-only) for a files-only site, with its imports pointed at this package, on a local Convex deployment. @@ -185,13 +185,15 @@ lists what differs and how to move an app. On Cloudflare, `wrangler deploy` uploads the files and the Worker code as one version, so the switch is atomic. Here two systems hold the two halves: the component's storage holds the files, and `npx convex deploy` pushes the code. `deploy` binds them the same way. It uploads the files as a new -version, writes that version's id to `.convex-hosting/version.js`, and then pushes the code, which -imports the file and asks the component for exactly that version. The push is the switch: no pointer -moves in a second step, so there is no moment when new code serves old files, and no page refers to -a file that is not uploaded yet. The first request the new code serves marks its version live and -deletes the versions that were live before it. A version whose push never came is deleted at a later -switch, once it is a day old; nothing is deleted by the clock alone. The one rule: run one deploy at -a time per deployment. The +version, writes that version's id and its files (each path's stored file, in the layout of +Cloudflare's asset manifest) to `.convex-hosting/version.js`, and then pushes the code, which +imports the file. The push is the switch: no pointer moves in a second step, so there is no moment +when new code serves old files, and no page refers to a file that is not uploaded yet. A request +reads no database: it costs one function call, the HTTP action, and a file adds the download of its +bytes, which Convex counts as a call too. After the push, `deploy` asks the served code to mark its +version live, which deletes the versions that were live before it. A version whose push never came +is deleted at a later switch, once it is a day old; nothing is deleted by the clock alone. The one +rule: run one deploy at a time per deployment. The [design](https://github.com/samebase/convex-hosting/blob/main/docs/design.md#orderings-and-timing) works through every interleaving. diff --git a/docs/design.md b/docs/design.md index 8b4d0dd8..61e420c5 100644 --- a/docs/design.md +++ b/docs/design.md @@ -23,27 +23,28 @@ gone from the production hostname. On Convex, two systems hold the two halves: `npx convex deploy` pushes the app code, and the site files live in a component's storage. The design binds them the way Cloudflare does: the pushed code -carries the id of the asset version it was built with, and asks the component for exactly that -version. The push is the switch. There is no pointer that a second step must move, so there is no -moment when new code serves old files. - -Only the pushed code knows which version a deployment runs, so the serving code reports it: the -first request that new code serves finds its version in state `ready` and marks it `live`. An older -upload never goes live over a newer one: a version is marked only when no live version was created -after it, so a request still running on replaced code cannot take the site back. Marking a version -live deletes the versions that were live before it, because their code is gone by definition. -Nothing is deleted by the clock alone: deletion runs only at a switch, when a new version becomes -live, so a deployment that gets no request deletes nothing and keeps its version intact for its -first request, whenever it comes. At a switch, a version that never became live is dead too, from a -push that failed, with one exception: a slower deploy whose push has not landed yet. So a never-live +carries the asset version it was built with, its id and its files, as a Worker carries its asset +manifest: each path's content hash, content type, and stored file. The push is the switch. There is +no pointer that a second step must move, so there is no moment when new code serves old files. A +request reads no database: the HTTP action answers from the files in its own code, and downloads the +bytes of a file from storage. + +Only the pushed code knows which version a deployment runs, so the serving code reports it: after +the push, the CLI sends one request with the version's mark token, which only that version's code +holds, and the code that answers marks its version `live`. An older upload never goes live over a +newer one: a version is marked only when no live version was created after it, so a request still +running on replaced code cannot take the site back. Marking a version live deletes the versions that +were live before it, because their code is gone by definition. Nothing is deleted by the clock +alone: deletion runs only at a switch, when a new version becomes live, so a version stays intact +until a newer one has served. At a switch, a version that never became live is dead too, from a push +that failed, with one exception: a slower deploy whose push has not landed yet. So a never-live version is deleted at a switch only when it is more than a day old; the day bounds how late a push may follow its upload, and it is the only time constant in the design. The precondition: deploys to one deployment do not overlap. When two overlap and the older upload is -pushed last, the component cannot tell its requests from requests still running on replaced code: -its version serves, but it never becomes live, and nothing is deleted until the next deploy. So run -one deploy at a time per deployment; the example workflows queue them, with one `concurrency` group -per deployment. +pushed last, its mark is refused like a mark of replaced code: its version serves, but it never +becomes live, and nothing is deleted until the next deploy. So run one deploy at a time per +deployment; the example workflows queue them, with one `concurrency` group per deployment. ## Deploy @@ -90,26 +91,38 @@ Bristol's production used it while hosting 0.3 and 0.4 ran side by side under tw 5. calls `finishVersion`, which puts the version in state `ready`. The CLI calls it only after every batch succeeded; a crashed upload leaves an `uploading` version, and a retry reuses every file the crashed run recorded, through step 3; - 6. writes `.convex-hosting/version.js` with the id, in the CLI's state folder at the project - root, like Wrangler's `.wrangler/`; the folder carries its own `.gitignore`, so nothing of it - reaches git and no tool writes into `convex/`. The file is a build artifact that `http.ts` - imports, as a server-rendered app's `http.ts` already imports its server build; the package - ships the declaration of that module (an ambient wildcard module in a script `.d.ts` that the - package's types entry references), so a fresh clone typechecks with nothing added. Then, still - inside `npx convex deploy`, Convex bundles `convex/` with the new id and pushes. The push is - the switch, and the command ends. + 6. reads the storage URL of every entry, with the deployment's `CONVEX_CLOUD_URL`, through inline + queries in the component (`npx convex run --component --inline-query`), which run + whatever release of this package the component is, so an upgrade's upload works before its + push installs the new functions; then writes `.convex-hosting/version.js` with the site: the + id, a random mark token, and the files (see Serve), in the CLI's state folder at the project + root, like Wrangler's `.wrangler/`. It writes a temporary file and renames it, so a running + `npx convex dev` never reads half of it; the folder carries its own `.gitignore`, so nothing + of it reaches git and no tool writes into `convex/`. The file is a build artifact that + `http.ts` imports, as a server-rendered app's `http.ts` already imports its server build; the + package ships the declaration of that module (an ambient wildcard module in a script `.d.ts` + that the package's types entry references), so a fresh clone typechecks with nothing added. + Then, still inside `npx convex deploy`, Convex bundles `convex/` with the new id and pushes. + The push is the switch, and the command ends. 3. `--dev`: the same steps, in one process: the CLI runs the build itself (Vite reads the deployment's URL from `.env.local`, so no nesting is needed), uploads, writes the version file, and pushes with `npx convex run --push`. -**The site URL.** When the push, and on a first install the upload after it, have ended, the CLI -asks the deployment for its site URL: `npx convex run --inline-query process.env.CONVEX_SITE_URL`, -with the selector of its other calls, which needs only the permission of the first-install probe. It -prints the URL and, when `GITHUB_OUTPUT` is set, appends `url=` to that file, so a -workflow step reads it as a step output. The value is the one the deployment gives its own -functions, so it is right for every kind of deployment (production, a preview, development, local, -self-hosted) and is the custom domain when the dashboard's "Override Environment Variables" sets -one; the CLI never builds it from a deployment name. +**The mark.** When the last push has ended, the CLI reads the site URL (below) and sends +`POST /.convex-hosting/mark` with the header `Convex-Hosting-Mark: `. The code +that answers calls `markLive` for its own version and answers the result. A failure, or an answer +from other code, is reported, and the deploy succeeds: nothing is deleted until a later version is +marked, so the cost is old files kept until the next deploy. + +**The site URL.** When the push, and on a first install the upload and the push after it, have +ended, the CLI asks the deployment for its site URL: +`npx convex run --inline-query process.env.CONVEX_SITE_URL`, with the selector of its other calls, +which needs only the permission of the first-install probe. It prints the URL and, when +`GITHUB_OUTPUT` is set, appends `url=` to that file, so a workflow step reads it as a step +output. The value is the one the deployment gives its own functions, so it is right for every kind +of deployment (production, a preview, development, local, self-hosted) and is the custom domain when +the dashboard's "Override Environment Variables" sets one; the CLI never builds it from a deployment +name. **First install.** The component's functions exist only after a push, and a new preview deployment exists only once `npx convex deploy` has created it, which happens before it runs the command. So @@ -117,11 +130,12 @@ the upload decides. Its first call is a probe, `npx convex run --component " was not found.` when the deployment does not have it (a function run against a missing component answers only a generic server error, which must not count). -On that exact message, the production and preview upload writes the version file and a marker file -in `.convex-hosting/` and exits without uploading, so the push that follows installs the component; -`deploy` sees the marker after `npx convex deploy` returns and runs the upload then. For `--dev`, in -one process, it writes the version file, pushes, and uploads. Until that upload ends, the site -answers 404 (see Serve). Once per deployment. +On that exact message, the production and preview upload writes a version file without files and a +marker file in `.convex-hosting/` and exits without uploading, so the push that follows installs the +component; `deploy` sees the marker after `npx convex deploy` returns, runs the upload then, and +pushes again with `npx convex deploy`. For `--dev`, in one process, it writes the version file, +pushes, uploads, and pushes again. Until the second push, the site answers 404 naming the version +(see Serve). Once per deployment. **The development loop.** Local work uses Vite's dev server, with hot reload, against the development deployment's URL, while `npx convex dev` pushes function changes, as in any Convex app. @@ -168,10 +182,10 @@ chain started, because the sweep runs before the version deletion in each chain. deleted version's unshared files, a file stored but never recorded, and the config files. An upload in progress that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it then fails with a message that says so, and a retry works. A push that the -command reports as failed may still have landed; the site then serves the new version, which marks -itself live at its first request, and the next deploy is a normal one. No resume logic. Two first -deploys at once are an overlap, which the precondition rules out: both push and upload, and the last -push serves. +command reports as failed may still have landed; the site then serves the new version, which stays +`ready` because the CLI sent no mark, and the next deploy is a normal one: its mark deletes the +versions before it. No resume logic. Two first deploys at once are an overlap, which the +precondition rules out: both push and upload, and the last push serves. **Browsers.** A page opened before a deploy keeps asking for its hashed files, which the new version does not have, exactly as on Cloudflare: they answer 404, or the shell on a files-only single-page @@ -191,9 +205,9 @@ picks the longest matching prefix, so only an exact route reaches the app there. ```ts import { routeAll } from "@samebase/convex-hosting"; -import { versionId } from "../.convex-hosting/version.js"; +import { site } from "../.convex-hosting/version.js"; -routeAll(http, components.hosting, versionId, server); +routeAll(http, components.hosting, site, server); ``` `serveSite` answers with the file when one matches. Otherwise it answers with the page that the @@ -207,68 +221,87 @@ upload ends. `worker` is the Worker script, the object with `fetch(request)` tha exports: the code that runs on a miss. Its absence is the files-only Worker, so `serveSite` is the one entry. -`serveSite` calls the component query `route` with the method, the URL, the four request headers -that Cloudflare's handler reads (`If-None-Match`, `Sec-Fetch-Mode`, and the presence of -`Authorization` and `Range`), and `hasUserWorker`. As on Cloudflare, the presence of code decides, -and `hasUserWorker` is Cloudflare's `has_user_worker`: `serveSite` passes `true` with `worker` and -`false` without it; the app sets no option. With code, the app is the Worker, and Cloudflare's -routing with a Worker applies: inside the query, Cloudflare's `canFetch` decides whether an asset +`serveSite` runs Cloudflare's handler in the action, on the request as it came, against the site's +files, so a request calls no function of the component. As on Cloudflare, the presence of code +decides, and `hasUserWorker` is Cloudflare's `has_user_worker`: `serveSite` passes `true` with +`worker` and `false` without it; the app sets no option. With code, the app is the Worker, and +Cloudflare's routing with a Worker applies: Cloudflare's `canFetch` decides whether an asset answers, a request that does not resolve to a file goes to the app, and `not_found_handling` (the 404 page, the single-page fallback) applies to navigation requests only. Without code, the site is a -Worker without a script, whose router sends every request to the asset handler: the query skips +Worker without a script, whose router sends every request to the asset handler: `serveSite` skips `canFetch` and runs `handleRequest`, so `not_found_handling` applies to every request, and a missing hashed file on a single-page app gets the shell with 200. One difference from Cloudflare follows from Convex's router and is stated, not fixed: an exact app route wins over an asset at the same path. -The component runs the handler with a fixed compatibility date at or after 2025-04-01, the date from -which Cloudflare treats `Sec-Fetch-Mode: navigate` requests this way; the date is package code, not -configuration. When an asset answers, Cloudflare's `handleRequest` computes the status and headers: -`Cache-Control: public, max-age=0, must-revalidate` (Cloudflare omits it when the request carries -`Authorization` or `Range`, and so do we), `ETag`, 304 for `If-None-Match`, `_headers` rules, -`_redirects`, `html_handling`, and the custom 404 page with its body. Cloudflare's own cases for -`html_handling` and path encoding (the test-cases files of `fixtures/workers-shared-asset-config` in -workers-sdk, copied by the same sync script as the handler) run through `route` in -`src/component/conformance.test.ts`, with each case's files as a version's entries. Cloudflare's -integration fixtures for static assets (`fixtures/workers-with-assets-only` in workers-sdk, copied -at the same pinned commit with their `public/` folders, their imports pointed at this package) run -against the whole path an app takes: our implementation of the helper they import to start -`wrangler dev` starts an anonymous local Convex deployment, deploys the fixture's assets with -`convex-hosting deploy --dev`, and returns the site's address. -`scripts/fixtures-expected-failures.json` lists each test that fails by a stated difference from -Cloudflare, and the run fails when the list and the outcome disagree. The query drops -`CF-Cache-Status`, which describes a cache we do not run, sets `Cache-Control: no-store` on every -404, because the deployment's Cloudflare front caches 404 answers on static paths, and returns the -status, the headers, and the storage URL of the body when the response has one, whatever the status. -`serveSite` fetches that body and returns the response. When the query finds no storage URL for the -entry, or storage answers 404, because a deletion pass removed the file, the answer is 404 with -`Cache-Control: no-store`; any other fetch failure answers 502 with no caching. An app cannot read a -component's storage, so each asset hit costs that one fetch. - -When the version does not exist, is still `uploading`, or is `deleting`, `serveSite` answers a 404 -response that names the version, with `Cache-Control: no-store`, so a half-installed site answers -404 rather than rendering pages without their files. The deployment's Cloudflare front keeps -`no-store` for a path without an extension and gives a path with one a four-hour browser `max-age` -anyway; the deploy order keeps that moot, because no page refers to a file that is not uploaded yet. -A `null` asset means one thing: no asset matched, and `worker` answers. - -When `route` reports the version in state `ready`, `serveSite` calls `markLive` once, before it -answers. `markLive` marks the version only when no live version was created after it, inside its own -transaction, so a request whose code was replaced, whenever it reaches its lookup or its mark, -cannot make its version newest, and concurrent first requests mark once. That is the only write the -serving path ever makes, once per deploy. - -`route` and `markLive` are the component's only public functions, because `serveSite` runs in the -app and an app can call only a component's public functions; clients cannot call them at all. The -CLI calls the other functions, which are internal, with `npx convex run --component`. - -The two callbacks that Cloudflare's code takes map to the version's entries: `exists(path)` reads -one index entry and returns its ETag, the sha256 followed by a short hash of the content type, so +The handler runs with a fixed compatibility date at or after 2025-04-01, the date from which +Cloudflare treats `Sec-Fetch-Mode: navigate` requests this way; the date is package code, which the +CLI writes into each site's config, not configuration. When an asset answers, Cloudflare's +`handleRequest` computes the status and headers: `Cache-Control: public, max-age=0, must-revalidate` +(Cloudflare omits it when the request carries `Authorization` or `Range`, and so do we), `ETag`, 304 +for `If-None-Match`, `_headers` rules, `_redirects`, `html_handling`, and the custom 404 page with +its body. Cloudflare's own cases for `html_handling` and path encoding (the test-cases files of +`fixtures/workers-shared-asset-config` in workers-sdk, copied by the same sync script as the +handler) run through the action's handler in `src/client/answer.test.ts`, with each case's files as +a site's manifest. Cloudflare's integration fixtures for static assets +(`fixtures/workers-with-assets-only` in workers-sdk, copied at the same pinned commit with their +`public/` folders, their imports pointed at this package) run against the whole path an app takes: +our implementation of the helper they import to start `wrangler dev` starts an anonymous local +Convex deployment, deploys the fixture's assets with `convex-hosting deploy --dev`, and returns the +site's address. `scripts/fixtures-expected-failures.json` lists each test that fails by a stated +difference from Cloudflare, and the run fails when the list and the outcome disagree. `serveSite` +drops `CF-Cache-Status`, which describes a cache we do not run, sets `Cache-Control: no-store` on +every 404, because the deployment's Cloudflare front caches 404 answers on static paths, and, when +the response has a body, downloads the file from its storage URL. When storage answers 404, because +a deletion pass removed the file, the answer is 404 with `Cache-Control: no-store`; any other fetch +failure answers 502 with no caching. An app cannot read a component's storage, so each answer with a +body costs that one download, which Convex counts as a function call; a redirect, a 304, a 405, and +a 404 without a page download nothing. + +The site's `files` are `null` in the code that a first install pushes before its upload: `serveSite` +then answers 404 naming the version, with `Cache-Control: no-store`, without calling `worker`, so a +half-installed site answers 404 rather than rendering pages without their files. The storage URLs +name the deployment they came from, so when the site's `cloudUrl` is not the deployment's +`CONVEX_CLOUD_URL` (a version file that a deploy elsewhere wrote, pushed by a running +`npx convex dev`), it answers 404 naming both, without rendering. A site of another format, which +only another release writes, answers 500 and asks for a deploy. The deployment's Cloudflare front +keeps `no-store` for a path without an extension and gives a path with one a four-hour browser +`max-age` anyway; the deploy order keeps that moot, because no page refers to a file that is not +uploaded yet. A `null` asset means one thing: no asset matched, and `worker` answers. + +A request with the header `Convex-Hosting-Mark` set to the site's mark token is the CLI's mark: +before anything else, `serveSite` calls `markLive` for its version and answers the result as JSON, +with `Cache-Control: no-store`. `markLive` marks the version only when no live version was created +after it, inside its own transaction, so code that was replaced cannot make its version newest, and +a repeated mark changes nothing. It never throws: it answers `marked`, `live`, `superseded`, +`uploading`, `deleting`, or `missing`, and the CLI reports the last four. That is the only write the +serving path ever makes, once per deploy. Any other request, with another token or none, calls no +function. + +`markLive` is the component's only public function, because `serveSite` runs in the app and an app +can call only a component's public functions; clients cannot call it at all. The CLI calls the other +functions, which are internal, with `npx convex run --component`. + +The two callbacks that Cloudflare's code takes map to the site's manifest: `exists(path)` finds the +path's entry and returns its ETag, the content hash followed by a short hash of the content type, so that identical bytes stored under two content types stay distinct; `getByETag` returns the content type of the entry that `exists` found and a placeholder stream, which `serveSite` replaces with the body. Nothing is added to Cloudflare's headers besides `no-store` on a 404. Long caching of hashed files is a `_headers` rule, as on Cloudflare. +**The site's files** (`src/client/manifest.ts`). The manifest is Cloudflare's: a 20-byte header, +zero and unused as in Cloudflare's, then one 40-byte entry per path, sorted by the path hash, the +first 16 bytes of the SHA-256 of the path, so a lookup is a binary search. An entry is the path +hash, the content hash (the first 16 bytes of the SHA-256 of the bytes), and a tail that holds the +index of the stored file (a big-endian u32) and of the content type (a big-endian u16, `0xffff` for +none). The manifest is one base64 string, and a lookup decodes only the bytes it compares, so its +cost does not grow with the site. The storage URLs are one prefix and one suffix around one key per +stored file, each padded to one width; the CLI rebuilds every URL from them before it writes the +file. Convex evaluates the HTTP module for every request, so the site is a few string literals and +nothing is parsed or decoded when the module loads. Measured on a cloud deployment on 2026-11-04: a +site of 100,000 files is a module of 8.9 MB, which adds about 2 ms to each request; a site of 400 +files is about 35 KB. + Other HTTP routes of the app (auth, APIs) win over the site route when they are exact paths or longer prefixes, by Convex's router rules for the same method. @@ -286,8 +319,9 @@ entries go, so a version half deleted cannot become live. Creation times come fr field per rule and Convex limits an object to 1,024 fields. A document is limited to 1 MiB, so the CLI refuses a config above 900 KiB, leaving room for the other fields and the encoding, and names the file that causes it. An entry keeps its own content type because the type belongs to the path, -not to the bytes: paths with identical bytes share one stored file but keep their own types, and -`route` serves without reading `_storage`. +not to the bytes: paths with identical bytes share one stored file but keep their own types, and the +site's manifest carries each type, so serving reads no `_storage` metadata. Serving does not read +`config` either; it makes a retried upload of the same id refuse another config. The package sets one limit of its own, 25 MiB per file, for the reason above. Convex's limits apply: 1 MiB per document, and the transaction limits (16,000 writes, 32,000 documents scanned, 16 MiB read @@ -298,29 +332,30 @@ and written, 8,192 array elements, 4,096 index ranges, argument and result sizes Every interleaving worked through for 0.4, what happens, and what checks it. "Component test" is a convex-test run of the exact order of transactions; "runtime" is a run against a local backend. -| What happens | Outcome | Checked by | -| ------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | -| A deploy pushes; the first request arrives | The version is marked live; the versions live before it are deleted | Component test, runtime | -| Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live at its first request; the other was never live and goes at a later switch when a day old | Component test (age rule) | -| Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy | Component test (stale request) | -| A request on old code is in flight when a push lands, and reaches `markLive` after the new code's first mark | Its version is older than the live one, so the mark is refused; the new version stays live and keeps its files | Component test (stale request) | -| Two first requests of one version | One mark; the second is a no-op | Component test | -| Two marks in one millisecond | The second is strictly later | Component test | -| A deploy dies before its push | A never-live version; deleted at a later switch when a day old | Component test (age rule) | -| An upload dies midway | An `uploading` version; same fate; a retry reuses its recorded files | Component test, runtime (reuse) | -| The push is reported as failed but landed | The version is `ready` and is marked live at its first request | Inherent; stated | -| No request for days, weeks | Nothing is deleted; the first request marks the version live | Inherent: deletion runs only at a switch | -| Many deploys, no requests in between | The first request marks the newest; older never-live versions go when a day old, younger ones at the next switch | Component test (age rule) | -| A push lands more than a day after its upload, after another switch | Its version is gone; the site answers 404 naming it; redeploy | Stated | -| An upload borrows a stored file; a switch deletes the lending version | The file survives: files go only when unreferenced, a day old, and already unreferenced when the chain started | Component test (sweep order) | -| Two switches during one upload | The borrowed file can go; `recordFiles` says so; a retry works | Stated | -| A first request reaches a version while its entries are being deleted in pages | The version is `deleting`: 404, no mark | Component test | -| Documents share a creation time at a page boundary | The cursor carries the ids seen at that time; none is skipped | Component test (crafted cursor) | -| First install: the component does not exist yet | Push first, then upload; 404 until the upload ends | Runtime (both flows) | -| Two first installs at once | Outside the precondition. Both push and upload; the last push serves | Stated | -| Two commands from one checkout at once | They overwrite each other's build output and version file | Stated, unsupported | -| A production deploy from a checkout where `npx convex dev` runs | Production's id is pushed to development until the next `deploy --dev` | Stated | -| `deploy --dev` against an anonymous local deployment without `npx convex dev` | Each Convex CLI call starts and stops its own backend; the upload fails with `fetch failed` | Runtime; stated in the README | +| What happens | Outcome | Checked by | +| --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | +| A deploy pushes; the CLI's mark reaches the new code | The version is marked live; the versions live before it are deleted | Component test, runtime | +| Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | +| Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy | Component test (stale request) | +| A mark for an older version reaches its code after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | +| Two marks of one version | One mark; the second answers `live` | Component test | +| Two marks in one millisecond | The second is strictly later | Component test | +| A deploy dies before its push | A never-live version; deleted at a later switch when a day old | Component test (age rule) | +| An upload dies midway | An `uploading` version; same fate; a retry reuses its recorded files | Component test, runtime (reuse) | +| The push is reported as failed but landed | The version serves, `ready`, since the CLI sent no mark; the next deploy's mark deletes the versions before it | Inherent; stated | +| No request for days, weeks | Nothing changes: the deploy marked its version, and deletion waits for the next mark | Inherent: deletion runs only at a switch | +| Many deploys in a row | Each deploy marks its version; the one before goes at that mark, never-live versions when a day old | Component test (age rule) | +| A push lands more than a day after its upload, after another switch | Its files are gone: pages render, and its files answer 404 from storage; redeploy | Stated | +| An upload borrows a stored file; a switch deletes the lending version | The file survives: files go only when unreferenced, a day old, and already unreferenced when the chain started | Component test (sweep order) | +| Two switches during one upload | The borrowed file can go; `recordFiles` says so; a retry works | Stated | +| A request on replaced code reaches a version while it is being deleted | Its files answer 404 from storage; a mark answers `deleting` | Component test, client test | +| Documents share a creation time at a page boundary | The cursor carries the ids seen at that time; none is skipped | Component test (crafted cursor) | +| The CLI's mark fails, or other code answers it | Reported; the deploy succeeds; nothing is deleted until the next deploy's mark | CLI test | +| First install: the component does not exist yet | Push a site without files, upload, push the site; 404 naming the version until the second push | CLI test, runtime (both flows) | +| Two first installs at once | Outside the precondition. Both push and upload; the last push serves | Stated | +| Two commands from one checkout at once | They overwrite each other's build output and version file | Stated, unsupported | +| A production deploy from a checkout where `npx convex dev` runs | Production's site is pushed to development, which answers 404 naming production's deployment until the next `deploy --dev` | Client test; stated | +| `deploy --dev` against an anonymous local deployment without `npx convex dev` | Each Convex CLI call starts and stops its own backend; the upload fails with `fetch failed` | Runtime; stated in the README | Not reproducible in the test runtime and not yet run against a cloud deployment: two real pushes in a chosen order, a preview deployment, an old HTTP action kept running across a push. A smoke script @@ -330,9 +365,8 @@ place for those. ## Stated, not solved - Deploys to one deployment do not overlap. When two overlap and the older upload is pushed last, - the component cannot tell its requests from requests still running on replaced code, so its - version serves but is never marked live, each of its requests calls `markLive` for nothing, and - nothing is deleted until the next deploy. + its mark is refused like a mark of replaced code, so its version serves but is never marked live, + and nothing is deleted until the next deploy. - An upload that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it fails with a message that says so, and a retry works. - No `run_worker_first`, no `base_path`, no selectable compatibility date: an app that needs its @@ -342,11 +376,11 @@ place for those. ## Not here, and why -- No live pointer that a command moves, no `activate`, no `getLiveVersion`: the pushed code names - its version, and the serving code reports it. -- No lock, no heartbeat, no cron, no call after the push besides the read of the site URL: a version - is deleted only after another version has served in its place. A one-day age bounds garbage from - failed deploys; it decides nothing about what is served. +- No live pointer that a command moves, no `activate`, no `getLiveVersion`: the pushed code carries + its version, and the served code marks it when the CLI asks. +- No lock, no heartbeat, no cron, no call after the push besides the read of the site URL and the + mark: a version is deleted only after another version has served in its place. A one-day age + bounds garbage from failed deploys; it decides nothing about what is served. - No marking of hashed files, no one-year `Cache-Control`: Cloudflare has neither. A site that wants them writes one `_headers` rule. - No component HTTP route, no `httpPrefix` mount, no second serving helper: one way for static and @@ -363,6 +397,22 @@ place for those. Approaches that were built or proposed during the 0.4 design and dropped, with the reason, so they are not proposed again. +- **A component query per request (`route`, 0.4 to 0.14).** An HTTP action reads the database only + through a query, so every request cost two function calls, and an answer with a body a third, its + download. On samebase.com in one billing period, `route` ran 109,000 times for 72,000 site + requests and 35,000 session refreshes, which the `/auth` exact routes sent through the site's + action and which never match a file. The pushed code now carries the site's files. +- **Marking live once per isolate, from the serving code.** Convex evaluates the HTTP module for + every request: on a cloud deployment on 2026-11-04, a module-level counter read 1 on every one of + 52 requests, 40 of them concurrent, while the module's own random id stayed the same. A + module-level flag would have called `markLive` on every request. +- **Marking live from the CLI with `npx convex run lib:markLive`.** When deploys overlap, the CLI + can mark a version whose code does not serve, and the mark deletes the files of the code that + does. The mark request reaches the code that serves, and its token makes only that deploy's code + mark. +- **Marking live on a random share of requests.** It kept the mark in the serving code for about one + call per hundred requests, but a site with little traffic would keep its old versions for days, + and every request would pay the draw. - **Deletion driven by the CLI after the push.** The order in which overlapping deploys report back is not the order in which their pushes landed, so a CLI could delete the version that is live. - **A deploy lock in the component, with a heartbeat and a two-minute expiry, and a kill of the push @@ -495,7 +545,8 @@ or ChessMerge goes; the list is checked at every release. At 0.8.0 and 0.5.0 tha - `packages/convex-hosting` - `src/component`: `schema.ts`, `lib.ts`, `convex.config.ts`, and its generated files. - - `src/client`: `routeAll` and the shipped declaration of the version module. + - `src/client`: `routeAll`, the site's files (`manifest.ts`: the builder that the CLI runs and the + lookup that the action runs), and the shipped declaration of the version module. - `src/cli`: the `convex-hosting` command: `deploy`, and `upload`, the inner step that `npx convex deploy --cmd` has to call as a program. - `src/workers-sdk`: Cloudflare's asset worker, its tests, and its html_handling and encoding diff --git a/docs/development.md b/docs/development.md index c8effe32..a6211aaa 100644 --- a/docs/development.md +++ b/docs/development.md @@ -44,7 +44,10 @@ Two cases are transient: ```ts vi.mock("../dist/server/server.js", () => ({ default: { fetch: async () => new Response() } })); - vi.mock("../.convex-hosting/version.js", () => ({ versionId: "test" })); + vi.mock("../.convex-hosting/version.js", () => ({ + versionId: "test", + site: { format: 1, versionId: "test", markToken: "test", files: null }, + })); ``` - `npx convex codegen` bundles `convex/http.ts`, so before the first `deploy --dev` it fails with diff --git a/docs/from-static-hosting.md b/docs/from-static-hosting.md index 839a6c7e..cc189b7a 100644 --- a/docs/from-static-hosting.md +++ b/docs/from-static-hosting.md @@ -10,14 +10,14 @@ and source on 2026-10-18, version 0.2.1. ## What differs -| | static-hosting | convex-hosting | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Pages | Files only | What no file answers goes to the app's server entry, an object with `fetch(request)`; TanStack Start has an [adapter](../packages/convex-hosting-tanstack-start) | -| File rules | Its own: a miss without an extension gets `index.html` unless deployed with `--no-spa`, and a miss with one is 404. Hashed file names get a one-year cache | Cloudflare's asset Worker: `_headers`, `_redirects`, `.assetsignore`, `html_handling`, and `not_found_handling` (see [Serving](./serving.md)). Every file revalidates unless `_headers` says otherwise | -| Routes | The component owns `/`, with the app's routes under `/api`, or a sub-path; or `registerStaticRoutes` adds a GET catch-all to `convex/http.ts` | `routeAll` adds a catch-all for every method to `convex/http.ts`, and exact routes win over it. There is no sub-path option | -| Deploy | Build, `npx convex deploy`, then upload. The upload's last mutation switches the files and deletes the previous ones, so code and files switch at different moments | Upload a new version, then push code that names it. The push switches code and files together, and the first request on the new code deletes the versions live before it ([how](../README.md#how-a-deploy-switches-the-site)) | -| CLI | `setup`, `deploy`, and `upload`; `--dist` defaults to `./dist` and `--build-command` to `npm run build` | `deploy`, with `--dist` required and `--build` optional; `--dev` and `--preview-name` pick the deployment ([options](./deploy.md#options)) | -| Reload prompt | `UpdateBanner` and `useDeploymentUpdates` | A query and a hook to copy, in [Development](./development.md#open-tabs-after-a-deploy) | +| | static-hosting | convex-hosting | +| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Pages | Files only | What no file answers goes to the app's server entry, an object with `fetch(request)`; TanStack Start has an [adapter](../packages/convex-hosting-tanstack-start) | +| File rules | Its own: a miss without an extension gets `index.html` unless deployed with `--no-spa`, and a miss with one is 404. Hashed file names get a one-year cache | Cloudflare's asset Worker: `_headers`, `_redirects`, `.assetsignore`, `html_handling`, and `not_found_handling` (see [Serving](./serving.md)). Every file revalidates unless `_headers` says otherwise | +| Routes | The component owns `/`, with the app's routes under `/api`, or a sub-path; or `registerStaticRoutes` adds a GET catch-all to `convex/http.ts` | `routeAll` adds a catch-all for every method to `convex/http.ts`, and exact routes win over it. There is no sub-path option | +| Deploy | Build, `npx convex deploy`, then upload. The upload's last mutation switches the files and deletes the previous ones, so code and files switch at different moments | Upload a new version, then push code that names it. The push switches code and files together, and the deploy then marks it live, which deletes the versions live before it ([how](../README.md#how-a-deploy-switches-the-site)) | +| CLI | `setup`, `deploy`, and `upload`; `--dist` defaults to `./dist` and `--build-command` to `npm run build` | `deploy`, with `--dist` required and `--build` optional; `--dev` and `--preview-name` pick the deployment ([options](./deploy.md#options)) | +| Reload prompt | `UpdateBanner` and `useDeploymentUpdates` | A query and a hook to copy, in [Development](./development.md#open-tabs-after-a-deploy) | ## How to move @@ -31,7 +31,7 @@ and source on 2026-10-18, version 0.2.1. `httpPrefix: "/api"` from `defineApp`, and add `/api` to the paths of your own routes whose URLs must stay. 3. In `convex/http.ts`, replace `registerStaticRoutes(...)` with - `routeAll(http, components.hosting, versionId)`, and import `versionId` from + `routeAll(http, components.hosting, site)`, and import `site` from `../.convex-hosting/version.js`. Your exact routes keep winning. A server-rendered app passes its server entry as the fourth argument. 4. In the deploy scripts, replace `@convex-dev/static-hosting deploy`, or the pair @@ -57,8 +57,8 @@ Then check three things: without a server entry answers a missing file with an extension, such as `/assets/old.js`, with `index.html`, where static-hosting answered 404. - **Old files.** The push that removes `app.use(staticHosting)` unmounts that component, and its - files stay until you delete it in the Convex dashboard. From then on, each deploy's first request - deletes the version that was live before it. + files stay until you delete it in the Convex dashboard. From then on, each deploy's mark deletes + the version that was live before it. ## From convex-hosting 0.3.x diff --git a/docs/serving.md b/docs/serving.md index 24600806..0ae660fd 100644 --- a/docs/serving.md +++ b/docs/serving.md @@ -26,18 +26,20 @@ the file when the page reloads. A local deployment, which has no front, sends th ## Routing -`routeAll(http, component, versionId, worker?)` routes the site's HTTP action for every method at -every path, and returns it. The action answers with the file that matches, else with what `worker` -answers (see [Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or -HEAD on a path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, +`routeAll(http, component, site, worker?)` routes the site's HTTP action for every method at every +path, and returns it. The action answers with the file that matches, else with what `worker` answers +(see [Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or HEAD on +a path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, else 404. `worker` is the Worker script, an object with `fetch(request)`: the code that runs on a miss. Everything it returns gets `Cache-Control: no-store`, and so does a 404, because the `*.convex.site` front caches paths with an extension. The front keeps `no-store` for a path without an extension and replaces it with a four-hour browser `max-age` for a path with one, so a browser that asks for a script before its upload ended keeps the 404; the deploy order prevents that case, -because no page refers to a file that is not uploaded yet. When the version does not exist or is -still uploading, it answers 404 naming the version. At the first request for a new version, it marks -the version live. +because no page refers to a file that is not uploaded yet. The site's files come with the pushed +code, in `.convex-hosting/version.js`, so a request reads no database: it costs one function call, +the HTTP action, and a file adds the download of its bytes, which Convex counts as a call too. A +redirect, a 304, a miss, and a rendered page download nothing. Until a first install's upload ends, +the site answers 404 naming the version. As on Cloudflare, the presence of code decides where `not_found_handling` (the single-page fallback or the 404 page) applies: diff --git a/examples/hello-world-assets-only/convex/http.ts b/examples/hello-world-assets-only/convex/http.ts index 68549db0..f71716a4 100644 --- a/examples/hello-world-assets-only/convex/http.ts +++ b/examples/hello-world-assets-only/convex/http.ts @@ -1,12 +1,12 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { versionId } from "../.convex-hosting/version.js"; +import { site } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else 404; another method than GET or HEAD on a file answers 405. -routeAll(http, components.hosting, versionId); +routeAll(http, components.hosting, site); export default http; diff --git a/examples/tanstack-spa/convex/http.ts b/examples/tanstack-spa/convex/http.ts index 02d1725d..61b5a7e4 100644 --- a/examples/tanstack-spa/convex/http.ts +++ b/examples/tanstack-spa/convex/http.ts @@ -1,12 +1,12 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { versionId } from "../.convex-hosting/version.js"; +import { site } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else the single-page fallback; another method than GET or HEAD on a file answers 405. -routeAll(http, components.hosting, versionId); +routeAll(http, components.hosting, site); export default http; diff --git a/examples/tanstack-ssr/convex/http.ts b/examples/tanstack-ssr/convex/http.ts index 2bd08d55..a8989b93 100644 --- a/examples/tanstack-ssr/convex/http.ts +++ b/examples/tanstack-ssr/convex/http.ts @@ -1,7 +1,7 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { versionId } from "../.convex-hosting/version.js"; +import { site } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; @@ -11,7 +11,7 @@ const http = httpRouter(); // Every method, every path: a file for a path that has one (another method than GET or HEAD on it // answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with // static assets does. -const handler = routeAll(http, components.hosting, versionId, server); +const handler = routeAll(http, components.hosting, site, server); // Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it // serves the key set, and the longest prefix wins, so the catch-all above never sees them. for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { diff --git a/packages/convex-hosting-tanstack-start/README.md b/packages/convex-hosting-tanstack-start/README.md index 3e9acb65..1efe029f 100644 --- a/packages/convex-hosting-tanstack-start/README.md +++ b/packages/convex-hosting-tanstack-start/README.md @@ -33,7 +33,7 @@ import { routeAll } from "@samebase/convex-hosting"; import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; -routeAll(http, components.hosting, versionId, server); +routeAll(http, components.hosting, site, server); ``` Import `@samebase/convex-hosting` before the server build: it defines `queueMicrotask` when it diff --git a/packages/convex-hosting/CHANGELOG.md b/packages/convex-hosting/CHANGELOG.md index c1f722c9..5df6977f 100644 --- a/packages/convex-hosting/CHANGELOG.md +++ b/packages/convex-hosting/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 0.15.0 + +- A request reads no database. The deploy writes the site's files into `.convex-hosting/version.js` + (each path's content hash, content type, and stored file, in the layout of Cloudflare's asset + manifest), and the HTTP action answers from them. A page, a miss, a redirect, a 304, and a session + refresh cost one function call, the HTTP action, where they cost two; an answer with a body costs + two, the action and the download of the file, where it cost three. The component's `route` query + is gone. +- Breaking: `routeAll` takes the site, `import { site } from "../.convex-hosting/version.js"` and + `routeAll(http, components.hosting, site, server)`. `versionId` stays exported for the query that + reloads open tabs. +- After the push, `deploy` sends one request with the version's mark token, and the code that + answers marks its version live; before, the first request did. `markLive` answers what it did and + never throws. +- A first install pushes twice: once to install the component, and once after the upload, to serve + the site. +- A version file uploaded to another deployment, such as production's pushed to development by a + running `npx convex dev`, answers 404 naming that deployment. + ## 0.14.0 - The README, which this package ships, starts with what the component is, who it is for, and the diff --git a/packages/convex-hosting/package.json b/packages/convex-hosting/package.json index 47dff2c3..7ccea746 100644 --- a/packages/convex-hosting/package.json +++ b/packages/convex-hosting/package.json @@ -1,6 +1,6 @@ { "name": "@samebase/convex-hosting", - "version": "0.14.0", + "version": "0.15.0", "description": "Serves a web app from its own Convex deployment: the files of a build, and the pages the app renders.", "keywords": [ "component", diff --git a/packages/convex-hosting/scripts/sync-workers-sdk.ts b/packages/convex-hosting/scripts/sync-workers-sdk.ts index 8b0f976c..a06e525f 100644 --- a/packages/convex-hosting/scripts/sync-workers-sdk.ts +++ b/packages/convex-hosting/scripts/sync-workers-sdk.ts @@ -2,7 +2,7 @@ // from cloudflare/workers-sdk (MIT OR Apache-2.0) into src/workers-sdk, at the commit recorded in // src/workers-sdk/UPSTREAM: the asset Worker and its tests from packages/workers-shared, and // Cloudflare's html_handling and encoding cases from fixtures/workers-shared-asset-config, which -// src/component/conformance.test.ts runs through `route`. +// src/client/answer.test.ts runs through the site's action. // // node scripts/sync-workers-sdk.ts [] // diff --git a/packages/convex-hosting/src/cli/convex.ts b/packages/convex-hosting/src/cli/convex.ts index 9476fdd0..1c6e161a 100644 --- a/packages/convex-hosting/src/cli/convex.ts +++ b/packages/convex-hosting/src/cli/convex.ts @@ -150,6 +150,33 @@ export async function siteUrl(cli: Cli, flags: string[]): Promise { return z.string().parse(JSON.parse(stdout)); } +/** + * Evaluates `code` as an inline query in the component and validates its result. An inline query + * runs whatever release of this package the component's functions are, so the upload of a new + * release reads with it before the push has installed the new functions. + */ +export async function runComponentQuery( + cli: Cli, + target: Target, + code: string, + result: z.ZodType, +): Promise { + const { exitCode, stdout, stderr } = await cli.convex([ + "run", + "--component", + target.component, + "--inline-query", + code, + ...target.flags, + ]); + if (exitCode !== 0) { + throw new Error( + stderr.trim() || stdout.trim() || `npx convex run --inline-query exited with ${exitCode}.`, + ); + } + return result.parse(JSON.parse(stdout)); +} + /** * Runs a function of the component with `npx convex run` and validates its result. The Convex CLI * prints the result as JSON from another process, so `result` checks it at runtime; its type makes diff --git a/packages/convex-hosting/src/cli/main.test.ts b/packages/convex-hosting/src/cli/main.test.ts index a78faa81..a505cb9f 100644 --- a/packages/convex-hosting/src/cli/main.test.ts +++ b/packages/convex-hosting/src/cli/main.test.ts @@ -12,6 +12,7 @@ import { import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { describe, expect, test } from "vite-plus/test"; +import { lookup, MARK_HEADER, MARK_PATH, storageUrl, type Site } from "../client/manifest.js"; import { deploymentSelector, type Cli } from "./convex.js"; import { main, VERSION_FILE } from "./main.js"; @@ -22,6 +23,12 @@ const missing = (component: string) => /** The site URL that the fake deployment gives its functions in `CONVEX_SITE_URL`. */ const SITE_URL = "https://happy-cat-123.convex.site"; +/** The fake deployment's `CONVEX_CLOUD_URL`, the origin of its storage URLs. */ +const CLOUD_URL = "https://happy-cat-123.convex.cloud"; + +/** The storage URL that the fake deployment gives a stored file. */ +const fileUrl = (storageId: string) => `${CLOUD_URL}/api/storage/${storageId}?component=c1`; + /** An app directory with `convex/` and the given files. */ function app(files: Record) { const cwd = mkdtempSync(join(tmpdir(), "convex-hosting-cli-")); @@ -33,19 +40,25 @@ function app(files: Record) { return cwd; } -/** What a `npx convex run` call is: the probe, the site URL query, or a function's name. */ +/** + * What a `npx convex run` call is: the probe, the site URL query, the storage URL query, or a + * function's name. + */ const callName = (args: string[]) => args.includes("process.env.CONVEX_SITE_URL") ? "site url" - : args.includes("--inline-query") - ? "probe" - : args[3]; + : args.some((arg) => arg.includes("ctx.storage.getUrl")) + ? "urls" + : args.includes("--inline-query") + ? "probe" + : args[3]; /** * A fake `Cli`: `npx convex run` answers like a deployment with the component, the build calls - * `build`, and `npx convex deploy` or `npx convex run --push` calls `push`. No processes, no - * network. `events` lists the builds, the probes, the site URL queries, the function calls, and the - * pushes in order. + * `build`, `npx convex deploy` or `npx convex run --push` calls `push`, and the site answers the + * mark request with `mark`. No processes, no network. `events` lists the builds, the probes, the + * site URL queries, the storage URL queries, the function calls, the pushes, and the marks in + * order. */ function fake( cwd: string, @@ -58,6 +71,8 @@ function fake( failing?: Record; build?: () => Promise; push?: (cli: Cli, args: string[]) => Promise; + /** The site's answer to the mark request; by default it marks the version of the file. */ + mark?: (token: string | null) => Promise; } = {}, ) { const runs: string[][] = []; @@ -65,6 +80,8 @@ function fake( const builds: string[] = []; const events: string[] = []; const stored = new Map(); + /** The entries that `recordFiles` recorded, by version. */ + const recorded = new Map(); const logs: string[] = []; const ok = (value: unknown) => ({ exitCode: 0, @@ -80,6 +97,17 @@ function fake( events.push("site url"); return ok(SITE_URL); } + if (callName(args) === "urls") { + events.push("urls"); + const code = args[args.indexOf("--inline-query") + 1]; + const [, versionId, after] = + /q\.eq\("versionId", ("[^"]*")\)\.gt\("path", ("[^"]*")\)/.exec(code) ?? []; + const files = (recorded.get(JSON.parse(versionId)) ?? []) + .filter(({ path }) => path > JSON.parse(after)) + .sort((a, b) => (a.path < b.path ? -1 : 1)) + .map(({ path, storageId }) => [path, fileUrl(storageId)]); + return ok({ cloudUrl: CLOUD_URL, files }); + } if (args.includes("--inline-query")) { events.push("probe"); return (options.installed?.() ?? true) @@ -91,6 +119,12 @@ function fake( if (failure !== undefined) return { exitCode: 1, stdout: "", stderr: failure }; const fnArgs = JSON.parse(args[4]); switch (args[3]) { + case "lib:recordFiles": + recorded.set(fnArgs.versionId, [ + ...(recorded.get(fnArgs.versionId) ?? []), + ...fnArgs.entries, + ]); + return ok(null); case "lib:generateUploadUrls": return ok(Array.from({ length: fnArgs.count }, (_, i) => `https://upload/${i}`)); case "lib:knownFiles": @@ -114,7 +148,16 @@ function fake( events.push("build"); return (await options.build?.()) ?? 0; }, - fetch: async (_url, init) => { + fetch: async (url, init) => { + if (url === SITE_URL + MARK_PATH) { + events.push("mark"); + const token = new Headers(init?.headers).get(MARK_HEADER); + if (options.mark !== undefined) return await options.mark(token); + const site = writtenSite(cwd); + return token === site.markToken + ? Response.json({ versionId: site.versionId, result: "marked" }) + : new Response("

Home

"); + } const storageId = `storage-${stored.size}`; stored.set(storageId, await new Response(init?.body).text()); return Response.json({ storageId }); @@ -139,6 +182,13 @@ function innerUpload(cli: Cli, args: string[]) { const versionFile = (cwd: string) => readFileSync(join(cwd, VERSION_FILE), "utf8"); const writtenVersionId = (cwd: string) => /"([^"]+)"/.exec(versionFile(cwd))?.[1]; +/** The site of the version file, as `convex/http.ts` imports it. */ +function writtenSite(cwd: string): Site { + const line = versionFile(cwd) + .split("\n") + .find((text) => text.startsWith("export const site = ")); + return JSON.parse(line?.slice("export const site = ".length, -1) ?? "null"); +} const site = { "dist/index.html": "

Home

", @@ -171,7 +221,7 @@ describe("help", () => { }); describe("deploy --dev", () => { - test("builds, uploads, writes the version file, pushes with npx convex run --push, and reports the site URL", async () => { + test("builds, uploads, writes the version file, pushes with npx convex run --push, marks, and reports the site URL", async () => { const cwd = app(site); let pushedVersionId: string | undefined; const { cli, events, builds, pushes, runs, logs } = fake(cwd, { @@ -193,8 +243,10 @@ describe("deploy --dev", () => { "lib:generateUploadUrls", "lib:recordFiles", "lib:finishVersion", + "urls", "push: run", "site url", + "mark", ]); // An inline query at the app's root, which exists before a first install. expect(pushes).toEqual([["run", "--push", "--inline-query", "null"]]); @@ -205,13 +257,14 @@ describe("deploy --dev", () => { expect(logs[logs.length - 1]).toBe(`Deployed version ${versionId} to ${SITE_URL}.`); }); - test("on a first install, writes the version file, pushes, then uploads", async () => { + test("on a first install, pushes a site without files, uploads, then pushes the site", async () => { const cwd = app(site); let pushed = false; + const pushedFiles: boolean[] = []; const { cli, events, callArgs } = fake(cwd, { installed: () => pushed, push: async () => { - expect(existsSync(join(cwd, VERSION_FILE))).toBe(true); + pushedFiles.push(writtenSite(cwd).files !== null); pushed = true; return 0; }, @@ -224,7 +277,14 @@ describe("deploy --dev", () => { "probe", "lib:generateUploadUrls", ]); - expect(events.slice(-2)).toEqual(["lib:finishVersion", "site url"]); + expect(events.slice(-5)).toEqual([ + "lib:finishVersion", + "urls", + "push: run", + "site url", + "mark", + ]); + expect(pushedFiles).toEqual([false, true]); expect(existsSync(join(cwd, ".convex-hosting", "first-install"))).toBe(false); expect(callArgs("lib:createVersion")[0].versionId).toBe(writtenVersionId(cwd)); }); @@ -330,6 +390,66 @@ describe("deploy reports", () => { ); }); + test("the mark carries the site's token, so only the code of this deploy marks", async () => { + const tokens: (string | null)[] = []; + const cwd = app(site); + const { cli, logs } = fake(cwd, { + push: innerUpload, + mark: async (token) => { + tokens.push(token); + return Response.json({ versionId: writtenSite(cwd).versionId, result: "marked" }); + }, + }); + expect(await main(DEPLOY, cli)).toBe(0); + expect(tokens).toEqual([writtenSite(cwd).markToken]); + expect(logs[logs.length - 1]).toMatch(/^Deployed version /); + }); + + test("a mark that fails or reaches other code is reported, and the deploy succeeds", async () => { + const answers: Record Promise> = { + "failed: fetch failed": async () => { + throw new TypeError("fetch failed"); + }, + "did not answer as version": async () => new Response("

Home

"), + }; + for (const [message, answer] of Object.entries(answers)) { + const { cli, logs } = fake(app(site), { push: innerUpload, mark: answer }); + expect(await main(DEPLOY, cli)).toBe(0); + expect(logs.some((line) => line.includes(message))).toBe(true); + expect(logs[logs.length - 1]).toMatch(/^Deployed version /); + } + }); + + test("a mark refused because a newer version is live says that deploys overlapped", async () => { + const cwd = app(site); + const { cli, logs } = fake(cwd, { + push: innerUpload, + mark: async () => + Response.json({ versionId: writtenSite(cwd).versionId, result: "superseded" }), + }); + expect(await main(DEPLOY, cli)).toBe(0); + expect(logs.some((line) => line.includes("a deploy overlapped this one"))).toBe(true); + }); + + test("a stored file that is gone before the version file is written fails the upload", async () => { + const cwd = app(site); + const { cli, logs } = fake(cwd); + const convex = cli.convex; + cli.convex = async (args) => + callName(args) === "urls" + ? { + exitCode: 0, + stdout: JSON.stringify({ cloudUrl: CLOUD_URL, files: [["/index.html", null]] }), + stderr: "", + } + : convex(args); + expect(await main(["upload", "--dist", "dist", "--version-id", "v1"], cli)).toBe(1); + expect(logs[logs.length - 1]).toBe( + "The stored file of /index.html is gone, deleted by the age rule; run the deploy again.", + ); + expect(existsSync(join(cwd, VERSION_FILE))).toBe(false); + }); + test("a failed upload names the file", async () => { const { cli, logs } = fake(app(site)); // The config, a string, stores; the files, bytes, do not. @@ -350,7 +470,7 @@ describe("deploy without --build", () => { expect(await main(["deploy", "--dev", "--dist", "dist"], cli)).toBe(0); expect(builds).toEqual([]); expect(events[0]).toBe("probe"); - expect(events.slice(-2)).toEqual(["push: run", "site url"]); + expect(events.slice(-3)).toEqual(["push: run", "site url", "mark"]); }); test("production runs only the upload inside npx convex deploy --cmd", async () => { @@ -358,7 +478,7 @@ describe("deploy without --build", () => { expect(await main(["deploy", "--dist", "dist"], cli)).toBe(0); expect(pushes[0][2]).toMatch(/^'.+' '.+' 'upload' '--dist' 'dist' '--version-id' '/); expect(events[0]).toBe("push: deploy"); - expect(events.slice(-2)).toEqual(["lib:finishVersion", "site url"]); + expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "site url", "mark"]); }); }); @@ -377,29 +497,37 @@ describe("deploy", () => { // `npx convex deploy` goes to production by default and has no --prod flag; every run gets it. expect(pushes[0]).not.toContain("--prod"); expect(runs.every((args) => args.includes("--prod"))).toBe(true); - // The upload runs inside the push, and only the site URL query runs after it. + // The upload runs inside the push; after it, the site URL query and the mark. expect(events[0]).toBe("push: deploy"); - expect(events.slice(-2)).toEqual(["lib:finishVersion", "site url"]); + expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "site url", "mark"]); expect(callArgs("lib:createVersion")[0].versionId).toBe(writtenVersionId(cwd)); }); - test("on a first install, uploads after the push", async () => { + test("on a first install, uploads after the push, then pushes again", async () => { const cwd = app(site); let pushed = false; - const { cli, calls } = fake(cwd, { + const pushedFiles: boolean[] = []; + const { cli, calls, pushes } = fake(cwd, { installed: () => pushed, push: async (cli, args) => { - const exitCode = await innerUpload(cli, args); - expect(existsSync(join(cwd, ".convex-hosting", "first-install"))).toBe(true); - expect(existsSync(join(cwd, VERSION_FILE))).toBe(true); - pushed = true; - return exitCode; + if (args.includes("--cmd")) { + const exitCode = await innerUpload(cli, args); + expect(existsSync(join(cwd, ".convex-hosting", "first-install"))).toBe(true); + pushedFiles.push(writtenSite(cwd).files !== null); + pushed = true; + return exitCode; + } + pushedFiles.push(writtenSite(cwd).files !== null); + return 0; }, }); expect(await main(DEPLOY, cli)).toBe(0); expect(calls().slice(0, 3)).toEqual(["probe", "probe", "lib:generateUploadUrls"]); - expect(calls().slice(-2)).toEqual(["lib:finishVersion", "site url"]); + expect(calls().slice(-3)).toEqual(["lib:finishVersion", "urls", "site url"]); + expect(pushes.map((args) => args[0])).toEqual(["deploy", "deploy"]); + expect(pushes[1]).toEqual(["deploy"]); + expect(pushedFiles).toEqual([false, true]); expect(existsSync(join(cwd, ".convex-hosting", "first-install"))).toBe(false); }); @@ -411,7 +539,7 @@ describe("deploy", () => { }, }); expect(await main(DEPLOY, cli)).toBe(1); - expect(events[events.length - 1]).toBe("lib:finishVersion"); + expect(events[events.length - 1]).toBe("urls"); expect(logs[logs.length - 1]).toBe("npx convex deploy failed with exit code 1."); }); @@ -484,6 +612,7 @@ describe("upload", () => { "lib:generateUploadUrls", "lib:recordFiles", "lib:finishVersion", + "urls", ]); // Inside `npx convex deploy` to production, every run gets --prod. expect(runs.every((args) => args.includes("--prod"))).toBe(true); @@ -521,7 +650,30 @@ describe("upload", () => { home.storageId, ); - expect(versionFile(cwd)).toBe('export const versionId = "v1";\n'); + expect(versionFile(cwd).split("\n")[0]).toBe('export const versionId = "v1";'); + const written = writtenSite(cwd); + expect(written).toMatchObject({ format: 1, versionId: "v1", markToken: expect.any(String) }); + const files = written.files; + if (files === null) throw new Error("The version file has no files."); + expect(files.cloudUrl).toBe(CLOUD_URL); + expect(files.config).toMatchObject({ + compatibility_date: "2025-04-01", + html_handling: "auto-trailing-slash", + not_found_handling: "single-page-application", + }); + expect(files.contentTypes).toEqual([ + "text/html; charset=utf-8", + "text/javascript; charset=utf-8", + ]); + // Every path finds its stored file and its type; the two copies share one stored file. + const found = await lookup(files, "/copy.html"); + expect(found).toEqual({ + contentHash: home.sha256.slice(0, 32), + file: (await lookup(files, "/index.html"))?.file, + contentType: "text/html; charset=utf-8", + }); + expect(storageUrl(files.storage, found?.file ?? -1)).toBe(fileUrl(home.storageId)); + expect(await lookup(files, "/private/notes.txt")).toBeNull(); expect(readFileSync(join(cwd, ".convex-hosting", ".gitignore"), "utf8")).toBe("*\n"); }); diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index d407cb01..972ff4fe 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -4,6 +4,7 @@ import { existsSync, mkdirSync, readFileSync, + renameSync, rmSync, writeFileSync, } from "node:fs"; @@ -11,7 +12,16 @@ import { join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { parseArgs } from "node:util"; import { z } from "zod"; +import { + buildSiteFiles, + MARK_HEADER, + MARK_PATH, + SITE_FORMAT, + type Site, + type SiteFiles, +} from "../client/manifest.js"; import { internal } from "../component/_generated/api.js"; +import type { Config } from "../component/lib.js"; import type { Id } from "../component/_generated/dataModel.js"; import { AssetConfigSchema } from "../workers-sdk/packages/workers-shared/utils/types.js"; import { @@ -19,12 +29,14 @@ import { probeComponent, readConvexEnv, runComponent, + runComponentQuery, siteUrl, type Cli, type Destination, type Target, } from "./convex.js"; import { readDist, type DistEntry, type HandlingOptions } from "./files.js"; +import { siteConfig } from "./site-config.js"; const USAGE = `Usage: convex-hosting deploy --dist [options] @@ -57,6 +69,12 @@ export const VERSION_FILE = join(STATE_DIR, "version.js"); */ const FIRST_INSTALL_MARKER = join(STATE_DIR, "first-install"); +/** + * Entries per inline query that reads the storage URLs: 2,000 entries and their `_storage` + * documents are 4,000 of the 32,000 documents a query may read, and about 300 KB of result. + */ +const URL_PAGE = 2000; + /** Files that the upload sends to storage at once. */ const UPLOAD_CONCURRENCY = 4; @@ -167,9 +185,9 @@ function quote(arg: string): string { } /** - * Builds, uploads, writes the version file, and pushes. The push is the switch: the first request - * that the new code serves marks its version live. Then it reports the site URL, for a person and, - * through `$GITHUB_OUTPUT`, for the next step of a GitHub Actions job. + * Builds, uploads, writes the version file, and pushes. The push is the switch. Then it asks the + * served code to mark its version live, and reports the site URL, for a person and, through + * `$GITHUB_OUTPUT`, for the next step of a GitHub Actions job. */ async function deploy(cli: Cli, options: Options, build: string | undefined) { // A deploy key wins over every selector in the Convex CLI, so a production key in the environment @@ -226,6 +244,7 @@ async function deploy(cli: Cli, options: Options, build: string | undefined) { const message = error instanceof Error ? error.message : String(error); throw new Error(`Deployed version ${versionId}, but reading the site URL failed: ${message}`); } + await markServedVersion(cli, url, readVersionFile(cli)); cli.log(`Deployed version ${versionId} to ${url}.`); if (cli.env.GITHUB_OUTPUT) appendFileSync(cli.env.GITHUB_OUTPUT, `url=${url}\n`); } @@ -236,7 +255,7 @@ async function deploy(cli: Cli, options: Options, build: string | undefined) { * reads `VITE_CONVEX_URL`). Then the upload runs here, and `npx convex run --push` pushes, with an inline * query at the app's root, which exists before the push installs the component. It works whether * or not `npx convex dev` runs; `npx convex dev --once` refuses while it runs a local deployment's - * backend. + * backend. A first install pushes, uploads, and pushes again. */ async function deployDev( cli: Cli, @@ -251,12 +270,22 @@ async function deployDev( } const missing = await upload(cli, options, target, versionId); if (missing !== undefined) cli.log(notInstalledYet(options.component)); + await pushDev(cli); + if (missing !== undefined) { + await uploadAfterPush(cli, options, target, versionId); + await pushDev(cli); + } +} + +async function pushDev(cli: Cli) { const exitCode = await cli.convexInherited(["run", "--push", "--inline-query", "null"]); if (exitCode !== 0) throw new Error(`npx convex run --push failed with exit code ${exitCode}.`); - if (missing !== undefined) await uploadAfterPush(cli, options, target, versionId); } -/** Production or a preview: the build, if any, and the upload run inside `npx convex deploy --cmd`. */ +/** + * Production or a preview: the build, if any, and the upload run inside `npx convex deploy --cmd`. + * A first install uploads after that push and pushes again with `npx convex deploy`. + */ async function deployWithConvexDeploy( cli: Cli, options: Options, @@ -299,7 +328,11 @@ async function deployWithConvexDeploy( const firstInstall = existsSync(marker); rmSync(marker, { force: true }); if (exitCode !== 0) throw new Error(`npx convex deploy failed with exit code ${exitCode}.`); - if (firstInstall) await uploadAfterPush(cli, options, target, versionId); + if (firstInstall) { + await uploadAfterPush(cli, options, target, versionId); + const again = await cli.convexInherited(["deploy", ...deployFlags]); + if (again !== 0) throw new Error(`npx convex deploy failed with exit code ${again}.`); + } } /** The upload inside `npx convex deploy --cmd`. On a first install, `deploy` uploads after the push. */ @@ -315,7 +348,7 @@ async function uploadInsideDeploy(cli: Cli, options: Options, versionId: string) } function notInstalledYet(component: string) { - return `The component "${component}" is not installed yet. The push installs it, and the upload runs after the push.`; + return `The component "${component}" is not installed yet. The push installs it, the upload runs after the push, and a second push serves the site.`; } /** The upload of a first install, after the push. The probe's output shows a mistyped `--component`. */ @@ -330,9 +363,9 @@ async function uploadAfterPush(cli: Cli, options: Options, target: Target, versi } /** - * Uploads `--dist` as version `versionId` and writes the version file. When the component is not - * installed yet, it writes only the version file, so that the push that follows installs the - * component, and returns the probe's output. + * Uploads `--dist` as version `versionId` and writes the version file with the site's files. When + * the component is not installed yet, it writes a version file without files, which serves + * nothing, so that the push that follows installs the component, and returns the probe's output. */ async function upload( cli: Cli, @@ -351,9 +384,11 @@ async function upload( z.array(z.string()).length(count), ); + // The CLI sends it after the push; see `MARK_HEADER`. + const markToken = randomUUID(); const missing = await probeComponent(cli, target); if (missing !== undefined) { - writeVersionFile(cli, versionId); + writeVersionFile(cli, { format: SITE_FORMAT, versionId, markToken, files: null }); return missing; } @@ -442,23 +477,142 @@ async function upload( await record(uploaded); } await runComponent(cli, target, internal.lib.finishVersion, { versionId }, z.null()); - writeVersionFile(cli, versionId); + const files = await siteFiles(cli, target, versionId, config, entries); + writeVersionFile(cli, { format: SITE_FORMAT, versionId, markToken, files }); cli.log(`Uploaded version ${versionId} and wrote ${VERSION_FILE}.`); return undefined; } -function writeVersionFile(cli: Cli, versionId: string) { - writeStateFile(cli, VERSION_FILE, `export const versionId = ${JSON.stringify(versionId)};\n`); +/** + * The files of the site that serving reads: the storage URL of each entry, which only the + * component can make, read with inline queries in the component, which work whatever release of + * this package its functions are, and the deployment's `CONVEX_CLOUD_URL`, their origin. + */ +async function siteFiles( + cli: Cli, + target: Target, + versionId: string, + config: Config, + entries: DistEntry[], +): Promise { + const urls = new Map(); + let cloudUrl = ""; + let after = ""; + for (;;) { + const page = await runComponentQuery( + cli, + target, + `const rows = await ctx.db.query("entries").withIndex("by_version_path", (q) => ` + + `q.eq("versionId", ${JSON.stringify(versionId)}).gt("path", ${JSON.stringify(after)}))` + + `.take(${URL_PAGE}); return { cloudUrl: process.env.CONVEX_CLOUD_URL, files: await ` + + `Promise.all(rows.map(async (row) => [row.path, await ctx.storage.getUrl(row.storageId)])) };`, + z.object({ + cloudUrl: z.string(), + files: z.array(z.tuple([z.string(), z.string().nullable()])), + }), + ); + cloudUrl = page.cloudUrl; + for (const [path, url] of page.files) { + if (url === null) { + throw new Error( + `The stored file of ${path} is gone, deleted by the age rule; run the deploy again.`, + ); + } + urls.set(path, url); + } + if (page.files.length < URL_PAGE) break; + after = page.files[page.files.length - 1][0]; + } + return await buildSiteFiles( + cloudUrl, + siteConfig(config), + entries.map(({ path, sha256, contentType }) => { + const url = urls.get(path); + if (url === undefined) throw new Error(`Version ${versionId} has no entry for ${path}.`); + return { path, sha256, contentType, url }; + }), + ); } -/** Writes a file of the state folder, and the folder's `.gitignore` when it is absent. */ +/** The line of the version file that holds the site. */ +const SITE_LINE = "export const site = "; + +/** + * Writes the version file. `versionId` is its own export too, for the app query that reloads + * pages on a new version. + */ +function writeVersionFile(cli: Cli, site: Site) { + writeStateFile( + cli, + VERSION_FILE, + `export const versionId = ${JSON.stringify(site.versionId)};\n${SITE_LINE}${JSON.stringify(site)};\n`, + ); +} + +/** The id and the mark token of the site in the version file that the upload wrote. */ +function readVersionFile(cli: Cli): Pick { + const line = readFileSync(join(cli.cwd, VERSION_FILE), "utf8") + .split("\n") + .find((text) => text.startsWith(SITE_LINE)); + if (line === undefined) throw new Error(`${VERSION_FILE} has no site.`); + return z + .object({ versionId: z.string(), markToken: z.string() }) + .parse(JSON.parse(line.slice(SITE_LINE.length, -1))); +} + +/** + * Asks the code that the deployment serves to mark its version live, with the site's mark token, + * which only the code of this deploy has. A failure deletes nothing: the versions live before stay + * until a later deploy marks its own, so it is reported, and the deploy succeeds. + */ +async function markServedVersion( + cli: Cli, + url: string, + site: Pick, +) { + const later = `Version ${site.versionId} serves, and the next deploy deletes the files of the versions before it.`; + let answer: unknown; + try { + const response = await cli.fetch(url + MARK_PATH, { + method: "POST", + headers: { [MARK_HEADER]: site.markToken }, + }); + // Other code answers the path with a page or a 404, which is no mark. + answer = response.ok ? await response.json().catch(() => null) : null; + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + cli.log(`Asking the site to mark version ${site.versionId} live failed: ${message}. ${later}`); + return; + } + const parsed = z.object({ versionId: z.string(), result: z.string() }).safeParse(answer); + if (!parsed.success || parsed.data.versionId !== site.versionId) { + cli.log( + `The site did not answer as version ${site.versionId}, so its code is not this deploy's.`, + ); + return; + } + const { result } = parsed.data; + if (result === "superseded") { + cli.log( + `A version created after ${site.versionId} is live, so a deploy overlapped this one; ${later}`, + ); + } else if (result !== "marked" && result !== "live") { + cli.log(`Version ${site.versionId} could not be marked live: it is ${result}.`); + } +} + +/** + * Writes a file of the state folder, and the folder's `.gitignore` when it is absent. It writes a + * temporary file and renames it, so a running `npx convex dev` never reads half a file. + */ function writeStateFile(cli: Cli, path: string, body: string) { const gitignore = join(cli.cwd, STATE_DIR, ".gitignore"); if (!existsSync(gitignore)) { mkdirSync(join(cli.cwd, STATE_DIR), { recursive: true }); writeFileSync(gitignore, "*\n"); } - writeFileSync(join(cli.cwd, path), body); + writeFileSync(join(cli.cwd, `${path}.tmp`), body); + renameSync(join(cli.cwd, `${path}.tmp`), join(cli.cwd, path)); } /** Stores one file through an upload URL and returns its storage id; `what` names it in errors. */ diff --git a/packages/convex-hosting/src/cli/site-config.ts b/packages/convex-hosting/src/cli/site-config.ts new file mode 100644 index 00000000..aa69a0ce --- /dev/null +++ b/packages/convex-hosting/src/cli/site-config.ts @@ -0,0 +1,17 @@ +import type { Config } from "../component/lib.js"; +import { normalizeConfiguration } from "../workers-sdk/packages/workers-shared/asset-worker/src/configuration.js"; +import { AssetConfigSchema } from "../workers-sdk/packages/workers-shared/utils/types.js"; + +/** + * The compatibility date of Cloudflare's handler. From 2025-04-01 on, Cloudflare applies + * `not_found_handling` to a request with `Sec-Fetch-Mode: navigate` when a Worker exists. + */ +const COMPATIBILITY_DATE = "2025-04-01"; + +/** A version's config as Cloudflare's handler takes it, which the site carries. */ +export function siteConfig(config: Config) { + return normalizeConfiguration({ + ...AssetConfigSchema.parse(config), + compatibility_date: COMPATIBILITY_DATE, + }); +} diff --git a/packages/convex-hosting/src/client/answer.test.ts b/packages/convex-hosting/src/client/answer.test.ts new file mode 100644 index 00000000..c5e9c0e8 --- /dev/null +++ b/packages/convex-hosting/src/client/answer.test.ts @@ -0,0 +1,234 @@ +import { describe, expect, test } from "vite-plus/test"; +import { siteConfig } from "../cli/site-config.js"; +import type { Config } from "../component/lib.js"; +import { encodingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/encoding-test-cases.js"; +import { htmlHandlingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/html-handling-test-cases.js"; +import { answer } from "./index.js"; +import { buildSiteFiles, storageUrl, type SiteFiles } from "./manifest.js"; + +type Files = Record; + +const CLOUD_URL = "https://example.convex.cloud"; +const ORIGIN = "https://example.convex.site"; + +async function sha256Hex(body: string) { + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); + return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); +} + +/** The stored file's URL of `body`: it names the bytes, so a test can tell which file answered. */ +async function bodyUrl(body: string) { + return `${CLOUD_URL}/api/storage/${await sha256Hex(body)}`; +} + +/** The site's files for `files` and `config`, as the upload builds them. */ +async function siteFiles(files: Files, config: Config = {}) { + const entries = await Promise.all( + Object.entries(files).map(async ([path, { body, contentType }]) => ({ + path, + sha256: await sha256Hex(body), + contentType, + url: await bodyUrl(body), + })), + ); + return await buildSiteFiles(CLOUD_URL, siteConfig(config), entries); +} + +/** Cloudflare's answer to one request, with the storage URL of its body, or `null` for a miss. */ +async function route( + files: SiteFiles, + path: string, + headers: Record = {}, + hasUserWorker = true, + method = "GET", +) { + const asset = await answer(files, new Request(ORIGIN + path, { method, headers }), hasUserWorker); + if (asset === null) return null; + return { + status: asset.status, + headers: Object.fromEntries(asset.headers), + bodyUrl: asset.file === null ? null : storageUrl(files.storage, asset.file), + }; +} + +const site: Files = { + "/index.html": { body: "

Home

", contentType: "text/html; charset=utf-8" }, + "/404.html": { body: "

Missing

", contentType: "text/html; charset=utf-8" }, + "/assets/app-a1.js": { body: "console.log(1)", contentType: "text/javascript; charset=utf-8" }, +}; + +describe("answer", () => { + test("a hit has Cloudflare's headers and an ETag; If-None-Match answers 304", async () => { + const files = await siteFiles(site); + const hit = await route(files, "/assets/app-a1.js"); + expect(hit?.status).toBe(200); + expect(hit?.headers["content-type"]).toBe("text/javascript; charset=utf-8"); + expect(hit?.headers["cache-control"]).toBe("public, max-age=0, must-revalidate"); + expect(hit?.headers["cf-cache-status"]).toBeUndefined(); + const eTag = hit?.headers.etag; + const sha256 = await sha256Hex("console.log(1)"); + expect(eTag).toMatch(new RegExp(`^"${sha256.slice(0, 32)}[0-9a-f]{8}"$`)); + expect(hit?.bodyUrl).toBe(await bodyUrl("console.log(1)")); + + const revalidated = await route(files, "/assets/app-a1.js", { "if-none-match": eTag ?? "" }); + expect(revalidated?.status).toBe(304); + expect(revalidated?.bodyUrl).toBeNull(); + }); + + test("the same bytes under two content types have two ETags", async () => { + const files = await siteFiles({ + "/a.txt": { body: "same", contentType: "text/plain" }, + "/a.js": { body: "same", contentType: "text/javascript" }, + }); + const txt = await route(files, "/a.txt"); + const js = await route(files, "/a.js"); + expect(txt?.headers.etag).not.toBe(js?.headers.etag); + expect(js?.headers["content-type"]).toBe("text/javascript"); + expect(txt?.bodyUrl).toBe(js?.bodyUrl); + }); + + test("with code, single-page-application answers navigations only", async () => { + const files = await siteFiles(site, { not_found_handling: "single-page-application" }); + const navigation = await route(files, "/settings/profile", { "sec-fetch-mode": "navigate" }); + const index = await route(files, "/"); + expect(navigation?.status).toBe(200); + expect(navigation?.headers.etag).toBe(index?.headers.etag); + expect(await route(files, "/settings/profile")).toBeNull(); + }); + + test("without code, single-page-application answers every request, as a files-only Worker", async () => { + const files = await siteFiles(site, { not_found_handling: "single-page-application" }); + const index = await route(files, "/"); + // No `Sec-Fetch-Mode`, as from curl, a monitor, or a link-preview bot. + const filesOnly = await route(files, "/about", {}, false); + expect(filesOnly?.status).toBe(200); + expect(filesOnly?.headers["content-type"]).toBe("text/html; charset=utf-8"); + expect(filesOnly?.headers.etag).toBe(index?.headers.etag); + // With code, the same request is a miss, which the app answers. + expect(await route(files, "/about", {}, true)).toBeNull(); + }); + + test("without code and with html_handling none, / answers index.html through the fallback", async () => { + const files = await siteFiles(site, { + html_handling: "none", + not_found_handling: "single-page-application", + }); + const root = await route(files, "/", {}, false); + const index = await route(files, "/index.html", {}, false); + expect(root?.status).toBe(200); + expect(root?.headers.etag).toBe(index?.headers.etag); + }); + + test("another method than GET or HEAD on a file answers 405; on a miss, the code or 404", async () => { + const files = await siteFiles(site); + for (const hasUserWorker of [true, false]) { + const post = await route(files, "/index.html", {}, hasUserWorker, "POST"); + expect(post?.status).toBe(405); + expect(post?.bodyUrl).toBeNull(); + } + expect(await route(files, "/missing", {}, true, "POST")).toBeNull(); + expect((await route(files, "/missing", {}, false, "POST"))?.status).toBe(404); + }); + + test("HEAD answers the file's headers without its body", async () => { + const files = await siteFiles(site); + const head = await route(files, "/", {}, true, "HEAD"); + expect(head?.status).toBe(200); + expect(head?.headers["content-type"]).toBe("text/html; charset=utf-8"); + expect(head?.bodyUrl).toBeNull(); + }); + + test("without code, a miss with not_found_handling none answers 404 with no-store", async () => { + const files = await siteFiles(site); + expect(await route(files, "/missing", {}, false)).toEqual({ + status: 404, + headers: { "cache-control": "no-store" }, + bodyUrl: null, + }); + }); + + test("the custom 404 page answers with its body and no-store", async () => { + const files = await siteFiles(site, { not_found_handling: "404-page" }); + const page = await route(files, "/missing", { "sec-fetch-mode": "navigate" }); + expect(page?.status).toBe(404); + expect(page?.bodyUrl).toBe(await bodyUrl("

Missing

")); + expect(page?.headers["cache-control"]).toBe("no-store"); + const filesOnly = await route(files, "/missing", {}, false); + expect(filesOnly?.status).toBe(404); + expect(filesOnly?.headers.etag).toBe(page?.headers.etag); + }); + + test("a _headers rule applies", async () => { + const files = await siteFiles(site, { + headers: { + version: 2, + rules: { "/assets/*": { set: { "Cache-Control": "public, max-age=31536000, immutable" } } }, + }, + }); + const hit = await route(files, "/assets/app-a1.js"); + expect(hit?.headers["cache-control"]).toBe("public, max-age=31536000, immutable"); + }); + + test("a _redirects rule applies", async () => { + const files = await siteFiles(site, { + redirects: { + version: 1, + staticRules: { "/old": { status: 301, to: "/", lineNumber: 1 } }, + rules: {}, + }, + }); + const redirect = await route(files, "/old?x=1"); + expect(redirect?.status).toBe(301); + expect(redirect?.headers.location).toBe("/?x=1"); + expect(redirect?.bodyUrl).toBeNull(); + }); +}); + +// Cloudflare's own cases for `html_handling` and path encoding, from +// fixtures/workers-shared-asset-config in cloudflare/workers-sdk. Upstream runs them against its +// asset Worker with `exists` mocked; here the files are a site's manifest. +describe("Cloudflare's conformance cases", () => { + /** Requests `path` and follows redirects, as the upstream test's `fetch` does. */ + async function follow(files: SiteFiles, path: string) { + let url = ORIGIN + path; + for (let hop = 0; hop < 8; hop++) { + const asset = await answer(files, new Request(url), false); + if (asset === null) throw new Error(`No asset for ${url}`); + const location = asset.headers.get("location"); + if (location !== null && asset.status >= 300 && asset.status < 400) { + url = new URL(location, url).href; + continue; + } + return { status: asset.status, url, eTag: asset.headers.get("etag"), redirected: hop > 0 }; + } + throw new Error(`Too many redirects from ${path}`); + } + + const suites = [ + { title: "html_handling", suite: htmlHandlingTestCases }, + { title: "encoding", suite: encodingTestCases }, + ]; + + describe.each(suites)("$title", ({ suite }) => { + describe.each(suite)("$html_handling", ({ html_handling, cases }) => { + test.each(cases)("$title", async ({ files, requestPath, matchedFile, finalPath }) => { + // Each file's body is its own path, so the ETag names it. + const site = await siteFiles( + Object.fromEntries(files.map((path) => [path, { body: path }])), + { html_handling, not_found_handling: "none" }, + ); + const response = await follow(site, requestPath); + if (matchedFile && finalPath) { + expect(response.status).toBe(200); + expect(response.url).toBe(ORIGIN + finalPath); + expect(response.redirected).toBe(requestPath !== finalPath); + expect(response.eTag).toMatch( + new RegExp(`^"${(await sha256Hex(matchedFile)).slice(0, 32)}`), + ); + } else { + expect(response.status).toBe(404); + } + }); + }); + }); +}); diff --git a/packages/convex-hosting/src/client/index.test.ts b/packages/convex-hosting/src/client/index.test.ts index 1069107a..31670dea 100644 --- a/packages/convex-hosting/src/client/index.test.ts +++ b/packages/convex-hosting/src/client/index.test.ts @@ -2,50 +2,74 @@ import { convexTest } from "convex-test"; import { anyApi, httpRouter, ROUTABLE_HTTP_METHODS } from "convex/server"; import { afterEach, describe, expect, test, vi } from "vite-plus/test"; +import { siteConfig } from "../cli/site-config.js"; +import type { Config } from "../component/lib.js"; import { internal } from "../component/_generated/api.js"; import schema from "../component/schema.js"; import { routeAll } from "./index.js"; +import { buildSiteFiles, MARK_HEADER, type Site } from "./manifest.js"; const modules = import.meta.glob(["../component/**/*.ts", "!../component/**/*.test.ts"]); /** The component's public functions, as an app reaches them through `components.hosting`. */ -const component = { lib: { route: anyApi.lib.route, markLive: anyApi.lib.markLive } }; +const component = { lib: { markLive: anyApi.lib.markLive } }; -/** Version `v1` with `/index.html` and `config`, and version `v2`, still uploading. */ -async function setup(config = "{}") { +const CLOUD_URL = "https://example.convex.cloud"; + +/** + * Version `v1` with `/index.html` and `config`, ready, and its site as the upload writes it. The + * site's action runs in an HTTP action, an action context where `fetch` is allowed; convex-test + * refuses `fetch` in `t.run`, which is a mutation. The response comes back as its parts, with the + * number of functions that the action called. + */ +async function setup(config: Config = {}) { // `markLive` schedules `collect`; the tests run it with `finish`. vi.useFakeTimers(); + vi.stubEnv("CONVEX_CLOUD_URL", CLOUD_URL); const t = convexTest(schema, modules); - const entry = { path: "/index.html", body: "

Home

" }; - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(entry.body)); + const body = "

Home

"; + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); const sha256 = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join( "", ); - const createVersion = async (versionId: string) => { - const configId = await t.run((ctx) => ctx.storage.store(new Blob([config]))); - await t.action(internal.lib.createVersion, { versionId, configId }); - }; - await createVersion("v1"); - const storageId = await t.run((ctx) => ctx.storage.store(new Blob([entry.body]))); + const configId = await t.run((ctx) => ctx.storage.store(new Blob([JSON.stringify(config)]))); + await t.action(internal.lib.createVersion, { versionId: "v1", configId }); + const storageId = await t.run((ctx) => ctx.storage.store(new Blob([body]))); + const entry = { path: "/index.html", sha256, contentType: "text/html" }; await t.mutation(internal.lib.recordFiles, { versionId: "v1", - entries: [{ path: entry.path, sha256, contentType: "text/html", storageId }], + entries: [{ ...entry, storageId }], }); await t.mutation(internal.lib.finishVersion, { versionId: "v1" }); - await createVersion("v2"); - // The site's action runs in an HTTP action, an action context where `fetch` is allowed; - // convex-test refuses `fetch` in `t.run`, which is a mutation. The response comes back as its - // parts, with the number of mutations that the action called. - const serve = (path: string, versionId = "v1", render?: () => Promise) => + const site: Site = { + format: 1, + versionId: "v1", + markToken: "token-1", + files: await buildSiteFiles(CLOUD_URL, siteConfig(config), [ + { ...entry, url: `${CLOUD_URL}/api/storage/${storageId}` }, + ]), + }; + + const serve = ( + path: string, + options: { + site?: Site; + render?: () => Promise; + headers?: Record; + method?: string; + } = {}, + ) => t.action(async (ctx) => { const runMutation = vi.spyOn(ctx, "runMutation"); + const runQuery = vi.spyOn(ctx, "runQuery"); const url = `https://example.convex.site${path}`; - const worker = render === undefined ? undefined : { fetch: render }; - const site = routeAll(httpRouter(), component, versionId, worker); + const worker = options.render === undefined ? undefined : { fetch: options.render }; + const action = routeAll(httpRouter(), component, options.site ?? site, worker); + const request = new Request(url, { method: options.method, headers: options.headers }); // @ts-expect-error httpActionGeneric keeps the function as _handler; PublicHttpAction does not declare it. - const response: Response = await site._handler(ctx, new Request(url)); + const response: Response = await action._handler(ctx, request); return { - mutations: runMutation.mock.calls.length, + calls: runMutation.mock.calls.length + runQuery.mock.calls.length, status: response.status, contentType: response.headers.get("content-type"), cacheControl: response.headers.get("cache-control"), @@ -53,37 +77,39 @@ async function setup(config = "{}") { body: await response.text(), }; }); - const state = (versionId: string) => + const state = () => t.run( async (ctx) => ( await ctx.db .query("versions") - .withIndex("by_versionId", (q) => q.eq("versionId", versionId)) + .withIndex("by_versionId", (q) => q.eq("versionId", "v1")) .unique() )?.state.kind, ); const finish = () => t.finishAllScheduledFunctions(vi.runAllTimers); - return { t, serve, state, finish }; + return { site, serve, state, finish }; } afterEach(() => { vi.unstubAllGlobals(); + vi.unstubAllEnvs(); vi.useRealTimers(); }); describe("routeAll", () => { - test("routes the action for every method Convex routes, at every path, and returns it", () => { + test("routes the action for every method Convex routes, at every path, and returns it", async () => { + const { site } = await setup(); const http = httpRouter(); - const site = routeAll(http, component, "v1"); + const action = routeAll(http, component, site); for (const method of ROUTABLE_HTTP_METHODS) { - expect(http.lookup("/any/path", method)).toEqual([site, method, "/*"]); + expect(http.lookup("/any/path", method)).toEqual([action, method, "/*"]); } }); }); describe("the site's action", () => { - test("answers a hit with the stored body and the handler's headers", async () => { + test("answers a hit with the stored body and the handler's headers, and calls no function", async () => { const fetchStorage = vi.fn(async () => new Response("

Home

")); vi.stubGlobal("fetch", fetchStorage); const hit = await (await setup()).serve("/"); @@ -91,64 +117,66 @@ describe("the site's action", () => { expect(hit.contentType).toBe("text/html"); expect(hit.body).toBe("

Home

"); expect(fetchStorage).toHaveBeenCalledOnce(); + expect(hit.calls).toBe(0); }); - test("the first request marks the version live; a later request makes no mutation call", async () => { - vi.stubGlobal("fetch", async () => new Response("

Home

")); - const { serve, state, finish } = await setup(); - expect(await state("v1")).toBe("ready"); - const first = await serve("/"); - expect(first.mutations).toBe(1); - expect(first.status).toBe(200); - expect(await state("v1")).toBe("live"); - const later = await serve("/"); - expect(later.mutations).toBe(0); - expect(later.status).toBe(200); + test("the request with the site's mark token marks the version live and answers the result", async () => { + const { site, serve, state, finish } = await setup(); + const render = vi.fn(async () => new Response("page")); + const marked = await serve("/.convex-hosting/mark", { + render, + method: "POST", + headers: { [MARK_HEADER]: site.markToken }, + }); + expect(marked.calls).toBe(1); + expect(JSON.parse(marked.body)).toEqual({ versionId: "v1", result: "marked" }); + expect(marked.cacheControl).toBe("no-store"); + expect(render).not.toHaveBeenCalled(); + expect(await state()).toBe("live"); + const again = await serve("/", { headers: { [MARK_HEADER]: site.markToken } }); + expect(JSON.parse(again.body)).toEqual({ versionId: "v1", result: "live" }); await finish(); - expect(await state("v1")).toBe("live"); + expect(await state()).toBe("live"); }); - test("concurrent first requests all mark the version live, and all answer", async () => { + test("a request with another mark token is an ordinary request, which calls no function", async () => { vi.stubGlobal("fetch", async () => new Response("

Home

")); - const { serve, state, finish } = await setup(); - const answers = await Promise.all([serve("/"), serve("/"), serve("/missing")]); - expect(answers.map(({ status }) => status)).toEqual([200, 200, 404]); - await finish(); - expect(await state("v1")).toBe("live"); + const { serve, state } = await setup(); + const other = await serve("/", { headers: { [MARK_HEADER]: "guess" } }); + expect(other.status).toBe(200); + expect(other.body).toBe("

Home

"); + expect(other.calls).toBe(0); + expect(await state()).toBe("ready"); }); - test("answers 404 for a version that is being deleted, and does not mark it", async () => { - const { t, serve } = await setup(); - await t.run(async (ctx) => { - const version = await ctx.db - .query("versions") - .withIndex("by_versionId", (q) => q.eq("versionId", "v1")) - .unique(); - if (version !== null) - await ctx.db.patch("versions", version._id, { state: { kind: "deleting" } }); - }); - const deleting = await serve("/"); - expect(deleting.status).toBe(404); - expect(deleting.body).toBe("Version v1 of the site is being deleted."); - expect(deleting.cacheControl).toBe("no-store"); - expect(deleting.mutations).toBe(0); + test("a first install's site, before its upload, answers 404 naming the version, without rendering", async () => { + const { site, serve } = await setup(); + const render = vi.fn(async () => new Response("page")); + const early = await serve("/", { site: { ...site, files: null }, render }); + expect(early.status).toBe(404); + expect(early.body).toBe("Version v1 of the site is not uploaded yet."); + expect(early.cacheControl).toBe("no-store"); + expect(render).not.toHaveBeenCalled(); }); - test("answers 404 naming a version that does not exist or is uploading, without rendering", async () => { - const { serve } = await setup(); + test("a site uploaded to another deployment answers 404 naming it, without rendering", async () => { + const { site, serve } = await setup(); + vi.stubEnv("CONVEX_CLOUD_URL", "https://other-dog-456.convex.cloud"); const render = vi.fn(async () => new Response("page")); - const missing = await serve("/", "v3", render); - expect(missing.status).toBe(404); - expect(missing.body).toContain("v3"); - expect(missing.cacheControl).toBe("no-store"); - const uploading = await serve("/", "v2", render); - expect(uploading.status).toBe(404); - expect(uploading.body).toContain("v2"); - expect(uploading.cacheControl).toBe("no-store"); - expect(missing.mutations + uploading.mutations).toBe(0); + const elsewhere = await serve("/", { site, render }); + expect(elsewhere.status).toBe(404); + expect(elsewhere.body).toContain(`was uploaded to ${CLOUD_URL}, not to this deployment`); expect(render).not.toHaveBeenCalled(); }); + test("a site of another format answers 500 and asks for a deploy", async () => { + const { site, serve } = await setup(); + // A version file that another release wrote. + const answer = await serve("/", { site: { ...site, format: 0 } }); + expect(answer.status).toBe(500); + expect(answer.body).toContain("Deploy again."); + }); + test("answers 404 when storage no longer has the file, and 502 for other failures", async () => { const { serve } = await setup(); vi.stubGlobal("fetch", async () => new Response(null, { status: 404 })); @@ -170,19 +198,26 @@ describe("the site's action", () => { test("answers a file without rendering", async () => { vi.stubGlobal("fetch", async () => new Response("

Home

")); const render = vi.fn(async () => new Response("page")); - const file = await (await setup()).serve("/", "v1", render); + const file = await (await setup()).serve("/", { render }); expect(file.status).toBe(200); expect(file.cacheControl).toBe("public, max-age=0, must-revalidate"); expect(file.body).toBe("

Home

"); expect(render).not.toHaveBeenCalled(); }); + test("a redirect downloads nothing", async () => { + const fetchStorage = vi.fn(async () => new Response("

Home

")); + vi.stubGlobal("fetch", fetchStorage); + const { serve } = await setup(); + const redirect = await serve("/index.html"); + expect(redirect.status).toBe(307); + expect(fetchStorage).not.toHaveBeenCalled(); + }); + test("answers a rendered page with no-store and keeps its other headers", async () => { const { serve } = await setup(); - const page = await serve( - "/todos", - "v1", - async () => + const page = await serve("/todos", { + render: async () => new Response("

Todos

", { status: 200, headers: [ @@ -191,11 +226,12 @@ describe("the site's action", () => { ["Set-Cookie", "b=2"], ], }), - ); + }); expect(page.status).toBe(200); expect(page.cacheControl).toBe("no-store"); expect(page.setCookie).toEqual(["a=1", "b=2"]); expect(page.body).toBe("

Todos

"); + expect(page.calls).toBe(0); }); test("answers a miss without render with 404 and no-store", async () => { @@ -206,16 +242,18 @@ describe("the site's action", () => { test("without render, the single-page fallback answers a request that is not a navigation", async () => { vi.stubGlobal("fetch", async () => new Response("

Home

")); - const spa = JSON.stringify({ not_found_handling: "single-page-application" }); - const page = await (await setup(spa)).serve("/about"); + const page = await ( + await setup({ not_found_handling: "single-page-application" }) + ).serve("/about"); expect(page.status).toBe(200); expect(page.body).toBe("

Home

"); }); test("with render, a request that is not a navigation and matches no file is rendered", async () => { - const spa = JSON.stringify({ not_found_handling: "single-page-application" }); const render = vi.fn(async () => new Response("

About

")); - const page = await (await setup(spa)).serve("/about", "v1", render); + const page = await ( + await setup({ not_found_handling: "single-page-application" }) + ).serve("/about", { render }); expect(render).toHaveBeenCalledOnce(); expect(page.status).toBe(200); expect(page.body).toBe("

About

"); diff --git a/packages/convex-hosting/src/client/index.ts b/packages/convex-hosting/src/client/index.ts index ee496493..3699c9da 100644 --- a/packages/convex-hosting/src/client/index.ts +++ b/packages/convex-hosting/src/client/index.ts @@ -2,21 +2,38 @@ import "./runtime.js"; import { httpActionGeneric, ROUTABLE_HTTP_METHODS, - type GenericActionCtx, - type GenericDataModel, type HttpRouter, type PublicHttpAction, } from "convex/server"; import type { ComponentApi } from "../component/_generated/component.js"; +import { Analytics } from "../workers-sdk/packages/workers-shared/asset-worker/src/analytics.js"; +import { + canFetch, + handleRequest, +} from "../workers-sdk/packages/workers-shared/asset-worker/src/handler.js"; +import { mockJaegerBinding } from "../workers-sdk/packages/workers-shared/utils/tracing.js"; +import { + lookup, + MARK_HEADER, + SITE_FORMAT, + storageUrl, + type ManifestHit, + type Site, + type SiteFiles, +} from "./manifest.js"; + +export type { Site } from "./manifest.js"; /** - * The HTTP action that serves the site, for `routeAll`: it answers a request with the file of - * version `versionId` (another method than GET or HEAD on a file answers 405), else with what - * `worker` answers, else 404. `worker` is the Worker script, the object with `fetch(request)` - * that the app's server entry exports: the code that runs on a miss. As on Cloudflare, the presence - * of code decides how `not_found_handling` applies: with `worker`, it applies to navigations only - * and `worker` answers the other misses; without it, the site is files only, so it applies to every - * request. + * The HTTP action that serves the site, for `routeAll`: it answers a request with the file of the + * site (another method than GET or HEAD on a file answers 405), else with what `worker` answers, + * else 404. `worker` is the Worker script, the object with `fetch(request)` that the app's server + * entry exports: the code that runs on a miss. As on Cloudflare, the presence of code decides how + * `not_found_handling` applies: with `worker`, it applies to navigations only and `worker` answers + * the other misses; without it, the site is files only, so it applies to every request. + * + * The site's files are in the pushed code, so a request calls no function of the component: a file + * costs this action and the download of its bytes, any other answer this action alone. * * A page and a 404 answer `Cache-Control: no-store`. The deployment's Cloudflare front keeps that * for a path without an extension and replaces it with a four-hour browser `max-age` for a path @@ -25,13 +42,38 @@ import type { ComponentApi } from "../component/_generated/component.js"; */ function serveSite( component: ComponentApi, - versionId: string, + site: Site, worker?: { fetch(request: Request): Promise }, ): PublicHttpAction { return httpActionGeneric(async (ctx, request) => { - const asset = await answer(ctx, component, request, versionId, worker !== undefined); - if (asset !== null) return asset; - // `route` answers every files-only request itself, so this 404 only fails closed. + if (site.format !== SITE_FORMAT) { + return notServed( + 500, + `.convex-hosting/version.js has format ${site.format}, and this release of ` + + `@samebase/convex-hosting reads format ${SITE_FORMAT}. Deploy again.`, + ); + } + if (request.headers.get(MARK_HEADER) === site.markToken) { + const result = await ctx.runMutation(component.lib.markLive, { versionId: site.versionId }); + return Response.json({ versionId: site.versionId, result }, { headers: NO_STORE }); + } + const { files } = site; + // A first install pushes before its upload; the deploy pushes again when the upload ends. + if (files === null) { + return notServed(404, `Version ${site.versionId} of the site is not uploaded yet.`); + } + // The storage URLs name the deployment they were taken from. + if (files.cloudUrl !== process.env.CONVEX_CLOUD_URL) { + return notServed( + 404, + `Version ${site.versionId} of the site was uploaded to ${files.cloudUrl}, not to this ` + + `deployment. Deploy to this deployment with convex-hosting deploy.`, + ); + } + + const asset = await answer(files, request, worker !== undefined); + if (asset !== null) return await withBody(files, asset); + // `answer` answers every files-only request itself, so this 404 only fails closed. if (worker === undefined) return new Response(null, { status: 404, headers: NO_STORE }); const page = await worker.fetch(request); const headers = new Headers(page.headers); @@ -52,88 +94,90 @@ function serveSite( export function routeAll( http: HttpRouter, component: ComponentApi, - versionId: string, + site: Site, worker?: { fetch(request: Request): Promise }, ): PublicHttpAction { - const site = serveSite(component, versionId, worker); + const action = serveSite(component, site, worker); for (const method of ROUTABLE_HTTP_METHODS) { - http.route({ pathPrefix: "/", method, handler: site }); + http.route({ pathPrefix: "/", method, handler: action }); } - return site; + return action; } +/** An answer of Cloudflare's handler, and the stored file of its body, if it has one. */ +export type Asset = { status: number; headers: Headers; file: number | null }; + /** - * Answers `request` with the asset of version `versionId` that Cloudflare's asset handler picks, - * or returns `null` when no asset matches. `hasUserWorker` is Cloudflare's `has_user_worker`. - * - * A version that does not exist, is still uploading, or is being deleted answers 404, so a - * half-installed site does not render pages without their files. The first request for a `ready` - * version marks it live, which deletes the versions that were live before it; a version older than - * the live one is never marked. + * Runs Cloudflare's asset handler for `request` against the site's files, or returns `null` when no + * asset answers. `hasUserWorker` is Cloudflare's `has_user_worker`: whether the app has code that + * answers a miss. With it, Cloudflare's router asks `canFetch` first, which keeps + * `not_found_handling` for navigations only, and the app answers the other misses. Without it, + * every request goes to `handleRequest`, so `not_found_handling` applies to all of them, and an + * asset always answers. */ -async function answer( - ctx: Pick, "runQuery" | "runMutation">, - component: ComponentApi, +export async function answer( + files: SiteFiles, request: Request, - versionId: string, hasUserWorker: boolean, -): Promise { - const { state, asset } = await ctx.runQuery(component.lib.route, { - versionId, - method: request.method, - url: request.url, - headers: handlerHeaders(request.headers), - hasUserWorker, - }); - if (state === null || state === "uploading" || state === "deleting") { - const problem = - state === null - ? "does not exist" - : state === "uploading" - ? "is still uploading" - : "is being deleted"; - return new Response(`Version ${versionId} of the site ${problem}.`, { - status: 404, - headers: NO_STORE, - }); - } - // Only the pushed code knows which version the deployment runs, so its first request reports it. - if (state === "ready") { - await ctx.runMutation(component.lib.markLive, { versionId }); - } - if (asset === null) return null; +): Promise { + const env = { JAEGER: mockJaegerBinding() }; + // `exists` returns an ETag; `getByETag` gets the entry back for that ETag. The ETag is the content + // hash and a short hash of the content type, so identical bytes under two types stay distinct. + const found = new Map(); + const exists = async (pathname: string) => { + const hit = await lookup(files, pathname); + if (hit === null) return null; + const eTag = hit.contentHash + (await shortHash(hit.contentType ?? "")); + found.set(eTag, hit); + return eTag; + }; + let body: ManifestHit | undefined; + const getByETag = async (eTag: string) => { + body = found.get(eTag); + if (body === undefined) throw new Error(`No entry has the ETag ${eTag}.`); + return { + // `withBody` replaces this placeholder with the stored file. + readableStream: new ReadableStream(), + contentType: body.contentType, + cacheStatus: "MISS" as const, + }; + }; - const headers = new Headers(); - for (const { name, value } of asset.headers) headers.append(name, value); - if (asset.bodyUrl === null) return new Response(null, { status: asset.status, headers }); + if (hasUserWorker && !(await canFetch(request, env, files.config, exists))) return null; + const response = await handleRequest( + request, + env, + files.config, + exists, + getByETag, + new Analytics(), + ); + // It describes Cloudflare's cache, which does not exist here. + response.headers.delete("CF-Cache-Status"); + // The deployment's Cloudflare front caches 404 answers on static paths. + if (response.status === 404) response.headers.set("Cache-Control", "no-store"); + return { + status: response.status, + headers: response.headers, + file: response.body !== null && body !== undefined ? body.file : null, + }; +} +/** The response of `asset`, with the stored file as its body when it has one. */ +async function withBody(files: SiteFiles, asset: Asset): Promise { + if (asset.file === null) + return new Response(null, { status: asset.status, headers: asset.headers }); // An app cannot read a component's storage, so the body comes from the storage URL. let stored: Response; try { - stored = await fetch(asset.bodyUrl); + stored = await fetch(storageUrl(files.storage, asset.file)); } catch { - return badGateway(); + return new Response(null, { status: 502, headers: NO_STORE }); } - // A deploy deleted the file between the query and the fetch. + // A deploy deleted the file: this code was replaced, and a later version's mark deleted it. if (stored.status === 404) return new Response(null, { status: 404, headers: NO_STORE }); - if (!stored.ok) return badGateway(); - return new Response(stored.body, { status: asset.status, headers }); -} - -/** - * The request headers that Cloudflare's handler reads. It reads only the presence of - * `Authorization` and `Range`, so their values (a credential, for one) stay out of the query. - */ -function handlerHeaders(headers: Headers): Record { - const picked: Record = {}; - for (const name of ["if-none-match", "sec-fetch-mode"]) { - const value = headers.get(name); - if (value !== null) picked[name] = value; - } - for (const name of ["authorization", "range"]) { - if (headers.has(name)) picked[name] = ""; - } - return picked; + if (!stored.ok) return new Response(null, { status: 502, headers: NO_STORE }); + return new Response(stored.body, { status: asset.status, headers: asset.headers }); } /** @@ -143,6 +187,15 @@ function handlerHeaders(headers: Headers): Record { */ const NO_STORE = { "Cache-Control": "no-store" }; -function badGateway() { - return new Response(null, { status: 502, headers: NO_STORE }); +/** A site that cannot serve this request, named in the body. */ +function notServed(status: number, message: string) { + return new Response(message, { status, headers: NO_STORE }); +} + +/** The first 8 hex digits of the SHA-256 of `text`. */ +async function shortHash(text: string) { + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)); + return Array.from(new Uint8Array(digest, 0, 4), (byte) => + byte.toString(16).padStart(2, "0"), + ).join(""); } diff --git a/packages/convex-hosting/src/client/manifest.test.ts b/packages/convex-hosting/src/client/manifest.test.ts new file mode 100644 index 00000000..acbf4938 --- /dev/null +++ b/packages/convex-hosting/src/client/manifest.test.ts @@ -0,0 +1,137 @@ +import { describe, expect, test } from "vite-plus/test"; +import { siteConfig } from "../cli/site-config.js"; +import { buildSiteFiles, lookup, storageUrl, type SiteEntry, type SiteFiles } from "./manifest.js"; + +const CLOUD_URL = "https://happy-cat-123.convex.cloud"; +const config = siteConfig({}); + +async function sha256Hex(text: string) { + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)); + return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); +} + +/** A storage URL as Convex makes them, with a key of the given length. */ +function url(key: string) { + return `${CLOUD_URL}/api/storage/${key}?component=m026ambq8g7g5yxf42tb4d4tfx8hg303`; +} + +/** `count` entries with distinct bytes; every third shares the bytes of the one before. */ +async function entries(count: number, paths = (i: number) => `/assets/chunk-${i}.js`) { + const list: SiteEntry[] = []; + for (let i = 0; i < count; i++) { + const body = `body ${i - (i % 3 === 2 ? 1 : 0)}`; + const sha256 = await sha256Hex(body); + list.push({ + path: paths(i), + sha256, + contentType: i % 5 === 4 ? undefined : i % 2 === 0 ? "text/javascript" : "text/html", + url: url(sha256.slice(0, 36)), + }); + } + return list; +} + +/** + * The reference reader: it decodes the whole manifest and reads every entry into a map by path + * hash, the plain way, which `lookup` must agree with for every path and every miss. + */ +async function reference(files: SiteFiles) { + const bytes = Uint8Array.from(atob(files.manifest), (char) => char.charCodeAt(0)); + const view = new DataView(bytes.buffer); + const hex = (from: number, to: number) => + Array.from(bytes.subarray(from, to), (byte) => byte.toString(16).padStart(2, "0")).join(""); + const byPathHash = new Map(); + for (let offset = 20; offset < bytes.length; offset += 40) { + const contentType = view.getUint16(offset + 36); + byPathHash.set(hex(offset, offset + 16), { + contentHash: hex(offset + 16, offset + 32), + file: view.getUint32(offset + 32), + contentType: contentType === 0xffff ? undefined : files.contentTypes[contentType], + }); + } + return async (path: string) => byPathHash.get((await sha256Hex(path)).slice(0, 32)) ?? null; +} + +describe("buildSiteFiles and lookup", () => { + test("every path finds its entry, and the reference reader agrees, at every size up to 64", async () => { + // Entries start 20 + 40i bytes in, so successive sizes put entries at every base64 alignment. + for (let count = 0; count <= 64; count++) { + const list = await entries(count); + const files = await buildSiteFiles(CLOUD_URL, config, list); + const read = await reference(files); + for (const entry of list) { + const hit = await lookup(files, entry.path); + expect(hit).toEqual(await read(entry.path)); + expect(hit).toEqual({ + contentHash: entry.sha256.slice(0, 32), + file: hit?.file, + contentType: entry.contentType, + }); + expect(storageUrl(files.storage, hit?.file ?? -1)).toBe(entry.url); + } + expect(await lookup(files, "/assets/missing.js")).toBeNull(); + } + }); + + test("paths with Unicode, spaces, and percent signs are found as the handler decodes them", async () => { + const paths = [ + "/café/menu.html", + "/a b/c.txt", + "/100%.html", + "/日本語/索引.html", + "/emoji/🙂.svg", + ]; + const list = await entries(paths.length, (i) => paths[i]); + const files = await buildSiteFiles(CLOUD_URL, config, list); + for (const path of paths) expect(await lookup(files, path)).not.toBeNull(); + expect(await lookup(files, "/caf%C3%A9/menu.html")).toBeNull(); + }); + + test("a large site: 5,000 entries all found, and misses miss", async () => { + const list = await entries(5000); + const files = await buildSiteFiles(CLOUD_URL, config, list); + const read = await reference(files); + for (const entry of list.filter((_, i) => i % 97 === 0)) { + expect(await lookup(files, entry.path)).toEqual(await read(entry.path)); + } + for (let i = 5000; i < 5100; i++) + expect(await lookup(files, `/assets/chunk-${i}.js`)).toBeNull(); + }); + + test("paths with the same bytes share one stored file and keep their own content types", async () => { + const sha256 = await sha256Hex("same"); + const files = await buildSiteFiles(CLOUD_URL, config, [ + { path: "/a.txt", sha256, contentType: "text/plain", url: url("k1") }, + { path: "/a.js", sha256, contentType: "text/javascript", url: url("k1") }, + ]); + const txt = await lookup(files, "/a.txt"); + const js = await lookup(files, "/a.js"); + expect(txt?.file).toBe(js?.file); + expect(txt?.contentHash).toBe(js?.contentHash); + expect([txt?.contentType, js?.contentType]).toEqual(["text/plain", "text/javascript"]); + // One stored file: its whole URL is the shared part. + expect(files.storage).toEqual({ prefix: url("k1"), suffix: "", width: 0, keys: "" }); + expect(storageUrl(files.storage, txt?.file ?? -1)).toBe(url("k1")); + }); + + test("storage keys of different lengths are padded, and every URL is rebuilt exactly", async () => { + const keys = ["a", "bcd", "efghij", "klmnopqrstuvwxyz0123456789abcdef0123"]; + const list = await entries(keys.length); + keys.forEach((key, i) => (list[i].url = url(key))); + const files = await buildSiteFiles(CLOUD_URL, config, list); + expect(files.storage.prefix).toBe(`${CLOUD_URL}/api/storage/`); + expect(files.storage.suffix).toBe("?component=m026ambq8g7g5yxf42tb4d4tfx8hg303"); + for (const entry of list) { + const hit = await lookup(files, entry.path); + expect(storageUrl(files.storage, hit?.file ?? -1)).toBe(entry.url); + } + }); + + test("a site with one file or no file", async () => { + const [one] = await entries(1); + const single = await buildSiteFiles(CLOUD_URL, config, [one]); + expect(storageUrl(single.storage, (await lookup(single, one.path))?.file ?? -1)).toBe(one.url); + const empty = await buildSiteFiles(CLOUD_URL, config, []); + expect(await lookup(empty, "/index.html")).toBeNull(); + }); +}); diff --git a/packages/convex-hosting/src/client/manifest.ts b/packages/convex-hosting/src/client/manifest.ts new file mode 100644 index 00000000..0a607f88 --- /dev/null +++ b/packages/convex-hosting/src/client/manifest.ts @@ -0,0 +1,267 @@ +import type { NormalizedAssetConfig } from "../workers-sdk/packages/workers-shared/asset-worker/src/types.js"; +import { + CONTENT_HASH_OFFSET, + CONTENT_HASH_SIZE, + ENTRY_SIZE, + HEADER_SIZE, + PATH_HASH_OFFSET, + PATH_HASH_SIZE, +} from "../workers-sdk/packages/workers-shared/utils/constants.js"; + +/** + * The format of `Site`. `serveSite` refuses a site of another format, which only a deploy with + * another release of this package writes. + */ +export const SITE_FORMAT = 1; + +/** + * The header with which the CLI, after the push, asks the served code to mark its version live. Its + * value is the site's `markToken`; a request without it is an ordinary request. + */ +export const MARK_HEADER = "Convex-Hosting-Mark"; + +/** The path of that request, which names it in logs; the header alone decides. */ +export const MARK_PATH = "/.convex-hosting/mark"; + +/** + * The site that one deploy pushes, as `.convex-hosting/version.js` exports it: the version's id, + * and everything that serving reads, so that a request reads no database. `files` is `null` in the + * code that a first install pushes before its upload, which serves nothing. + */ +export type Site = { + /** `SITE_FORMAT` of the release that wrote it. */ + format: number; + versionId: string; + /** + * The CLI sends it after the push, so that only the CLI makes the served code mark its version + * live; another request with the header pays nothing more than any other request. + */ + markToken: string; + files: SiteFiles | null; +}; + +export type SiteFiles = { + /** The deployment's `CONVEX_CLOUD_URL` at the upload: the origin of every storage URL. */ + cloudUrl: string; + /** Cloudflare's normalized `AssetConfig` for the version, as its handler takes it. */ + config: NormalizedAssetConfig; + /** The base64 of the manifest bytes; see `buildSiteFiles`. */ + manifest: string; + /** The content types of the entries, sorted; an entry holds an index into it. */ + contentTypes: string[]; + /** + * The storage URL of each stored file, sorted: `prefix`, then the file's `width` characters of + * `keys`, then `suffix`. Convex's storage URLs of one component share all but the file's key. + */ + storage: { prefix: string; suffix: string; width: number; keys: string }; +}; + +/** One file of a version, as the upload knows it. */ +export type SiteEntry = { + /** The URL path, such as `/assets/index-a1b2.js`. */ + path: string; + /** The hex SHA-256 of the bytes. */ + sha256: string; + contentType: string | undefined; + /** The storage URL of the bytes. */ + url: string; +}; + +/** Where an entry's tail keeps the index of its stored file (a big-endian u32). */ +const FILE_OFFSET = CONTENT_HASH_OFFSET + CONTENT_HASH_SIZE; +/** Where an entry's tail keeps the index of its content type (a big-endian u16). */ +const CONTENT_TYPE_OFFSET = FILE_OFFSET + 4; +/** The content type index of an entry without a content type. */ +const NO_CONTENT_TYPE = 0xffff; + +/** One entry that `lookup` found. */ +export type ManifestHit = { + /** The hex of the manifest's content hash: the first 16 bytes of the SHA-256 of the bytes. */ + contentHash: string; + /** The index of the stored file in `SiteFiles.storage`. */ + file: number; + /** The entry's content type, if it has one. */ + contentType: string | undefined; +}; + +/** The first 16 bytes of the SHA-256 of the UTF-8 of `path`: Cloudflare's path hash. */ +async function hashPath(path: string): Promise { + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(path)); + return new Uint8Array(digest, 0, PATH_HASH_SIZE); +} + +function hexToBytes(hex: string): Uint8Array { + const bytes = new Uint8Array(hex.length / 2); + for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16); + return bytes; +} + +function bytesToHex(bytes: Uint8Array): string { + return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(""); +} + +function compareBytes(a: Uint8Array, b: Uint8Array): number { + for (let i = 0; i < a.length; i++) { + if (a[i] !== b[i]) return a[i] - b[i]; + } + return 0; +} + +/** The position of each value of `values`, which has no repeats. */ +function indexOf(values: string[]): (value: string) => number { + const positions = new Map(values.map((value, index) => [value, index])); + return (value) => { + const position = positions.get(value); + if (position === undefined) throw new Error(`${value} is not in the list it was taken from.`); + return position; + }; +} + +function commonPrefixLength(a: string, b: string): number { + let i = 0; + while (i < a.length && i < b.length && a[i] === b[i]) i++; + return i; +} + +function commonSuffixLength(a: string, b: string): number { + let i = 0; + while (i < a.length && i < b.length && a[a.length - 1 - i] === b[b.length - 1 - i]) i++; + return i; +} + +/** + * The storage URLs as one shared prefix and suffix around one key per file, each key padded with + * spaces to the width of the longest, since a URL has no space. Convex's URLs of one component + * differ only in the file's key, but that is Convex's choice, so the split is computed, and every + * URL is rebuilt from it and compared before it is used. + */ +function compressUrls(urls: string[]): SiteFiles["storage"] { + if (urls.length === 0) return { prefix: "", suffix: "", width: 0, keys: "" }; + let prefixLength = urls[0].length; + for (const url of urls) prefixLength = Math.min(prefixLength, commonPrefixLength(urls[0], url)); + const rests = urls.map((url) => url.slice(prefixLength)); + let suffixLength = rests[0].length; + for (const rest of rests) + suffixLength = Math.min(suffixLength, commonSuffixLength(rests[0], rest)); + const keys = rests.map((rest) => rest.slice(0, rest.length - suffixLength)); + const width = Math.max(...keys.map((key) => key.length)); + const storage = { + prefix: urls[0].slice(0, prefixLength), + suffix: rests[0].slice(rests[0].length - suffixLength), + width, + keys: keys.map((key) => key.padEnd(width, " ")).join(""), + }; + urls.forEach((url, file) => { + if (storageUrl(storage, file) !== url) { + throw new Error(`The storage URL ${url} does not survive its compression.`); + } + }); + return storage; +} + +/** + * Builds the files of a site. The manifest is Cloudflare's: a 20-byte header (zero, unused, as in + * Cloudflare's) and one 40-byte entry per path, sorted by the path hash, so that a lookup is a + * binary search. An entry is the path hash, the content hash, and a tail, which here holds the + * index of the stored file and the index of the content type. + */ +export async function buildSiteFiles( + cloudUrl: string, + config: NormalizedAssetConfig, + entries: SiteEntry[], +): Promise { + const urls = [...new Set(entries.map(({ url }) => url))].sort(); + const contentTypes = [ + ...new Set( + entries.flatMap(({ contentType }) => (contentType === undefined ? [] : [contentType])), + ), + ].sort(); + if (contentTypes.length >= NO_CONTENT_TYPE) + throw new Error("The site has too many content types."); + const fileIndex = indexOf(urls); + const contentTypeIndex = indexOf(contentTypes); + + const hashed = await Promise.all( + entries.map(async (entry) => ({ entry, pathHash: await hashPath(entry.path) })), + ); + hashed.sort((a, b) => compareBytes(a.pathHash, b.pathHash)); + const bytes = new Uint8Array(HEADER_SIZE + hashed.length * ENTRY_SIZE); + const view = new DataView(bytes.buffer); + hashed.forEach(({ entry, pathHash }, i) => { + if (i > 0 && compareBytes(hashed[i - 1].pathHash, pathHash) === 0) { + throw new Error(`${hashed[i - 1].entry.path} and ${entry.path} have the same path hash.`); + } + const offset = HEADER_SIZE + i * ENTRY_SIZE; + bytes.set(pathHash, offset + PATH_HASH_OFFSET); + bytes.set( + hexToBytes(entry.sha256).subarray(0, CONTENT_HASH_SIZE), + offset + CONTENT_HASH_OFFSET, + ); + view.setUint32(offset + FILE_OFFSET, fileIndex(entry.url)); + view.setUint16( + offset + CONTENT_TYPE_OFFSET, + entry.contentType === undefined ? NO_CONTENT_TYPE : contentTypeIndex(entry.contentType), + ); + }); + + let binary = ""; + for (let i = 0; i < bytes.length; i += 0x8000) { + binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000)); + } + return { cloudUrl, config, manifest: btoa(binary), contentTypes, storage: compressUrls(urls) }; +} + +/** + * `length` bytes of the base64 `text` from byte `offset`, decoding only the base64 groups that hold + * them, so that a lookup costs the same for any size of manifest. + */ +function bytesAt(text: string, offset: number, length: number): Uint8Array { + const start = Math.floor(offset / 3); + const end = Math.ceil((offset + length) / 3); + const decoded = atob(text.slice(start * 4, end * 4)); + const bytes = new Uint8Array(length); + for (let i = 0; i < length; i++) bytes[i] = decoded.charCodeAt(offset - start * 3 + i); + return bytes; +} + +/** The number of entries of a base64 manifest. */ +function entryCount(manifest: string): number { + const padding = manifest.endsWith("==") ? 2 : manifest.endsWith("=") ? 1 : 0; + return ((manifest.length / 4) * 3 - padding - HEADER_SIZE) / ENTRY_SIZE; +} + +/** Finds the entry of `path` by binary search over the path hashes, or returns `null`. */ +export async function lookup(files: SiteFiles, path: string): Promise { + const pathHash = await hashPath(path); + let low = 0; + let high = entryCount(files.manifest) - 1; + while (low <= high) { + const middle = (low + high) >> 1; + const offset = HEADER_SIZE + middle * ENTRY_SIZE; + const order = compareBytes( + pathHash, + bytesAt(files.manifest, offset + PATH_HASH_OFFSET, PATH_HASH_SIZE), + ); + if (order < 0) { + high = middle - 1; + } else if (order > 0) { + low = middle + 1; + } else { + const entry = bytesAt(files.manifest, offset, ENTRY_SIZE); + const view = new DataView(entry.buffer); + const contentType = view.getUint16(CONTENT_TYPE_OFFSET); + return { + contentHash: bytesToHex(entry.subarray(CONTENT_HASH_OFFSET, FILE_OFFSET)), + file: view.getUint32(FILE_OFFSET), + contentType: contentType === NO_CONTENT_TYPE ? undefined : files.contentTypes[contentType], + }; + } + } + return null; +} + +/** The storage URL of stored file `file`. */ +export function storageUrl(storage: SiteFiles["storage"], file: number): string { + const key = storage.keys.slice(file * storage.width, (file + 1) * storage.width).trimEnd(); + return storage.prefix + key + storage.suffix; +} diff --git a/packages/convex-hosting/src/client/version-module.d.ts b/packages/convex-hosting/src/client/version-module.d.ts index 696a4ec9..6311b267 100644 --- a/packages/convex-hosting/src/client/version-module.d.ts +++ b/packages/convex-hosting/src/client/version-module.d.ts @@ -3,4 +3,5 @@ // in an ambient context. declare module "*/.convex-hosting/version.js" { export const versionId: string; + export const site: import("./manifest.js").Site; } diff --git a/packages/convex-hosting/src/component/_generated/component.ts b/packages/convex-hosting/src/component/_generated/component.ts index d9bfea95..44e4f586 100644 --- a/packages/convex-hosting/src/component/_generated/component.ts +++ b/packages/convex-hosting/src/component/_generated/component.ts @@ -28,27 +28,7 @@ export type ComponentApi = "mutation", "internal", { versionId: string }, - null, - Name - >; - route: FunctionReference< - "query", - "internal", - { - hasUserWorker: boolean; - headers: Record; - method: string; - url: string; - versionId: string; - }, - { - asset: null | { - bodyUrl: string | null; - headers: Array<{ name: string; value: string }>; - status: number; - }; - state: "uploading" | "ready" | "live" | "deleting" | null; - }, + "marked" | "live" | "superseded" | "uploading" | "deleting" | "missing", Name >; }; diff --git a/packages/convex-hosting/src/component/conformance.test.ts b/packages/convex-hosting/src/component/conformance.test.ts deleted file mode 100644 index aafe1029..00000000 --- a/packages/convex-hosting/src/component/conformance.test.ts +++ /dev/null @@ -1,84 +0,0 @@ -/// -// Cloudflare's own cases for `html_handling` and path encoding, from -// fixtures/workers-shared-asset-config in cloudflare/workers-sdk, run through `route`. Upstream -// runs them against its asset Worker with `exists` mocked; here the files are a version's entries. -import { convexTest } from "convex-test"; -import { describe, expect, test } from "vite-plus/test"; -import type { Config } from "./lib.js"; -import { api, internal } from "./_generated/api.js"; -import schema from "./schema.js"; -import { encodingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/encoding-test-cases.js"; -import { htmlHandlingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/html-handling-test-cases.js"; - -const modules = import.meta.glob(["./**/*.ts", "!./**/*.test.ts"]); - -const ORIGIN = "https://example.convex.site"; - -async function sha256Hex(body: string) { - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); - return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); -} - -/** Uploads `files` as version `versionId`. Each file's body is its own path, so the ETag names it. */ -async function uploadVersion( - t: ReturnType, - versionId: string, - files: string[], - config: Config, -) { - const configId = await t.run((ctx) => ctx.storage.store(new Blob([JSON.stringify(config)]))); - await t.action(internal.lib.createVersion, { versionId, configId }); - const entries = []; - for (const path of files) { - const storageId = await t.run((ctx) => ctx.storage.store(new Blob([path]))); - entries.push({ path, sha256: await sha256Hex(path), storageId }); - } - await t.mutation(internal.lib.recordFiles, { versionId, entries }); - await t.mutation(internal.lib.finishVersion, { versionId }); -} - -/** Requests `path` and follows redirects, as the upstream test's `fetch` does. */ -async function follow(t: ReturnType, versionId: string, path: string) { - let url = ORIGIN + path; - for (let hop = 0; hop < 8; hop++) { - const { asset } = await t.query(api.lib.route, { - versionId, - method: "GET", - url, - headers: {}, - hasUserWorker: false, - }); - if (asset === null) throw new Error(`No asset for ${url}`); - const header = (name: string) => asset.headers.find((h) => h.name === name)?.value; - const location = header("location"); - if (location !== undefined && asset.status >= 300 && asset.status < 400) { - url = new URL(location, url).href; - continue; - } - return { status: asset.status, url, eTag: header("etag"), redirected: hop > 0 }; - } - throw new Error(`Too many redirects from ${path}`); -} - -const suites = [ - { title: "html_handling", suite: htmlHandlingTestCases }, - { title: "encoding", suite: encodingTestCases }, -]; - -describe.each(suites)("$title", ({ suite }) => { - describe.each(suite)("$html_handling", ({ html_handling, cases }) => { - test.each(cases)("$title", async ({ files, requestPath, matchedFile, finalPath }) => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", files, { html_handling, not_found_handling: "none" }); - const response = await follow(t, "v1", requestPath); - if (matchedFile && finalPath) { - expect(response.status).toBe(200); - expect(response.url).toBe(ORIGIN + finalPath); - expect(response.redirected).toBe(requestPath !== finalPath); - expect(response.eTag).toMatch(new RegExp(`^"${await sha256Hex(matchedFile)}`)); - } else { - expect(response.status).toBe(404); - } - }); - }); -}); diff --git a/packages/convex-hosting/src/component/lib.test.ts b/packages/convex-hosting/src/component/lib.test.ts index c67b1262..196512dc 100644 --- a/packages/convex-hosting/src/component/lib.test.ts +++ b/packages/convex-hosting/src/component/lib.test.ts @@ -71,25 +71,8 @@ const site: Files = { "/assets/app-a1.js": { body: "console.log(1)", contentType: "text/javascript; charset=utf-8" }, }; -function route( - t: ReturnType, - versionId: string, - path: string, - headers: Record = {}, - hasUserWorker = true, - method = "GET", -) { - return t.query(api.lib.route, { - versionId, - method, - url: `https://example.convex.site${path}`, - headers, - hasUserWorker, - }); -} - async function markLive(t: ReturnType, versionId: string) { - await t.mutation(api.lib.markLive, { versionId }); + return await t.mutation(api.lib.markLive, { versionId }); } /** The kind of each version's state, and the number of `collect` chains that `markLive` started. */ @@ -104,10 +87,6 @@ async function liveness(t: ReturnType) { })); } -function header(asset: { headers: { name: string; value: string }[] } | null, name: string) { - return asset?.headers.find((h) => h.name === name)?.value; -} - afterEach(() => { vi.useRealTimers(); }); @@ -201,7 +180,7 @@ describe("markLive", () => { vi.useFakeTimers(); const t = convexTest(schema, modules); await uploadVersion(t, "v1", site); - await markLive(t, "v1"); + expect(await markLive(t, "v1")).toBe("marked"); const state = async () => await t.run( async (ctx) => @@ -215,32 +194,31 @@ describe("markLive", () => { const live = await state(); expect(live).toEqual({ kind: "live", at: Date.now() }); vi.advanceTimersByTime(1000); - await markLive(t, "v1"); + expect(await markLive(t, "v1")).toBe("live"); expect(await state()).toEqual(live); - expect((await route(t, "v1", "/")).state).toBe("live"); }); - test("refuses a version that is uploading or does not exist", async () => { + test("does not mark a version that is uploading or does not exist, and says so", async () => { const t = convexTest(schema, modules); await createVersion(t, "v1"); - await expect(markLive(t, "v1")).rejects.toThrow("Version v1 is still uploading."); - await expect(markLive(t, "v2")).rejects.toThrow("Version v2 does not exist."); + expect(await markLive(t, "v1")).toBe("uploading"); + expect(await markLive(t, "v2")).toBe("missing"); + expect((await liveness(t)).versions).toEqual({ v1: "uploading" }); }); - test("an older upload never goes live over a newer one: a stale request's mark is refused", async () => { + test("an older upload never goes live over a newer one: a mark of replaced code is refused", async () => { vi.useFakeTimers(); const t = convexTest(schema, modules); await uploadVersion(t, "a", site); await uploadVersion(t, "b", site); - // B's code replaces A's and its first request marks B live. - await markLive(t, "b"); + // B's code replaces A's, and B's deploy marks B live. + expect(await markLive(t, "b")).toBe("marked"); await t.finishAllScheduledFunctions(vi.runAllTimers); - // A request that started on A's code reaches its mark after that. + // A's mark arrives after that, from an overlapping deploy of A. vi.advanceTimersByTime(1000); - await markLive(t, "a"); + expect(await markLive(t, "a")).toBe("superseded"); expect(await liveness(t)).toEqual({ versions: { a: "ready", b: "live" }, collects: 1 }); await t.finishAllScheduledFunctions(vi.runAllTimers); - expect((await route(t, "b", "/assets/app-a1.js")).asset?.status).toBe(200); expect((await tables(t)).entries).toContain("b/assets/app-a1.js"); }); @@ -265,7 +243,7 @@ describe("markLive", () => { expect((await liveness(t)).versions).toEqual({ b: "live" }); }); - test("two first requests of one version mark it live once", async () => { + test("two marks of one version mark it live once", async () => { vi.useFakeTimers(); const t = convexTest(schema, modules); await uploadVersion(t, "a", site); @@ -373,9 +351,8 @@ describe("collect", () => { const after = await tables(t); expect(after.versions).toEqual([["large", "deleting"]]); expect(after.entries).toHaveLength(1); - // A request between the pages answers 404 and cannot mark the version live. - expect(await route(t, "large", "/0.txt")).toEqual({ state: "deleting", asset: null }); - await expect(markLive(t, "large")).rejects.toThrow("Version large is being deleted."); + // A mark between the pages cannot make the version live. + expect(await markLive(t, "large")).toBe("deleting"); // The next call reads the same version again and ends it. expect(await pendingSteps(t)).toEqual([{ kind: "versions" }]); await runNext(t); @@ -450,164 +427,3 @@ describe("collect", () => { ]); }); }); - -describe("route", () => { - test("a hit has Cloudflare's headers and an ETag; If-None-Match answers 304", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site); - const { state, asset } = await route(t, "v1", "/assets/app-a1.js"); - expect(state).toBe("ready"); - expect(asset?.status).toBe(200); - expect(header(asset, "content-type")).toBe("text/javascript; charset=utf-8"); - expect(header(asset, "cache-control")).toBe("public, max-age=0, must-revalidate"); - expect(header(asset, "cf-cache-status")).toBeUndefined(); - const eTag = header(asset, "etag"); - expect(eTag).toMatch(new RegExp(`^"${await sha256Hex("console.log(1)")}[0-9a-f]{8}"$`)); - expect(asset?.bodyUrl).toEqual(expect.any(String)); - - const revalidated = await route(t, "v1", "/assets/app-a1.js", { "if-none-match": eTag ?? "" }); - expect(revalidated.asset?.status).toBe(304); - expect(revalidated.asset?.bodyUrl).toBeNull(); - }); - - test("the same bytes under two content types have two ETags", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", { - "/a.txt": { body: "same", contentType: "text/plain" }, - "/a.js": { body: "same", contentType: "text/javascript" }, - }); - const txt = await route(t, "v1", "/a.txt"); - const js = await route(t, "v1", "/a.js"); - expect(header(txt.asset, "etag")).not.toBe(header(js.asset, "etag")); - expect(header(js.asset, "content-type")).toBe("text/javascript"); - }); - - test("with code, single-page-application answers navigations only", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site, { not_found_handling: "single-page-application" }); - const navigation = await route(t, "v1", "/settings/profile", { "sec-fetch-mode": "navigate" }); - const index = await route(t, "v1", "/"); - expect(navigation.asset?.status).toBe(200); - expect(header(navigation.asset, "etag")).toBe(header(index.asset, "etag")); - - expect(await route(t, "v1", "/settings/profile")).toEqual({ state: "ready", asset: null }); - }); - - test("without code, single-page-application answers every request, as a files-only Worker", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site, { not_found_handling: "single-page-application" }); - const index = await route(t, "v1", "/"); - // No `Sec-Fetch-Mode`, as from curl, a monitor, or a link-preview bot. - const filesOnly = await route(t, "v1", "/about", {}, false); - expect(filesOnly.asset?.status).toBe(200); - expect(header(filesOnly.asset, "content-type")).toBe("text/html; charset=utf-8"); - expect(header(filesOnly.asset, "etag")).toBe(header(index.asset, "etag")); - // With code, the same request is a miss, which the app answers. - expect(await route(t, "v1", "/about", {}, true)).toEqual({ state: "ready", asset: null }); - }); - - test("without code and with html_handling none, / answers index.html through the fallback", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site, { - html_handling: "none", - not_found_handling: "single-page-application", - }); - const { asset } = await route(t, "v1", "/", {}, false); - const index = await route(t, "v1", "/index.html", {}, false); - expect(asset?.status).toBe(200); - expect(header(asset, "etag")).toBe(header(index.asset, "etag")); - }); - - test("another method than GET or HEAD on a file answers 405; on a miss, the code or 404", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site); - for (const hasUserWorker of [true, false]) { - const post = await route(t, "v1", "/index.html", {}, hasUserWorker, "POST"); - expect(post.asset?.status).toBe(405); - expect(post.asset?.bodyUrl).toBeNull(); - } - expect(await route(t, "v1", "/missing", {}, true, "POST")).toEqual({ - state: "ready", - asset: null, - }); - const miss = await route(t, "v1", "/missing", {}, false, "POST"); - expect(miss.asset?.status).toBe(404); - }); - - test("without code, a miss with not_found_handling none answers 404 with no-store", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site); - const miss = await route(t, "v1", "/missing", {}, false); - expect(miss.asset).toEqual({ - status: 404, - headers: [{ name: "cache-control", value: "no-store" }], - bodyUrl: null, - }); - }); - - test("the custom 404 page answers with its body and no-store", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site, { not_found_handling: "404-page" }); - const { asset } = await route(t, "v1", "/missing", { "sec-fetch-mode": "navigate" }); - expect(asset?.status).toBe(404); - expect(asset?.bodyUrl).toEqual(expect.any(String)); - expect(header(asset, "cache-control")).toBe("no-store"); - const filesOnly = await route(t, "v1", "/missing", {}, false); - expect(filesOnly.asset?.status).toBe(404); - expect(header(filesOnly.asset, "etag")).toBe(header(asset, "etag")); - }); - - test("a file that is gone from storage answers 404 with no-store", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site); - await t.run(async (ctx) => { - const entry = await ctx.db - .query("entries") - .withIndex("by_version_path", (q) => q.eq("versionId", "v1").eq("path", "/index.html")) - .unique(); - if (entry !== null) await ctx.storage.delete(entry.storageId); - }); - expect(await route(t, "v1", "/")).toEqual({ - state: "ready", - asset: { - status: 404, - headers: [{ name: "cache-control", value: "no-store" }], - bodyUrl: null, - }, - }); - }); - - test("a _headers rule applies", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site, { - headers: { - version: 2, - rules: { "/assets/*": { set: { "Cache-Control": "public, max-age=31536000, immutable" } } }, - }, - }); - const { asset } = await route(t, "v1", "/assets/app-a1.js"); - expect(header(asset, "cache-control")).toBe("public, max-age=31536000, immutable"); - }); - - test("a _redirects rule applies", async () => { - const t = convexTest(schema, modules); - await uploadVersion(t, "v1", site, { - redirects: { - version: 1, - staticRules: { "/old": { status: 301, to: "/", lineNumber: 1 } }, - rules: {}, - }, - }); - const { asset } = await route(t, "v1", "/old?x=1"); - expect(asset?.status).toBe(301); - expect(header(asset, "location")).toBe("/?x=1"); - expect(asset?.bodyUrl).toBeNull(); - }); - - test("a version that is uploading or does not exist reports its state", async () => { - const t = convexTest(schema, modules); - await createVersion(t, "v1"); - expect(await route(t, "v1", "/")).toEqual({ state: "uploading", asset: null }); - expect(await route(t, "v2", "/")).toEqual({ state: null, asset: null }); - }); -}); diff --git a/packages/convex-hosting/src/component/lib.ts b/packages/convex-hosting/src/component/lib.ts index f4013592..de36eb89 100644 --- a/packages/convex-hosting/src/component/lib.ts +++ b/packages/convex-hosting/src/component/lib.ts @@ -1,30 +1,16 @@ import { ConvexError, v } from "convex/values"; import { z } from "zod"; -import { Analytics } from "../workers-sdk/packages/workers-shared/asset-worker/src/analytics.js"; -import { normalizeConfiguration } from "../workers-sdk/packages/workers-shared/asset-worker/src/configuration.js"; -import { - canFetch, - handleRequest, -} from "../workers-sdk/packages/workers-shared/asset-worker/src/handler.js"; -import { mockJaegerBinding } from "../workers-sdk/packages/workers-shared/utils/tracing.js"; import { AssetConfigSchema } from "../workers-sdk/packages/workers-shared/utils/types.js"; import { internal } from "./_generated/api.js"; -import type { Doc, Id } from "./_generated/dataModel.js"; +import type { Id } from "./_generated/dataModel.js"; import { internalAction, internalMutation, internalQuery, mutation, - query, type QueryCtx, } from "./_generated/server.js"; -/** - * The compatibility date of Cloudflare's handler. From 2025-04-01 on, Cloudflare applies - * `not_found_handling` to a request with `Sec-Fetch-Mode: navigate` when a Worker exists. - */ -const COMPATIBILITY_DATE = "2025-04-01"; - /** * A version that never became live, and a stored file that no entry references, are garbage once * they are a day old: a failed deploy leaves them, and an upload in progress is younger. This age @@ -247,37 +233,42 @@ export const finishVersion = internalMutation({ }); /** - * Marks a `ready` version `live` and schedules `collect`. `serveSite` calls it at each request that - * finds the version `ready`. An older upload never goes live over a newer one: the mark does nothing - * when a live version was created after this one. So a request that started on replaced code, and - * reaches its lookup or its mark after the new code's first request marked the new version, cannot - * make the old version newest, and `collect` cannot delete the new version's files. A version that - * is already live stays as it is, so concurrent first requests are fine. + * Marks a `ready` version `live` and schedules `collect`, and says what it did. `serveSite` calls + * it for the request that the CLI sends after the push, with the site's mark token, so only the + * code that serves marks its own version. An older upload never goes live over a newer one: the + * mark does nothing when a live version was created after this one. So a request that runs on + * replaced code cannot make the old version newest, and `collect` cannot delete the new version's + * files. A version that is already live stays as it is, so a repeated mark is fine. It never + * throws, so the CLI reads every outcome from the answer. * * Precondition: deploys to one deployment do not overlap. When two overlap and the older upload is - * pushed last, its requests look like requests of replaced code: its version serves but stays + * pushed last, its mark is refused like a mark of replaced code: its version serves but stays * `ready`, and nothing is deleted until the next deploy. */ export const markLive = mutation({ args: { versionId: v.string() }, - returns: v.null(), + returns: v.union( + /** It was `ready` and is now the newest live version. */ + v.literal("marked"), + v.literal("live"), + /** A live version was created after it, so it stays as it is. */ + v.literal("superseded"), + v.literal("uploading"), + v.literal("deleting"), + v.literal("missing"), + ), handler: async (ctx, { versionId }) => { - const version = await getVersionOrThrow(ctx, versionId); - if (version.state.kind === "live") return null; - if (version.state.kind === "uploading") { - throw new ConvexError(`Version ${versionId} is still uploading.`); - } - if (version.state.kind === "deleting") { - throw new ConvexError(`Version ${versionId} is being deleted.`); - } + const version = await getVersion(ctx, versionId); + if (version === null) return "missing"; + if (version.state.kind !== "ready") return version.state.kind; const newest = await getNewestLive(ctx); - if (newest !== null && newest.createdAt > version._creationTime) return null; + if (newest !== null && newest.createdAt > version._creationTime) return "superseded"; // Later than every live `at`, also within one millisecond or when the clock moves back, so that // `at` follows creation order and `collect` deletes the versions live before this one. const at = newest === null ? Date.now() : Math.max(Date.now(), newest.at + 1); await ctx.db.patch("versions", version._id, { state: { kind: "live", at } }); await ctx.scheduler.runAfter(0, internal.lib.collect, { step: { kind: "files" } }); - return null; + return "marked"; }, }); @@ -380,7 +371,7 @@ export const collect = internalMutation({ for (const entry of entries) await ctx.db.delete("entries", entry._id); if (entries.length === budget) { // The version may have more entries: the next call reads it again. Until its row goes, - // it is `deleting`, so that no request serves it or marks it live between the pages. + // it is `deleting`, so that no mark makes it live between the pages. if (state.kind !== "deleting") { await ctx.db.patch("versions", version._id, { state: { kind: "deleting" } }); } @@ -413,130 +404,9 @@ function advance( : { at: document._creationTime, seen: [document._id] }; } -const routeHeaders = v.record(v.string(), v.string()); - -/** - * Runs Cloudflare's asset handler for one request against one version. `state` is the kind of the - * version's state, or `null` when the version does not exist. `asset` is `null` when the version is - * uploading, being deleted, or does not exist, or when no asset answers. - * - * `hasUserWorker` is Cloudflare's `has_user_worker`: whether the app has code that answers a miss. - * With it, Cloudflare's router asks `canFetch` first, which keeps `not_found_handling` for - * navigations only, and the app answers the other misses. Without it, every request goes to - * `handleRequest`, so `not_found_handling` applies to all of them, and an asset always answers. - */ -export const route = query({ - args: { - versionId: v.string(), - method: v.string(), - url: v.string(), - headers: routeHeaders, - hasUserWorker: v.boolean(), - }, - returns: v.object({ - state: v.union( - v.literal("uploading"), - v.literal("ready"), - v.literal("live"), - v.literal("deleting"), - v.null(), - ), - asset: v.union( - v.null(), - v.object({ - status: v.number(), - headers: v.array(v.object({ name: v.string(), value: v.string() })), - /** The storage URL of the body, when the response has one. */ - bodyUrl: v.union(v.string(), v.null()), - }), - ), - }), - handler: async (ctx, { versionId, method, url, headers, hasUserWorker }) => { - const version = await getVersion(ctx, versionId); - if (version === null) return { state: null, asset: null }; - const state = version.state.kind; - if (state === "uploading" || state === "deleting") { - return { state, asset: null }; - } - - const configuration = normalizeConfiguration({ - ...AssetConfigSchema.parse(JSON.parse(version.config)), - compatibility_date: COMPATIBILITY_DATE, - }); - const request = new Request(url, { method, headers }); - const env = { JAEGER: mockJaegerBinding() }; - - // `exists` returns an ETag; `getByETag` gets the entry back for that ETag. - const found = new Map>(); - const exists = async (pathname: string) => { - const entry = await getEntry(ctx, versionId, pathname); - if (entry === null) return null; - const eTag = entry.sha256 + (await shortHash(entry.contentType ?? "")); - found.set(eTag, entry); - return eTag; - }; - let bodyEntry: Doc<"entries"> | undefined; - const getByETag = async (eTag: string) => { - bodyEntry = found.get(eTag); - if (bodyEntry === undefined) throw new Error(`No entry has the ETag ${eTag}.`); - return { - // `serveSite` replaces this placeholder with the stored file. - readableStream: new ReadableStream(), - contentType: bodyEntry.contentType, - cacheStatus: "MISS" as const, - }; - }; - - if (hasUserWorker && !(await canFetch(request, env, configuration, exists))) { - return { state, asset: null }; - } - const response = await handleRequest( - request, - env, - configuration, - exists, - getByETag, - new Analytics(), - ); - // It describes Cloudflare's cache, which does not exist here. - response.headers.delete("CF-Cache-Status"); - // The deployment's Cloudflare front caches 404 answers on static paths. - if (response.status === 404) response.headers.set("Cache-Control", "no-store"); - - let bodyUrl: string | null = null; - if (response.body !== null && bodyEntry !== undefined) { - bodyUrl = await ctx.storage.getUrl(bodyEntry.storageId); - // The file is gone from storage. As in `serveSite` when storage answers 404, the answer must - // not stay in a cache. - if (bodyUrl === null) { - return { - state, - asset: { status: 404, headers: [{ name: "cache-control", value: "no-store" }], bodyUrl }, - }; - } - } - return { - state, - asset: { - status: response.status, - headers: [...response.headers].map(([name, value]) => ({ name, value })), - bodyUrl, - }, - }; - }, -}); - /** Convex's `_storage` table holds the sha256 in base64; entries hold it in hex. */ function base64ToHex(base64: string) { return Array.from(atob(base64), (char) => char.charCodeAt(0).toString(16).padStart(2, "0")).join( "", ); } - -/** The first 8 hex digits of the SHA-256 of `text`. */ -async function shortHash(text: string) { - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)); - return Array.from(new Uint8Array(digest, 0, 4), (byte) => - byte.toString(16).padStart(2, "0"), - ).join(""); -} diff --git a/packages/convex-hosting/src/component/schema.ts b/packages/convex-hosting/src/component/schema.ts index 723b0dae..5415e30e 100644 --- a/packages/convex-hosting/src/component/schema.ts +++ b/packages/convex-hosting/src/component/schema.ts @@ -6,7 +6,7 @@ export default defineSchema({ versions: defineTable({ versionId: v.string(), /** - * `live` carries the time the first request of the version's pushed code marked it live, so a + * `live` carries the time the version's pushed code marked it live, at its deploy's mark, so a * version cannot have a live time without being live. */ state: v.union( @@ -38,7 +38,7 @@ export default defineSchema({ sha256: v.string(), /** * The type belongs to the path, not to the bytes: paths with identical bytes share one stored - * file but keep their own types, and `route` serves without reading `_storage`. Absent when + * file but keep their own types, and the site's manifest carries each type. Absent when * the `mime` package has no type for the file name. */ contentType: v.optional(v.string()), From e4b3e7f6200d165753b23a8f2902d66d3e2ee827 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 01:42:26 +0200 Subject: [PATCH 02/20] Refresh the example patches for routeAll's site argument --- examples/hello-world-assets-only-workers.patch | 6 +++--- examples/tanstack-ssr-workers.patch | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/hello-world-assets-only-workers.patch b/examples/hello-world-assets-only-workers.patch index 24ca5ec4..783ee851 100644 --- a/examples/hello-world-assets-only-workers.patch +++ b/examples/hello-world-assets-only-workers.patch @@ -12,20 +12,20 @@ index 41a6c4afe86dc311eed5da6e75804b73bdc4462f..00000000000000000000000000000000 -export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index 68549db0c7867c3c98d3caae46fb994864126d94..0000000000000000000000000000000000000000 +index f71716a43c9d61ec1f5faf1c1165548296d1386f..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; --import { versionId } from "../.convex-hosting/version.js"; +-import { site } from "../.convex-hosting/version.js"; - -const http = httpRouter(); - -// Every method, every path, as a Cloudflare Worker without a script: a file for a path that has -// one, else 404; another method than GET or HEAD on a file answers 405. --routeAll(http, components.hosting, versionId); +-routeAll(http, components.hosting, site); - -export default http; diff --git a/convex/tsconfig.json b/convex/tsconfig.json diff --git a/examples/tanstack-ssr-workers.patch b/examples/tanstack-ssr-workers.patch index bcfe2650..058a9d89 100644 --- a/examples/tanstack-ssr-workers.patch +++ b/examples/tanstack-ssr-workers.patch @@ -18,14 +18,14 @@ index 1831f4b4fa5703fe1332d9cf45fb2308a57be703..dcc4d5f09735722e1164710651a0c69d export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index 2bd08d55546dfacc4e31f84614c81a5625beee4e..0000000000000000000000000000000000000000 +index a8989b93e04e6fc60bbf5577c7ffc5ea39a4015d..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; --import { versionId } from "../.convex-hosting/version.js"; +-import { site } from "../.convex-hosting/version.js"; -// Type only, nothing is bundled: the server build imported below. -import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; -import server from "../dist/server/server.js"; @@ -35,7 +35,7 @@ index 2bd08d55546dfacc4e31f84614c81a5625beee4e..00000000000000000000000000000000 -// Every method, every path: a file for a path that has one (another method than GET or HEAD on it -// answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with -// static assets does. --const handler = routeAll(http, components.hosting, versionId, server); +-const handler = routeAll(http, components.hosting, site, server); -// Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it -// serves the key set, and the longest prefix wins, so the catch-all above never sees them. -for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { From 9007184db5b59bd4f0be4ab411c748f49fbccf49 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 01:57:29 +0200 Subject: [PATCH 03/20] Review fixes: no redirect for the mark, a large output buffer, no spread 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. --- docs/deploy.md | 18 +++++----- packages/convex-hosting/src/cli/convex.ts | 3 +- packages/convex-hosting/src/cli/main.test.ts | 35 +++++++++++++++++-- packages/convex-hosting/src/cli/main.ts | 2 ++ .../convex-hosting/src/client/manifest.ts | 4 ++- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/docs/deploy.md b/docs/deploy.md index 2277f238..51459a76 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -1,12 +1,14 @@ # Deploy `deploy` runs `npx convex deploy` with your build and the upload of `--dist` as its `--cmd`. The -pushed code names the version it was built with, so the push switches the site. Then the command -prints the site URL, which it asks the deployment for (`CONVEX_SITE_URL`), and ends. The first -request that the new code serves marks its version live, which deletes the versions that were live -before it. A version that never becomes live, from a deploy that failed, is deleted at the first -switch after it is a day old, and the stored files that no version uses go at the switch after that. -Nothing is deleted while a site gets no request. +pushed code carries the version it was built with and that version's files, so the push switches the +site. Then the command reads the site URL from the deployment (`CONVEX_SITE_URL`), sends one request +to it with the version's mark token, which makes the code that answers mark its version live and +delete the versions that were live before it, prints the site URL, and ends. When that request +fails, the deploy still succeeds and says so; the old versions then stay until the next deploy's +mark. A version that never becomes live, from a deploy that failed, is deleted at the first switch +after it is a day old, and the stored files that no version uses go at the switch after that. +Nothing is deleted but at a deploy's mark. `deploy` goes to production. `--preview-name ` sends it to that preview (with a login or a project's preview deploy key; always pass the name with that key), and `--dev` to the development @@ -15,8 +17,8 @@ deployment (see [Development](./development.md)). A deploy key in `CONVEX_DEPLOY plain `deploy`, and so does `CONVEX_SELF_HOSTED_URL` for a self-hosted deployment; `--dev` refuses a key, and `--preview-name` accepts only a preview key, so a production key cannot redirect either. -The first deploy to a deployment pushes the component, then uploads the files. Until that upload -ends, the site answers 404. +The first deploy to a deployment pushes the component, uploads the files, and pushes again. Until +the second push, the site answers 404 naming the version. Run one deploy at a time per deployment; in GitHub Actions, the job's `concurrency` group queues them (see [GitHub Actions](#github-actions)). diff --git a/packages/convex-hosting/src/cli/convex.ts b/packages/convex-hosting/src/cli/convex.ts index 1c6e161a..1163fd54 100644 --- a/packages/convex-hosting/src/cli/convex.ts +++ b/packages/convex-hosting/src/cli/convex.ts @@ -46,7 +46,8 @@ export const nodeCli: Cli = { execFile( process.execPath, [convexBin(process.cwd()), ...args], - { encoding: "utf8" }, + // A page of storage URLs can pass Node's default of 1 MiB. + { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }, (error, stdout, stderr) => { const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : 1; resolve({ exitCode, stdout, stderr }); diff --git a/packages/convex-hosting/src/cli/main.test.ts b/packages/convex-hosting/src/cli/main.test.ts index a505cb9f..9a992973 100644 --- a/packages/convex-hosting/src/cli/main.test.ts +++ b/packages/convex-hosting/src/cli/main.test.ts @@ -72,7 +72,7 @@ function fake( build?: () => Promise; push?: (cli: Cli, args: string[]) => Promise; /** The site's answer to the mark request; by default it marks the version of the file. */ - mark?: (token: string | null) => Promise; + mark?: (token: string | null, init: RequestInit | undefined) => Promise; } = {}, ) { const runs: string[][] = []; @@ -102,9 +102,11 @@ function fake( const code = args[args.indexOf("--inline-query") + 1]; const [, versionId, after] = /q\.eq\("versionId", ("[^"]*")\)\.gt\("path", ("[^"]*")\)/.exec(code) ?? []; + const take = Number(/\.take\((\d+)\)/.exec(code)?.[1]); const files = (recorded.get(JSON.parse(versionId)) ?? []) .filter(({ path }) => path > JSON.parse(after)) .sort((a, b) => (a.path < b.path ? -1 : 1)) + .slice(0, take) .map(({ path, storageId }) => [path, fileUrl(storageId)]); return ok({ cloudUrl: CLOUD_URL, files }); } @@ -152,7 +154,7 @@ function fake( if (url === SITE_URL + MARK_PATH) { events.push("mark"); const token = new Headers(init?.headers).get(MARK_HEADER); - if (options.mark !== undefined) return await options.mark(token); + if (options.mark !== undefined) return await options.mark(token, init); const site = writtenSite(cwd); return token === site.markToken ? Response.json({ versionId: site.versionId, result: "marked" }) @@ -420,6 +422,20 @@ describe("deploy reports", () => { } }); + test("the mark follows no redirect, which would carry the token to another origin", async () => { + const redirects: (RequestRedirect | undefined)[] = []; + const { cli, logs } = fake(app(site), { + push: innerUpload, + mark: async (_token, init) => { + redirects.push(init?.redirect); + return new Response(null, { status: 307, headers: { Location: "https://other.example/" } }); + }, + }); + expect(await main(DEPLOY, cli)).toBe(0); + expect(redirects).toEqual(["manual"]); + expect(logs.some((line) => line.includes("did not answer as version"))).toBe(true); + }); + test("a mark refused because a newer version is live says that deploys overlapped", async () => { const cwd = app(site); const { cli, logs } = fake(cwd, { @@ -677,6 +693,21 @@ describe("upload", () => { expect(readFileSync(join(cwd, ".convex-hosting", ".gitignore"), "utf8")).toBe("*\n"); }); + test("reads the storage URLs a page at a time, and every path finds its stored file", async () => { + const files = Object.fromEntries( + Array.from({ length: 2500 }, (_, i) => [`dist/assets/${i}.js`, `console.log(${i})`]), + ); + const cwd = app(files); + const { cli, calls } = fake(cwd); + expect(await main(upload(), cli)).toBe(0); + expect(calls().filter((name) => name === "urls")).toHaveLength(2); + const written = writtenSite(cwd).files; + if (written === null) throw new Error("The version file has no files."); + for (const i of [0, 1999, 2000, 2499]) { + expect(await lookup(written, `/assets/${i}.js`)).not.toBeNull(); + } + }); + test("does not upload the files that knownFiles knows, and records them with their stored file", async () => { const home = createHash("sha256").update("

Home

").digest("hex"); const { cli, calls, callArgs } = fake(app(site), { known: { [home]: "known-home" } }); diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index 972ff4fe..68021fba 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -573,9 +573,11 @@ async function markServedVersion( const later = `Version ${site.versionId} serves, and the next deploy deletes the files of the versions before it.`; let answer: unknown; try { + // A redirect would carry the token to another origin, so it counts as other code answering. const response = await cli.fetch(url + MARK_PATH, { method: "POST", headers: { [MARK_HEADER]: site.markToken }, + redirect: "manual", }); // Other code answers the path with a page or a 404, which is no mark. answer = response.ok ? await response.json().catch(() => null) : null; diff --git a/packages/convex-hosting/src/client/manifest.ts b/packages/convex-hosting/src/client/manifest.ts index 0a607f88..314bb257 100644 --- a/packages/convex-hosting/src/client/manifest.ts +++ b/packages/convex-hosting/src/client/manifest.ts @@ -144,7 +144,9 @@ function compressUrls(urls: string[]): SiteFiles["storage"] { for (const rest of rests) suffixLength = Math.min(suffixLength, commonSuffixLength(rests[0], rest)); const keys = rests.map((rest) => rest.slice(0, rest.length - suffixLength)); - const width = Math.max(...keys.map((key) => key.length)); + // A loop, since a spread passes one argument per stored file, more than V8 allows on a large site. + let width = 0; + for (const key of keys) width = Math.max(width, key.length); const storage = { prefix: urls[0].slice(0, prefixLength), suffix: rests[0].slice(rests[0].length - suffixLength), From 59a16b265e416d417d8a1cb860b2ca2181dd479a Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 02:20:34 +0200 Subject: [PATCH 04/20] Refuse more than 100,000 files, Cloudflare's limit per Worker version 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. --- docs/deploy.md | 3 ++- docs/design.md | 11 +++++++---- packages/convex-hosting/src/cli/files.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/deploy.md b/docs/deploy.md index 51459a76..8f24f7c7 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -53,7 +53,8 @@ The two handling options work as Each file of `--dist` must be 25 MiB or smaller, and the CLI names a file that is larger. This is Cloudflare's limit per asset, and the HTTP action that serves a file cannot answer more than -Convex's 100 MiB response limit anyway. +Convex's 100 MiB response limit anyway. A site has at most 100,000 files, Cloudflare's limit per +Worker version on its Paid plan. ## Deploy tools and CI diff --git a/docs/design.md b/docs/design.md index 61e420c5..6187df36 100644 --- a/docs/design.md +++ b/docs/design.md @@ -75,7 +75,8 @@ Bristol's production used it while hosting 0.3 and 0.4 ran side by side under tw Wrangler does (a link to nothing, or to a folder that contains it, is skipped with a message; a link to another folder uploads its files under both paths), and computes each file's sha256 and content type; refuses a file above 25 MiB, Cloudflare's limit per asset (the HTTP action - that serves a file could not answer more than Convex's 100 MiB response limit anyway); reads + that serves a file could not answer more than Convex's 100 MiB response limit anyway), and + more than 100,000 files, Cloudflare's limit per Worker version on its Paid plan; reads `_headers` and `_redirects` with Cloudflare's parsers into the version's config; 2. stores the config as one file through an upload URL, because `npx convex run` passes arguments on the command line, which the operating system limits, and a `_redirects` file can be large; @@ -323,9 +324,11 @@ not to the bytes: paths with identical bytes share one stored file but keep thei site's manifest carries each type, so serving reads no `_storage` metadata. Serving does not read `config` either; it makes a retried upload of the same id refuse another config. -The package sets one limit of its own, 25 MiB per file, for the reason above. Convex's limits apply: -1 MiB per document, and the transaction limits (16,000 writes, 32,000 documents scanned, 16 MiB read -and written, 8,192 array elements, 4,096 index ranges, argument and result sizes) shape the batches. +The package sets two limits of its own, Cloudflare's: 25 MiB per file, for the reason above, and +100,000 files per site, the most that the site's files were measured with in the pushed code. +Convex's limits apply: 1 MiB per document, and the transaction limits (16,000 writes, 32,000 +documents scanned, 16 MiB read and written, 8,192 array elements, 4,096 index ranges, argument and +result sizes) shape the batches. ## Orderings and timing diff --git a/packages/convex-hosting/src/cli/files.ts b/packages/convex-hosting/src/cli/files.ts index 41bcc7bb..e7ff818f 100644 --- a/packages/convex-hosting/src/cli/files.ts +++ b/packages/convex-hosting/src/cli/files.ts @@ -10,6 +10,7 @@ import { parseHeaders } from "../workers-sdk/packages/workers-shared/utils/confi import { parseRedirects } from "../workers-sdk/packages/workers-shared/utils/configuration/parseRedirects.js"; import { HEADERS_FILENAME, + MAX_ASSET_COUNT, MAX_ASSET_SIZE, REDIRECTS_FILENAME, } from "../workers-sdk/packages/workers-shared/utils/constants.js"; @@ -72,6 +73,13 @@ export async function readDist( } walk(file); } else if (stats.isFile() && !assetsIgnoreFunction(ignorePath)) { + // Cloudflare's limit per Worker version on its Paid plan, 100,000 files. + if (entries.length === MAX_ASSET_COUNT) { + throw new Error( + `${dist} has more than ${MAX_ASSET_COUNT.toLocaleString("en-US")} files, Cloudflare's ` + + "limit per Worker version. List the files that are not served in .assetsignore.", + ); + } const bytes = readFileSync(file); // Cloudflare's limit per asset, 25 MiB. The HTTP action that serves a file cannot answer // more than Convex's 100 MiB response limit anyway. From 787b8b62799901f029868cd7a622cd08fc422d5f Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 02:31:05 +0200 Subject: [PATCH 05/20] bench: what one request costs on 0.14.0, this branch, and static-hosting 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. --- bench/.gitignore | 3 + bench/README.md | 114 +++++ bench/load.js | 43 ++ bench/report.ts | 68 +++ .../convex-hosting-0.14.0-400-page.json | 48 +++ .../convex-hosting-0.14.0-400-page.k6.json | 221 ++++++++++ .../convex-hosting-0.14.0-400-rendered.json | 48 +++ ...convex-hosting-0.14.0-400-rendered.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-page.json | 47 ++ .../convex-hosting-branch-400-page.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-rendered.json | 47 ++ ...convex-hosting-branch-400-rendered.k6.json | 221 ++++++++++ .../static-hosting-0.2.1-400-page.json | 48 +++ .../static-hosting-0.2.1-400-page.k6.json | 221 ++++++++++ .../convex-hosting-0.14.0-400-asset.json | 48 +++ .../convex-hosting-0.14.0-400-asset.k6.json | 221 ++++++++++ .../convex-hosting-0.14.0-400-page.json | 48 +++ .../convex-hosting-0.14.0-400-page.k6.json | 221 ++++++++++ .../convex-hosting-0.14.0-400-rendered.json | 48 +++ ...convex-hosting-0.14.0-400-rendered.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-asset.json | 47 ++ .../convex-hosting-branch-400-asset.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-page.json | 47 ++ .../convex-hosting-branch-400-page.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-rendered.json | 47 ++ ...convex-hosting-branch-400-rendered.k6.json | 221 ++++++++++ .../static-hosting-0.2.1-400-asset.json | 48 +++ .../static-hosting-0.2.1-400-asset.k6.json | 221 ++++++++++ .../static-hosting-0.2.1-400-page.json | 48 +++ .../static-hosting-0.2.1-400-page.k6.json | 221 ++++++++++ .../convex-hosting-0.14.0-400-asset.json | 48 +++ .../convex-hosting-0.14.0-400-asset.k6.json | 221 ++++++++++ .../convex-hosting-0.14.0-400-page.json | 48 +++ .../convex-hosting-0.14.0-400-page.k6.json | 221 ++++++++++ .../convex-hosting-0.14.0-400-rendered.json | 48 +++ ...convex-hosting-0.14.0-400-rendered.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-asset.json | 47 ++ .../convex-hosting-branch-400-asset.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-page.json | 47 ++ .../convex-hosting-branch-400-page.k6.json | 221 ++++++++++ .../convex-hosting-branch-400-rendered.json | 47 ++ ...convex-hosting-branch-400-rendered.k6.json | 221 ++++++++++ .../static-hosting-0.2.1-400-asset.json | 48 +++ .../static-hosting-0.2.1-400-asset.k6.json | 221 ++++++++++ .../static-hosting-0.2.1-400-page.json | 48 +++ .../static-hosting-0.2.1-400-page.k6.json | 221 ++++++++++ bench/run.ts | 402 ++++++++++++++++++ bench/site.ts | 39 ++ 48 files changed, 6310 insertions(+) create mode 100644 bench/.gitignore create mode 100644 bench/README.md create mode 100644 bench/load.js create mode 100644 bench/report.ts create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json create mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json create mode 100644 bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json create mode 100644 bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json create mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json create mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json create mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json create mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json create mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json create mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json create mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json create mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json create mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json create mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json create mode 100644 bench/run.ts create mode 100644 bench/site.ts diff --git a/bench/.gitignore b/bench/.gitignore new file mode 100644 index 00000000..3eb949ad --- /dev/null +++ b/bench/.gitignore @@ -0,0 +1,3 @@ +# Apps, packed builds, and raw function logs of the runs. +/.work/ +/results/**/*.logs.jsonl diff --git a/bench/README.md b/bench/README.md new file mode 100644 index 00000000..43f28c2f --- /dev/null +++ b/bench/README.md @@ -0,0 +1,114 @@ +# Benchmark + +What one request to a hosted site costs on Convex, for three ways to serve it: + +- **convex-hosting 0.14.0**, from npm: the HTTP action asks the component's `route` query which file + answers. +- **convex-hosting 0.15.0**, this branch, packed: the HTTP action answers from the site's files, + which the deploy writes into the pushed code. +- **@convex-dev/static-hosting 0.2.1**, from npm, mounted at `/` + (`app.use(staticHosting, { httpPrefix: "/" })`), the mode its README calls the fastest: the + component's own HTTP action runs its `resolveAsset` query and reads the file from storage. + +Convex bills function calls: every query, mutation, action, and HTTP action, and every download of a +stored file ([usage limits](https://docs.convex.dev/production/usage-limits)). A flood against a +site spends them, so calls per request decide what a flood costs, and when the team's spending limit +turns every project off. + +## Method + +- **One Convex cloud project per target**, each with its own development deployment, created by + `run.ts`: `convex-hosting-bench-014`, `convex-hosting-bench` (this branch), and + `convex-hosting-bench-static`. Convex 1.46.0 in each app. +- **The same synthetic site** for all three, from `site.ts`: `index.html`, `404.html`, and 400 + scripts of about 2 KB with Vite-style hashed names, every file with its own bytes. +- **Cases.** `page`: `GET /` with `Sec-Fetch-Mode: navigate`, answered by `index.html`. `asset`: + `GET` of a hashed script. `rendered`: `GET /rendered` with `Sec-Fetch-Mode: navigate`, a path with + no file, answered by the app's code; the convex-hosting apps pass a worker that returns one small + page, so the case measures hosting and not a framework. static-hosting renders no page, so it has + no `rendered` case. +- **No cache answers.** Each request carries a unique query string, so the Cloudflare front of + `*.convex.site` passes every request to the HTTP action, as it does in a flood. +- **Every response is checked**: the status and a marker in its body (`load.js`). A fast error is + not a result. +- **Open load**: k6's `constant-arrival-rate` executor sends a fixed number of requests per second + whatever the latency, and reports the requests it could not send (`dropped`). +- **Server side** from the deployment's own log stream (`npx convex logs --success --jsonl`), + started before the load and drained after it: every function execution of every request, grouped + by request id. `logCompleteness` is the HTTP actions logged over the requests k6 sent; every run + below logged all of them. A stored file's download does not appear in the logs, so + `billedCallsPerRequest` adds one for each answer whose body is a stored file. Convex counts a + query served from its cache as a call too. +- **The client** is one laptop in Chișinău, so client latency includes the round trip to the + deployments; the server-side numbers do not depend on it. + +Run it: + +```sh +brew install k6 # or https://grafana.com/docs/k6/latest/set-up/install-k6/ +node bench/run.ts convex-hosting-0.14.0 --run --files 400 --rate 25 --duration 60s +node bench/run.ts convex-hosting-branch --run --files 400 --rate 25 --duration 60s +node bench/run.ts static-hosting-0.2.1 --run --files 400 --rate 25 --duration 60s +node bench/report.ts +``` + +The first run of a target creates its project in the team in `BENCH_TEAM` (default `nicu`) and +deploys; `--no-deploy` reuses the deployed site. `bench/.work/` holds the apps and the packed branch +build; `bench/results//` holds one JSON file per case and k6's own summary next to it. + +## Results, 2026-11-04 + +400 files. Two rounds at 25 requests/s for 60 s per case (1,500 requests each), one at 100 +requests/s (6,000 each), targets taking turns. Every response passed its checks, k6 dropped no +request, and the logs held every request. `node bench/report.ts ` prints the full tables. + +**Calls per request.** The same in every round: + +| Case | 0.14.0: functions / billed | 0.15.0: functions / billed | static-hosting 0.2.1: functions / billed | +| -------- | -------------------------: | -------------------------: | ---------------------------------------: | +| page | 2 / 3 | **1 / 2** | 2 / 3 | +| asset | 2 / 3 | **1 / 2** | 2 / 3 | +| rendered | 2 / 2 | **1 / 1** | cannot render | + +**HTTP action time**, the median in ms of each round, from the deployment's logs: + +| Case | Rate | 0.14.0 | 0.15.0 | static-hosting 0.2.1 | +| -------- | ----- | ---------- | ---------- | -------------------- | +| page | 25/s | 83.7, 94.2 | 57.6, 52.6 | 41.2, 41.8 | +| page | 100/s | 85.8 | 50.4 | 40.9 | +| asset | 25/s | 80.2, 77.7 | 52.4, 51.8 | 41.2, 41.9 | +| rendered | 25/s | 38.5, 52.1 | 6.8, 6.5 | | +| rendered | 100/s | 37.1 | 6.3 | | + +What the numbers say: + +- **0.15.0 runs one function per request**; 0.14.0 and static-hosting run two. With the download of + a stored body, which Convex bills too, a file costs 2 calls in place of 3, and a rendered page 1 + in place of 2. A flood of one million file requests is 2 million billed calls, not 3 million. +- **A rendered page is about 6 to 8 times faster** in the action (6.5 ms against 37 to 52 ms), since + the action no longer waits for a query. +- **A file is about 30 ms faster than 0.14.0 and about 10 ms slower than static-hosting.** + static-hosting's action runs inside the component, so it reads the file from storage directly; an + app's action cannot read a component's storage, so 0.14.0 and 0.15.0 fetch the file's storage URL. + The price of static-hosting's way is the second function, and that its component cannot hand a + request to the app's code, so it renders no page. +- **Query cache.** static-hosting's `resolveAsset` takes only the path, so Convex answered all of + its calls from the query cache (`cachedResult: true` in the logs), which is cheap in time but is + still a call. 0.14.0's `route` takes the full URL, so a unique query string made every call run. +- **Client latency** includes the round trip from Chișinău; its tails moved between rounds by more + than the targets differ (0.15.0 page p95: 734 ms in round 1, 248 ms in round 2), so the tables + above use the deployment's own times. + +**Large sites.** 0.15.0 carries the site's files in the pushed code, so its cost grows with the +number of files. Measured on the same cloud deployment: + +- a site object of 100,000 files is an 8.9 MB module; it pushed in 4 s, and each request ran about 2 + ms longer (median 5.6 ms against 3.6 ms for a minimal action, 40 sequential requests each); +- memory: a request could hold 86 MiB of arrays without the 100,000-file site and 77 MiB with it, + the same on two runs each, so the site takes about 9 MiB; +- 100,000 files is the most that the CLI accepts, Cloudflare's limit per Worker version. + +**Provenance.** The 0.15.0 deployment of the 400-file runs was built at commit `e4b3e7f`; the +`commit` field of those results is the checkout's HEAD when each case ran. The serving code +(`src/client/index.ts`, and `lookup` in `src/client/manifest.ts`) is the same at the head of the +pull request; later commits changed the CLI and the builder only. diff --git a/bench/load.js b/bench/load.js new file mode 100644 index 00000000..bfcdd91b --- /dev/null +++ b/bench/load.js @@ -0,0 +1,43 @@ +// k6 load script for one case. Every request carries a unique query string, so no cache in front +// of the deployment answers it: each one reaches the HTTP action, as a flood would. Every response +// is checked for its status and for a marker in its body. +// +// k6 run -e BASE=https://.convex.site -e TARGET_PATH=/ -e STATUS=200 \ +// -e MARKER="Benchmark site" -e RATE=25 -e DURATION=60s -e OUT=summary.json load.js +import http from "k6/http"; +import { check } from "k6"; +import exec from "k6/execution"; + +const rate = Number(__ENV.RATE ?? 25); +export const options = { + scenarios: { + load: { + executor: "constant-arrival-rate", + rate, + timeUnit: "1s", + duration: __ENV.DURATION ?? "60s", + preAllocatedVUs: Math.max(20, rate * 2), + maxVUs: Math.max(200, rate * 10), + }, + }, + summaryTrendStats: ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], +}; + +const status = Number(__ENV.STATUS ?? 200); +const marker = __ENV.MARKER ?? ""; + +export default function () { + const url = `${__ENV.BASE}${__ENV.TARGET_PATH}?bench=${exec.scenario.iterationInTest}-${Date.now()}`; + const response = http.get(url, { + headers: { "Sec-Fetch-Mode": __ENV.FETCH_MODE ?? "no-cors" }, + redirects: 0, + }); + check(response, { + status: (r) => r.status === status, + body: (r) => typeof r.body === "string" && r.body.includes(marker), + }); +} + +export function handleSummary(data) { + return { [__ENV.OUT ?? "summary.json"]: JSON.stringify(data, null, 2) }; +} diff --git a/bench/report.ts b/bench/report.ts new file mode 100644 index 00000000..a7dc7fcd --- /dev/null +++ b/bench/report.ts @@ -0,0 +1,68 @@ +// Prints the results of one or more runs as Markdown tables: one row per target and case, with the +// function calls per request that the deployment's logs show, the calls Convex bills (the logged +// functions plus the download of a stored body), the HTTP action's own time, and the latency and +// throughput that k6 saw. +// node bench/report.ts [ ...] +import { readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; + +type Result = { + target: string; + files: number; + rate: number; + duration: string; + case: string; + client: { + requests: number; + rate: number; + checksPassed: number; + dropped: number; + latencyMs: { median: number; p95: number; p99: number }; + }; + server: { + logCompleteness: number | null; + functionsPerRequest: number | null; + billedCallsPerRequest: number | null; + byFunction: Record; + httpActionMs: { median: number | null; p95: number | null }; + innerFunctionMs: { median: number | null }; + }; +}; + +const BENCH = new URL(".", import.meta.url).pathname; +const runs = process.argv.slice(2); +if (runs.length === 0) throw new Error("Usage: node bench/report.ts [ ...]"); + +const fixed = (value: number | null | undefined, digits = 0) => + value === null || value === undefined ? "n/a" : value.toFixed(digits); + +for (const run of runs) { + const dir = join(BENCH, "results", run); + const results: Result[] = readdirSync(dir) + .filter((name) => name.endsWith(".json") && !name.endsWith(".k6.json")) + .map((name) => JSON.parse(readFileSync(join(dir, name), "utf8"))); + const order = ["page", "asset", "rendered"]; + results.sort( + (a, b) => order.indexOf(a.case) - order.indexOf(b.case) || a.target.localeCompare(b.target), + ); + const first = results[0]; + console.log(`### ${run}: ${first.rate} requests/s for ${first.duration}, ${first.files} files\n`); + console.log( + "| Case | Target | Requests | Checks passed | Functions per request | Billed calls per request | HTTP action ms (median / p95) | Inner function ms (median) | Latency ms (median / p95 / p99) | Functions logged |", + ); + console.log("| --- | --- | --: | --: | --: | --: | --: | --: | --: | --- |"); + for (const r of results) { + const functions = Object.entries(r.server.byFunction) + .map(([name, count]) => `${name}: ${count}`) + .join("
"); + console.log( + `| ${r.case} | ${r.target} | ${r.client.requests} | ${fixed(r.client.checksPassed * 100, 1)}% | ` + + `${fixed(r.server.functionsPerRequest, 2)} | ${fixed(r.server.billedCallsPerRequest, 2)} | ` + + `${fixed(r.server.httpActionMs.median, 1)} / ${fixed(r.server.httpActionMs.p95, 1)} | ` + + `${fixed(r.server.innerFunctionMs.median, 1)} | ` + + `${fixed(r.client.latencyMs.median)} / ${fixed(r.client.latencyMs.p95)} / ${fixed(r.client.latencyMs.p99)} | ` + + `${functions} |`, + ); + } + console.log(""); +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json new file mode 100644 index 00000000..ad602956 --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "59a16b265e416d417d8a1cb860b2ca2181dd479a", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 100, + "duration": "60s", + "date": "2026-11-04T00:22:32.215Z", + "case": "page", + "path": "/", + "client": { + "requests": 6001, + "rate": 99.62973466614376, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 257.023, + "p90": 311.373, + "p95": 352.592, + "p99": 710.21, + "max": 1378.176 + } + }, + "server": { + "httpActionsLogged": 6001, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 6001, + "Query hosting/lib:route": 6001 + }, + "httpActionMs": { + "median": 85.795543, + "p95": 156.00752500000002 + }, + "innerFunctionMs": { + "median": 31.378944, + "p95": 85.21054 + } + } +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json new file mode 100644 index 00000000..955d8e40 --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 6001, + "fails": 0 + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 6001, + "fails": 0 + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e" + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdErrTTY": false, + "testRunDurationMs": 60233.022, + "isStdOutTTY": false + }, + "metrics": { + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.7769236793868597, + "min": 0, + "med": 0, + "p(90)": 0.001, + "p(95)": 0.001, + "p(99)": 22.866, + "max": 85.516 + } + }, + "data_sent": { + "contains": "data", + "values": { + "count": 710911, + "rate": 11802.678603773193 + }, + "type": "counter" + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 24, + "min": 21, + "max": 66 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 200, + "min": 200, + "max": 200 + } + }, + "http_reqs": { + "contains": "default", + "values": { + "rate": 99.62973466614376, + "count": 6001 + }, + "type": "counter" + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.30612881186468904, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 8.367, + "max": 47.705 + } + }, + "http_req_waiting": { + "values": { + "p(99)": 561.915, + "max": 1377.941, + "avg": 266.65621546408966, + "min": 188.848, + "med": 256.588, + "p(90)": 308.042, + "p(95)": 341.194 + }, + "type": "trend", + "contains": "time" + }, + "checks": { + "contains": "default", + "values": { + "rate": 1, + "passes": 12002, + "fails": 0 + }, + "type": "rate" + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 352.592, + "p(99)": 710.21, + "max": 1378.176, + "avg": 271.37595484086063, + "min": 188.954, + "med": 257.023, + "p(90)": 311.373 + } + }, + "http_req_tls_handshaking": { + "values": { + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.618, + "max": 60.395, + "avg": 0.4579161806365606, + "min": 0 + }, + "type": "trend", + "contains": "time" + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 2857976, + "rate": 47448.65698420378 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "max": 1378.176, + "avg": 271.37595484086063, + "min": 188.954, + "med": 257.023, + "p(90)": 311.373, + "p(95)": 352.592, + "p(99)": 710.21 + } + }, + "http_req_receiving": { + "contains": "time", + "values": { + "min": 0.01, + "med": 0.058, + "p(90)": 0.381, + "p(95)": 0.623, + "p(99)": 12.551, + "max": 1068.873, + "avg": 4.605456923846026 + }, + "type": "trend" + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.009, + "med": 0.095, + "p(90)": 0.187, + "p(95)": 0.207, + "p(99)": 0.259, + "max": 8.943, + "avg": 0.11428245292451296 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.62973466614376 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "fails": 6001, + "rate": 0, + "passes": 0 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 759.27625, + "max": 1433.568875, + "avg": 272.38817758223536, + "min": 189.196875, + "med": 257.454167, + "p(90)": 312.858333, + "p(95)": 354.188833 + } + } + } +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json new file mode 100644 index 00000000..98126da7 --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "59a16b265e416d417d8a1cb860b2ca2181dd479a", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 100, + "duration": "60s", + "date": "2026-11-04T00:23:55.775Z", + "case": "rendered", + "path": "/rendered", + "client": { + "requests": 6001, + "rate": 99.68078561415406, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 179.878, + "p90": 209.266, + "p95": 223.76, + "p99": 267.863, + "max": 473.518 + } + }, + "server": { + "httpActionsLogged": 6001, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 0, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 6001, + "Query hosting/lib:route": 6001 + }, + "httpActionMs": { + "median": 37.111976999999996, + "p95": 78.535619 + }, + "innerFunctionMs": { + "median": 30.263236, + "p95": 69.118443 + } + } +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json new file mode 100644 index 00000000..015ecda3 --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json @@ -0,0 +1,221 @@ +{ + "options": { + "noColor": false, + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "" + }, + "state": { + "testRunDurationMs": 60202.174, + "isStdOutTTY": false, + "isStdErrTTY": false + }, + "metrics": { + "http_req_receiving": { + "contains": "time", + "values": { + "avg": 0.22484269288451914, + "min": 0.008, + "med": 0.066, + "p(90)": 0.372, + "p(95)": 0.565, + "p(99)": 1.892, + "max": 35.566 + }, + "type": "trend" + }, + "http_req_duration{expected_response:true}": { + "contains": "time", + "values": { + "med": 179.878, + "p(90)": 209.266, + "p(95)": 223.76, + "p(99)": 267.863, + "max": 473.518, + "avg": 185.8849725045822, + "min": 160.12 + }, + "type": "trend" + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 12002, + "fails": 0 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 1999951, + "rate": 33220.57771534962 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0, + "p(99)": 7.584, + "max": 61.924, + "avg": 0.31845892351274785, + "min": 0, + "med": 0, + "p(90)": 0 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "rate": 12220.505525265582, + "count": 735701 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 0.244, + "max": 3.647, + "avg": 0.09366355607398792, + "min": 0.011, + "med": 0.087, + "p(90)": 0.142, + "p(95)": 0.168 + } + }, + "http_req_tls_handshaking": { + "contains": "time", + "values": { + "avg": 0.4922129645059154, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 12.694, + "max": 68.277 + }, + "type": "trend" + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 267.582, + "max": 472.918, + "avg": 185.56646625562368, + "min": 159.781, + "med": 179.589, + "p(90)": 208.874, + "p(95)": 223.33 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.68078561415406 + } + }, + "vus_max": { + "values": { + "value": 200, + "min": 200, + "max": 200 + }, + "type": "gauge", + "contains": "default" + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "max": 473.718917, + "avg": 186.9450982289622, + "min": 160.367041, + "med": 180.499208, + "p(90)": 211.515583, + "p(95)": 227.79675, + "p(99)": 272.715125 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 6001 + } + }, + "http_reqs": { + "contains": "default", + "values": { + "rate": 99.68078561415406, + "count": 6001 + }, + "type": "counter" + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 20, + "min": 16, + "max": 28 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 185.8849725045822, + "min": 160.12, + "med": 179.878, + "p(90)": 209.266, + "p(95)": 223.76, + "p(99)": 267.863, + "max": 473.518 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "med": 0.001, + "p(90)": 0.001, + "p(95)": 0.001, + "p(99)": 21.237, + "max": 118.636, + "avg": 0.8143279453425541, + "min": 0 + } + } + }, + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 6001 + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 6001, + "fails": 0 + } + ] + } +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json new file mode 100644 index 00000000..80f82fbc --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 100, + "duration": "60s", + "date": "2026-11-04T00:19:44.797Z", + "case": "page", + "path": "/", + "client": { + "requests": 6001, + "rate": 99.43415981440592, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 231.491, + "p90": 483.475, + "p95": 788.765, + "p99": 1176.617, + "max": 4670.928 + } + }, + "server": { + "httpActionsLogged": 6001, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 6001 + }, + "httpActionMs": { + "median": 50.372121, + "p95": 104.557229 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json new file mode 100644 index 00000000..921faa54 --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 6001, + "fails": 0, + "name": "status" + }, + { + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 6001 + } + ], + "name": "" + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60351.493 + }, + "metrics": { + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0, + "p(95)": 0, + "p(99)": 11.609, + "max": 43.512, + "avg": 0.3835814030994833, + "min": 0, + "med": 0 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.43415981440592 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 2857407, + "rate": 47346.08636773907 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 30, + "min": 25, + "max": 54 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 483.618417, + "p(95)": 789.117209, + "p(99)": 1176.848667, + "max": 4684.919584, + "avg": 311.984442438594, + "min": 190.540041, + "med": 232.1015 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 200, + "min": 200, + "max": 200 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.43415981440592 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "min": 190.415, + "med": 231.491, + "p(90)": 483.475, + "p(95)": 788.765, + "p(99)": 1176.617, + "max": 4670.928, + "avg": 311.1250681553072 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0.001, + "p(90)": 0.001, + "p(95)": 0.001, + "p(99)": 19.499, + "max": 47.717, + "avg": 0.6157192134645288 + } + }, + "http_req_waiting": { + "values": { + "min": 190.314, + "med": 230.41, + "p(90)": 418.975, + "p(95)": 467.186, + "p(99)": 844.68, + "max": 4670.824, + "avg": 272.4702454590907 + }, + "type": "trend", + "contains": "time" + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 311.1250681553072, + "min": 190.415, + "med": 231.491, + "p(90)": 483.475, + "p(95)": 788.765, + "p(99)": 1176.617, + "max": 4670.928 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.22682986168971828, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 7.128, + "max": 31.236 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.09273021163139508, + "min": 0.011, + "med": 0.085, + "p(90)": 0.145, + "p(95)": 0.174, + "p(99)": 0.243, + "max": 2.378 + } + }, + "http_req_receiving": { + "contains": "time", + "values": { + "max": 1910.575, + "avg": 38.562092484585904, + "min": 0.009, + "med": 0.068, + "p(90)": 0.781, + "p(95)": 540.043, + "p(99)": 633.404 + }, + "type": "trend" + }, + "checks": { + "values": { + "passes": 12002, + "fails": 0, + "rate": 1 + }, + "type": "rate", + "contains": "default" + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 6001 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 711578, + "rate": 11790.561668457813 + } + } + } +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json new file mode 100644 index 00000000..e4222b40 --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 100, + "duration": "60s", + "date": "2026-11-04T00:21:08.328Z", + "case": "rendered", + "path": "/rendered", + "client": { + "requests": 6001, + "rate": 99.70718222020065, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 162.833, + "p90": 214.632, + "p95": 406.845, + "p99": 754.098, + "max": 1898.888 + } + }, + "server": { + "httpActionsLogged": 6001, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 0, + "billedCallsPerRequest": 1, + "byFunction": { + "HttpAction GET /*": 6001 + }, + "httpActionMs": { + "median": 6.285255, + "p95": 24.15231 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json new file mode 100644 index 00000000..cbed74a9 --- /dev/null +++ b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 6001 + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 6001, + "fails": 0 + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60186.236 + }, + "metrics": { + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 182.49748058656922, + "min": 140.39, + "med": 162.379, + "p(90)": 200.722, + "p(95)": 300.682, + "p(99)": 559.133, + "max": 982.644 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 6001 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 17, + "min": 15, + "max": 47 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.7268691884686606, + "min": 0, + "med": 0, + "p(90)": 0.001, + "p(95)": 0.001, + "p(99)": 20.342, + "max": 102.977 + } + }, + "http_req_duration{expected_response:true}": { + "contains": "time", + "values": { + "p(99)": 754.098, + "max": 1898.888, + "avg": 196.3969903349441, + "min": 140.56, + "med": 162.833, + "p(90)": 214.632, + "p(95)": 406.845 + }, + "type": "trend" + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "rate": 12232.830110857903, + "count": 736248 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.70718222020065 + } + }, + "http_req_sending": { + "values": { + "p(90)": 0.139, + "p(95)": 0.179, + "p(99)": 0.231, + "max": 3.798, + "avg": 0.07968638560239942, + "min": 0.01, + "med": 0.064 + }, + "type": "trend", + "contains": "time" + }, + "iteration_duration": { + "values": { + "p(90)": 218.328958, + "p(95)": 407.025625, + "p(99)": 754.716083, + "max": 1899.0645, + "avg": 197.29451881436395, + "min": 140.647959, + "med": 164.059875 + }, + "type": "trend", + "contains": "time" + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.70718222020065 + } + }, + "vus_max": { + "contains": "default", + "values": { + "min": 200, + "max": 200, + "value": 200 + }, + "type": "gauge" + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "passes": 12002, + "fails": 0, + "rate": 1 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "max": 71.844, + "avg": 0.43535710714880843, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 12.25 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 1999668, + "rate": 33224.67283051228 + } + }, + "http_req_connecting": { + "contains": "time", + "values": { + "avg": 0.2880094984169305, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 7.348, + "max": 56.339 + }, + "type": "trend" + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.825, + "p(99)": 557.986, + "max": 1700.456, + "avg": 13.819823362772837, + "min": 0.008, + "med": 0.051, + "p(90)": 0.511 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 214.632, + "p(95)": 406.845, + "p(99)": 754.098, + "max": 1898.888, + "avg": 196.3969903349441, + "min": 140.56, + "med": 162.833 + } + } + } +} diff --git a/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json b/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json new file mode 100644 index 00000000..75f28e70 --- /dev/null +++ b/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json @@ -0,0 +1,48 @@ +{ + "target": "static-hosting-0.2.1", + "dependencies": { + "@convex-dev/static-hosting": "0.2.1" + }, + "convex": "1.46.0", + "commit": "59a16b265e416d417d8a1cb860b2ca2181dd479a", + "deployment": "handsome-rooster-935", + "files": 400, + "rate": 100, + "duration": "60s", + "date": "2026-11-04T00:25:19.633Z", + "case": "page", + "path": "/", + "client": { + "requests": 6001, + "rate": 99.70882066829435, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 182.379, + "p90": 201.938, + "p95": 223.055, + "p99": 442.519, + "max": 670.182 + } + }, + "server": { + "httpActionsLogged": 6001, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 6001, + "Query staticHosting/lib:resolveAsset": 6001 + }, + "httpActionMs": { + "median": 40.893583, + "p95": 69.520205 + }, + "innerFunctionMs": { + "median": 0.0283, + "p95": 0.038408000000000005 + } + } +} diff --git a/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json b/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json new file mode 100644 index 00000000..1c76c75b --- /dev/null +++ b/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 6001, + "fails": 0, + "name": "status" + }, + { + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 6001, + "fails": 0, + "name": "body" + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60185.247 + }, + "metrics": { + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 200, + "min": 200, + "max": 200 + } + }, + "http_req_waiting": { + "contains": "time", + "values": { + "p(99)": 441.971, + "max": 670.013, + "avg": 191.35601866355586, + "min": 160.659, + "med": 182.155, + "p(90)": 201.668, + "p(95)": 222.508 + }, + "type": "trend" + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "min": 160.887042, + "med": 182.793125, + "p(90)": 203.914042, + "p(95)": 227.372834, + "p(99)": 457.769125, + "max": 670.344542, + "avg": 192.54206877287078 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.70882066829435 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "min": 160.755, + "med": 182.379, + "p(90)": 201.938, + "p(95)": 223.055, + "p(99)": 442.519, + "max": 670.182, + "avg": 191.58453757707073 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.7157502082987204, + "min": 0, + "med": 0.001, + "p(90)": 0.001, + "p(95)": 0.001, + "p(99)": 20.427, + "max": 103.591 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.08995550741543076, + "min": 0.009, + "med": 0.081, + "p(90)": 0.139, + "p(95)": 0.167, + "p(99)": 0.228, + "max": 3.565 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.009, + "med": 0.063, + "p(90)": 0.3, + "p(95)": 0.461, + "p(99)": 0.764, + "max": 33.057, + "avg": 0.13856340609898304 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "fails": 0, + "rate": 1, + "passes": 12002 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 2900034, + "rate": 48185.130817856414 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0, + "p(95)": 0, + "p(99)": 12.413, + "max": 47.272, + "avg": 0.402736710548242, + "min": 0, + "med": 0 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 191.58453757707073, + "min": 160.755, + "med": 182.379, + "p(90)": 201.938, + "p(95)": 223.055, + "p(99)": 442.519, + "max": 670.182 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 6001 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 711070, + "rate": 11814.6894038667 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0, + "p(99)": 6.985, + "max": 90.022, + "avg": 0.30727745375770704, + "min": 0, + "med": 0, + "p(90)": 0 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 6001, + "rate": 99.70882066829435 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 19, + "min": 17, + "max": 23 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json new file mode 100644 index 00000000..fa5a0b57 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "e4b3e7f6200d165753b23a8f2902d66d3e2ee827", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-03T23:58:47.518Z", + "case": "asset", + "path": "/assets/chunk-200-ICKA4Pr8.js", + "client": { + "requests": 1501, + "rate": 24.92914252469102, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 286.718, + "p90": 459.315, + "p95": 481.152, + "p99": 587.487, + "max": 960.162 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1501, + "Query hosting/lib:route": 1501 + }, + "httpActionMs": { + "median": 80.194192, + "p95": 134.30827100000002 + }, + "innerFunctionMs": { + "median": 27.237614999999998, + "p95": 59.55118 + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json new file mode 100644 index 00000000..3dfd3035 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "passes": 1501, + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad" + }, + { + "passes": 1501, + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff" + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdErrTTY": false, + "testRunDurationMs": 60210.655, + "isStdOutTTY": false + }, + "metrics": { + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3002, + "fails": 0 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 26.797, + "max": 474.577, + "avg": 2.6636855429714767, + "min": 0, + "med": 0.001 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 7, + "min": 5, + "max": 15 + } + }, + "http_req_duration{expected_response:true}": { + "values": { + "med": 286.718, + "p(90)": 459.315, + "p(95)": 481.152, + "p(99)": 587.487, + "max": 960.162, + "avg": 327.1648767488346, + "min": 198.447 + }, + "type": "trend", + "contains": "time" + }, + "http_reqs": { + "values": { + "count": 1501, + "rate": 24.92914252469102 + }, + "type": "counter", + "contains": "default" + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.92914252469102 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "max": 471.024, + "avg": 0.8314117255163225, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 15.061 + } + }, + "http_req_connecting": { + "values": { + "avg": 1.8256508994003993, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 12.419, + "max": 421.713 + }, + "type": "trend", + "contains": "time" + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "med": 0.195, + "p(90)": 0.657, + "p(95)": 1.192, + "p(99)": 4.175, + "max": 209.629, + "avg": 0.6361852098600932, + "min": 0.019 + } + }, + "iteration_duration": { + "contains": "time", + "values": { + "min": 198.703416, + "med": 292.407334, + "p(90)": 462.313042, + "p(95)": 488.362458, + "p(99)": 627.809667, + "max": 960.272042, + "avg": 330.160511512991 + }, + "type": "trend" + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 3545619, + "rate": 58886.90299084107 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 222924, + "rate": 3702.401177997482 + } + }, + "http_req_duration": { + "values": { + "avg": 327.1648767488346, + "min": 198.447, + "med": 286.718, + "p(90)": 459.315, + "p(95)": 481.152, + "p(99)": 587.487, + "max": 960.162 + }, + "type": "trend", + "contains": "time" + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 326.3933451032647, + "min": 198.072, + "med": 285.331, + "p(90)": 458.723, + "p(95)": 480.313, + "p(99)": 587.294, + "max": 958.989 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "fails": 1501, + "rate": 0, + "passes": 0 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.244, + "p(99)": 0.297, + "max": 6.482, + "avg": 0.13534643570952684, + "min": 0.013, + "med": 0.116, + "p(90)": 0.212 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json new file mode 100644 index 00000000..2d761bff --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "e4b3e7f6200d165753b23a8f2902d66d3e2ee827", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-03T23:57:23.976Z", + "case": "page", + "path": "/", + "client": { + "requests": 1501, + "rate": 24.83249029427659, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 225.488, + "p90": 274.719, + "p95": 382.311, + "p99": 591.463, + "max": 729.529 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1501, + "Query hosting/lib:route": 1501 + }, + "httpActionMs": { + "median": 83.74910000000001, + "p95": 140.898077 + }, + "innerFunctionMs": { + "median": 29.727267, + "p95": 72.000154 + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json new file mode 100644 index 00000000..fb34de54 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "checks": [ + { + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1501, + "fails": 0, + "name": "status" + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0 + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [] + }, + "options": { + "noColor": false, + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "" + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60445.005 + }, + "metrics": { + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 5, + "min": 5, + "max": 16 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 0.317, + "max": 4.907, + "avg": 0.13103597601598926, + "min": 0.019, + "med": 0.112, + "p(90)": 0.209, + "p(95)": 0.247 + } + }, + "data_sent": { + "contains": "data", + "values": { + "count": 176710, + "rate": 2923.4839173228625 + }, + "type": "counter" + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 382.311, + "p(99)": 591.463, + "max": 729.529, + "avg": 245.02712125249843, + "min": 197.468, + "med": 225.488, + "p(90)": 274.719 + } + }, + "http_req_connecting": { + "values": { + "max": 31.54, + "avg": 0.20375816122584936, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 5.829 + }, + "type": "trend", + "contains": "time" + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 274.524, + "p(95)": 382.071, + "p(99)": 591.347, + "max": 729.375, + "avg": 244.65334643570972, + "min": 197.222, + "med": 225.134 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "med": 226.362458, + "p(90)": 275.344042, + "p(95)": 382.681, + "p(99)": 591.608208, + "max": 729.757416, + "avg": 245.97733114790134, + "min": 197.784292 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.83249029427659 + } + }, + "checks": { + "contains": "default", + "values": { + "rate": 1, + "passes": 3002, + "fails": 0 + }, + "type": "rate" + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.338, + "max": 30.867, + "avg": 0.41455229846768815 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 245.02712125249843, + "min": 197.468, + "med": 225.488, + "p(90)": 274.719, + "p(95)": 382.311, + "p(99)": 591.463, + "max": 729.529 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1501 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.83249029427659 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.015, + "med": 0.082, + "p(90)": 0.248, + "p(95)": 0.462, + "p(99)": 6.565, + "max": 18.362, + "avg": 0.24273884077281854 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 715038, + "rate": 11829.563087967317 + } + }, + "vus_max": { + "values": { + "min": 50, + "max": 50, + "value": 50 + }, + "type": "gauge", + "contains": "default" + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 19.232, + "max": 42.831, + "avg": 0.6267275149899891, + "min": 0, + "med": 0.001, + "p(90)": 0.001, + "p(95)": 0.002 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json new file mode 100644 index 00000000..a2fbfa81 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "e4b3e7f6200d165753b23a8f2902d66d3e2ee827", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:00:11.028Z", + "case": "rendered", + "path": "/rendered", + "client": { + "requests": 1501, + "rate": 24.93262833406008, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 221.347, + "p90": 722.982, + "p95": 803.121, + "p99": 1278.326, + "max": 3090.314 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 0, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1501, + "Query hosting/lib:route": 1501 + }, + "httpActionMs": { + "median": 38.503006, + "p95": 215.91706399999998 + }, + "innerFunctionMs": { + "median": 32.138822, + "p95": 196.070833 + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json new file mode 100644 index 00000000..7a2185f7 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1501, + "fails": 0 + }, + { + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0, + "name": "body" + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e" + }, + "options": { + "noColor": false, + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "" + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60202.237 + }, + "metrics": { + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 1.005, + "p(95)": 535.285, + "p(99)": 587.028, + "max": 1717.155, + "avg": 38.5436708860759, + "min": 0.013, + "med": 0.098 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1501 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 804.023125, + "p(99)": 1278.603834, + "max": 3090.603375, + "avg": 323.5828255216518, + "min": 192.988334, + "med": 222.442125, + "p(90)": 724.163708 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0, + "p(99)": 13.183, + "max": 19.941, + "avg": 0.4156715522984677, + "min": 0, + "med": 0, + "p(90)": 0 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "med": 221.347, + "p(90)": 722.982, + "p(95)": 803.121, + "p(99)": 1278.326, + "max": 3090.314, + "avg": 322.5866742171876, + "min": 192.565 + } + }, + "http_reqs": { + "values": { + "count": 1501, + "rate": 24.93262833406008 + }, + "type": "counter", + "contains": "default" + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.20107928047968024, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 5.083, + "max": 30.915 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 183765, + "rate": 3052.4613229903734 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 803.121, + "p(99)": 1278.326, + "max": 3090.314, + "avg": 322.5866742171876, + "min": 192.565, + "med": 221.347, + "p(90)": 722.982 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.93262833406008 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3002, + "fails": 0 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "med": 0.133, + "p(90)": 0.23, + "p(95)": 0.255, + "p(99)": 0.3, + "max": 1.434, + "avg": 0.14385809460359786, + "min": 0.014 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 283.89914523650833, + "min": 192.318, + "med": 219.026, + "p(90)": 424.568, + "p(95)": 612.216, + "p(99)": 1139.34, + "max": 3090.178 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 5, + "min": 5, + "max": 21 + } + }, + "data_received": { + "contains": "data", + "values": { + "count": 500794, + "rate": 8318.528097220042 + }, + "type": "counter" + }, + "http_req_blocked": { + "values": { + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 18.689, + "max": 57.874, + "avg": 0.6501752165222993, + "min": 0 + }, + "type": "trend", + "contains": "time" + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json new file mode 100644 index 00000000..711b59e0 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:02:59.282Z", + "case": "asset", + "path": "/assets/chunk-200-ICKA4Pr8.js", + "client": { + "requests": 1501, + "rate": 24.805091227622473, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 254.698, + "p90": 428.481, + "p95": 453.995, + "p99": 528.431, + "max": 696.138 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1501 + }, + "httpActionMs": { + "median": 52.426236, + "p95": 119.598738 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json new file mode 100644 index 00000000..95ac946f --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json @@ -0,0 +1,221 @@ +{ + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60511.771 + }, + "metrics": { + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 223072, + "rate": 3686.4232580467688 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 5, + "min": 4, + "max": 10 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 5.452, + "max": 21.092, + "avg": 0.1817435043304463 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "passes": 3002, + "fails": 0, + "rate": 1 + } + }, + "http_req_receiving": { + "contains": "time", + "values": { + "max": 45.378, + "avg": 0.44689540306462316, + "min": 0.022, + "med": 0.219, + "p(90)": 0.72, + "p(95)": 1.18, + "p(99)": 3.027 + }, + "type": "trend" + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.13669953364423718, + "min": 0.024, + "med": 0.125, + "p(90)": 0.214, + "p(95)": 0.245, + "p(99)": 0.313, + "max": 1.396 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.049, + "max": 45.218, + "avg": 0.4439940039973351, + "min": 0, + "med": 0 + } + }, + "http_reqs": { + "contains": "default", + "values": { + "count": 1501, + "rate": 24.805091227622473 + }, + "type": "counter" + }, + "http_req_failed": { + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1501 + }, + "type": "rate" + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 298.01425249833443, + "min": 170.938, + "med": 254.698, + "p(90)": 428.481, + "p(95)": 453.995, + "p(99)": 528.431, + "max": 696.138 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 528.431, + "max": 696.138, + "avg": 298.01425249833443, + "min": 170.938, + "med": 254.698, + "p(90)": 428.481, + "p(95)": 453.995 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.805091227622473 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.002, + "p(99)": 18.95, + "max": 50.884, + "avg": 0.6341339107261625, + "min": 0, + "med": 0.001, + "p(90)": 0.002 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 3542242, + "rate": 58538.06526336834 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 455.199375, + "p(99)": 528.660584, + "max": 696.65725, + "avg": 299.00296180946054, + "min": 171.363583, + "med": 258.097625, + "p(90)": 429.209333 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 427.381, + "p(95)": 453.422, + "p(99)": 527.694, + "max": 695.672, + "avg": 297.4306575616258, + "min": 170.161, + "med": 254.501 + } + }, + "vus_max": { + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + }, + "type": "gauge" + } + }, + "root_group": { + "groups": [], + "checks": [ + { + "passes": 1501, + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad" + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0 + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e" + }, + "options": { + "summaryTimeUnit": "", + "noColor": false, + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"] + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json new file mode 100644 index 00000000..4e4d4892 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:01:35.471Z", + "case": "page", + "path": "/", + "client": { + "requests": 1501, + "rate": 24.91967968864645, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 237.133, + "p90": 445.967, + "p95": 733.616, + "p99": 1156.65, + "max": 3474.021 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1501 + }, + "httpActionMs": { + "median": 57.570224, + "p95": 150.741701 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json new file mode 100644 index 00000000..612f2bd3 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1501 + }, + { + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0, + "name": "body", + "path": "::body" + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60233.519 + }, + "metrics": { + "iteration_duration": { + "values": { + "p(90)": 446.15725, + "p(95)": 733.85, + "p(99)": 1156.892125, + "max": 3474.300541, + "avg": 299.5787605562957, + "min": 176.004959, + "med": 237.972541 + }, + "type": "trend", + "contains": "time" + }, + "http_reqs": { + "values": { + "count": 1501, + "rate": 24.91967968864645 + }, + "type": "counter", + "contains": "default" + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 464.275, + "p(99)": 954.468, + "max": 3473.863, + "avg": 275.59089073950724, + "min": 174.563, + "med": 235.509, + "p(90)": 352.751 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "max": 3474.021, + "avg": 298.41526915389744, + "min": 175.62, + "med": 237.133, + "p(90)": 445.967, + "p(95)": 733.616, + "p(99)": 1156.65 + } + }, + "vus": { + "contains": "default", + "values": { + "value": 6, + "min": 4, + "max": 18 + }, + "type": "gauge" + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "min": 175.62, + "med": 237.133, + "p(90)": 445.967, + "p(95)": 733.616, + "p(99)": 1156.65, + "max": 3474.021, + "avg": 298.41526915389744 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 714217, + "rate": 11857.467600390408 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.02, + "med": 0.09, + "p(90)": 0.368, + "p(95)": 6.154, + "p(99)": 569.765, + "max": 1765.179, + "avg": 22.676794137241846 + } + }, + "data_sent": { + "values": { + "count": 177187, + "rate": 2941.6677448315777 + }, + "type": "counter", + "contains": "data" + }, + "http_req_blocked": { + "values": { + "p(99)": 22.475, + "max": 106.992, + "avg": 0.8181105929380224, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002 + }, + "type": "trend", + "contains": "time" + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.91967968864645 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 6.208, + "max": 88.413, + "avg": 0.300180546302465 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1501 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3002, + "fails": 0 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "max": 47.403, + "avg": 0.5018427714856762, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 14.683 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.257, + "p(99)": 0.318, + "max": 6.179, + "avg": 0.1475842771485677, + "min": 0.019, + "med": 0.132, + "p(90)": 0.227 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json new file mode 100644 index 00000000..128f14fe --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:04:22.709Z", + "case": "rendered", + "path": "/rendered", + "client": { + "requests": 1500, + "rate": 24.953610406467362, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 155.63549999999998, + "p90": 197.228, + "p95": 219.61004999999992, + "p99": 351.1921999999999, + "max": 756.188 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 0, + "billedCallsPerRequest": 1, + "byFunction": { + "HttpAction GET /*": 1500 + }, + "httpActionMs": { + "median": 6.828411, + "p95": 51.278107000000006 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json new file mode 100644 index 00000000..301188b6 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500 + }, + { + "passes": 1500, + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff" + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60111.542 + }, + "metrics": { + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.42965066666666674, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.360009999999999, + "max": 21.467 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.953610406467362 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 168.8048753333333, + "min": 141.345, + "med": 155.303, + "p(90)": 196.399, + "p(95)": 218.79614999999998, + "p(99)": 325.49924999999973, + "max": 543.879 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "med": 0.095, + "p(90)": 0.3383000000000001, + "p(95)": 0.5450499999999999, + "p(99)": 5.658919999999999, + "max": 562.729, + "avg": 1.3719860000000035, + "min": 0.009 + } + }, + "http_req_blocked": { + "contains": "time", + "values": { + "avg": 0.6863839999999809, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 20.826289999999975, + "max": 45.573 + }, + "type": "trend" + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "min": 141.477, + "med": 155.63549999999998, + "p(90)": 197.228, + "p(95)": 219.61004999999992, + "p(99)": 351.1921999999999, + "max": 756.188, + "avg": 170.30926000000025 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "min": 50, + "max": 50, + "value": 50 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "max": 756.188, + "avg": 170.30926000000025, + "min": 141.477, + "med": 155.63549999999998, + "p(90)": 197.228, + "p(95)": 219.61004999999992, + "p(99)": 351.1921999999999 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.953610406467362 + } + }, + "data_received": { + "contains": "data", + "values": { + "count": 499944, + "rate": 8316.938534033947 + }, + "type": "counter" + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 201.992542, + "p(95)": 221.12645384999996, + "p(99)": 351.63643757999995, + "max": 756.568125, + "avg": 171.34394521666647, + "min": 141.811666, + "med": 157.037146 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.13239866666666658, + "min": 0.024, + "med": 0.124, + "p(90)": 0.20610000000000003, + "p(95)": 0.23604999999999993, + "p(99)": 0.28901, + "max": 1.028 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 183515, + "rate": 3052.9078758285723 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 3, + "min": 3, + "max": 8 + } + }, + "http_req_connecting": { + "contains": "time", + "values": { + "max": 32.034, + "avg": 0.2487620000000001, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 6.343779999999999 + }, + "type": "trend" + } + } +} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json new file mode 100644 index 00000000..5707a73c --- /dev/null +++ b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json @@ -0,0 +1,48 @@ +{ + "target": "static-hosting-0.2.1", + "dependencies": { + "@convex-dev/static-hosting": "0.2.1" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "handsome-rooster-935", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:07:10.308Z", + "case": "asset", + "path": "/assets/chunk-200-ICKA4Pr8.js", + "client": { + "requests": 1500, + "rate": 24.864716465068796, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 218.94, + "p90": 399.06080000000003, + "p95": 425.9124499999999, + "p99": 464.18411, + "max": 513.511 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1500, + "Query staticHosting/lib:resolveAsset": 1500 + }, + "httpActionMs": { + "median": 41.247077, + "p95": 66.25379500000001 + }, + "innerFunctionMs": { + "median": 0.02624, + "p95": 0.031795000000000004 + } + } +} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json new file mode 100644 index 00000000..45b91750 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500, + "fails": 0 + }, + { + "passes": 1500, + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff" + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "testRunDurationMs": 60326.447, + "isStdOutTTY": false, + "isStdErrTTY": false + }, + "metrics": { + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 402.9010711, + "p(95)": 429.24734614999994, + "p(99)": 465.94778991, + "max": 521.145292, + "avg": 281.6569808719999, + "min": 165.800625, + "med": 220.593771 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.864716465068796 + } + }, + "http_reqs": { + "values": { + "rate": 24.864716465068796, + "count": 1500 + }, + "type": "counter", + "contains": "default" + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 399.06080000000003, + "p(95)": 425.9124499999999, + "p(99)": 464.18411, + "max": 513.511, + "avg": 280.53669400000024, + "min": 165.558, + "med": 218.94 + } + }, + "http_req_failed": { + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + }, + "type": "rate", + "contains": "default" + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.765380666666647, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 21.131439999999994, + "max": 62.012 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0, + "p(99)": 6.083979999999999, + "max": 24.246, + "avg": 0.22953333333333342, + "min": 0, + "med": 0, + "p(90)": 0 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.5274920000000001, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.818379999999998, + "max": 57.944 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 464.18411, + "max": 513.511, + "avg": 280.53669400000024, + "min": 165.558, + "med": 218.94, + "p(90)": 399.06080000000003, + "p(95)": 425.9124499999999 + } + }, + "data_received": { + "contains": "data", + "values": { + "count": 3543930, + "rate": 58745.87641470083 + }, + "type": "counter" + }, + "vus_max": { + "contains": "default", + "values": { + "min": 50, + "max": 50, + "value": 50 + }, + "type": "gauge" + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.7892999999999997, + "p(99)": 1.7550499999999987, + "max": 7.21, + "avg": 0.3112199999999997, + "min": 0.016, + "med": 0.209, + "p(90)": 0.6383000000000001 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 223211, + "rate": 3700.0521512563137 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 5, + "min": 4, + "max": 9 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.028, + "med": 0.13, + "p(90)": 0.222, + "p(95)": 0.254, + "p(99)": 0.3070999999999999, + "max": 1.811, + "avg": 0.14055799999999974 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 398.6608, + "p(95)": 425.22769999999986, + "p(99)": 463.72496, + "max": 513.244, + "avg": 280.0849159999998, + "min": 165.451, + "med": 218.548 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json new file mode 100644 index 00000000..e00e6098 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json @@ -0,0 +1,48 @@ +{ + "target": "static-hosting-0.2.1", + "dependencies": { + "@convex-dev/static-hosting": "0.2.1" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "handsome-rooster-935", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:05:46.680Z", + "case": "page", + "path": "/", + "client": { + "requests": 1500, + "rate": 24.938959817599773, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 183.47050000000002, + "p90": 213.703, + "p95": 245.98624999999987, + "p99": 351.2222599999998, + "max": 532.496 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1500, + "Query staticHosting/lib:resolveAsset": 1500 + }, + "httpActionMs": { + "median": 41.210496, + "p95": 94.89908399999999 + }, + "innerFunctionMs": { + "median": 0.026396, + "p95": 0.035913 + } + } +} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json new file mode 100644 index 00000000..608ab719 --- /dev/null +++ b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500, + "fails": 0, + "name": "status", + "path": "::status" + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1500, + "fails": 0 + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60146.855 + }, + "metrics": { + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0.209, + "p(95)": 0.24804999999999994, + "p(99)": 0.2910399999999999, + "max": 1.919, + "avg": 0.13232799999999992, + "min": 0.022, + "med": 0.118 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "http_req_receiving": { + "values": { + "max": 2.471, + "avg": 0.12381600000000012, + "min": 0.019, + "med": 0.088, + "p(90)": 0.179, + "p(95)": 0.307, + "p(99)": 0.8575199999999993 + }, + "type": "trend", + "contains": "time" + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 177079, + "rate": 2944.1107103605 + } + }, + "iteration_duration": { + "values": { + "p(99)": 351.4263232399997, + "max": 549.688209, + "avg": 194.71997728933363, + "min": 163.976041, + "med": 184.1376045, + "p(90)": 215.8298291, + "p(95)": 248.13045209999999 + }, + "type": "trend", + "contains": "time" + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.938959817599773 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "min": 4, + "max": 6, + "value": 4 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.938959817599773 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "avg": 193.70460933333334, + "min": 163.651, + "med": 183.47050000000002, + "p(90)": 213.703, + "p(95)": 245.98624999999987, + "p(99)": 351.2222599999998, + "max": 532.496 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 4.436649999999999, + "max": 32.969, + "avg": 0.18396400000000002, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0 + } + }, + "http_req_failed": { + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + }, + "type": "rate" + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.31721, + "max": 43.532, + "avg": 0.46327599999999997 + } + }, + "http_req_waiting": { + "values": { + "avg": 193.44846533333285, + "min": 163.529, + "med": 183.2735, + "p(90)": 213.3579, + "p(95)": 245.59009999999995, + "p(99)": 350.93935999999974, + "max": 532.293 + }, + "type": "trend", + "contains": "time" + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 245.98624999999987, + "p(99)": 351.2222599999998, + "max": 532.496, + "avg": 193.70460933333334, + "min": 163.651, + "med": 183.47050000000002, + "p(90)": 213.703 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 725133, + "rate": 12056.041832943718 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 19.281739999999992, + "max": 47.977, + "avg": 0.6694046666666478, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json new file mode 100644 index 00000000..062680f0 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:09:58.001Z", + "case": "asset", + "path": "/assets/chunk-200-ICKA4Pr8.js", + "client": { + "requests": 1500, + "rate": 24.841964530378064, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 276.27750000000003, + "p90": 442.10010000000005, + "p95": 466.6368499999999, + "p99": 519.62816, + "max": 648.455 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1500, + "Query hosting/lib:route": 1500 + }, + "httpActionMs": { + "median": 77.749256, + "p95": 117.937741 + }, + "innerFunctionMs": { + "median": 24.847019000000003, + "p95": 49.027361 + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json new file mode 100644 index 00000000..2eb9e713 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json @@ -0,0 +1,221 @@ +{ + "state": { + "isStdErrTTY": false, + "testRunDurationMs": 60381.698, + "isStdOutTTY": false + }, + "metrics": { + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.841964530378064 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "max": 648.455, + "avg": 320.3830993333335, + "min": 196.774, + "med": 276.27750000000003, + "p(90)": 442.10010000000005, + "p(95)": 466.6368499999999, + "p(99)": 519.62816 + } + }, + "http_req_waiting": { + "values": { + "avg": 319.89546199999955, + "min": 195.165, + "med": 275.819, + "p(90)": 441.81640000000004, + "p(95)": 466.4402499999999, + "p(99)": 519.01136, + "max": 648.194 + }, + "type": "trend", + "contains": "time" + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 7, + "min": 6, + "max": 11 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "max": 21.209, + "avg": 0.42850199999999994, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.048079999999992 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 222924, + "rate": 3691.913400646666 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 321.41687628266664, + "min": 197.093625, + "med": 278.723396, + "p(90)": 444.31056670000004, + "p(95)": 469.06316425, + "p(99)": 519.9614881599999, + "max": 648.753958 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + } + }, + "http_req_duration": { + "values": { + "med": 276.27750000000003, + "p(90)": 442.10010000000005, + "p(95)": 466.6368499999999, + "p(99)": 519.62816, + "max": 648.455, + "avg": 320.3830993333335, + "min": 196.774 + }, + "type": "trend", + "contains": "time" + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.6965373333333142, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 21.19843, + "max": 49.459 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 3542308, + "rate": 58665.25979444964 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.016, + "med": 0.2025, + "p(90)": 0.653, + "p(95)": 0.8630499999999999, + "p(99)": 2.260359999999998, + "max": 37.989, + "avg": 0.3514653333333334 + } + }, + "http_req_connecting": { + "contains": "time", + "values": { + "p(99)": 7.284179999999996, + "max": 32.907, + "avg": 0.26016199999999995, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0 + }, + "type": "trend" + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.841964530378064 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 0.305, + "max": 4.155, + "avg": 0.1361720000000004, + "min": 0.017, + "med": 0.12, + "p(90)": 0.21410000000000004, + "p(95)": 0.249 + } + } + }, + "root_group": { + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500, + "fails": 0, + "name": "status", + "path": "::status" + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1500, + "fails": 0 + } + ], + "name": "" + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json new file mode 100644 index 00000000..b69990ab --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:08:34.142Z", + "case": "page", + "path": "/", + "client": { + "requests": 1500, + "rate": 24.930197110104846, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 238.1245, + "p90": 306.75790000000006, + "p95": 340.1665, + "p99": 601.6465399999998, + "max": 821.121 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1500, + "Query hosting/lib:route": 1500 + }, + "httpActionMs": { + "median": 94.170697, + "p95": 188.944432 + }, + "innerFunctionMs": { + "median": 38.220148, + "p95": 119.30128900000001 + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json new file mode 100644 index 00000000..c70541e0 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60167.996 + }, + "metrics": { + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 713700, + "rate": 11861.787784987886 + } + }, + "data_sent": { + "contains": "data", + "values": { + "count": 176968, + "rate": 2941.2314147873562 + }, + "type": "counter" + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "passes": 0, + "fails": 1500, + "rate": 0 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "rate": 24.930197110104846, + "count": 1500 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.018, + "med": 0.133, + "p(90)": 0.216, + "p(95)": 0.247, + "p(99)": 0.30401999999999996, + "max": 1.603, + "avg": 0.1415313333333331 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.930197110104846 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "med": 238.44287450000002, + "p(90)": 308.4518878, + "p(95)": 345.49676875, + "p(99)": 602.5027111699995, + "max": 836.342792, + "avg": 256.93249321533364, + "min": 199.048083 + } + }, + "http_req_receiving": { + "values": { + "p(90)": 0.2703000000000001, + "p(95)": 0.5064499999999994, + "p(99)": 3.866329999999985, + "max": 31.946, + "avg": 0.256588, + "min": 0.014, + "med": 0.0835 + }, + "type": "trend", + "contains": "time" + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "max": 50, + "value": 50, + "min": 50 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "avg": 255.9439099999998, + "min": 198.816, + "med": 238.1245, + "p(90)": 306.75790000000006, + "p(95)": 340.1665, + "p(99)": 601.6465399999998, + "max": 821.121 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 601.4221099999997, + "max": 799.46, + "avg": 255.54579066666665, + "min": 198.377, + "med": 237.802, + "p(90)": 306.48990000000003, + "p(95)": 340.00780000000003 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 306.75790000000006, + "p(95)": 340.1665, + "p(99)": 601.6465399999998, + "max": 821.121, + "avg": 255.9439099999998, + "min": 198.816, + "med": 238.1245 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 19.08436, + "max": 44.886, + "avg": 0.6357946666666451, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002 + } + }, + "http_req_connecting": { + "values": { + "p(90)": 0, + "p(95)": 0, + "p(99)": 5.82717, + "max": 16.183, + "avg": 0.18027666666666667, + "min": 0, + "med": 0 + }, + "type": "trend", + "contains": "time" + }, + "http_req_tls_handshaking": { + "values": { + "p(95)": 0, + "p(99)": 13.497409999999999, + "max": 38.01, + "avg": 0.4393886666666665, + "min": 0, + "med": 0, + "p(90)": 0 + }, + "type": "trend", + "contains": "time" + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + }, + "vus": { + "values": { + "min": 5, + "max": 13, + "value": 5 + }, + "type": "gauge", + "contains": "default" + } + }, + "root_group": { + "groups": [], + "checks": [ + { + "passes": 1500, + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad" + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1500, + "fails": 0 + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e" + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json new file mode 100644 index 00000000..a53cfd33 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-0.14.0", + "dependencies": { + "@samebase/convex-hosting": "0.14.0" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "frugal-ferret-267", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:11:21.520Z", + "case": "rendered", + "path": "/rendered", + "client": { + "requests": 1501, + "rate": 24.94122735198225, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 196.765, + "p90": 267.272, + "p95": 319.946, + "p99": 388.553, + "max": 462.215 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 0, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1501, + "Query hosting/lib:route": 1501 + }, + "httpActionMs": { + "median": 52.083235, + "p95": 168.71917 + }, + "innerFunctionMs": { + "median": 42.863363, + "p95": 134.382957 + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json new file mode 100644 index 00000000..1a7a7b0d --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1501 + }, + { + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0, + "name": "body", + "path": "::body" + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60181.481 + }, + "metrics": { + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.94122735198225 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.249, + "p(99)": 0.301, + "max": 6.581, + "avg": 0.1449780146568955, + "min": 0.016, + "med": 0.131, + "p(90)": 0.224 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 4, + "min": 4, + "max": 9 + } + }, + "data_received": { + "values": { + "count": 500170, + "rate": 8311.028437468995 + }, + "type": "counter", + "contains": "data" + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.94122735198225 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "max": 41.869, + "avg": 0.41782078614257157, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 12.187 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 212.9299648167893, + "min": 164.51775, + "med": 197.727042, + "p(90)": 268.373084, + "p(95)": 320.474208, + "p(99)": 393.135625, + "max": 462.539917 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "avg": 211.9557774816791, + "min": 164.038, + "med": 196.765, + "p(90)": 267.272, + "p(95)": 319.946, + "p(99)": 388.553, + "max": 462.215 + } + }, + "checks": { + "contains": "default", + "values": { + "fails": 0, + "rate": 1, + "passes": 3002 + }, + "type": "rate" + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 183323, + "rate": 3046.1696348084224 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 5.127, + "max": 18.565, + "avg": 0.19394270486342435, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "med": 196.765, + "p(90)": 267.272, + "p(95)": 319.946, + "p(99)": 388.553, + "max": 462.215, + "avg": 211.9557774816791, + "min": 164.038 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "max": 129.303, + "avg": 0.3859000666222523, + "min": 0.014, + "med": 0.095, + "p(90)": 0.311, + "p(95)": 0.53, + "p(99)": 5.057 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 18.059, + "max": 45.988, + "avg": 0.6240179880079756, + "min": 0, + "med": 0.001 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 211.4248994003995, + "min": 163.676, + "med": 196.282, + "p(90)": 266.82, + "p(95)": 316.087, + "p(99)": 387.57, + "max": 457.541 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "fails": 1501, + "rate": 0, + "passes": 0 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json new file mode 100644 index 00000000..cd736974 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:14:09.590Z", + "case": "asset", + "path": "/assets/chunk-200-ICKA4Pr8.js", + "client": { + "requests": 1501, + "rate": 24.869355938191646, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 355.262, + "p90": 418.642, + "p95": 443.636, + "p99": 492.54, + "max": 757.795 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1501 + }, + "httpActionMs": { + "median": 51.838714, + "p95": 92.062591 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json new file mode 100644 index 00000000..f4e013a8 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json @@ -0,0 +1,221 @@ +{ + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60355.403 + }, + "metrics": { + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "min": 169.740666, + "med": 355.783958, + "p(90)": 420.099791, + "p(95)": 445.583667, + "p(99)": 494.896459, + "max": 758.218084, + "avg": 303.03876074550243 + } + }, + "vus_max": { + "contains": "default", + "values": { + "max": 50, + "value": 50, + "min": 50 + }, + "type": "gauge" + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 19.038, + "max": 54.922, + "avg": 0.6482658227847914, + "min": 0, + "med": 0.001 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "max": 6.419, + "avg": 0.13806595602931404, + "min": 0.019, + "med": 0.123, + "p(90)": 0.217, + "p(95)": 0.247, + "p(99)": 0.303 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "passes": 0, + "fails": 1501, + "rate": 0 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 302.0437028647564, + "min": 169.436, + "med": 355.262, + "p(90)": 418.642, + "p(95)": 443.636, + "p(99)": 492.54, + "max": 757.795 + } + }, + "http_req_connecting": { + "values": { + "p(90)": 0, + "p(95)": 0, + "p(99)": 4.881, + "max": 43.383, + "avg": 0.20293271152564954, + "min": 0, + "med": 0 + }, + "type": "trend", + "contains": "time" + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.869355938191646 + } + }, + "vus": { + "contains": "default", + "values": { + "max": 9, + "value": 8, + "min": 4 + }, + "type": "gauge" + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "max": 757.545, + "avg": 301.56511525649574, + "min": 168.118, + "med": 354.56, + "p(90)": 418.428, + "p(95)": 442.725, + "p(99)": 491.761 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 222838, + "rate": 3692.0969610624584 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.869355938191646 + } + }, + "http_req_duration{expected_response:true}": { + "contains": "time", + "values": { + "med": 355.262, + "p(90)": 418.642, + "p(95)": 443.636, + "p(99)": 492.54, + "max": 757.795, + "avg": 302.0437028647564, + "min": 169.436 + }, + "type": "trend" + }, + "http_req_receiving": { + "contains": "time", + "values": { + "max": 13.283, + "avg": 0.3405216522318455, + "min": 0.014, + "med": 0.194, + "p(90)": 0.625, + "p(95)": 0.806, + "p(99)": 2.894 + }, + "type": "trend" + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 3542248, + "rate": 58689.82433933877 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.139, + "max": 38.424, + "avg": 0.4375882744836775, + "min": 0 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3002, + "fails": 0 + } + } + }, + "root_group": { + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1501, + "fails": 0 + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0 + } + ], + "name": "" + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json new file mode 100644 index 00000000..16e2f58a --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:12:45.925Z", + "case": "page", + "path": "/", + "client": { + "requests": 1501, + "rate": 24.934123497534255, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 196.604, + "p90": 226.715, + "p95": 247.656, + "p99": 465.25, + "max": 910.409 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1501 + }, + "httpActionMs": { + "median": 52.636536, + "p95": 91.936576 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json new file mode 100644 index 00000000..9b7f74b5 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1501, + "fails": 0 + }, + { + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0, + "name": "body" + } + ] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60198.627 + }, + "metrics": { + "http_req_tls_handshaking": { + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 14.17, + "max": 23.827, + "avg": 0.44172085276482353 + }, + "type": "trend", + "contains": "time" + }, + "checks": { + "values": { + "rate": 1, + "passes": 3002, + "fails": 0 + }, + "type": "rate", + "contains": "default" + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 21.917, + "max": 47.625, + "avg": 0.6947654896735326, + "min": 0 + } + }, + "http_req_sending": { + "contains": "time", + "values": { + "p(95)": 0.238, + "p(99)": 0.282, + "max": 0.653, + "avg": 0.13203464357095276, + "min": 0.018, + "med": 0.123, + "p(90)": 0.211 + }, + "type": "trend" + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.934123497534255 + } + }, + "http_req_connecting": { + "contains": "time", + "values": { + "avg": 0.2290879413724183, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 7.052, + "max": 33.399 + }, + "type": "trend" + }, + "http_req_waiting": { + "values": { + "p(99)": 465.007, + "max": 857.724, + "avg": 207.75307395069933, + "min": 176.065, + "med": 196.284, + "p(90)": 226.219, + "p(95)": 247.333 + }, + "type": "trend", + "contains": "time" + }, + "vus_max": { + "values": { + "value": 50, + "min": 50, + "max": 50 + }, + "type": "gauge", + "contains": "default" + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 247.656, + "p(99)": 465.25, + "max": 910.409, + "avg": 208.11429380413085, + "min": 176.432, + "med": 196.604, + "p(90)": 226.715 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 177047, + "rate": 2941.047143816087 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 465.25, + "max": 910.409, + "avg": 208.11429380413085, + "min": 176.432, + "med": 196.604, + "p(90)": 226.715, + "p(95)": 247.656 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1501 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 248.951041, + "p(99)": 485.20225, + "max": 910.895666, + "avg": 209.1479989067286, + "min": 176.875416, + "med": 197.122208, + "p(90)": 228.631875 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "max": 8, + "value": 5, + "min": 4 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.934123497534255 + } + }, + "http_req_receiving": { + "values": { + "avg": 0.22918520986009358, + "min": 0.011, + "med": 0.084, + "p(90)": 0.257, + "p(95)": 0.461, + "p(99)": 1.874, + "max": 52.5 + }, + "type": "trend", + "contains": "time" + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "rate": 11844.240234914327, + "count": 713007 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json new file mode 100644 index 00000000..0f96ce13 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json @@ -0,0 +1,47 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "clean-swordfish-403", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:15:32.997Z", + "case": "rendered", + "path": "/rendered", + "client": { + "requests": 1500, + "rate": 24.95143286763757, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 149.472, + "p90": 160.89770000000001, + "p95": 176.1119, + "p99": 380.59317999999996, + "max": 586.243 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 0, + "billedCallsPerRequest": 1, + "byFunction": { + "HttpAction GET /*": 1500 + }, + "httpActionMs": { + "median": 6.487045, + "p95": 15.376284 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json new file mode 100644 index 00000000..e84777d3 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500, + "fails": 0 + }, + { + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1500 + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e" + }, + "options": { + "noColor": false, + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "" + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60116.788 + }, + "metrics": { + "iteration_duration": { + "contains": "time", + "values": { + "p(95)": 180.96892884999994, + "p(99)": 380.99749641999995, + "max": 586.8335, + "avg": 158.11574064333342, + "min": 141.360208, + "med": 149.955229, + "p(90)": 164.4127709 + }, + "type": "trend" + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.019, + "med": 0.125, + "p(90)": 0.203, + "p(95)": 0.231, + "p(99)": 0.28001000000000004, + "max": 1.427, + "avg": 0.13205133333333322 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.6570626666666464, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 20.009719999999994, + "max": 49.499 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.5390499999999999, + "p(99)": 3.9099699999999973, + "max": 8.028, + "avg": 0.21880666666666726, + "min": 0.024, + "med": 0.098, + "p(90)": 0.307 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.95143286763757 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 4, + "min": 3, + "max": 7 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 183328, + "rate": 3049.5308565055075 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "data_received": { + "values": { + "rate": 8315.264614603162, + "count": 499887 + }, + "type": "counter", + "contains": "data" + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "min": 140.757, + "med": 149.2, + "p(90)": 160.6266, + "p(95)": 175.38044999999994, + "p(99)": 380.28768999999994, + "max": 581.331, + "avg": 156.75396799999993 + } + }, + "http_req_connecting": { + "values": { + "p(99)": 6.092809999999998, + "max": 35.071, + "avg": 0.22891266666666668, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0 + }, + "type": "trend", + "contains": "time" + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.42016000000000014, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.438270000000001, + "max": 37.344 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 157.10482599999997, + "min": 141.17, + "med": 149.472, + "p(90)": 160.89770000000001, + "p(95)": 176.1119, + "p(99)": 380.59317999999996, + "max": 586.243 + } + }, + "http_req_duration{expected_response:true}": { + "contains": "time", + "values": { + "max": 586.243, + "avg": 157.10482599999997, + "min": 141.17, + "med": 149.472, + "p(90)": 160.89770000000001, + "p(95)": 176.1119, + "p(99)": 380.59317999999996 + }, + "type": "trend" + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.95143286763757 + } + } + } +} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json new file mode 100644 index 00000000..44c5b8ab --- /dev/null +++ b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json @@ -0,0 +1,48 @@ +{ + "target": "static-hosting-0.2.1", + "dependencies": { + "@convex-dev/static-hosting": "0.2.1" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "handsome-rooster-935", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:18:20.164Z", + "case": "asset", + "path": "/assets/chunk-200-ICKA4Pr8.js", + "client": { + "requests": 1500, + "rate": 24.934864316270893, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 357.42999999999995, + "p90": 405.0565, + "p95": 427.42074999999994, + "p99": 460.8187, + "max": 518.583 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1500, + "Query staticHosting/lib:resolveAsset": 1500 + }, + "httpActionMs": { + "median": 41.909085, + "p95": 63.403824 + }, + "innerFunctionMs": { + "median": 0.026527, + "p95": 0.035799 + } + } +} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json new file mode 100644 index 00000000..d71d845b --- /dev/null +++ b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json @@ -0,0 +1,221 @@ +{ + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "testRunDurationMs": 60156.734, + "isStdOutTTY": false, + "isStdErrTTY": false + }, + "metrics": { + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.953479999999997, + "max": 43.073, + "avg": 0.4766333333333332, + "min": 0 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "rate": 3709.177429745438, + "count": 223132 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.7380999999999999, + "p(99)": 1.885779999999999, + "max": 9.809, + "avg": 0.29534000000000005, + "min": 0.021, + "med": 0.187, + "p(90)": 0.5951 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "min": 50, + "max": 50, + "value": 50 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 297.4572339999998, + "min": 164.348, + "med": 356.899, + "p(90)": 404.1775, + "p(95)": 427.0609, + "p(99)": 460.50805, + "max": 518.22 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 20.603229999999996, + "max": 47.621, + "avg": 0.6867233333333137, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002 + } + }, + "http_req_connecting": { + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 6.021609999999996, + "max": 19.917, + "avg": 0.20223533333333335 + }, + "type": "trend" + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 297.89772666666664, + "min": 165.267, + "med": 357.42999999999995, + "p(90)": 405.0565, + "p(95)": 427.42074999999994, + "p(99)": 460.8187, + "max": 518.583 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + }, + "iteration_duration": { + "contains": "time", + "values": { + "avg": 298.93632925600014, + "min": 165.662875, + "med": 358.129708, + "p(90)": 406.1098372, + "p(95)": 428.4115101, + "p(99)": 462.61087667, + "max": 519.034333 + }, + "type": "trend" + }, + "http_reqs": { + "contains": "default", + "values": { + "count": 1500, + "rate": 24.934864316270893 + }, + "type": "counter" + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.019, + "med": 0.135, + "p(90)": 0.23510000000000003, + "p(95)": 0.26204999999999995, + "p(99)": 0.32201, + "max": 1.46, + "avg": 0.14515266666666657 + } + }, + "http_req_failed": { + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + }, + "type": "rate" + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 5, + "min": 4, + "max": 9 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 3543922, + "rate": 58911.476144964916 + } + }, + "http_req_duration{expected_response:true}": { + "values": { + "min": 165.267, + "med": 357.42999999999995, + "p(90)": 405.0565, + "p(95)": 427.42074999999994, + "p(99)": 460.8187, + "max": 518.583, + "avg": 297.89772666666664 + }, + "type": "trend", + "contains": "time" + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.934864316270893 + } + } + }, + "root_group": { + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500, + "fails": 0 + }, + { + "passes": 1500, + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff" + } + ] + } +} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json new file mode 100644 index 00000000..445b4711 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json @@ -0,0 +1,48 @@ +{ + "target": "static-hosting-0.2.1", + "dependencies": { + "@convex-dev/static-hosting": "0.2.1" + }, + "convex": "1.46.0", + "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", + "deployment": "handsome-rooster-935", + "files": 400, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:16:56.707Z", + "case": "page", + "path": "/", + "client": { + "requests": 1500, + "rate": 24.941520863108313, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 189.49599999999998, + "p90": 224.9675, + "p95": 241.3964, + "p99": 457.18186999999995, + "max": 841.721 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 2, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 3, + "byFunction": { + "HttpAction GET /*": 1500, + "Query staticHosting/lib:resolveAsset": 1500 + }, + "httpActionMs": { + "median": 41.772134, + "p95": 73.603138 + }, + "innerFunctionMs": { + "median": 0.025822, + "p95": 0.031492000000000006 + } + } +} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json new file mode 100644 index 00000000..24cc2965 --- /dev/null +++ b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json @@ -0,0 +1,221 @@ +{ + "metrics": { + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "med": 189.49599999999998, + "p(90)": 224.9675, + "p(95)": 241.3964, + "p(99)": 457.18186999999995, + "max": 841.721, + "avg": 201.20935666666688, + "min": 165.176 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.039739999999993, + "max": 20.612, + "avg": 0.41250999999999993 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.13223933333333318, + "min": 0.017, + "med": 0.121, + "p(90)": 0.21, + "p(95)": 0.24704999999999994, + "p(99)": 0.32001999999999997, + "max": 1.742 + } + }, + "http_req_receiving": { + "contains": "time", + "values": { + "med": 0.086, + "p(90)": 0.195, + "p(95)": 0.2960499999999999, + "p(99)": 0.7480699999999932, + "max": 536.245, + "avg": 0.5243020000000003, + "min": 0.014 + }, + "type": "trend" + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "passes": 3000, + "fails": 0, + "rate": 1 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "med": 189.3005, + "p(90)": 224.65040000000002, + "p(95)": 240.80124999999998, + "p(99)": 455.39019, + "max": 841.654, + "avg": 200.55281533333377, + "min": 165.031 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.941520863108313 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 241.90188574999993, + "p(99)": 477.16250833, + "max": 868.810833, + "avg": 202.23315793999996, + "min": 165.387833, + "med": 190.428146, + "p(90)": 225.51523809999998 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.941520863108313 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 5, + "min": 4, + "max": 8 + } + }, + "http_req_duration": { + "values": { + "p(99)": 457.18186999999995, + "max": 841.721, + "avg": 201.20935666666688, + "min": 165.176, + "med": 189.49599999999998, + "p(90)": 224.9675, + "p(95)": 241.3964 + }, + "type": "trend", + "contains": "time" + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "p(99)": 7.096939999999999, + "max": 31.546, + "avg": 0.2306026666666667, + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "data_sent": { + "values": { + "count": 177234, + "rate": 2946.990339101426 + }, + "type": "counter", + "contains": "data" + }, + "data_received": { + "contains": "data", + "values": { + "count": 725292, + "rate": 12059.923699897037 + }, + "type": "counter" + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.6716153333333145, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 20.83756, + "max": 53.018 + } + } + }, + "root_group": { + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500, + "fails": 0 + }, + { + "passes": 1500, + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff" + } + ], + "name": "" + }, + "options": { + "summaryTimeUnit": "", + "noColor": false, + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"] + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60140.679 + } +} diff --git a/bench/run.ts b/bench/run.ts new file mode 100644 index 00000000..0d23efdc --- /dev/null +++ b/bench/run.ts @@ -0,0 +1,402 @@ +// Benchmarks one hosting target on its own Convex cloud project: it writes the target's app to +// bench/.work// with the package pinned to one exact version, deploys a synthetic site to +// the project's development deployment, then runs each case with k6 at a fixed arrival rate while +// it streams the deployment's function logs. One JSON file per case goes to bench/results//. +// +// node bench/run.ts --run [--files 400] [--rate 25] [--duration 60s] +// [--cases page,asset,rendered] [--no-deploy] +// +// Targets: convex-hosting-0.14.0 (npm), convex-hosting-branch (this checkout, packed), and +// static-hosting-0.2.1 (npm, the component-owned mode its README calls the fastest). +import { execFileSync, spawn } from "node:child_process"; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { dirname, join, resolve } from "node:path"; +import { parseArgs } from "node:util"; +import { writeSite } from "./site.ts"; + +const BENCH = dirname(new URL(import.meta.url).pathname); +const REPO = resolve(BENCH, ".."); +const TEAM = process.env.BENCH_TEAM ?? "nicu"; +const CONVEX = "1.46.0"; + +/** A page that `worker` renders, for the case that no file answers. */ +const WORKER = `{ + fetch: async () => + new Response("Rendered

Rendered

", { + headers: { "Content-Type": "text/html; charset=utf-8" }, + }), +}`; + +const hostingConfig = `import { defineApp } from "convex/server"; +import hosting from "@samebase/convex-hosting/convex.config"; + +const app = defineApp(); +app.use(hosting); +export default app; +`; + +const hostingHttp = ( + siteExport: "versionId" | "site", +) => `import { httpRouter } from "convex/server"; +import { routeAll } from "@samebase/convex-hosting"; +import { components } from "./_generated/api.js"; +import { ${siteExport} } from "../.convex-hosting/version.js"; + +const http = httpRouter(); +// A worker that renders one small page, so the rendered case measures hosting, not a framework. +routeAll(http, components.hosting, ${siteExport}, ${WORKER}); +export default http; +`; + +type Target = { + project: string; + dependencies: Record; + files: Record; + cases: CaseName[]; + deploy: (cwd: string) => void; +}; + +function packBranch(): string { + const dir = join(BENCH, ".work", "pack"); + mkdirSync(dir, { recursive: true }); + const output = execFileSync("pnpm", ["pack", "--pack-destination", dir], { + cwd: join(REPO, "packages", "convex-hosting"), + encoding: "utf8", + }); + const tarball = output.trim().split("\n").pop() ?? ""; + if (!tarball.endsWith(".tgz")) throw new Error(`pnpm pack printed no tarball:\n${output}`); + return tarball; +} + +const targets: Record Target> = { + "convex-hosting-0.14.0": () => ({ + project: "convex-hosting-bench-014", + dependencies: { "@samebase/convex-hosting": "0.14.0" }, + files: { "convex/convex.config.ts": hostingConfig, "convex/http.ts": hostingHttp("versionId") }, + cases: ["page", "asset", "rendered"], + deploy: (cwd) => sh(cwd, "npx", ["convex-hosting", "deploy", "--dev", "--dist", "site"]), + }), + "convex-hosting-branch": () => ({ + project: "convex-hosting-bench", + dependencies: { "@samebase/convex-hosting": `file:${packBranch()}` }, + files: { "convex/convex.config.ts": hostingConfig, "convex/http.ts": hostingHttp("site") }, + cases: ["page", "asset", "rendered"], + deploy: (cwd) => sh(cwd, "npx", ["convex-hosting", "deploy", "--dev", "--dist", "site"]), + }), + "static-hosting-0.2.1": () => ({ + project: "convex-hosting-bench-static", + dependencies: { "@convex-dev/static-hosting": "0.2.1" }, + files: { + "convex/convex.config.ts": `import { defineApp } from "convex/server"; +import staticHosting from "@convex-dev/static-hosting/convex.config"; + +// The component owns "/", the mode static-hosting's README calls the fastest. +const app = defineApp({ httpPrefix: "/api" }); +app.use(staticHosting, { httpPrefix: "/" }); +export default app; +`, + }, + // It renders no page: a path without a file answers its index.html or 404. + cases: ["page", "asset"], + deploy: (cwd) => { + sh(cwd, "npx", ["convex", "dev", "--once"]); + sh(cwd, "npx", ["@convex-dev/static-hosting", "upload", "--dist", "site", "--no-spa"]); + }, + }), +}; + +type CaseName = "page" | "asset" | "rendered"; +type Case = { + path: (paths: { asset: string }) => string; + marker: string; + fetchMode: string; + /** Whether the answer's body is a stored file, whose download Convex counts as a call. */ + download: boolean; +}; +const CASES: Record = { + page: { path: () => "/", marker: "Benchmark site", fetchMode: "navigate", download: true }, + asset: { + path: (paths) => paths.asset, + marker: "export const chunk", + fetchMode: "no-cors", + download: true, + }, + rendered: { path: () => "/rendered", marker: "Rendered", fetchMode: "navigate", download: false }, +}; + +function sh(cwd: string, command: string, args: string[]) { + execFileSync(command, args, { cwd, stdio: "inherit" }); +} + +function convexEnv(cwd: string) { + const env = readFileSync(join(cwd, ".env.local"), "utf8"); + const deployment = /^CONVEX_DEPLOYMENT=(?:dev:)?([a-z0-9-]+)/m.exec(env)?.[1]; + const site = /^CONVEX_SITE_URL=(\S+)/m.exec(env)?.[1]; + if (deployment === undefined) throw new Error(`${cwd}/.env.local has no CONVEX_DEPLOYMENT.`); + return { deployment, site: site ?? `https://${deployment}.convex.site` }; +} + +/** Writes the app and binds it to the target's project, creating the project on the first run. */ +function setUp(name: string, target: Target, files: number) { + const cwd = join(BENCH, ".work", name); + mkdirSync(join(cwd, "convex"), { recursive: true }); + const pkg = { + name: `bench-${name}`, + private: true, + type: "module", + dependencies: { convex: CONVEX, ...target.dependencies }, + }; + writeFileSync(join(cwd, "package.json"), `${JSON.stringify(pkg, null, 2)}\n`); + for (const [path, body] of Object.entries(target.files)) writeFileSync(join(cwd, path), body); + sh(cwd, "npm", ["install", "--no-audit", "--no-fund", "--loglevel=error"]); + if (!existsSync(join(cwd, ".env.local"))) { + const configure = (kind: string) => + execFileSync( + "npx", + [ + "convex", + "dev", + "--once", + "--configure", + kind, + "--team", + TEAM, + "--project", + target.project, + "--dev-deployment", + "cloud", + ], + { cwd, stdio: "inherit" }, + ); + // The first push fails while `.convex-hosting/version.js` does not exist yet; the project and + // `.env.local` are configured by then, which is what this step is for. + try { + configure("existing"); + } catch { + if (!existsSync(join(cwd, ".env.local"))) { + try { + configure("new"); + } catch { + if (!existsSync(join(cwd, ".env.local"))) + throw new Error(`Configuring ${target.project} failed.`); + } + } + } + } + const paths = writeSite(files, cwd); + return { cwd, paths }; +} + +const median = (values: number[]) => quantile(values, 0.5); +function quantile(values: number[], q: number) { + if (values.length === 0) return null; + const sorted = [...values].sort((a, b) => a - b); + return sorted[Math.min(sorted.length - 1, Math.floor(q * sorted.length))]; +} + +type LogEntry = { + kind: string; + udfType: string; + identifier: string; + componentPath: string | null; + requestId: string; + executionId: string; + timestamp: number; + executionTime: number; + success: { status?: string } | null; +}; + +/** Runs one case with k6 while the deployment's logs stream to a file, and measures both. */ +async function runCase( + cwd: string, + site: string, + caseName: CaseName, + paths: { asset: string }, + options: { rate: number; duration: string; out: string }, +) { + const spec = CASES[caseName]; + const logFile = `${options.out}.logs.jsonl`; + const logs = spawn("npx", ["convex", "logs", "--success", "--jsonl"], { + cwd, + stdio: ["ignore", "pipe", "ignore"], + }); + const chunks: Buffer[] = []; + logs.stdout.on("data", (chunk: Buffer) => chunks.push(chunk)); + await new Promise((done) => setTimeout(done, 8000)); + const start = Date.now() / 1000; + const summaryFile = `${options.out}.k6.json`; + execFileSync( + "k6", + [ + "run", + "--quiet", + "-e", + `BASE=${site}`, + "-e", + `TARGET_PATH=${spec.path(paths)}`, + "-e", + "STATUS=200", + "-e", + `MARKER=${spec.marker}`, + "-e", + `FETCH_MODE=${spec.fetchMode}`, + "-e", + `RATE=${options.rate}`, + "-e", + `DURATION=${options.duration}`, + "-e", + `OUT=${summaryFile}`, + join(BENCH, "load.js"), + ], + { stdio: "inherit" }, + ); + const end = Date.now() / 1000; + // Logs arrive a few seconds after the executions. + await new Promise((done) => setTimeout(done, 15000)); + logs.kill(); + writeFileSync(logFile, Buffer.concat(chunks)); + + const entries: LogEntry[] = Buffer.concat(chunks) + .toString("utf8") + .split("\n") + .flatMap((line) => { + try { + const entry = JSON.parse(line); + return entry?.kind === "Completion" ? [entry] : []; + } catch { + return []; + } + }) + .filter((entry) => entry.timestamp >= start - 1 && entry.timestamp <= end + 10); + const unique = [...new Map(entries.map((entry) => [entry.executionId, entry])).values()]; + const http = unique.filter((entry) => entry.udfType === "HttpAction"); + const requestIds = new Set(http.map((entry) => entry.requestId)); + const inner = unique.filter( + (entry) => entry.udfType !== "HttpAction" && requestIds.has(entry.requestId), + ); + const byFunction: Record = {}; + for (const entry of [...http, ...inner]) { + const key = `${entry.udfType} ${entry.componentPath ? `${entry.componentPath}/` : ""}${entry.identifier}`; + byFunction[key] = (byFunction[key] ?? 0) + 1; + } + const k6 = JSON.parse(readFileSync(summaryFile, "utf8")); + const metric = (name: string) => k6.metrics[name]?.values ?? {}; + const requests = metric("http_reqs").count ?? 0; + const checks = metric("checks"); + const executionsPerRequest = + http.length === 0 ? null : (http.length + inner.length) / http.length; + const passRate = checks.rate ?? 0; + return { + case: caseName, + path: spec.path(paths), + client: { + requests, + rate: metric("http_reqs").rate, + checksPassed: passRate, + failed: metric("http_req_failed").rate, + dropped: metric("dropped_iterations").count ?? 0, + latencyMs: { + median: metric("http_req_duration").med, + p90: metric("http_req_duration")["p(90)"], + p95: metric("http_req_duration")["p(95)"], + p99: metric("http_req_duration")["p(99)"], + max: metric("http_req_duration").max, + }, + }, + server: { + httpActionsLogged: http.length, + logCompleteness: requests === 0 ? null : http.length / requests, + functionsPerRequest: executionsPerRequest, + downloadsPerRequest: spec.download ? 1 : 0, + billedCallsPerRequest: + executionsPerRequest === null ? null : executionsPerRequest + (spec.download ? 1 : 0), + byFunction, + httpActionMs: { + median: median(http.map((entry) => entry.executionTime * 1000)), + p95: quantile( + http.map((entry) => entry.executionTime * 1000), + 0.95, + ), + }, + innerFunctionMs: { + median: median(inner.map((entry) => entry.executionTime * 1000)), + p95: quantile( + inner.map((entry) => entry.executionTime * 1000), + 0.95, + ), + }, + }, + }; +} + +async function main() { + const { values, positionals } = parseArgs({ + allowPositionals: true, + options: { + run: { type: "string" }, + files: { type: "string", default: "400" }, + rate: { type: "string", default: "25" }, + duration: { type: "string", default: "60s" }, + cases: { type: "string" }, + "no-deploy": { type: "boolean", default: false }, + }, + }); + const [name] = positionals; + const make = targets[name ?? ""]; + if (make === undefined || values.run === undefined) { + throw new Error( + `Usage: node bench/run.ts <${Object.keys(targets).join(" | ")}> --run [options]`, + ); + } + const target = make(); + const files = Number(values.files); + const { cwd, paths } = setUp(name, target, files); + let deploySeconds: number | null = null; + if (!values["no-deploy"]) { + const started = Date.now(); + target.deploy(cwd); + deploySeconds = (Date.now() - started) / 1000; + console.error(`Deployed ${files} files in ${deploySeconds.toFixed(0)} s.`); + } + const { deployment, site } = convexEnv(cwd); + const cases = (values.cases?.split(",") ?? target.cases) as CaseName[]; + const outDir = join(BENCH, "results", values.run); + mkdirSync(outDir, { recursive: true }); + const commit = execFileSync("git", ["rev-parse", "HEAD"], { cwd: REPO, encoding: "utf8" }).trim(); + for (const caseName of cases) { + const out = join(outDir, `${name}-${files}-${caseName}`); + console.error( + `${name}, ${files} files, ${caseName}: ${values.rate}/s for ${values.duration} on ${site}`, + ); + const result = await runCase(cwd, site, caseName, paths, { + rate: Number(values.rate), + duration: values.duration, + out, + }); + const record = { + target: name, + // The packed branch build lives in bench/.work/pack, whatever the checkout's path. + dependencies: Object.fromEntries( + Object.entries(target.dependencies).map(([name, spec]) => [ + name, + spec.replace(`file:${BENCH}/`, "file:bench/"), + ]), + ), + convex: CONVEX, + commit, + deployment, + files, + deploySeconds, + rate: Number(values.rate), + duration: values.duration, + date: new Date().toISOString(), + ...result, + }; + writeFileSync(`${out}.json`, `${JSON.stringify(record, null, 2)}\n`); + console.error( + JSON.stringify({ case: caseName, client: result.client, server: result.server }, null, 2), + ); + } +} + +await main(); diff --git a/bench/site.ts b/bench/site.ts new file mode 100644 index 00000000..7c0462f5 --- /dev/null +++ b/bench/site.ts @@ -0,0 +1,39 @@ +// Writes a synthetic built site to `/site`: an index page, a 404 page, and `count` scripts of +// about 2 KB, named the way Vite names chunks. Every file has its own bytes, so every file is stored +// once. The path of a script in the middle goes to `/paths.json`, outside the site. +// node site.ts +import { createHash } from "node:crypto"; +import { mkdirSync, rmSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; + +export function writeSite(count: number, dir: string) { + const site = join(dir, "site"); + rmSync(site, { recursive: true, force: true }); + mkdirSync(join(site, "assets"), { recursive: true }); + const names: string[] = []; + for (let i = 0; i < count; i++) { + const body = `export const chunk${i} = ${JSON.stringify("x".repeat(2000))}; // chunk ${i}\n`; + const hash = createHash("sha256").update(body).digest("base64url").slice(0, 8); + const name = `/assets/chunk-${i}-${hash}.js`; + writeFileSync(join(site, name), body); + names.push(name); + } + const page = (title: string) => + `${title}` + + `

${title}

\n`; + writeFileSync(join(site, "index.html"), page("Benchmark site")); + writeFileSync(join(site, "404.html"), page("Not found")); + const paths = { asset: names[Math.floor(count / 2)] }; + writeFileSync(join(dir, "paths.json"), `${JSON.stringify(paths)}\n`); + return paths; +} + +if (import.meta.main) { + const count = Number(process.argv[2]); + const dir = process.argv[3]; + if (!Number.isInteger(count) || count < 1 || dir === undefined) { + throw new Error("Usage: node site.ts "); + } + writeSite(count, dir); + console.log(`Wrote ${count} scripts, index.html and 404.html to ${join(dir, "site")}.`); +} From 4a8fed433f61479ff899fa192aefdc8431731537 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 03:00:57 +0200 Subject: [PATCH 06/20] Type the generated site with JSDoc; pass the site in the fixtures' app 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. --- packages/convex-hosting/src/cli/main.test.ts | 6 +++++- packages/convex-hosting/src/cli/main.ts | 8 ++++++-- .../fixtures/shared/src/run-wrangler-long-lived.ts | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/convex-hosting/src/cli/main.test.ts b/packages/convex-hosting/src/cli/main.test.ts index 9a992973..05ebcfc5 100644 --- a/packages/convex-hosting/src/cli/main.test.ts +++ b/packages/convex-hosting/src/cli/main.test.ts @@ -666,7 +666,11 @@ describe("upload", () => { home.storageId, ); - expect(versionFile(cwd).split("\n")[0]).toBe('export const versionId = "v1";'); + expect(versionFile(cwd).split("\n").slice(0, 2)).toEqual([ + 'export const versionId = "v1";', + // tsc reads the file itself in an app whose convex/tsconfig.json sets allowJs. + '/** @type {import("@samebase/convex-hosting").Site} */', + ]); const written = writtenSite(cwd); expect(written).toMatchObject({ format: 1, versionId: "v1", markToken: expect.any(String) }); const files = written.files; diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index 68021fba..ec73254c 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -539,13 +539,17 @@ const SITE_LINE = "export const site = "; /** * Writes the version file. `versionId` is its own export too, for the app query that reloads - * pages on a new version. + * pages on a new version. The site carries its type as JSDoc: Convex's default + * `convex/tsconfig.json` sets `allowJs`, so tsc reads this file instead of the package's + * declaration, and would infer `string` where `Site` has a union of literals. */ function writeVersionFile(cli: Cli, site: Site) { writeStateFile( cli, VERSION_FILE, - `export const versionId = ${JSON.stringify(site.versionId)};\n${SITE_LINE}${JSON.stringify(site)};\n`, + `export const versionId = ${JSON.stringify(site.versionId)};\n` + + `/** @type {import("@samebase/convex-hosting").Site} */\n` + + `${SITE_LINE}${JSON.stringify(site)};\n`, ); } diff --git a/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts b/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts index 64d5f8b9..c2419f39 100644 --- a/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts +++ b/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts @@ -96,11 +96,11 @@ export default app; `import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { versionId } from "../.convex-hosting/version.js"; +import { site } from "../.convex-hosting/version.js"; const http = httpRouter(); -routeAll(http, components.hosting, versionId); +routeAll(http, components.hosting, site); export default http; `, From 02c093b303f3a707f8344f9c6da94fd198923e82 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 03:00:58 +0200 Subject: [PATCH 07/20] bench: a 10,000-file site, and how long its deploy took --- bench/README.md | 5 + .../convex-hosting-branch-10000-asset.json | 48 ++++ .../convex-hosting-branch-10000-asset.k6.json | 221 ++++++++++++++++++ .../convex-hosting-branch-10000-page.json | 48 ++++ .../convex-hosting-branch-10000-page.k6.json | 221 ++++++++++++++++++ .../convex-hosting-branch-10000-rendered.json | 48 ++++ ...nvex-hosting-branch-10000-rendered.k6.json | 221 ++++++++++++++++++ 7 files changed, 812 insertions(+) create mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json create mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json create mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json create mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json create mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json create mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json diff --git a/bench/README.md b/bench/README.md index 43f28c2f..9b70453b 100644 --- a/bench/README.md +++ b/bench/README.md @@ -106,6 +106,11 @@ number of files. Measured on the same cloud deployment: ms longer (median 5.6 ms against 3.6 ms for a minimal action, 40 sequential requests each); - memory: a request could hold 86 MiB of arrays without the 100,000-file site and 77 MiB with it, the same on two runs each, so the site takes about 9 MiB; +- a real 10,000-file site (a 0.89 MB `version.js`) served the same as 400 files: HTTP action median + 51.1 ms for the page, 51.3 ms for the asset, 6.7 ms for the rendered page, one function per + request, every check passed (`2026-11-04-files-10000`); +- deploying those 10,000 files took 1,519 s. The upload makes about one `npx convex run` call per 60 + files and each call starts a process, so deploy time grows with the file count; serving does not; - 100,000 files is the most that the CLI accepts, Cloudflare's limit per Worker version. **Provenance.** The 0.15.0 deployment of the 400-file runs was built at commit `e4b3e7f`; the diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json new file mode 100644 index 00000000..10005e23 --- /dev/null +++ b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:/Users/nicu/dev/claude_worktrees/convex-hosting/manifest-serving/bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "787b8b62799901f029868cd7a622cd08fc422d5f", + "deployment": "clean-swordfish-403", + "files": 10000, + "deploySeconds": 1519.45, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:57:26.554Z", + "case": "asset", + "path": "/assets/chunk-5000-kF1X3LF9.js", + "client": { + "requests": 1500, + "rate": 24.86410935434207, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 364.0105, + "p90": 411.1783, + "p95": 430.6901, + "p99": 470.42904999999996, + "max": 517.487 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1500 + }, + "httpActionMs": { + "median": 51.27682, + "p95": 69.993623 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json new file mode 100644 index 00000000..9c5b3c8a --- /dev/null +++ b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [], + "checks": [ + { + "fails": 0, + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500 + }, + { + "passes": 1500, + "fails": 0, + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff" + } + ], + "name": "" + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60327.92 + }, + "metrics": { + "iteration_duration": { + "values": { + "p(99)": 470.7103325, + "max": 517.825708, + "avg": 305.90268958666695, + "min": 172.242625, + "med": 364.6433125, + "p(90)": 412.00411280000003, + "p(95)": 432.17006489999994 + }, + "type": "trend", + "contains": "time" + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 4.994639999999999, + "max": 27.179, + "avg": 0.20584399999999997 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "avg": 304.4408666666664, + "min": 171.31, + "med": 363.525, + "p(90)": 410.7861, + "p(95)": 430.4151, + "p(99)": 470.1576, + "max": 517.1 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "avg": 0.32309533333333357, + "min": 0.02, + "med": 0.199, + "p(90)": 0.6352000000000001, + "p(95)": 0.809, + "p(99)": 2.3743799999999995, + "max": 11.959 + } + }, + "data_sent": { + "contains": "data", + "values": { + "count": 224437, + "rate": 3720.284074106981 + }, + "type": "counter" + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 7, + "min": 4, + "max": 10 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 411.1783, + "p(95)": 430.6901, + "p(99)": 470.42904999999996, + "max": 517.487, + "avg": 304.9031146666664, + "min": 171.795, + "med": 364.0105 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 430.6901, + "p(99)": 470.42904999999996, + "max": 517.487, + "avg": 304.9031146666664, + "min": 171.795, + "med": 364.0105, + "p(90)": 411.1783 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 3543638, + "rate": 58739.60182946802 + } + }, + "http_req_failed": { + "type": "rate", + "contains": "default", + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.86410935434207 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0.002, + "p(99)": 18.652659999999997, + "max": 41.048, + "avg": 0.6275346666666477, + "min": 0, + "med": 0.001, + "p(90)": 0.002 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "rate": 24.86410935434207, + "count": 1500 + } + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.14015, + "max": 18.484, + "avg": 0.41370133333333325, + "min": 0, + "med": 0 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "min": 50, + "max": 50, + "value": 50 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "max": 1.151, + "avg": 0.13915266666666679, + "min": 0.018, + "med": 0.132, + "p(90)": 0.221, + "p(95)": 0.252, + "p(99)": 0.32404999999999995 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3000, + "fails": 0 + } + } + } +} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json new file mode 100644 index 00000000..6e3d8362 --- /dev/null +++ b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:/Users/nicu/dev/claude_worktrees/convex-hosting/manifest-serving/bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "787b8b62799901f029868cd7a622cd08fc422d5f", + "deployment": "clean-swordfish-403", + "files": 10000, + "deploySeconds": 1519.45, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:56:02.855Z", + "case": "page", + "path": "/", + "client": { + "requests": 1500, + "rate": 24.929008830586177, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 193.6695, + "p90": 225.17890000000003, + "p95": 236.8473, + "p99": 368.04908999999947, + "max": 557.027 + } + }, + "server": { + "httpActionsLogged": 1500, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 1, + "billedCallsPerRequest": 2, + "byFunction": { + "HttpAction GET /*": 1500 + }, + "httpActionMs": { + "median": 51.106435, + "p95": 75.74766199999999 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json new file mode 100644 index 00000000..7b6ff70b --- /dev/null +++ b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1500, + "fails": 0 + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1500, + "fails": 0 + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e", + "groups": [] + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "isStdOutTTY": false, + "isStdErrTTY": false, + "testRunDurationMs": 60170.864 + }, + "metrics": { + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "min": 50, + "max": 50, + "value": 50 + } + }, + "http_req_sending": { + "type": "trend", + "contains": "time", + "values": { + "med": 0.135, + "p(90)": 0.223, + "p(95)": 0.262, + "p(99)": 0.4720799999999999, + "max": 1.863, + "avg": 0.14796066666666627, + "min": 0.019 + } + }, + "http_req_receiving": { + "type": "trend", + "contains": "time", + "values": { + "min": 0.021, + "med": 0.092, + "p(90)": 0.191, + "p(95)": 0.2840499999999999, + "p(99)": 1.2169699999999974, + "max": 14.058, + "avg": 0.16429266666666686 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "avg": 202.01387066666666, + "min": 175.228, + "med": 193.6695, + "p(90)": 225.17890000000003, + "p(95)": 236.8473, + "p(99)": 368.04908999999947, + "max": 557.027 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "min": 0, + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 5.864459999999999, + "max": 22.877, + "avg": 0.20405866666666672 + } + }, + "http_reqs": { + "type": "counter", + "contains": "default", + "values": { + "count": 1500, + "rate": 24.929008830586177 + } + }, + "iteration_duration": { + "type": "trend", + "contains": "time", + "values": { + "avg": 203.04487211333333, + "min": 175.732292, + "med": 194.1988955, + "p(90)": 226.4959962, + "p(95)": 237.27997944999996, + "p(99)": 368.2446894999995, + "max": 618.0325 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "passes": 3000, + "fails": 0, + "rate": 1 + } + }, + "http_req_blocked": { + "type": "trend", + "contains": "time", + "values": { + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002, + "p(99)": 20.32886999999999, + "max": 58.704, + "avg": 0.6583759999999774, + "min": 0 + } + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "rate": 11843.888430786035, + "count": 712657 + } + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "value": 5, + "min": 4, + "max": 7 + } + }, + "http_req_failed": { + "values": { + "rate": 0, + "passes": 0, + "fails": 1500 + }, + "type": "rate", + "contains": "default" + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "p(95)": 0, + "p(99)": 12.717329999999997, + "max": 27.166, + "avg": 0.42339333333333345, + "min": 0, + "med": 0, + "p(90)": 0 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "min": 174.923, + "med": 193.3435, + "p(90)": 224.9302, + "p(95)": 236.64245, + "p(99)": 367.9315799999995, + "max": 556.962, + "avg": 201.70161733333356 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 177152, + "rate": 2944.1491815706686 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "med": 193.6695, + "p(90)": 225.17890000000003, + "p(95)": 236.8473, + "p(99)": 368.04908999999947, + "max": 557.027, + "avg": 202.01387066666666, + "min": 175.228 + } + }, + "iterations": { + "values": { + "count": 1500, + "rate": 24.929008830586177 + }, + "type": "counter", + "contains": "default" + } + } +} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json new file mode 100644 index 00000000..80605c3b --- /dev/null +++ b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json @@ -0,0 +1,48 @@ +{ + "target": "convex-hosting-branch", + "dependencies": { + "@samebase/convex-hosting": "file:/Users/nicu/dev/claude_worktrees/convex-hosting/manifest-serving/bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" + }, + "convex": "1.46.0", + "commit": "787b8b62799901f029868cd7a622cd08fc422d5f", + "deployment": "clean-swordfish-403", + "files": 10000, + "deploySeconds": 1519.45, + "rate": 25, + "duration": "60s", + "date": "2026-11-04T00:58:50.382Z", + "case": "rendered", + "path": "/rendered", + "client": { + "requests": 1501, + "rate": 24.9558476023366, + "checksPassed": 1, + "failed": 0, + "dropped": 0, + "latencyMs": { + "median": 163.722, + "p90": 199.32, + "p95": 353.607, + "p99": 751.205, + "max": 1128.569 + } + }, + "server": { + "httpActionsLogged": 1501, + "logCompleteness": 1, + "functionsPerRequest": 1, + "downloadsPerRequest": 0, + "billedCallsPerRequest": 1, + "byFunction": { + "HttpAction GET /*": 1501 + }, + "httpActionMs": { + "median": 6.688814000000001, + "p95": 9.801931 + }, + "innerFunctionMs": { + "median": null, + "p95": null + } + } +} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json new file mode 100644 index 00000000..d82110dc --- /dev/null +++ b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json @@ -0,0 +1,221 @@ +{ + "root_group": { + "groups": [], + "checks": [ + { + "name": "status", + "path": "::status", + "id": "a03b851833f5ba257445456aa0ce3cad", + "passes": 1501, + "fails": 0 + }, + { + "name": "body", + "path": "::body", + "id": "8369d5a9d3d9bb2eaaad52fc460fedff", + "passes": 1501, + "fails": 0 + } + ], + "name": "", + "path": "", + "id": "d41d8cd98f00b204e9800998ecf8427e" + }, + "options": { + "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], + "summaryTimeUnit": "", + "noColor": false + }, + "state": { + "testRunDurationMs": 60146.224, + "isStdOutTTY": false, + "isStdErrTTY": false + }, + "metrics": { + "http_req_failed": { + "values": { + "rate": 0, + "passes": 0, + "fails": 1501 + }, + "type": "rate", + "contains": "default" + }, + "vus": { + "type": "gauge", + "contains": "default", + "values": { + "min": 3, + "max": 7, + "value": 3 + } + }, + "http_req_duration": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 199.32, + "p(95)": 353.607, + "p(99)": 751.205, + "max": 1128.569, + "avg": 189.91941838774144, + "min": 141.718, + "med": 163.722 + } + }, + "iterations": { + "type": "counter", + "contains": "default", + "values": { + "count": 1501, + "rate": 24.9558476023366 + } + }, + "http_reqs": { + "contains": "default", + "values": { + "count": 1501, + "rate": 24.9558476023366 + }, + "type": "counter" + }, + "http_req_blocked": { + "contains": "time", + "values": { + "p(99)": 20.09, + "max": 47.313, + "avg": 0.660359760159874, + "min": 0, + "med": 0.001, + "p(90)": 0.002, + "p(95)": 0.002 + }, + "type": "trend" + }, + "iteration_duration": { + "values": { + "p(95)": 353.845709, + "p(99)": 751.608375, + "max": 1128.713667, + "avg": 190.93100290073258, + "min": 141.913459, + "med": 165.275584, + "p(90)": 203.417292 + }, + "type": "trend", + "contains": "time" + }, + "http_req_tls_handshaking": { + "type": "trend", + "contains": "time", + "values": { + "p(90)": 0, + "p(95)": 0, + "p(99)": 13.213, + "max": 38.137, + "avg": 0.4305909393737511, + "min": 0, + "med": 0 + } + }, + "http_req_waiting": { + "type": "trend", + "contains": "time", + "values": { + "min": 141.381, + "med": 163.364, + "p(90)": 192.91, + "p(95)": 214.424, + "p(99)": 401.341, + "max": 1081.993, + "avg": 177.2899120586276 + } + }, + "http_req_connecting": { + "type": "trend", + "contains": "time", + "values": { + "med": 0, + "p(90)": 0, + "p(95)": 0, + "p(99)": 5.259, + "max": 33.192, + "avg": 0.22209860093271153, + "min": 0 + } + }, + "http_req_sending": { + "values": { + "avg": 0.13957828114590273, + "min": 0.018, + "med": 0.128, + "p(90)": 0.218, + "p(95)": 0.251, + "p(99)": 0.319, + "max": 1.342 + }, + "type": "trend", + "contains": "time" + }, + "http_req_receiving": { + "values": { + "avg": 12.489928047968037, + "min": 0.01, + "med": 0.092, + "p(90)": 0.327, + "p(95)": 0.556, + "p(99)": 556.013, + "max": 943.125 + }, + "type": "trend", + "contains": "time" + }, + "data_received": { + "type": "counter", + "contains": "data", + "values": { + "count": 500116, + "rate": 8315.002451359209 + } + }, + "data_sent": { + "type": "counter", + "contains": "data", + "values": { + "count": 183996, + "rate": 3059.1446605193373 + } + }, + "vus_max": { + "type": "gauge", + "contains": "default", + "values": { + "value": 50, + "min": 50, + "max": 50 + } + }, + "checks": { + "type": "rate", + "contains": "default", + "values": { + "rate": 1, + "passes": 3002, + "fails": 0 + } + }, + "http_req_duration{expected_response:true}": { + "type": "trend", + "contains": "time", + "values": { + "avg": 189.91941838774144, + "min": 141.718, + "med": 163.722, + "p(90)": 199.32, + "p(95)": 353.607, + "p(99)": 751.205, + "max": 1128.569 + } + } + } +} From 51d6f5027f3d22b60001d5e0f241d618fd2b7ae9 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Wed, 4 Nov 2026 03:01:08 +0200 Subject: [PATCH 08/20] bench: count the calls of the 10,000-file deploy correctly --- bench/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bench/README.md b/bench/README.md index 9b70453b..b0d3d704 100644 --- a/bench/README.md +++ b/bench/README.md @@ -109,8 +109,10 @@ number of files. Measured on the same cloud deployment: - a real 10,000-file site (a 0.89 MB `version.js`) served the same as 400 files: HTTP action median 51.1 ms for the page, 51.3 ms for the asset, 6.7 ms for the rendered page, one function per request, every check passed (`2026-11-04-files-10000`); -- deploying those 10,000 files took 1,519 s. The upload makes about one `npx convex run` call per 60 - files and each call starts a process, so deploy time grows with the file count; serving does not; +- deploying those 10,000 files took 1,519 s: about 360 `npx convex run` calls, each its own process + (`knownFiles` per 119 files, `generateUploadUrls` per 100, `recordFiles` per 60, and 5 pages of + storage URLs), and the files themselves, four at a time. Deploy time grows with the file count; + serving does not; - 100,000 files is the most that the CLI accepts, Cloudflare's limit per Worker version. **Provenance.** The 0.15.0 deployment of the 400-file runs was built at commit `e4b3e7f`; the From b2e050888349c2cad04a32b0bbe4df53efcc74d2 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 15:00:11 +0200 Subject: [PATCH 09/20] Move the benchmark to its own branch, nicu-hosting-bench --- bench/.gitignore | 3 - bench/README.md | 121 ------ bench/load.js | 43 -- bench/report.ts | 68 --- .../convex-hosting-branch-10000-asset.json | 48 --- .../convex-hosting-branch-10000-asset.k6.json | 221 ---------- .../convex-hosting-branch-10000-page.json | 48 --- .../convex-hosting-branch-10000-page.k6.json | 221 ---------- .../convex-hosting-branch-10000-rendered.json | 48 --- ...nvex-hosting-branch-10000-rendered.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-page.json | 48 --- .../convex-hosting-0.14.0-400-page.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-rendered.json | 48 --- ...convex-hosting-0.14.0-400-rendered.k6.json | 221 ---------- .../convex-hosting-branch-400-page.json | 47 -- .../convex-hosting-branch-400-page.k6.json | 221 ---------- .../convex-hosting-branch-400-rendered.json | 47 -- ...convex-hosting-branch-400-rendered.k6.json | 221 ---------- .../static-hosting-0.2.1-400-page.json | 48 --- .../static-hosting-0.2.1-400-page.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-asset.json | 48 --- .../convex-hosting-0.14.0-400-asset.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-page.json | 48 --- .../convex-hosting-0.14.0-400-page.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-rendered.json | 48 --- ...convex-hosting-0.14.0-400-rendered.k6.json | 221 ---------- .../convex-hosting-branch-400-asset.json | 47 -- .../convex-hosting-branch-400-asset.k6.json | 221 ---------- .../convex-hosting-branch-400-page.json | 47 -- .../convex-hosting-branch-400-page.k6.json | 221 ---------- .../convex-hosting-branch-400-rendered.json | 47 -- ...convex-hosting-branch-400-rendered.k6.json | 221 ---------- .../static-hosting-0.2.1-400-asset.json | 48 --- .../static-hosting-0.2.1-400-asset.k6.json | 221 ---------- .../static-hosting-0.2.1-400-page.json | 48 --- .../static-hosting-0.2.1-400-page.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-asset.json | 48 --- .../convex-hosting-0.14.0-400-asset.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-page.json | 48 --- .../convex-hosting-0.14.0-400-page.k6.json | 221 ---------- .../convex-hosting-0.14.0-400-rendered.json | 48 --- ...convex-hosting-0.14.0-400-rendered.k6.json | 221 ---------- .../convex-hosting-branch-400-asset.json | 47 -- .../convex-hosting-branch-400-asset.k6.json | 221 ---------- .../convex-hosting-branch-400-page.json | 47 -- .../convex-hosting-branch-400-page.k6.json | 221 ---------- .../convex-hosting-branch-400-rendered.json | 47 -- ...convex-hosting-branch-400-rendered.k6.json | 221 ---------- .../static-hosting-0.2.1-400-asset.json | 48 --- .../static-hosting-0.2.1-400-asset.k6.json | 221 ---------- .../static-hosting-0.2.1-400-page.json | 48 --- .../static-hosting-0.2.1-400-page.k6.json | 221 ---------- bench/run.ts | 402 ------------------ bench/site.ts | 39 -- 54 files changed, 7124 deletions(-) delete mode 100644 bench/.gitignore delete mode 100644 bench/README.md delete mode 100644 bench/load.js delete mode 100644 bench/report.ts delete mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json delete mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json delete mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json delete mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json delete mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json delete mode 100644 bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json delete mode 100644 bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json delete mode 100644 bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json delete mode 100644 bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json delete mode 100644 bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json delete mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json delete mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json delete mode 100644 bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json delete mode 100644 bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json delete mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json delete mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json delete mode 100644 bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json delete mode 100644 bench/run.ts delete mode 100644 bench/site.ts diff --git a/bench/.gitignore b/bench/.gitignore deleted file mode 100644 index 3eb949ad..00000000 --- a/bench/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Apps, packed builds, and raw function logs of the runs. -/.work/ -/results/**/*.logs.jsonl diff --git a/bench/README.md b/bench/README.md deleted file mode 100644 index b0d3d704..00000000 --- a/bench/README.md +++ /dev/null @@ -1,121 +0,0 @@ -# Benchmark - -What one request to a hosted site costs on Convex, for three ways to serve it: - -- **convex-hosting 0.14.0**, from npm: the HTTP action asks the component's `route` query which file - answers. -- **convex-hosting 0.15.0**, this branch, packed: the HTTP action answers from the site's files, - which the deploy writes into the pushed code. -- **@convex-dev/static-hosting 0.2.1**, from npm, mounted at `/` - (`app.use(staticHosting, { httpPrefix: "/" })`), the mode its README calls the fastest: the - component's own HTTP action runs its `resolveAsset` query and reads the file from storage. - -Convex bills function calls: every query, mutation, action, and HTTP action, and every download of a -stored file ([usage limits](https://docs.convex.dev/production/usage-limits)). A flood against a -site spends them, so calls per request decide what a flood costs, and when the team's spending limit -turns every project off. - -## Method - -- **One Convex cloud project per target**, each with its own development deployment, created by - `run.ts`: `convex-hosting-bench-014`, `convex-hosting-bench` (this branch), and - `convex-hosting-bench-static`. Convex 1.46.0 in each app. -- **The same synthetic site** for all three, from `site.ts`: `index.html`, `404.html`, and 400 - scripts of about 2 KB with Vite-style hashed names, every file with its own bytes. -- **Cases.** `page`: `GET /` with `Sec-Fetch-Mode: navigate`, answered by `index.html`. `asset`: - `GET` of a hashed script. `rendered`: `GET /rendered` with `Sec-Fetch-Mode: navigate`, a path with - no file, answered by the app's code; the convex-hosting apps pass a worker that returns one small - page, so the case measures hosting and not a framework. static-hosting renders no page, so it has - no `rendered` case. -- **No cache answers.** Each request carries a unique query string, so the Cloudflare front of - `*.convex.site` passes every request to the HTTP action, as it does in a flood. -- **Every response is checked**: the status and a marker in its body (`load.js`). A fast error is - not a result. -- **Open load**: k6's `constant-arrival-rate` executor sends a fixed number of requests per second - whatever the latency, and reports the requests it could not send (`dropped`). -- **Server side** from the deployment's own log stream (`npx convex logs --success --jsonl`), - started before the load and drained after it: every function execution of every request, grouped - by request id. `logCompleteness` is the HTTP actions logged over the requests k6 sent; every run - below logged all of them. A stored file's download does not appear in the logs, so - `billedCallsPerRequest` adds one for each answer whose body is a stored file. Convex counts a - query served from its cache as a call too. -- **The client** is one laptop in Chișinău, so client latency includes the round trip to the - deployments; the server-side numbers do not depend on it. - -Run it: - -```sh -brew install k6 # or https://grafana.com/docs/k6/latest/set-up/install-k6/ -node bench/run.ts convex-hosting-0.14.0 --run --files 400 --rate 25 --duration 60s -node bench/run.ts convex-hosting-branch --run --files 400 --rate 25 --duration 60s -node bench/run.ts static-hosting-0.2.1 --run --files 400 --rate 25 --duration 60s -node bench/report.ts -``` - -The first run of a target creates its project in the team in `BENCH_TEAM` (default `nicu`) and -deploys; `--no-deploy` reuses the deployed site. `bench/.work/` holds the apps and the packed branch -build; `bench/results//` holds one JSON file per case and k6's own summary next to it. - -## Results, 2026-11-04 - -400 files. Two rounds at 25 requests/s for 60 s per case (1,500 requests each), one at 100 -requests/s (6,000 each), targets taking turns. Every response passed its checks, k6 dropped no -request, and the logs held every request. `node bench/report.ts ` prints the full tables. - -**Calls per request.** The same in every round: - -| Case | 0.14.0: functions / billed | 0.15.0: functions / billed | static-hosting 0.2.1: functions / billed | -| -------- | -------------------------: | -------------------------: | ---------------------------------------: | -| page | 2 / 3 | **1 / 2** | 2 / 3 | -| asset | 2 / 3 | **1 / 2** | 2 / 3 | -| rendered | 2 / 2 | **1 / 1** | cannot render | - -**HTTP action time**, the median in ms of each round, from the deployment's logs: - -| Case | Rate | 0.14.0 | 0.15.0 | static-hosting 0.2.1 | -| -------- | ----- | ---------- | ---------- | -------------------- | -| page | 25/s | 83.7, 94.2 | 57.6, 52.6 | 41.2, 41.8 | -| page | 100/s | 85.8 | 50.4 | 40.9 | -| asset | 25/s | 80.2, 77.7 | 52.4, 51.8 | 41.2, 41.9 | -| rendered | 25/s | 38.5, 52.1 | 6.8, 6.5 | | -| rendered | 100/s | 37.1 | 6.3 | | - -What the numbers say: - -- **0.15.0 runs one function per request**; 0.14.0 and static-hosting run two. With the download of - a stored body, which Convex bills too, a file costs 2 calls in place of 3, and a rendered page 1 - in place of 2. A flood of one million file requests is 2 million billed calls, not 3 million. -- **A rendered page is about 6 to 8 times faster** in the action (6.5 ms against 37 to 52 ms), since - the action no longer waits for a query. -- **A file is about 30 ms faster than 0.14.0 and about 10 ms slower than static-hosting.** - static-hosting's action runs inside the component, so it reads the file from storage directly; an - app's action cannot read a component's storage, so 0.14.0 and 0.15.0 fetch the file's storage URL. - The price of static-hosting's way is the second function, and that its component cannot hand a - request to the app's code, so it renders no page. -- **Query cache.** static-hosting's `resolveAsset` takes only the path, so Convex answered all of - its calls from the query cache (`cachedResult: true` in the logs), which is cheap in time but is - still a call. 0.14.0's `route` takes the full URL, so a unique query string made every call run. -- **Client latency** includes the round trip from Chișinău; its tails moved between rounds by more - than the targets differ (0.15.0 page p95: 734 ms in round 1, 248 ms in round 2), so the tables - above use the deployment's own times. - -**Large sites.** 0.15.0 carries the site's files in the pushed code, so its cost grows with the -number of files. Measured on the same cloud deployment: - -- a site object of 100,000 files is an 8.9 MB module; it pushed in 4 s, and each request ran about 2 - ms longer (median 5.6 ms against 3.6 ms for a minimal action, 40 sequential requests each); -- memory: a request could hold 86 MiB of arrays without the 100,000-file site and 77 MiB with it, - the same on two runs each, so the site takes about 9 MiB; -- a real 10,000-file site (a 0.89 MB `version.js`) served the same as 400 files: HTTP action median - 51.1 ms for the page, 51.3 ms for the asset, 6.7 ms for the rendered page, one function per - request, every check passed (`2026-11-04-files-10000`); -- deploying those 10,000 files took 1,519 s: about 360 `npx convex run` calls, each its own process - (`knownFiles` per 119 files, `generateUploadUrls` per 100, `recordFiles` per 60, and 5 pages of - storage URLs), and the files themselves, four at a time. Deploy time grows with the file count; - serving does not; -- 100,000 files is the most that the CLI accepts, Cloudflare's limit per Worker version. - -**Provenance.** The 0.15.0 deployment of the 400-file runs was built at commit `e4b3e7f`; the -`commit` field of those results is the checkout's HEAD when each case ran. The serving code -(`src/client/index.ts`, and `lookup` in `src/client/manifest.ts`) is the same at the head of the -pull request; later commits changed the CLI and the builder only. diff --git a/bench/load.js b/bench/load.js deleted file mode 100644 index bfcdd91b..00000000 --- a/bench/load.js +++ /dev/null @@ -1,43 +0,0 @@ -// k6 load script for one case. Every request carries a unique query string, so no cache in front -// of the deployment answers it: each one reaches the HTTP action, as a flood would. Every response -// is checked for its status and for a marker in its body. -// -// k6 run -e BASE=https://.convex.site -e TARGET_PATH=/ -e STATUS=200 \ -// -e MARKER="Benchmark site" -e RATE=25 -e DURATION=60s -e OUT=summary.json load.js -import http from "k6/http"; -import { check } from "k6"; -import exec from "k6/execution"; - -const rate = Number(__ENV.RATE ?? 25); -export const options = { - scenarios: { - load: { - executor: "constant-arrival-rate", - rate, - timeUnit: "1s", - duration: __ENV.DURATION ?? "60s", - preAllocatedVUs: Math.max(20, rate * 2), - maxVUs: Math.max(200, rate * 10), - }, - }, - summaryTrendStats: ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], -}; - -const status = Number(__ENV.STATUS ?? 200); -const marker = __ENV.MARKER ?? ""; - -export default function () { - const url = `${__ENV.BASE}${__ENV.TARGET_PATH}?bench=${exec.scenario.iterationInTest}-${Date.now()}`; - const response = http.get(url, { - headers: { "Sec-Fetch-Mode": __ENV.FETCH_MODE ?? "no-cors" }, - redirects: 0, - }); - check(response, { - status: (r) => r.status === status, - body: (r) => typeof r.body === "string" && r.body.includes(marker), - }); -} - -export function handleSummary(data) { - return { [__ENV.OUT ?? "summary.json"]: JSON.stringify(data, null, 2) }; -} diff --git a/bench/report.ts b/bench/report.ts deleted file mode 100644 index a7dc7fcd..00000000 --- a/bench/report.ts +++ /dev/null @@ -1,68 +0,0 @@ -// Prints the results of one or more runs as Markdown tables: one row per target and case, with the -// function calls per request that the deployment's logs show, the calls Convex bills (the logged -// functions plus the download of a stored body), the HTTP action's own time, and the latency and -// throughput that k6 saw. -// node bench/report.ts [ ...] -import { readdirSync, readFileSync } from "node:fs"; -import { join } from "node:path"; - -type Result = { - target: string; - files: number; - rate: number; - duration: string; - case: string; - client: { - requests: number; - rate: number; - checksPassed: number; - dropped: number; - latencyMs: { median: number; p95: number; p99: number }; - }; - server: { - logCompleteness: number | null; - functionsPerRequest: number | null; - billedCallsPerRequest: number | null; - byFunction: Record; - httpActionMs: { median: number | null; p95: number | null }; - innerFunctionMs: { median: number | null }; - }; -}; - -const BENCH = new URL(".", import.meta.url).pathname; -const runs = process.argv.slice(2); -if (runs.length === 0) throw new Error("Usage: node bench/report.ts [ ...]"); - -const fixed = (value: number | null | undefined, digits = 0) => - value === null || value === undefined ? "n/a" : value.toFixed(digits); - -for (const run of runs) { - const dir = join(BENCH, "results", run); - const results: Result[] = readdirSync(dir) - .filter((name) => name.endsWith(".json") && !name.endsWith(".k6.json")) - .map((name) => JSON.parse(readFileSync(join(dir, name), "utf8"))); - const order = ["page", "asset", "rendered"]; - results.sort( - (a, b) => order.indexOf(a.case) - order.indexOf(b.case) || a.target.localeCompare(b.target), - ); - const first = results[0]; - console.log(`### ${run}: ${first.rate} requests/s for ${first.duration}, ${first.files} files\n`); - console.log( - "| Case | Target | Requests | Checks passed | Functions per request | Billed calls per request | HTTP action ms (median / p95) | Inner function ms (median) | Latency ms (median / p95 / p99) | Functions logged |", - ); - console.log("| --- | --- | --: | --: | --: | --: | --: | --: | --: | --- |"); - for (const r of results) { - const functions = Object.entries(r.server.byFunction) - .map(([name, count]) => `${name}: ${count}`) - .join("
"); - console.log( - `| ${r.case} | ${r.target} | ${r.client.requests} | ${fixed(r.client.checksPassed * 100, 1)}% | ` + - `${fixed(r.server.functionsPerRequest, 2)} | ${fixed(r.server.billedCallsPerRequest, 2)} | ` + - `${fixed(r.server.httpActionMs.median, 1)} / ${fixed(r.server.httpActionMs.p95, 1)} | ` + - `${fixed(r.server.innerFunctionMs.median, 1)} | ` + - `${fixed(r.client.latencyMs.median)} / ${fixed(r.client.latencyMs.p95)} / ${fixed(r.client.latencyMs.p99)} | ` + - `${functions} |`, - ); - } - console.log(""); -} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json deleted file mode 100644 index 10005e23..00000000 --- a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:/Users/nicu/dev/claude_worktrees/convex-hosting/manifest-serving/bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "787b8b62799901f029868cd7a622cd08fc422d5f", - "deployment": "clean-swordfish-403", - "files": 10000, - "deploySeconds": 1519.45, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:57:26.554Z", - "case": "asset", - "path": "/assets/chunk-5000-kF1X3LF9.js", - "client": { - "requests": 1500, - "rate": 24.86410935434207, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 364.0105, - "p90": 411.1783, - "p95": 430.6901, - "p99": 470.42904999999996, - "max": 517.487 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1500 - }, - "httpActionMs": { - "median": 51.27682, - "p95": 69.993623 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json deleted file mode 100644 index 9c5b3c8a..00000000 --- a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-asset.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500 - }, - { - "passes": 1500, - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff" - } - ], - "name": "" - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60327.92 - }, - "metrics": { - "iteration_duration": { - "values": { - "p(99)": 470.7103325, - "max": 517.825708, - "avg": 305.90268958666695, - "min": 172.242625, - "med": 364.6433125, - "p(90)": 412.00411280000003, - "p(95)": 432.17006489999994 - }, - "type": "trend", - "contains": "time" - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 4.994639999999999, - "max": 27.179, - "avg": 0.20584399999999997 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 304.4408666666664, - "min": 171.31, - "med": 363.525, - "p(90)": 410.7861, - "p(95)": 430.4151, - "p(99)": 470.1576, - "max": 517.1 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.32309533333333357, - "min": 0.02, - "med": 0.199, - "p(90)": 0.6352000000000001, - "p(95)": 0.809, - "p(99)": 2.3743799999999995, - "max": 11.959 - } - }, - "data_sent": { - "contains": "data", - "values": { - "count": 224437, - "rate": 3720.284074106981 - }, - "type": "counter" - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 7, - "min": 4, - "max": 10 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 411.1783, - "p(95)": 430.6901, - "p(99)": 470.42904999999996, - "max": 517.487, - "avg": 304.9031146666664, - "min": 171.795, - "med": 364.0105 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 430.6901, - "p(99)": 470.42904999999996, - "max": 517.487, - "avg": 304.9031146666664, - "min": 171.795, - "med": 364.0105, - "p(90)": 411.1783 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 3543638, - "rate": 58739.60182946802 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.86410935434207 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.002, - "p(99)": 18.652659999999997, - "max": 41.048, - "avg": 0.6275346666666477, - "min": 0, - "med": 0.001, - "p(90)": 0.002 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "rate": 24.86410935434207, - "count": 1500 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.14015, - "max": 18.484, - "avg": 0.41370133333333325, - "min": 0, - "med": 0 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "min": 50, - "max": 50, - "value": 50 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "max": 1.151, - "avg": 0.13915266666666679, - "min": 0.018, - "med": 0.132, - "p(90)": 0.221, - "p(95)": 0.252, - "p(99)": 0.32404999999999995 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - } - } -} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json deleted file mode 100644 index 6e3d8362..00000000 --- a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:/Users/nicu/dev/claude_worktrees/convex-hosting/manifest-serving/bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "787b8b62799901f029868cd7a622cd08fc422d5f", - "deployment": "clean-swordfish-403", - "files": 10000, - "deploySeconds": 1519.45, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:56:02.855Z", - "case": "page", - "path": "/", - "client": { - "requests": 1500, - "rate": 24.929008830586177, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 193.6695, - "p90": 225.17890000000003, - "p95": 236.8473, - "p99": 368.04908999999947, - "max": 557.027 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1500 - }, - "httpActionMs": { - "median": 51.106435, - "p95": 75.74766199999999 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json deleted file mode 100644 index 7b6ff70b..00000000 --- a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500, - "fails": 0 - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1500, - "fails": 0 - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60170.864 - }, - "metrics": { - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "min": 50, - "max": 50, - "value": 50 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "med": 0.135, - "p(90)": 0.223, - "p(95)": 0.262, - "p(99)": 0.4720799999999999, - "max": 1.863, - "avg": 0.14796066666666627, - "min": 0.019 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.021, - "med": 0.092, - "p(90)": 0.191, - "p(95)": 0.2840499999999999, - "p(99)": 1.2169699999999974, - "max": 14.058, - "avg": 0.16429266666666686 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "avg": 202.01387066666666, - "min": 175.228, - "med": 193.6695, - "p(90)": 225.17890000000003, - "p(95)": 236.8473, - "p(99)": 368.04908999999947, - "max": 557.027 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 5.864459999999999, - "max": 22.877, - "avg": 0.20405866666666672 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.929008830586177 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 203.04487211333333, - "min": 175.732292, - "med": 194.1988955, - "p(90)": 226.4959962, - "p(95)": 237.27997944999996, - "p(99)": 368.2446894999995, - "max": 618.0325 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "passes": 3000, - "fails": 0, - "rate": 1 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 20.32886999999999, - "max": 58.704, - "avg": 0.6583759999999774, - "min": 0 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "rate": 11843.888430786035, - "count": 712657 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 5, - "min": 4, - "max": 7 - } - }, - "http_req_failed": { - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - }, - "type": "rate", - "contains": "default" - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0, - "p(99)": 12.717329999999997, - "max": 27.166, - "avg": 0.42339333333333345, - "min": 0, - "med": 0, - "p(90)": 0 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "min": 174.923, - "med": 193.3435, - "p(90)": 224.9302, - "p(95)": 236.64245, - "p(99)": 367.9315799999995, - "max": 556.962, - "avg": 201.70161733333356 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 177152, - "rate": 2944.1491815706686 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "med": 193.6695, - "p(90)": 225.17890000000003, - "p(95)": 236.8473, - "p(99)": 368.04908999999947, - "max": 557.027, - "avg": 202.01387066666666, - "min": 175.228 - } - }, - "iterations": { - "values": { - "count": 1500, - "rate": 24.929008830586177 - }, - "type": "counter", - "contains": "default" - } - } -} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json deleted file mode 100644 index 80605c3b..00000000 --- a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:/Users/nicu/dev/claude_worktrees/convex-hosting/manifest-serving/bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "787b8b62799901f029868cd7a622cd08fc422d5f", - "deployment": "clean-swordfish-403", - "files": 10000, - "deploySeconds": 1519.45, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:58:50.382Z", - "case": "rendered", - "path": "/rendered", - "client": { - "requests": 1501, - "rate": 24.9558476023366, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 163.722, - "p90": 199.32, - "p95": 353.607, - "p99": 751.205, - "max": 1128.569 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 0, - "billedCallsPerRequest": 1, - "byFunction": { - "HttpAction GET /*": 1501 - }, - "httpActionMs": { - "median": 6.688814000000001, - "p95": 9.801931 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json b/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json deleted file mode 100644 index d82110dc..00000000 --- a/bench/results/2026-11-04-files-10000/convex-hosting-branch-10000-rendered.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1501, - "fails": 0 - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0 - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e" - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "testRunDurationMs": 60146.224, - "isStdOutTTY": false, - "isStdErrTTY": false - }, - "metrics": { - "http_req_failed": { - "values": { - "rate": 0, - "passes": 0, - "fails": 1501 - }, - "type": "rate", - "contains": "default" - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "min": 3, - "max": 7, - "value": 3 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 199.32, - "p(95)": 353.607, - "p(99)": 751.205, - "max": 1128.569, - "avg": 189.91941838774144, - "min": 141.718, - "med": 163.722 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.9558476023366 - } - }, - "http_reqs": { - "contains": "default", - "values": { - "count": 1501, - "rate": 24.9558476023366 - }, - "type": "counter" - }, - "http_req_blocked": { - "contains": "time", - "values": { - "p(99)": 20.09, - "max": 47.313, - "avg": 0.660359760159874, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002 - }, - "type": "trend" - }, - "iteration_duration": { - "values": { - "p(95)": 353.845709, - "p(99)": 751.608375, - "max": 1128.713667, - "avg": 190.93100290073258, - "min": 141.913459, - "med": 165.275584, - "p(90)": 203.417292 - }, - "type": "trend", - "contains": "time" - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.213, - "max": 38.137, - "avg": 0.4305909393737511, - "min": 0, - "med": 0 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "min": 141.381, - "med": 163.364, - "p(90)": 192.91, - "p(95)": 214.424, - "p(99)": 401.341, - "max": 1081.993, - "avg": 177.2899120586276 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 5.259, - "max": 33.192, - "avg": 0.22209860093271153, - "min": 0 - } - }, - "http_req_sending": { - "values": { - "avg": 0.13957828114590273, - "min": 0.018, - "med": 0.128, - "p(90)": 0.218, - "p(95)": 0.251, - "p(99)": 0.319, - "max": 1.342 - }, - "type": "trend", - "contains": "time" - }, - "http_req_receiving": { - "values": { - "avg": 12.489928047968037, - "min": 0.01, - "med": 0.092, - "p(90)": 0.327, - "p(95)": 0.556, - "p(99)": 556.013, - "max": 943.125 - }, - "type": "trend", - "contains": "time" - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 500116, - "rate": 8315.002451359209 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 183996, - "rate": 3059.1446605193373 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3002, - "fails": 0 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "avg": 189.91941838774144, - "min": 141.718, - "med": 163.722, - "p(90)": 199.32, - "p(95)": 353.607, - "p(99)": 751.205, - "max": 1128.569 - } - } - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json deleted file mode 100644 index ad602956..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "59a16b265e416d417d8a1cb860b2ca2181dd479a", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 100, - "duration": "60s", - "date": "2026-11-04T00:22:32.215Z", - "case": "page", - "path": "/", - "client": { - "requests": 6001, - "rate": 99.62973466614376, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 257.023, - "p90": 311.373, - "p95": 352.592, - "p99": 710.21, - "max": 1378.176 - } - }, - "server": { - "httpActionsLogged": 6001, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 6001, - "Query hosting/lib:route": 6001 - }, - "httpActionMs": { - "median": 85.795543, - "p95": 156.00752500000002 - }, - "innerFunctionMs": { - "median": 31.378944, - "p95": 85.21054 - } - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json deleted file mode 100644 index 955d8e40..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 6001, - "fails": 0 - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 6001, - "fails": 0 - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e" - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdErrTTY": false, - "testRunDurationMs": 60233.022, - "isStdOutTTY": false - }, - "metrics": { - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.7769236793868597, - "min": 0, - "med": 0, - "p(90)": 0.001, - "p(95)": 0.001, - "p(99)": 22.866, - "max": 85.516 - } - }, - "data_sent": { - "contains": "data", - "values": { - "count": 710911, - "rate": 11802.678603773193 - }, - "type": "counter" - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 24, - "min": 21, - "max": 66 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 200, - "min": 200, - "max": 200 - } - }, - "http_reqs": { - "contains": "default", - "values": { - "rate": 99.62973466614376, - "count": 6001 - }, - "type": "counter" - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.30612881186468904, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 8.367, - "max": 47.705 - } - }, - "http_req_waiting": { - "values": { - "p(99)": 561.915, - "max": 1377.941, - "avg": 266.65621546408966, - "min": 188.848, - "med": 256.588, - "p(90)": 308.042, - "p(95)": 341.194 - }, - "type": "trend", - "contains": "time" - }, - "checks": { - "contains": "default", - "values": { - "rate": 1, - "passes": 12002, - "fails": 0 - }, - "type": "rate" - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 352.592, - "p(99)": 710.21, - "max": 1378.176, - "avg": 271.37595484086063, - "min": 188.954, - "med": 257.023, - "p(90)": 311.373 - } - }, - "http_req_tls_handshaking": { - "values": { - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.618, - "max": 60.395, - "avg": 0.4579161806365606, - "min": 0 - }, - "type": "trend", - "contains": "time" - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 2857976, - "rate": 47448.65698420378 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "max": 1378.176, - "avg": 271.37595484086063, - "min": 188.954, - "med": 257.023, - "p(90)": 311.373, - "p(95)": 352.592, - "p(99)": 710.21 - } - }, - "http_req_receiving": { - "contains": "time", - "values": { - "min": 0.01, - "med": 0.058, - "p(90)": 0.381, - "p(95)": 0.623, - "p(99)": 12.551, - "max": 1068.873, - "avg": 4.605456923846026 - }, - "type": "trend" - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.009, - "med": 0.095, - "p(90)": 0.187, - "p(95)": 0.207, - "p(99)": 0.259, - "max": 8.943, - "avg": 0.11428245292451296 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.62973466614376 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "fails": 6001, - "rate": 0, - "passes": 0 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 759.27625, - "max": 1433.568875, - "avg": 272.38817758223536, - "min": 189.196875, - "med": 257.454167, - "p(90)": 312.858333, - "p(95)": 354.188833 - } - } - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json deleted file mode 100644 index 98126da7..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "59a16b265e416d417d8a1cb860b2ca2181dd479a", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 100, - "duration": "60s", - "date": "2026-11-04T00:23:55.775Z", - "case": "rendered", - "path": "/rendered", - "client": { - "requests": 6001, - "rate": 99.68078561415406, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 179.878, - "p90": 209.266, - "p95": 223.76, - "p99": 267.863, - "max": 473.518 - } - }, - "server": { - "httpActionsLogged": 6001, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 0, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 6001, - "Query hosting/lib:route": 6001 - }, - "httpActionMs": { - "median": 37.111976999999996, - "p95": 78.535619 - }, - "innerFunctionMs": { - "median": 30.263236, - "p95": 69.118443 - } - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json deleted file mode 100644 index 015ecda3..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-0.14.0-400-rendered.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "options": { - "noColor": false, - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "" - }, - "state": { - "testRunDurationMs": 60202.174, - "isStdOutTTY": false, - "isStdErrTTY": false - }, - "metrics": { - "http_req_receiving": { - "contains": "time", - "values": { - "avg": 0.22484269288451914, - "min": 0.008, - "med": 0.066, - "p(90)": 0.372, - "p(95)": 0.565, - "p(99)": 1.892, - "max": 35.566 - }, - "type": "trend" - }, - "http_req_duration{expected_response:true}": { - "contains": "time", - "values": { - "med": 179.878, - "p(90)": 209.266, - "p(95)": 223.76, - "p(99)": 267.863, - "max": 473.518, - "avg": 185.8849725045822, - "min": 160.12 - }, - "type": "trend" - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 12002, - "fails": 0 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 1999951, - "rate": 33220.57771534962 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0, - "p(99)": 7.584, - "max": 61.924, - "avg": 0.31845892351274785, - "min": 0, - "med": 0, - "p(90)": 0 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "rate": 12220.505525265582, - "count": 735701 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 0.244, - "max": 3.647, - "avg": 0.09366355607398792, - "min": 0.011, - "med": 0.087, - "p(90)": 0.142, - "p(95)": 0.168 - } - }, - "http_req_tls_handshaking": { - "contains": "time", - "values": { - "avg": 0.4922129645059154, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 12.694, - "max": 68.277 - }, - "type": "trend" - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 267.582, - "max": 472.918, - "avg": 185.56646625562368, - "min": 159.781, - "med": 179.589, - "p(90)": 208.874, - "p(95)": 223.33 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.68078561415406 - } - }, - "vus_max": { - "values": { - "value": 200, - "min": 200, - "max": 200 - }, - "type": "gauge", - "contains": "default" - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "max": 473.718917, - "avg": 186.9450982289622, - "min": 160.367041, - "med": 180.499208, - "p(90)": 211.515583, - "p(95)": 227.79675, - "p(99)": 272.715125 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 6001 - } - }, - "http_reqs": { - "contains": "default", - "values": { - "rate": 99.68078561415406, - "count": 6001 - }, - "type": "counter" - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 20, - "min": 16, - "max": 28 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 185.8849725045822, - "min": 160.12, - "med": 179.878, - "p(90)": 209.266, - "p(95)": 223.76, - "p(99)": 267.863, - "max": 473.518 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "med": 0.001, - "p(90)": 0.001, - "p(95)": 0.001, - "p(99)": 21.237, - "max": 118.636, - "avg": 0.8143279453425541, - "min": 0 - } - } - }, - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 6001 - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 6001, - "fails": 0 - } - ] - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json deleted file mode 100644 index 80f82fbc..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 100, - "duration": "60s", - "date": "2026-11-04T00:19:44.797Z", - "case": "page", - "path": "/", - "client": { - "requests": 6001, - "rate": 99.43415981440592, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 231.491, - "p90": 483.475, - "p95": 788.765, - "p99": 1176.617, - "max": 4670.928 - } - }, - "server": { - "httpActionsLogged": 6001, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 6001 - }, - "httpActionMs": { - "median": 50.372121, - "p95": 104.557229 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json deleted file mode 100644 index 921faa54..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 6001, - "fails": 0, - "name": "status" - }, - { - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 6001 - } - ], - "name": "" - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60351.493 - }, - "metrics": { - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0, - "p(95)": 0, - "p(99)": 11.609, - "max": 43.512, - "avg": 0.3835814030994833, - "min": 0, - "med": 0 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.43415981440592 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 2857407, - "rate": 47346.08636773907 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 30, - "min": 25, - "max": 54 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 483.618417, - "p(95)": 789.117209, - "p(99)": 1176.848667, - "max": 4684.919584, - "avg": 311.984442438594, - "min": 190.540041, - "med": 232.1015 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 200, - "min": 200, - "max": 200 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.43415981440592 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "min": 190.415, - "med": 231.491, - "p(90)": 483.475, - "p(95)": 788.765, - "p(99)": 1176.617, - "max": 4670.928, - "avg": 311.1250681553072 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0.001, - "p(90)": 0.001, - "p(95)": 0.001, - "p(99)": 19.499, - "max": 47.717, - "avg": 0.6157192134645288 - } - }, - "http_req_waiting": { - "values": { - "min": 190.314, - "med": 230.41, - "p(90)": 418.975, - "p(95)": 467.186, - "p(99)": 844.68, - "max": 4670.824, - "avg": 272.4702454590907 - }, - "type": "trend", - "contains": "time" - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 311.1250681553072, - "min": 190.415, - "med": 231.491, - "p(90)": 483.475, - "p(95)": 788.765, - "p(99)": 1176.617, - "max": 4670.928 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.22682986168971828, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 7.128, - "max": 31.236 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.09273021163139508, - "min": 0.011, - "med": 0.085, - "p(90)": 0.145, - "p(95)": 0.174, - "p(99)": 0.243, - "max": 2.378 - } - }, - "http_req_receiving": { - "contains": "time", - "values": { - "max": 1910.575, - "avg": 38.562092484585904, - "min": 0.009, - "med": 0.068, - "p(90)": 0.781, - "p(95)": 540.043, - "p(99)": 633.404 - }, - "type": "trend" - }, - "checks": { - "values": { - "passes": 12002, - "fails": 0, - "rate": 1 - }, - "type": "rate", - "contains": "default" - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 6001 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 711578, - "rate": 11790.561668457813 - } - } - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json deleted file mode 100644 index e4222b40..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 100, - "duration": "60s", - "date": "2026-11-04T00:21:08.328Z", - "case": "rendered", - "path": "/rendered", - "client": { - "requests": 6001, - "rate": 99.70718222020065, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 162.833, - "p90": 214.632, - "p95": 406.845, - "p99": 754.098, - "max": 1898.888 - } - }, - "server": { - "httpActionsLogged": 6001, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 0, - "billedCallsPerRequest": 1, - "byFunction": { - "HttpAction GET /*": 6001 - }, - "httpActionMs": { - "median": 6.285255, - "p95": 24.15231 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json b/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json deleted file mode 100644 index cbed74a9..00000000 --- a/bench/results/2026-11-04-load-100/convex-hosting-branch-400-rendered.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 6001 - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 6001, - "fails": 0 - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60186.236 - }, - "metrics": { - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 182.49748058656922, - "min": 140.39, - "med": 162.379, - "p(90)": 200.722, - "p(95)": 300.682, - "p(99)": 559.133, - "max": 982.644 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 6001 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 17, - "min": 15, - "max": 47 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.7268691884686606, - "min": 0, - "med": 0, - "p(90)": 0.001, - "p(95)": 0.001, - "p(99)": 20.342, - "max": 102.977 - } - }, - "http_req_duration{expected_response:true}": { - "contains": "time", - "values": { - "p(99)": 754.098, - "max": 1898.888, - "avg": 196.3969903349441, - "min": 140.56, - "med": 162.833, - "p(90)": 214.632, - "p(95)": 406.845 - }, - "type": "trend" - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "rate": 12232.830110857903, - "count": 736248 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.70718222020065 - } - }, - "http_req_sending": { - "values": { - "p(90)": 0.139, - "p(95)": 0.179, - "p(99)": 0.231, - "max": 3.798, - "avg": 0.07968638560239942, - "min": 0.01, - "med": 0.064 - }, - "type": "trend", - "contains": "time" - }, - "iteration_duration": { - "values": { - "p(90)": 218.328958, - "p(95)": 407.025625, - "p(99)": 754.716083, - "max": 1899.0645, - "avg": 197.29451881436395, - "min": 140.647959, - "med": 164.059875 - }, - "type": "trend", - "contains": "time" - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.70718222020065 - } - }, - "vus_max": { - "contains": "default", - "values": { - "min": 200, - "max": 200, - "value": 200 - }, - "type": "gauge" - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "passes": 12002, - "fails": 0, - "rate": 1 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "max": 71.844, - "avg": 0.43535710714880843, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 12.25 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 1999668, - "rate": 33224.67283051228 - } - }, - "http_req_connecting": { - "contains": "time", - "values": { - "avg": 0.2880094984169305, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 7.348, - "max": 56.339 - }, - "type": "trend" - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.825, - "p(99)": 557.986, - "max": 1700.456, - "avg": 13.819823362772837, - "min": 0.008, - "med": 0.051, - "p(90)": 0.511 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 214.632, - "p(95)": 406.845, - "p(99)": 754.098, - "max": 1898.888, - "avg": 196.3969903349441, - "min": 140.56, - "med": 162.833 - } - } - } -} diff --git a/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json b/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json deleted file mode 100644 index 75f28e70..00000000 --- a/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "static-hosting-0.2.1", - "dependencies": { - "@convex-dev/static-hosting": "0.2.1" - }, - "convex": "1.46.0", - "commit": "59a16b265e416d417d8a1cb860b2ca2181dd479a", - "deployment": "handsome-rooster-935", - "files": 400, - "rate": 100, - "duration": "60s", - "date": "2026-11-04T00:25:19.633Z", - "case": "page", - "path": "/", - "client": { - "requests": 6001, - "rate": 99.70882066829435, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 182.379, - "p90": 201.938, - "p95": 223.055, - "p99": 442.519, - "max": 670.182 - } - }, - "server": { - "httpActionsLogged": 6001, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 6001, - "Query staticHosting/lib:resolveAsset": 6001 - }, - "httpActionMs": { - "median": 40.893583, - "p95": 69.520205 - }, - "innerFunctionMs": { - "median": 0.0283, - "p95": 0.038408000000000005 - } - } -} diff --git a/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json b/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json deleted file mode 100644 index 1c76c75b..00000000 --- a/bench/results/2026-11-04-load-100/static-hosting-0.2.1-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 6001, - "fails": 0, - "name": "status" - }, - { - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 6001, - "fails": 0, - "name": "body" - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60185.247 - }, - "metrics": { - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 200, - "min": 200, - "max": 200 - } - }, - "http_req_waiting": { - "contains": "time", - "values": { - "p(99)": 441.971, - "max": 670.013, - "avg": 191.35601866355586, - "min": 160.659, - "med": 182.155, - "p(90)": 201.668, - "p(95)": 222.508 - }, - "type": "trend" - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "min": 160.887042, - "med": 182.793125, - "p(90)": 203.914042, - "p(95)": 227.372834, - "p(99)": 457.769125, - "max": 670.344542, - "avg": 192.54206877287078 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.70882066829435 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "min": 160.755, - "med": 182.379, - "p(90)": 201.938, - "p(95)": 223.055, - "p(99)": 442.519, - "max": 670.182, - "avg": 191.58453757707073 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.7157502082987204, - "min": 0, - "med": 0.001, - "p(90)": 0.001, - "p(95)": 0.001, - "p(99)": 20.427, - "max": 103.591 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.08995550741543076, - "min": 0.009, - "med": 0.081, - "p(90)": 0.139, - "p(95)": 0.167, - "p(99)": 0.228, - "max": 3.565 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.009, - "med": 0.063, - "p(90)": 0.3, - "p(95)": 0.461, - "p(99)": 0.764, - "max": 33.057, - "avg": 0.13856340609898304 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "fails": 0, - "rate": 1, - "passes": 12002 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 2900034, - "rate": 48185.130817856414 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0, - "p(95)": 0, - "p(99)": 12.413, - "max": 47.272, - "avg": 0.402736710548242, - "min": 0, - "med": 0 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 191.58453757707073, - "min": 160.755, - "med": 182.379, - "p(90)": 201.938, - "p(95)": 223.055, - "p(99)": 442.519, - "max": 670.182 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 6001 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 711070, - "rate": 11814.6894038667 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0, - "p(99)": 6.985, - "max": 90.022, - "avg": 0.30727745375770704, - "min": 0, - "med": 0, - "p(90)": 0 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 6001, - "rate": 99.70882066829435 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 19, - "min": 17, - "max": 23 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json deleted file mode 100644 index fa5a0b57..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "e4b3e7f6200d165753b23a8f2902d66d3e2ee827", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-03T23:58:47.518Z", - "case": "asset", - "path": "/assets/chunk-200-ICKA4Pr8.js", - "client": { - "requests": 1501, - "rate": 24.92914252469102, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 286.718, - "p90": 459.315, - "p95": 481.152, - "p99": 587.487, - "max": 960.162 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1501, - "Query hosting/lib:route": 1501 - }, - "httpActionMs": { - "median": 80.194192, - "p95": 134.30827100000002 - }, - "innerFunctionMs": { - "median": 27.237614999999998, - "p95": 59.55118 - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json deleted file mode 100644 index 3dfd3035..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-asset.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "passes": 1501, - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad" - }, - { - "passes": 1501, - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff" - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdErrTTY": false, - "testRunDurationMs": 60210.655, - "isStdOutTTY": false - }, - "metrics": { - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3002, - "fails": 0 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 26.797, - "max": 474.577, - "avg": 2.6636855429714767, - "min": 0, - "med": 0.001 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 7, - "min": 5, - "max": 15 - } - }, - "http_req_duration{expected_response:true}": { - "values": { - "med": 286.718, - "p(90)": 459.315, - "p(95)": 481.152, - "p(99)": 587.487, - "max": 960.162, - "avg": 327.1648767488346, - "min": 198.447 - }, - "type": "trend", - "contains": "time" - }, - "http_reqs": { - "values": { - "count": 1501, - "rate": 24.92914252469102 - }, - "type": "counter", - "contains": "default" - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.92914252469102 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "max": 471.024, - "avg": 0.8314117255163225, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 15.061 - } - }, - "http_req_connecting": { - "values": { - "avg": 1.8256508994003993, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 12.419, - "max": 421.713 - }, - "type": "trend", - "contains": "time" - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "med": 0.195, - "p(90)": 0.657, - "p(95)": 1.192, - "p(99)": 4.175, - "max": 209.629, - "avg": 0.6361852098600932, - "min": 0.019 - } - }, - "iteration_duration": { - "contains": "time", - "values": { - "min": 198.703416, - "med": 292.407334, - "p(90)": 462.313042, - "p(95)": 488.362458, - "p(99)": 627.809667, - "max": 960.272042, - "avg": 330.160511512991 - }, - "type": "trend" - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 3545619, - "rate": 58886.90299084107 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 222924, - "rate": 3702.401177997482 - } - }, - "http_req_duration": { - "values": { - "avg": 327.1648767488346, - "min": 198.447, - "med": 286.718, - "p(90)": 459.315, - "p(95)": 481.152, - "p(99)": 587.487, - "max": 960.162 - }, - "type": "trend", - "contains": "time" - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 326.3933451032647, - "min": 198.072, - "med": 285.331, - "p(90)": 458.723, - "p(95)": 480.313, - "p(99)": 587.294, - "max": 958.989 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "fails": 1501, - "rate": 0, - "passes": 0 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.244, - "p(99)": 0.297, - "max": 6.482, - "avg": 0.13534643570952684, - "min": 0.013, - "med": 0.116, - "p(90)": 0.212 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json deleted file mode 100644 index 2d761bff..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "e4b3e7f6200d165753b23a8f2902d66d3e2ee827", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-03T23:57:23.976Z", - "case": "page", - "path": "/", - "client": { - "requests": 1501, - "rate": 24.83249029427659, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 225.488, - "p90": 274.719, - "p95": 382.311, - "p99": 591.463, - "max": 729.529 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1501, - "Query hosting/lib:route": 1501 - }, - "httpActionMs": { - "median": 83.74910000000001, - "p95": 140.898077 - }, - "innerFunctionMs": { - "median": 29.727267, - "p95": 72.000154 - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json deleted file mode 100644 index fb34de54..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "checks": [ - { - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1501, - "fails": 0, - "name": "status" - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0 - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [] - }, - "options": { - "noColor": false, - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "" - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60445.005 - }, - "metrics": { - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 5, - "min": 5, - "max": 16 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 0.317, - "max": 4.907, - "avg": 0.13103597601598926, - "min": 0.019, - "med": 0.112, - "p(90)": 0.209, - "p(95)": 0.247 - } - }, - "data_sent": { - "contains": "data", - "values": { - "count": 176710, - "rate": 2923.4839173228625 - }, - "type": "counter" - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 382.311, - "p(99)": 591.463, - "max": 729.529, - "avg": 245.02712125249843, - "min": 197.468, - "med": 225.488, - "p(90)": 274.719 - } - }, - "http_req_connecting": { - "values": { - "max": 31.54, - "avg": 0.20375816122584936, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 5.829 - }, - "type": "trend", - "contains": "time" - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 274.524, - "p(95)": 382.071, - "p(99)": 591.347, - "max": 729.375, - "avg": 244.65334643570972, - "min": 197.222, - "med": 225.134 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "med": 226.362458, - "p(90)": 275.344042, - "p(95)": 382.681, - "p(99)": 591.608208, - "max": 729.757416, - "avg": 245.97733114790134, - "min": 197.784292 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.83249029427659 - } - }, - "checks": { - "contains": "default", - "values": { - "rate": 1, - "passes": 3002, - "fails": 0 - }, - "type": "rate" - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.338, - "max": 30.867, - "avg": 0.41455229846768815 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 245.02712125249843, - "min": 197.468, - "med": 225.488, - "p(90)": 274.719, - "p(95)": 382.311, - "p(99)": 591.463, - "max": 729.529 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1501 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.83249029427659 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.015, - "med": 0.082, - "p(90)": 0.248, - "p(95)": 0.462, - "p(99)": 6.565, - "max": 18.362, - "avg": 0.24273884077281854 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 715038, - "rate": 11829.563087967317 - } - }, - "vus_max": { - "values": { - "min": 50, - "max": 50, - "value": 50 - }, - "type": "gauge", - "contains": "default" - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 19.232, - "max": 42.831, - "avg": 0.6267275149899891, - "min": 0, - "med": 0.001, - "p(90)": 0.001, - "p(95)": 0.002 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json deleted file mode 100644 index a2fbfa81..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "e4b3e7f6200d165753b23a8f2902d66d3e2ee827", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:00:11.028Z", - "case": "rendered", - "path": "/rendered", - "client": { - "requests": 1501, - "rate": 24.93262833406008, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 221.347, - "p90": 722.982, - "p95": 803.121, - "p99": 1278.326, - "max": 3090.314 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 0, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1501, - "Query hosting/lib:route": 1501 - }, - "httpActionMs": { - "median": 38.503006, - "p95": 215.91706399999998 - }, - "innerFunctionMs": { - "median": 32.138822, - "p95": 196.070833 - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json deleted file mode 100644 index 7a2185f7..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-0.14.0-400-rendered.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1501, - "fails": 0 - }, - { - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0, - "name": "body" - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e" - }, - "options": { - "noColor": false, - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "" - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60202.237 - }, - "metrics": { - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 1.005, - "p(95)": 535.285, - "p(99)": 587.028, - "max": 1717.155, - "avg": 38.5436708860759, - "min": 0.013, - "med": 0.098 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1501 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 804.023125, - "p(99)": 1278.603834, - "max": 3090.603375, - "avg": 323.5828255216518, - "min": 192.988334, - "med": 222.442125, - "p(90)": 724.163708 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0, - "p(99)": 13.183, - "max": 19.941, - "avg": 0.4156715522984677, - "min": 0, - "med": 0, - "p(90)": 0 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "med": 221.347, - "p(90)": 722.982, - "p(95)": 803.121, - "p(99)": 1278.326, - "max": 3090.314, - "avg": 322.5866742171876, - "min": 192.565 - } - }, - "http_reqs": { - "values": { - "count": 1501, - "rate": 24.93262833406008 - }, - "type": "counter", - "contains": "default" - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.20107928047968024, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 5.083, - "max": 30.915 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 183765, - "rate": 3052.4613229903734 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 803.121, - "p(99)": 1278.326, - "max": 3090.314, - "avg": 322.5866742171876, - "min": 192.565, - "med": 221.347, - "p(90)": 722.982 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.93262833406008 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3002, - "fails": 0 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "med": 0.133, - "p(90)": 0.23, - "p(95)": 0.255, - "p(99)": 0.3, - "max": 1.434, - "avg": 0.14385809460359786, - "min": 0.014 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 283.89914523650833, - "min": 192.318, - "med": 219.026, - "p(90)": 424.568, - "p(95)": 612.216, - "p(99)": 1139.34, - "max": 3090.178 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 5, - "min": 5, - "max": 21 - } - }, - "data_received": { - "contains": "data", - "values": { - "count": 500794, - "rate": 8318.528097220042 - }, - "type": "counter" - }, - "http_req_blocked": { - "values": { - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 18.689, - "max": 57.874, - "avg": 0.6501752165222993, - "min": 0 - }, - "type": "trend", - "contains": "time" - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json deleted file mode 100644 index 711b59e0..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:02:59.282Z", - "case": "asset", - "path": "/assets/chunk-200-ICKA4Pr8.js", - "client": { - "requests": 1501, - "rate": 24.805091227622473, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 254.698, - "p90": 428.481, - "p95": 453.995, - "p99": 528.431, - "max": 696.138 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1501 - }, - "httpActionMs": { - "median": 52.426236, - "p95": 119.598738 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json deleted file mode 100644 index 95ac946f..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-asset.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60511.771 - }, - "metrics": { - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 223072, - "rate": 3686.4232580467688 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 5, - "min": 4, - "max": 10 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 5.452, - "max": 21.092, - "avg": 0.1817435043304463 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "passes": 3002, - "fails": 0, - "rate": 1 - } - }, - "http_req_receiving": { - "contains": "time", - "values": { - "max": 45.378, - "avg": 0.44689540306462316, - "min": 0.022, - "med": 0.219, - "p(90)": 0.72, - "p(95)": 1.18, - "p(99)": 3.027 - }, - "type": "trend" - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.13669953364423718, - "min": 0.024, - "med": 0.125, - "p(90)": 0.214, - "p(95)": 0.245, - "p(99)": 0.313, - "max": 1.396 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.049, - "max": 45.218, - "avg": 0.4439940039973351, - "min": 0, - "med": 0 - } - }, - "http_reqs": { - "contains": "default", - "values": { - "count": 1501, - "rate": 24.805091227622473 - }, - "type": "counter" - }, - "http_req_failed": { - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1501 - }, - "type": "rate" - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 298.01425249833443, - "min": 170.938, - "med": 254.698, - "p(90)": 428.481, - "p(95)": 453.995, - "p(99)": 528.431, - "max": 696.138 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 528.431, - "max": 696.138, - "avg": 298.01425249833443, - "min": 170.938, - "med": 254.698, - "p(90)": 428.481, - "p(95)": 453.995 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.805091227622473 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.002, - "p(99)": 18.95, - "max": 50.884, - "avg": 0.6341339107261625, - "min": 0, - "med": 0.001, - "p(90)": 0.002 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 3542242, - "rate": 58538.06526336834 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 455.199375, - "p(99)": 528.660584, - "max": 696.65725, - "avg": 299.00296180946054, - "min": 171.363583, - "med": 258.097625, - "p(90)": 429.209333 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 427.381, - "p(95)": 453.422, - "p(99)": 527.694, - "max": 695.672, - "avg": 297.4306575616258, - "min": 170.161, - "med": 254.501 - } - }, - "vus_max": { - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - }, - "type": "gauge" - } - }, - "root_group": { - "groups": [], - "checks": [ - { - "passes": 1501, - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad" - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0 - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e" - }, - "options": { - "summaryTimeUnit": "", - "noColor": false, - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"] - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json deleted file mode 100644 index 4e4d4892..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:01:35.471Z", - "case": "page", - "path": "/", - "client": { - "requests": 1501, - "rate": 24.91967968864645, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 237.133, - "p90": 445.967, - "p95": 733.616, - "p99": 1156.65, - "max": 3474.021 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1501 - }, - "httpActionMs": { - "median": 57.570224, - "p95": 150.741701 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json deleted file mode 100644 index 612f2bd3..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1501 - }, - { - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0, - "name": "body", - "path": "::body" - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60233.519 - }, - "metrics": { - "iteration_duration": { - "values": { - "p(90)": 446.15725, - "p(95)": 733.85, - "p(99)": 1156.892125, - "max": 3474.300541, - "avg": 299.5787605562957, - "min": 176.004959, - "med": 237.972541 - }, - "type": "trend", - "contains": "time" - }, - "http_reqs": { - "values": { - "count": 1501, - "rate": 24.91967968864645 - }, - "type": "counter", - "contains": "default" - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 464.275, - "p(99)": 954.468, - "max": 3473.863, - "avg": 275.59089073950724, - "min": 174.563, - "med": 235.509, - "p(90)": 352.751 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "max": 3474.021, - "avg": 298.41526915389744, - "min": 175.62, - "med": 237.133, - "p(90)": 445.967, - "p(95)": 733.616, - "p(99)": 1156.65 - } - }, - "vus": { - "contains": "default", - "values": { - "value": 6, - "min": 4, - "max": 18 - }, - "type": "gauge" - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "min": 175.62, - "med": 237.133, - "p(90)": 445.967, - "p(95)": 733.616, - "p(99)": 1156.65, - "max": 3474.021, - "avg": 298.41526915389744 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 714217, - "rate": 11857.467600390408 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.02, - "med": 0.09, - "p(90)": 0.368, - "p(95)": 6.154, - "p(99)": 569.765, - "max": 1765.179, - "avg": 22.676794137241846 - } - }, - "data_sent": { - "values": { - "count": 177187, - "rate": 2941.6677448315777 - }, - "type": "counter", - "contains": "data" - }, - "http_req_blocked": { - "values": { - "p(99)": 22.475, - "max": 106.992, - "avg": 0.8181105929380224, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002 - }, - "type": "trend", - "contains": "time" - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.91967968864645 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 6.208, - "max": 88.413, - "avg": 0.300180546302465 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1501 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3002, - "fails": 0 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "max": 47.403, - "avg": 0.5018427714856762, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 14.683 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.257, - "p(99)": 0.318, - "max": 6.179, - "avg": 0.1475842771485677, - "min": 0.019, - "med": 0.132, - "p(90)": 0.227 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json deleted file mode 100644 index 128f14fe..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:04:22.709Z", - "case": "rendered", - "path": "/rendered", - "client": { - "requests": 1500, - "rate": 24.953610406467362, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 155.63549999999998, - "p90": 197.228, - "p95": 219.61004999999992, - "p99": 351.1921999999999, - "max": 756.188 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 0, - "billedCallsPerRequest": 1, - "byFunction": { - "HttpAction GET /*": 1500 - }, - "httpActionMs": { - "median": 6.828411, - "p95": 51.278107000000006 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json b/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json deleted file mode 100644 index 301188b6..00000000 --- a/bench/results/2026-11-04-steady-1/convex-hosting-branch-400-rendered.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500 - }, - { - "passes": 1500, - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff" - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60111.542 - }, - "metrics": { - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.42965066666666674, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.360009999999999, - "max": 21.467 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.953610406467362 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 168.8048753333333, - "min": 141.345, - "med": 155.303, - "p(90)": 196.399, - "p(95)": 218.79614999999998, - "p(99)": 325.49924999999973, - "max": 543.879 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "med": 0.095, - "p(90)": 0.3383000000000001, - "p(95)": 0.5450499999999999, - "p(99)": 5.658919999999999, - "max": 562.729, - "avg": 1.3719860000000035, - "min": 0.009 - } - }, - "http_req_blocked": { - "contains": "time", - "values": { - "avg": 0.6863839999999809, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 20.826289999999975, - "max": 45.573 - }, - "type": "trend" - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "min": 141.477, - "med": 155.63549999999998, - "p(90)": 197.228, - "p(95)": 219.61004999999992, - "p(99)": 351.1921999999999, - "max": 756.188, - "avg": 170.30926000000025 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "min": 50, - "max": 50, - "value": 50 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "max": 756.188, - "avg": 170.30926000000025, - "min": 141.477, - "med": 155.63549999999998, - "p(90)": 197.228, - "p(95)": 219.61004999999992, - "p(99)": 351.1921999999999 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.953610406467362 - } - }, - "data_received": { - "contains": "data", - "values": { - "count": 499944, - "rate": 8316.938534033947 - }, - "type": "counter" - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 201.992542, - "p(95)": 221.12645384999996, - "p(99)": 351.63643757999995, - "max": 756.568125, - "avg": 171.34394521666647, - "min": 141.811666, - "med": 157.037146 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.13239866666666658, - "min": 0.024, - "med": 0.124, - "p(90)": 0.20610000000000003, - "p(95)": 0.23604999999999993, - "p(99)": 0.28901, - "max": 1.028 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 183515, - "rate": 3052.9078758285723 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 3, - "min": 3, - "max": 8 - } - }, - "http_req_connecting": { - "contains": "time", - "values": { - "max": 32.034, - "avg": 0.2487620000000001, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 6.343779999999999 - }, - "type": "trend" - } - } -} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json deleted file mode 100644 index 5707a73c..00000000 --- a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "static-hosting-0.2.1", - "dependencies": { - "@convex-dev/static-hosting": "0.2.1" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "handsome-rooster-935", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:07:10.308Z", - "case": "asset", - "path": "/assets/chunk-200-ICKA4Pr8.js", - "client": { - "requests": 1500, - "rate": 24.864716465068796, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 218.94, - "p90": 399.06080000000003, - "p95": 425.9124499999999, - "p99": 464.18411, - "max": 513.511 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1500, - "Query staticHosting/lib:resolveAsset": 1500 - }, - "httpActionMs": { - "median": 41.247077, - "p95": 66.25379500000001 - }, - "innerFunctionMs": { - "median": 0.02624, - "p95": 0.031795000000000004 - } - } -} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json deleted file mode 100644 index 45b91750..00000000 --- a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-asset.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500, - "fails": 0 - }, - { - "passes": 1500, - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff" - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "testRunDurationMs": 60326.447, - "isStdOutTTY": false, - "isStdErrTTY": false - }, - "metrics": { - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 402.9010711, - "p(95)": 429.24734614999994, - "p(99)": 465.94778991, - "max": 521.145292, - "avg": 281.6569808719999, - "min": 165.800625, - "med": 220.593771 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.864716465068796 - } - }, - "http_reqs": { - "values": { - "rate": 24.864716465068796, - "count": 1500 - }, - "type": "counter", - "contains": "default" - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 399.06080000000003, - "p(95)": 425.9124499999999, - "p(99)": 464.18411, - "max": 513.511, - "avg": 280.53669400000024, - "min": 165.558, - "med": 218.94 - } - }, - "http_req_failed": { - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - }, - "type": "rate", - "contains": "default" - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.765380666666647, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 21.131439999999994, - "max": 62.012 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0, - "p(99)": 6.083979999999999, - "max": 24.246, - "avg": 0.22953333333333342, - "min": 0, - "med": 0, - "p(90)": 0 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.5274920000000001, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.818379999999998, - "max": 57.944 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 464.18411, - "max": 513.511, - "avg": 280.53669400000024, - "min": 165.558, - "med": 218.94, - "p(90)": 399.06080000000003, - "p(95)": 425.9124499999999 - } - }, - "data_received": { - "contains": "data", - "values": { - "count": 3543930, - "rate": 58745.87641470083 - }, - "type": "counter" - }, - "vus_max": { - "contains": "default", - "values": { - "min": 50, - "max": 50, - "value": 50 - }, - "type": "gauge" - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.7892999999999997, - "p(99)": 1.7550499999999987, - "max": 7.21, - "avg": 0.3112199999999997, - "min": 0.016, - "med": 0.209, - "p(90)": 0.6383000000000001 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 223211, - "rate": 3700.0521512563137 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 5, - "min": 4, - "max": 9 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.028, - "med": 0.13, - "p(90)": 0.222, - "p(95)": 0.254, - "p(99)": 0.3070999999999999, - "max": 1.811, - "avg": 0.14055799999999974 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 398.6608, - "p(95)": 425.22769999999986, - "p(99)": 463.72496, - "max": 513.244, - "avg": 280.0849159999998, - "min": 165.451, - "med": 218.548 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json deleted file mode 100644 index e00e6098..00000000 --- a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "static-hosting-0.2.1", - "dependencies": { - "@convex-dev/static-hosting": "0.2.1" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "handsome-rooster-935", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:05:46.680Z", - "case": "page", - "path": "/", - "client": { - "requests": 1500, - "rate": 24.938959817599773, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 183.47050000000002, - "p90": 213.703, - "p95": 245.98624999999987, - "p99": 351.2222599999998, - "max": 532.496 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1500, - "Query staticHosting/lib:resolveAsset": 1500 - }, - "httpActionMs": { - "median": 41.210496, - "p95": 94.89908399999999 - }, - "innerFunctionMs": { - "median": 0.026396, - "p95": 0.035913 - } - } -} diff --git a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json b/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json deleted file mode 100644 index 608ab719..00000000 --- a/bench/results/2026-11-04-steady-1/static-hosting-0.2.1-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500, - "fails": 0, - "name": "status", - "path": "::status" - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1500, - "fails": 0 - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60146.855 - }, - "metrics": { - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0.209, - "p(95)": 0.24804999999999994, - "p(99)": 0.2910399999999999, - "max": 1.919, - "avg": 0.13232799999999992, - "min": 0.022, - "med": 0.118 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "http_req_receiving": { - "values": { - "max": 2.471, - "avg": 0.12381600000000012, - "min": 0.019, - "med": 0.088, - "p(90)": 0.179, - "p(95)": 0.307, - "p(99)": 0.8575199999999993 - }, - "type": "trend", - "contains": "time" - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 177079, - "rate": 2944.1107103605 - } - }, - "iteration_duration": { - "values": { - "p(99)": 351.4263232399997, - "max": 549.688209, - "avg": 194.71997728933363, - "min": 163.976041, - "med": 184.1376045, - "p(90)": 215.8298291, - "p(95)": 248.13045209999999 - }, - "type": "trend", - "contains": "time" - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.938959817599773 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "min": 4, - "max": 6, - "value": 4 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.938959817599773 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "avg": 193.70460933333334, - "min": 163.651, - "med": 183.47050000000002, - "p(90)": 213.703, - "p(95)": 245.98624999999987, - "p(99)": 351.2222599999998, - "max": 532.496 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 4.436649999999999, - "max": 32.969, - "avg": 0.18396400000000002, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0 - } - }, - "http_req_failed": { - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - }, - "type": "rate" - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.31721, - "max": 43.532, - "avg": 0.46327599999999997 - } - }, - "http_req_waiting": { - "values": { - "avg": 193.44846533333285, - "min": 163.529, - "med": 183.2735, - "p(90)": 213.3579, - "p(95)": 245.59009999999995, - "p(99)": 350.93935999999974, - "max": 532.293 - }, - "type": "trend", - "contains": "time" - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 245.98624999999987, - "p(99)": 351.2222599999998, - "max": 532.496, - "avg": 193.70460933333334, - "min": 163.651, - "med": 183.47050000000002, - "p(90)": 213.703 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 725133, - "rate": 12056.041832943718 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 19.281739999999992, - "max": 47.977, - "avg": 0.6694046666666478, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json deleted file mode 100644 index 062680f0..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:09:58.001Z", - "case": "asset", - "path": "/assets/chunk-200-ICKA4Pr8.js", - "client": { - "requests": 1500, - "rate": 24.841964530378064, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 276.27750000000003, - "p90": 442.10010000000005, - "p95": 466.6368499999999, - "p99": 519.62816, - "max": 648.455 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1500, - "Query hosting/lib:route": 1500 - }, - "httpActionMs": { - "median": 77.749256, - "p95": 117.937741 - }, - "innerFunctionMs": { - "median": 24.847019000000003, - "p95": 49.027361 - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json deleted file mode 100644 index 2eb9e713..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-asset.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "state": { - "isStdErrTTY": false, - "testRunDurationMs": 60381.698, - "isStdOutTTY": false - }, - "metrics": { - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.841964530378064 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "max": 648.455, - "avg": 320.3830993333335, - "min": 196.774, - "med": 276.27750000000003, - "p(90)": 442.10010000000005, - "p(95)": 466.6368499999999, - "p(99)": 519.62816 - } - }, - "http_req_waiting": { - "values": { - "avg": 319.89546199999955, - "min": 195.165, - "med": 275.819, - "p(90)": 441.81640000000004, - "p(95)": 466.4402499999999, - "p(99)": 519.01136, - "max": 648.194 - }, - "type": "trend", - "contains": "time" - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 7, - "min": 6, - "max": 11 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "max": 21.209, - "avg": 0.42850199999999994, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.048079999999992 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 222924, - "rate": 3691.913400646666 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 321.41687628266664, - "min": 197.093625, - "med": 278.723396, - "p(90)": 444.31056670000004, - "p(95)": 469.06316425, - "p(99)": 519.9614881599999, - "max": 648.753958 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - } - }, - "http_req_duration": { - "values": { - "med": 276.27750000000003, - "p(90)": 442.10010000000005, - "p(95)": 466.6368499999999, - "p(99)": 519.62816, - "max": 648.455, - "avg": 320.3830993333335, - "min": 196.774 - }, - "type": "trend", - "contains": "time" - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.6965373333333142, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 21.19843, - "max": 49.459 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 3542308, - "rate": 58665.25979444964 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.016, - "med": 0.2025, - "p(90)": 0.653, - "p(95)": 0.8630499999999999, - "p(99)": 2.260359999999998, - "max": 37.989, - "avg": 0.3514653333333334 - } - }, - "http_req_connecting": { - "contains": "time", - "values": { - "p(99)": 7.284179999999996, - "max": 32.907, - "avg": 0.26016199999999995, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0 - }, - "type": "trend" - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.841964530378064 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 0.305, - "max": 4.155, - "avg": 0.1361720000000004, - "min": 0.017, - "med": 0.12, - "p(90)": 0.21410000000000004, - "p(95)": 0.249 - } - } - }, - "root_group": { - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500, - "fails": 0, - "name": "status", - "path": "::status" - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1500, - "fails": 0 - } - ], - "name": "" - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json deleted file mode 100644 index b69990ab..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:08:34.142Z", - "case": "page", - "path": "/", - "client": { - "requests": 1500, - "rate": 24.930197110104846, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 238.1245, - "p90": 306.75790000000006, - "p95": 340.1665, - "p99": 601.6465399999998, - "max": 821.121 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1500, - "Query hosting/lib:route": 1500 - }, - "httpActionMs": { - "median": 94.170697, - "p95": 188.944432 - }, - "innerFunctionMs": { - "median": 38.220148, - "p95": 119.30128900000001 - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json deleted file mode 100644 index c70541e0..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60167.996 - }, - "metrics": { - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 713700, - "rate": 11861.787784987886 - } - }, - "data_sent": { - "contains": "data", - "values": { - "count": 176968, - "rate": 2941.2314147873562 - }, - "type": "counter" - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "passes": 0, - "fails": 1500, - "rate": 0 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "rate": 24.930197110104846, - "count": 1500 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.018, - "med": 0.133, - "p(90)": 0.216, - "p(95)": 0.247, - "p(99)": 0.30401999999999996, - "max": 1.603, - "avg": 0.1415313333333331 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.930197110104846 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "med": 238.44287450000002, - "p(90)": 308.4518878, - "p(95)": 345.49676875, - "p(99)": 602.5027111699995, - "max": 836.342792, - "avg": 256.93249321533364, - "min": 199.048083 - } - }, - "http_req_receiving": { - "values": { - "p(90)": 0.2703000000000001, - "p(95)": 0.5064499999999994, - "p(99)": 3.866329999999985, - "max": 31.946, - "avg": 0.256588, - "min": 0.014, - "med": 0.0835 - }, - "type": "trend", - "contains": "time" - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "max": 50, - "value": 50, - "min": 50 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "avg": 255.9439099999998, - "min": 198.816, - "med": 238.1245, - "p(90)": 306.75790000000006, - "p(95)": 340.1665, - "p(99)": 601.6465399999998, - "max": 821.121 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 601.4221099999997, - "max": 799.46, - "avg": 255.54579066666665, - "min": 198.377, - "med": 237.802, - "p(90)": 306.48990000000003, - "p(95)": 340.00780000000003 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 306.75790000000006, - "p(95)": 340.1665, - "p(99)": 601.6465399999998, - "max": 821.121, - "avg": 255.9439099999998, - "min": 198.816, - "med": 238.1245 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 19.08436, - "max": 44.886, - "avg": 0.6357946666666451, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002 - } - }, - "http_req_connecting": { - "values": { - "p(90)": 0, - "p(95)": 0, - "p(99)": 5.82717, - "max": 16.183, - "avg": 0.18027666666666667, - "min": 0, - "med": 0 - }, - "type": "trend", - "contains": "time" - }, - "http_req_tls_handshaking": { - "values": { - "p(95)": 0, - "p(99)": 13.497409999999999, - "max": 38.01, - "avg": 0.4393886666666665, - "min": 0, - "med": 0, - "p(90)": 0 - }, - "type": "trend", - "contains": "time" - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - }, - "vus": { - "values": { - "min": 5, - "max": 13, - "value": 5 - }, - "type": "gauge", - "contains": "default" - } - }, - "root_group": { - "groups": [], - "checks": [ - { - "passes": 1500, - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad" - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1500, - "fails": 0 - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e" - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json deleted file mode 100644 index a53cfd33..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "convex-hosting-0.14.0", - "dependencies": { - "@samebase/convex-hosting": "0.14.0" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "frugal-ferret-267", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:11:21.520Z", - "case": "rendered", - "path": "/rendered", - "client": { - "requests": 1501, - "rate": 24.94122735198225, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 196.765, - "p90": 267.272, - "p95": 319.946, - "p99": 388.553, - "max": 462.215 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 0, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1501, - "Query hosting/lib:route": 1501 - }, - "httpActionMs": { - "median": 52.083235, - "p95": 168.71917 - }, - "innerFunctionMs": { - "median": 42.863363, - "p95": 134.382957 - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json deleted file mode 100644 index 1a7a7b0d..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-0.14.0-400-rendered.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "fails": 0, - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1501 - }, - { - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0, - "name": "body", - "path": "::body" - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60181.481 - }, - "metrics": { - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.94122735198225 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.249, - "p(99)": 0.301, - "max": 6.581, - "avg": 0.1449780146568955, - "min": 0.016, - "med": 0.131, - "p(90)": 0.224 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 4, - "min": 4, - "max": 9 - } - }, - "data_received": { - "values": { - "count": 500170, - "rate": 8311.028437468995 - }, - "type": "counter", - "contains": "data" - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.94122735198225 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "max": 41.869, - "avg": 0.41782078614257157, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 12.187 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 212.9299648167893, - "min": 164.51775, - "med": 197.727042, - "p(90)": 268.373084, - "p(95)": 320.474208, - "p(99)": 393.135625, - "max": 462.539917 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "avg": 211.9557774816791, - "min": 164.038, - "med": 196.765, - "p(90)": 267.272, - "p(95)": 319.946, - "p(99)": 388.553, - "max": 462.215 - } - }, - "checks": { - "contains": "default", - "values": { - "fails": 0, - "rate": 1, - "passes": 3002 - }, - "type": "rate" - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 183323, - "rate": 3046.1696348084224 - } - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 5.127, - "max": 18.565, - "avg": 0.19394270486342435, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "med": 196.765, - "p(90)": 267.272, - "p(95)": 319.946, - "p(99)": 388.553, - "max": 462.215, - "avg": 211.9557774816791, - "min": 164.038 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "max": 129.303, - "avg": 0.3859000666222523, - "min": 0.014, - "med": 0.095, - "p(90)": 0.311, - "p(95)": 0.53, - "p(99)": 5.057 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 18.059, - "max": 45.988, - "avg": 0.6240179880079756, - "min": 0, - "med": 0.001 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 211.4248994003995, - "min": 163.676, - "med": 196.282, - "p(90)": 266.82, - "p(95)": 316.087, - "p(99)": 387.57, - "max": 457.541 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "fails": 1501, - "rate": 0, - "passes": 0 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json deleted file mode 100644 index cd736974..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:14:09.590Z", - "case": "asset", - "path": "/assets/chunk-200-ICKA4Pr8.js", - "client": { - "requests": 1501, - "rate": 24.869355938191646, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 355.262, - "p90": 418.642, - "p95": 443.636, - "p99": 492.54, - "max": 757.795 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1501 - }, - "httpActionMs": { - "median": 51.838714, - "p95": 92.062591 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json deleted file mode 100644 index f4e013a8..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-asset.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60355.403 - }, - "metrics": { - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "min": 169.740666, - "med": 355.783958, - "p(90)": 420.099791, - "p(95)": 445.583667, - "p(99)": 494.896459, - "max": 758.218084, - "avg": 303.03876074550243 - } - }, - "vus_max": { - "contains": "default", - "values": { - "max": 50, - "value": 50, - "min": 50 - }, - "type": "gauge" - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 19.038, - "max": 54.922, - "avg": 0.6482658227847914, - "min": 0, - "med": 0.001 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "max": 6.419, - "avg": 0.13806595602931404, - "min": 0.019, - "med": 0.123, - "p(90)": 0.217, - "p(95)": 0.247, - "p(99)": 0.303 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "passes": 0, - "fails": 1501, - "rate": 0 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 302.0437028647564, - "min": 169.436, - "med": 355.262, - "p(90)": 418.642, - "p(95)": 443.636, - "p(99)": 492.54, - "max": 757.795 - } - }, - "http_req_connecting": { - "values": { - "p(90)": 0, - "p(95)": 0, - "p(99)": 4.881, - "max": 43.383, - "avg": 0.20293271152564954, - "min": 0, - "med": 0 - }, - "type": "trend", - "contains": "time" - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.869355938191646 - } - }, - "vus": { - "contains": "default", - "values": { - "max": 9, - "value": 8, - "min": 4 - }, - "type": "gauge" - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "max": 757.545, - "avg": 301.56511525649574, - "min": 168.118, - "med": 354.56, - "p(90)": 418.428, - "p(95)": 442.725, - "p(99)": 491.761 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 222838, - "rate": 3692.0969610624584 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.869355938191646 - } - }, - "http_req_duration{expected_response:true}": { - "contains": "time", - "values": { - "med": 355.262, - "p(90)": 418.642, - "p(95)": 443.636, - "p(99)": 492.54, - "max": 757.795, - "avg": 302.0437028647564, - "min": 169.436 - }, - "type": "trend" - }, - "http_req_receiving": { - "contains": "time", - "values": { - "max": 13.283, - "avg": 0.3405216522318455, - "min": 0.014, - "med": 0.194, - "p(90)": 0.625, - "p(95)": 0.806, - "p(99)": 2.894 - }, - "type": "trend" - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 3542248, - "rate": 58689.82433933877 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.139, - "max": 38.424, - "avg": 0.4375882744836775, - "min": 0 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3002, - "fails": 0 - } - } - }, - "root_group": { - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1501, - "fails": 0 - }, - { - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0 - } - ], - "name": "" - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json deleted file mode 100644 index 16e2f58a..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:12:45.925Z", - "case": "page", - "path": "/", - "client": { - "requests": 1501, - "rate": 24.934123497534255, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 196.604, - "p90": 226.715, - "p95": 247.656, - "p99": 465.25, - "max": 910.409 - } - }, - "server": { - "httpActionsLogged": 1501, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 2, - "byFunction": { - "HttpAction GET /*": 1501 - }, - "httpActionMs": { - "median": 52.636536, - "p95": 91.936576 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json deleted file mode 100644 index 9b7f74b5..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1501, - "fails": 0 - }, - { - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1501, - "fails": 0, - "name": "body" - } - ] - }, - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60198.627 - }, - "metrics": { - "http_req_tls_handshaking": { - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 14.17, - "max": 23.827, - "avg": 0.44172085276482353 - }, - "type": "trend", - "contains": "time" - }, - "checks": { - "values": { - "rate": 1, - "passes": 3002, - "fails": 0 - }, - "type": "rate", - "contains": "default" - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 21.917, - "max": 47.625, - "avg": 0.6947654896735326, - "min": 0 - } - }, - "http_req_sending": { - "contains": "time", - "values": { - "p(95)": 0.238, - "p(99)": 0.282, - "max": 0.653, - "avg": 0.13203464357095276, - "min": 0.018, - "med": 0.123, - "p(90)": 0.211 - }, - "type": "trend" - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.934123497534255 - } - }, - "http_req_connecting": { - "contains": "time", - "values": { - "avg": 0.2290879413724183, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 7.052, - "max": 33.399 - }, - "type": "trend" - }, - "http_req_waiting": { - "values": { - "p(99)": 465.007, - "max": 857.724, - "avg": 207.75307395069933, - "min": 176.065, - "med": 196.284, - "p(90)": 226.219, - "p(95)": 247.333 - }, - "type": "trend", - "contains": "time" - }, - "vus_max": { - "values": { - "value": 50, - "min": 50, - "max": 50 - }, - "type": "gauge", - "contains": "default" - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 247.656, - "p(99)": 465.25, - "max": 910.409, - "avg": 208.11429380413085, - "min": 176.432, - "med": 196.604, - "p(90)": 226.715 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 177047, - "rate": 2941.047143816087 - } - }, - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 465.25, - "max": 910.409, - "avg": 208.11429380413085, - "min": 176.432, - "med": 196.604, - "p(90)": 226.715, - "p(95)": 247.656 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1501 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 248.951041, - "p(99)": 485.20225, - "max": 910.895666, - "avg": 209.1479989067286, - "min": 176.875416, - "med": 197.122208, - "p(90)": 228.631875 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "max": 8, - "value": 5, - "min": 4 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1501, - "rate": 24.934123497534255 - } - }, - "http_req_receiving": { - "values": { - "avg": 0.22918520986009358, - "min": 0.011, - "med": 0.084, - "p(90)": 0.257, - "p(95)": 0.461, - "p(99)": 1.874, - "max": 52.5 - }, - "type": "trend", - "contains": "time" - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "rate": 11844.240234914327, - "count": 713007 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json deleted file mode 100644 index 0f96ce13..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "target": "convex-hosting-branch", - "dependencies": { - "@samebase/convex-hosting": "file:bench/.work/pack/samebase-convex-hosting-0.15.0.tgz" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "clean-swordfish-403", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:15:32.997Z", - "case": "rendered", - "path": "/rendered", - "client": { - "requests": 1500, - "rate": 24.95143286763757, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 149.472, - "p90": 160.89770000000001, - "p95": 176.1119, - "p99": 380.59317999999996, - "max": 586.243 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 1, - "downloadsPerRequest": 0, - "billedCallsPerRequest": 1, - "byFunction": { - "HttpAction GET /*": 1500 - }, - "httpActionMs": { - "median": 6.487045, - "p95": 15.376284 - }, - "innerFunctionMs": { - "median": null, - "p95": null - } - } -} diff --git a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json b/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json deleted file mode 100644 index e84777d3..00000000 --- a/bench/results/2026-11-04-steady-2/convex-hosting-branch-400-rendered.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "root_group": { - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500, - "fails": 0 - }, - { - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff", - "passes": 1500 - } - ], - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e" - }, - "options": { - "noColor": false, - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "" - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60116.788 - }, - "metrics": { - "iteration_duration": { - "contains": "time", - "values": { - "p(95)": 180.96892884999994, - "p(99)": 380.99749641999995, - "max": 586.8335, - "avg": 158.11574064333342, - "min": 141.360208, - "med": 149.955229, - "p(90)": 164.4127709 - }, - "type": "trend" - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.019, - "med": 0.125, - "p(90)": 0.203, - "p(95)": 0.231, - "p(99)": 0.28001000000000004, - "max": 1.427, - "avg": 0.13205133333333322 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.6570626666666464, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 20.009719999999994, - "max": 49.499 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.5390499999999999, - "p(99)": 3.9099699999999973, - "max": 8.028, - "avg": 0.21880666666666726, - "min": 0.024, - "med": 0.098, - "p(90)": 0.307 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.95143286763757 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 4, - "min": 3, - "max": 7 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "count": 183328, - "rate": 3049.5308565055075 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "data_received": { - "values": { - "rate": 8315.264614603162, - "count": 499887 - }, - "type": "counter", - "contains": "data" - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "min": 140.757, - "med": 149.2, - "p(90)": 160.6266, - "p(95)": 175.38044999999994, - "p(99)": 380.28768999999994, - "max": 581.331, - "avg": 156.75396799999993 - } - }, - "http_req_connecting": { - "values": { - "p(99)": 6.092809999999998, - "max": 35.071, - "avg": 0.22891266666666668, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0 - }, - "type": "trend", - "contains": "time" - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.42016000000000014, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.438270000000001, - "max": 37.344 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 157.10482599999997, - "min": 141.17, - "med": 149.472, - "p(90)": 160.89770000000001, - "p(95)": 176.1119, - "p(99)": 380.59317999999996, - "max": 586.243 - } - }, - "http_req_duration{expected_response:true}": { - "contains": "time", - "values": { - "max": 586.243, - "avg": 157.10482599999997, - "min": 141.17, - "med": 149.472, - "p(90)": 160.89770000000001, - "p(95)": 176.1119, - "p(99)": 380.59317999999996 - }, - "type": "trend" - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.95143286763757 - } - } - } -} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json deleted file mode 100644 index 44c5b8ab..00000000 --- a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "static-hosting-0.2.1", - "dependencies": { - "@convex-dev/static-hosting": "0.2.1" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "handsome-rooster-935", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:18:20.164Z", - "case": "asset", - "path": "/assets/chunk-200-ICKA4Pr8.js", - "client": { - "requests": 1500, - "rate": 24.934864316270893, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 357.42999999999995, - "p90": 405.0565, - "p95": 427.42074999999994, - "p99": 460.8187, - "max": 518.583 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1500, - "Query staticHosting/lib:resolveAsset": 1500 - }, - "httpActionMs": { - "median": 41.909085, - "p95": 63.403824 - }, - "innerFunctionMs": { - "median": 0.026527, - "p95": 0.035799 - } - } -} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json deleted file mode 100644 index d71d845b..00000000 --- a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-asset.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "options": { - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"], - "summaryTimeUnit": "", - "noColor": false - }, - "state": { - "testRunDurationMs": 60156.734, - "isStdOutTTY": false, - "isStdErrTTY": false - }, - "metrics": { - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.953479999999997, - "max": 43.073, - "avg": 0.4766333333333332, - "min": 0 - } - }, - "data_sent": { - "type": "counter", - "contains": "data", - "values": { - "rate": 3709.177429745438, - "count": 223132 - } - }, - "http_req_receiving": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 0.7380999999999999, - "p(99)": 1.885779999999999, - "max": 9.809, - "avg": 0.29534000000000005, - "min": 0.021, - "med": 0.187, - "p(90)": 0.5951 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "min": 50, - "max": 50, - "value": 50 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "avg": 297.4572339999998, - "min": 164.348, - "med": 356.899, - "p(90)": 404.1775, - "p(95)": 427.0609, - "p(99)": 460.50805, - "max": 518.22 - } - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 20.603229999999996, - "max": 47.621, - "avg": 0.6867233333333137, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002 - } - }, - "http_req_connecting": { - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 6.021609999999996, - "max": 19.917, - "avg": 0.20223533333333335 - }, - "type": "trend" - }, - "http_req_duration": { - "type": "trend", - "contains": "time", - "values": { - "avg": 297.89772666666664, - "min": 165.267, - "med": 357.42999999999995, - "p(90)": 405.0565, - "p(95)": 427.42074999999994, - "p(99)": 460.8187, - "max": 518.583 - } - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "rate": 1, - "passes": 3000, - "fails": 0 - } - }, - "iteration_duration": { - "contains": "time", - "values": { - "avg": 298.93632925600014, - "min": 165.662875, - "med": 358.129708, - "p(90)": 406.1098372, - "p(95)": 428.4115101, - "p(99)": 462.61087667, - "max": 519.034333 - }, - "type": "trend" - }, - "http_reqs": { - "contains": "default", - "values": { - "count": 1500, - "rate": 24.934864316270893 - }, - "type": "counter" - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "min": 0.019, - "med": 0.135, - "p(90)": 0.23510000000000003, - "p(95)": 0.26204999999999995, - "p(99)": 0.32201, - "max": 1.46, - "avg": 0.14515266666666657 - } - }, - "http_req_failed": { - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - }, - "type": "rate" - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 5, - "min": 4, - "max": 9 - } - }, - "data_received": { - "type": "counter", - "contains": "data", - "values": { - "count": 3543922, - "rate": 58911.476144964916 - } - }, - "http_req_duration{expected_response:true}": { - "values": { - "min": 165.267, - "med": 357.42999999999995, - "p(90)": 405.0565, - "p(95)": 427.42074999999994, - "p(99)": 460.8187, - "max": 518.583, - "avg": 297.89772666666664 - }, - "type": "trend", - "contains": "time" - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.934864316270893 - } - } - }, - "root_group": { - "name": "", - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500, - "fails": 0 - }, - { - "passes": 1500, - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff" - } - ] - } -} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json deleted file mode 100644 index 445b4711..00000000 --- a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "target": "static-hosting-0.2.1", - "dependencies": { - "@convex-dev/static-hosting": "0.2.1" - }, - "convex": "1.46.0", - "commit": "9007184db5b59bd4f0be4ab411c748f49fbccf49", - "deployment": "handsome-rooster-935", - "files": 400, - "rate": 25, - "duration": "60s", - "date": "2026-11-04T00:16:56.707Z", - "case": "page", - "path": "/", - "client": { - "requests": 1500, - "rate": 24.941520863108313, - "checksPassed": 1, - "failed": 0, - "dropped": 0, - "latencyMs": { - "median": 189.49599999999998, - "p90": 224.9675, - "p95": 241.3964, - "p99": 457.18186999999995, - "max": 841.721 - } - }, - "server": { - "httpActionsLogged": 1500, - "logCompleteness": 1, - "functionsPerRequest": 2, - "downloadsPerRequest": 1, - "billedCallsPerRequest": 3, - "byFunction": { - "HttpAction GET /*": 1500, - "Query staticHosting/lib:resolveAsset": 1500 - }, - "httpActionMs": { - "median": 41.772134, - "p95": 73.603138 - }, - "innerFunctionMs": { - "median": 0.025822, - "p95": 0.031492000000000006 - } - } -} diff --git a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json b/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json deleted file mode 100644 index 24cc2965..00000000 --- a/bench/results/2026-11-04-steady-2/static-hosting-0.2.1-400-page.k6.json +++ /dev/null @@ -1,221 +0,0 @@ -{ - "metrics": { - "http_req_duration{expected_response:true}": { - "type": "trend", - "contains": "time", - "values": { - "med": 189.49599999999998, - "p(90)": 224.9675, - "p(95)": 241.3964, - "p(99)": 457.18186999999995, - "max": 841.721, - "avg": 201.20935666666688, - "min": 165.176 - } - }, - "http_req_tls_handshaking": { - "type": "trend", - "contains": "time", - "values": { - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0, - "p(99)": 13.039739999999993, - "max": 20.612, - "avg": 0.41250999999999993 - } - }, - "http_req_sending": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.13223933333333318, - "min": 0.017, - "med": 0.121, - "p(90)": 0.21, - "p(95)": 0.24704999999999994, - "p(99)": 0.32001999999999997, - "max": 1.742 - } - }, - "http_req_receiving": { - "contains": "time", - "values": { - "med": 0.086, - "p(90)": 0.195, - "p(95)": 0.2960499999999999, - "p(99)": 0.7480699999999932, - "max": 536.245, - "avg": 0.5243020000000003, - "min": 0.014 - }, - "type": "trend" - }, - "checks": { - "type": "rate", - "contains": "default", - "values": { - "passes": 3000, - "fails": 0, - "rate": 1 - } - }, - "http_req_failed": { - "type": "rate", - "contains": "default", - "values": { - "rate": 0, - "passes": 0, - "fails": 1500 - } - }, - "http_req_waiting": { - "type": "trend", - "contains": "time", - "values": { - "med": 189.3005, - "p(90)": 224.65040000000002, - "p(95)": 240.80124999999998, - "p(99)": 455.39019, - "max": 841.654, - "avg": 200.55281533333377, - "min": 165.031 - } - }, - "http_reqs": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.941520863108313 - } - }, - "iteration_duration": { - "type": "trend", - "contains": "time", - "values": { - "p(95)": 241.90188574999993, - "p(99)": 477.16250833, - "max": 868.810833, - "avg": 202.23315793999996, - "min": 165.387833, - "med": 190.428146, - "p(90)": 225.51523809999998 - } - }, - "iterations": { - "type": "counter", - "contains": "default", - "values": { - "count": 1500, - "rate": 24.941520863108313 - } - }, - "vus": { - "type": "gauge", - "contains": "default", - "values": { - "value": 5, - "min": 4, - "max": 8 - } - }, - "http_req_duration": { - "values": { - "p(99)": 457.18186999999995, - "max": 841.721, - "avg": 201.20935666666688, - "min": 165.176, - "med": 189.49599999999998, - "p(90)": 224.9675, - "p(95)": 241.3964 - }, - "type": "trend", - "contains": "time" - }, - "http_req_connecting": { - "type": "trend", - "contains": "time", - "values": { - "p(99)": 7.096939999999999, - "max": 31.546, - "avg": 0.2306026666666667, - "min": 0, - "med": 0, - "p(90)": 0, - "p(95)": 0 - } - }, - "vus_max": { - "type": "gauge", - "contains": "default", - "values": { - "value": 50, - "min": 50, - "max": 50 - } - }, - "data_sent": { - "values": { - "count": 177234, - "rate": 2946.990339101426 - }, - "type": "counter", - "contains": "data" - }, - "data_received": { - "contains": "data", - "values": { - "count": 725292, - "rate": 12059.923699897037 - }, - "type": "counter" - }, - "http_req_blocked": { - "type": "trend", - "contains": "time", - "values": { - "avg": 0.6716153333333145, - "min": 0, - "med": 0.001, - "p(90)": 0.002, - "p(95)": 0.002, - "p(99)": 20.83756, - "max": 53.018 - } - } - }, - "root_group": { - "path": "", - "id": "d41d8cd98f00b204e9800998ecf8427e", - "groups": [], - "checks": [ - { - "name": "status", - "path": "::status", - "id": "a03b851833f5ba257445456aa0ce3cad", - "passes": 1500, - "fails": 0 - }, - { - "passes": 1500, - "fails": 0, - "name": "body", - "path": "::body", - "id": "8369d5a9d3d9bb2eaaad52fc460fedff" - } - ], - "name": "" - }, - "options": { - "summaryTimeUnit": "", - "noColor": false, - "summaryTrendStats": ["avg", "min", "med", "p(90)", "p(95)", "p(99)", "max"] - }, - "state": { - "isStdOutTTY": false, - "isStdErrTTY": false, - "testRunDurationMs": 60140.679 - } -} diff --git a/bench/run.ts b/bench/run.ts deleted file mode 100644 index 0d23efdc..00000000 --- a/bench/run.ts +++ /dev/null @@ -1,402 +0,0 @@ -// Benchmarks one hosting target on its own Convex cloud project: it writes the target's app to -// bench/.work// with the package pinned to one exact version, deploys a synthetic site to -// the project's development deployment, then runs each case with k6 at a fixed arrival rate while -// it streams the deployment's function logs. One JSON file per case goes to bench/results//. -// -// node bench/run.ts --run [--files 400] [--rate 25] [--duration 60s] -// [--cases page,asset,rendered] [--no-deploy] -// -// Targets: convex-hosting-0.14.0 (npm), convex-hosting-branch (this checkout, packed), and -// static-hosting-0.2.1 (npm, the component-owned mode its README calls the fastest). -import { execFileSync, spawn } from "node:child_process"; -import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; -import { dirname, join, resolve } from "node:path"; -import { parseArgs } from "node:util"; -import { writeSite } from "./site.ts"; - -const BENCH = dirname(new URL(import.meta.url).pathname); -const REPO = resolve(BENCH, ".."); -const TEAM = process.env.BENCH_TEAM ?? "nicu"; -const CONVEX = "1.46.0"; - -/** A page that `worker` renders, for the case that no file answers. */ -const WORKER = `{ - fetch: async () => - new Response("Rendered

Rendered

", { - headers: { "Content-Type": "text/html; charset=utf-8" }, - }), -}`; - -const hostingConfig = `import { defineApp } from "convex/server"; -import hosting from "@samebase/convex-hosting/convex.config"; - -const app = defineApp(); -app.use(hosting); -export default app; -`; - -const hostingHttp = ( - siteExport: "versionId" | "site", -) => `import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; -import { ${siteExport} } from "../.convex-hosting/version.js"; - -const http = httpRouter(); -// A worker that renders one small page, so the rendered case measures hosting, not a framework. -routeAll(http, components.hosting, ${siteExport}, ${WORKER}); -export default http; -`; - -type Target = { - project: string; - dependencies: Record; - files: Record; - cases: CaseName[]; - deploy: (cwd: string) => void; -}; - -function packBranch(): string { - const dir = join(BENCH, ".work", "pack"); - mkdirSync(dir, { recursive: true }); - const output = execFileSync("pnpm", ["pack", "--pack-destination", dir], { - cwd: join(REPO, "packages", "convex-hosting"), - encoding: "utf8", - }); - const tarball = output.trim().split("\n").pop() ?? ""; - if (!tarball.endsWith(".tgz")) throw new Error(`pnpm pack printed no tarball:\n${output}`); - return tarball; -} - -const targets: Record Target> = { - "convex-hosting-0.14.0": () => ({ - project: "convex-hosting-bench-014", - dependencies: { "@samebase/convex-hosting": "0.14.0" }, - files: { "convex/convex.config.ts": hostingConfig, "convex/http.ts": hostingHttp("versionId") }, - cases: ["page", "asset", "rendered"], - deploy: (cwd) => sh(cwd, "npx", ["convex-hosting", "deploy", "--dev", "--dist", "site"]), - }), - "convex-hosting-branch": () => ({ - project: "convex-hosting-bench", - dependencies: { "@samebase/convex-hosting": `file:${packBranch()}` }, - files: { "convex/convex.config.ts": hostingConfig, "convex/http.ts": hostingHttp("site") }, - cases: ["page", "asset", "rendered"], - deploy: (cwd) => sh(cwd, "npx", ["convex-hosting", "deploy", "--dev", "--dist", "site"]), - }), - "static-hosting-0.2.1": () => ({ - project: "convex-hosting-bench-static", - dependencies: { "@convex-dev/static-hosting": "0.2.1" }, - files: { - "convex/convex.config.ts": `import { defineApp } from "convex/server"; -import staticHosting from "@convex-dev/static-hosting/convex.config"; - -// The component owns "/", the mode static-hosting's README calls the fastest. -const app = defineApp({ httpPrefix: "/api" }); -app.use(staticHosting, { httpPrefix: "/" }); -export default app; -`, - }, - // It renders no page: a path without a file answers its index.html or 404. - cases: ["page", "asset"], - deploy: (cwd) => { - sh(cwd, "npx", ["convex", "dev", "--once"]); - sh(cwd, "npx", ["@convex-dev/static-hosting", "upload", "--dist", "site", "--no-spa"]); - }, - }), -}; - -type CaseName = "page" | "asset" | "rendered"; -type Case = { - path: (paths: { asset: string }) => string; - marker: string; - fetchMode: string; - /** Whether the answer's body is a stored file, whose download Convex counts as a call. */ - download: boolean; -}; -const CASES: Record = { - page: { path: () => "/", marker: "Benchmark site", fetchMode: "navigate", download: true }, - asset: { - path: (paths) => paths.asset, - marker: "export const chunk", - fetchMode: "no-cors", - download: true, - }, - rendered: { path: () => "/rendered", marker: "Rendered", fetchMode: "navigate", download: false }, -}; - -function sh(cwd: string, command: string, args: string[]) { - execFileSync(command, args, { cwd, stdio: "inherit" }); -} - -function convexEnv(cwd: string) { - const env = readFileSync(join(cwd, ".env.local"), "utf8"); - const deployment = /^CONVEX_DEPLOYMENT=(?:dev:)?([a-z0-9-]+)/m.exec(env)?.[1]; - const site = /^CONVEX_SITE_URL=(\S+)/m.exec(env)?.[1]; - if (deployment === undefined) throw new Error(`${cwd}/.env.local has no CONVEX_DEPLOYMENT.`); - return { deployment, site: site ?? `https://${deployment}.convex.site` }; -} - -/** Writes the app and binds it to the target's project, creating the project on the first run. */ -function setUp(name: string, target: Target, files: number) { - const cwd = join(BENCH, ".work", name); - mkdirSync(join(cwd, "convex"), { recursive: true }); - const pkg = { - name: `bench-${name}`, - private: true, - type: "module", - dependencies: { convex: CONVEX, ...target.dependencies }, - }; - writeFileSync(join(cwd, "package.json"), `${JSON.stringify(pkg, null, 2)}\n`); - for (const [path, body] of Object.entries(target.files)) writeFileSync(join(cwd, path), body); - sh(cwd, "npm", ["install", "--no-audit", "--no-fund", "--loglevel=error"]); - if (!existsSync(join(cwd, ".env.local"))) { - const configure = (kind: string) => - execFileSync( - "npx", - [ - "convex", - "dev", - "--once", - "--configure", - kind, - "--team", - TEAM, - "--project", - target.project, - "--dev-deployment", - "cloud", - ], - { cwd, stdio: "inherit" }, - ); - // The first push fails while `.convex-hosting/version.js` does not exist yet; the project and - // `.env.local` are configured by then, which is what this step is for. - try { - configure("existing"); - } catch { - if (!existsSync(join(cwd, ".env.local"))) { - try { - configure("new"); - } catch { - if (!existsSync(join(cwd, ".env.local"))) - throw new Error(`Configuring ${target.project} failed.`); - } - } - } - } - const paths = writeSite(files, cwd); - return { cwd, paths }; -} - -const median = (values: number[]) => quantile(values, 0.5); -function quantile(values: number[], q: number) { - if (values.length === 0) return null; - const sorted = [...values].sort((a, b) => a - b); - return sorted[Math.min(sorted.length - 1, Math.floor(q * sorted.length))]; -} - -type LogEntry = { - kind: string; - udfType: string; - identifier: string; - componentPath: string | null; - requestId: string; - executionId: string; - timestamp: number; - executionTime: number; - success: { status?: string } | null; -}; - -/** Runs one case with k6 while the deployment's logs stream to a file, and measures both. */ -async function runCase( - cwd: string, - site: string, - caseName: CaseName, - paths: { asset: string }, - options: { rate: number; duration: string; out: string }, -) { - const spec = CASES[caseName]; - const logFile = `${options.out}.logs.jsonl`; - const logs = spawn("npx", ["convex", "logs", "--success", "--jsonl"], { - cwd, - stdio: ["ignore", "pipe", "ignore"], - }); - const chunks: Buffer[] = []; - logs.stdout.on("data", (chunk: Buffer) => chunks.push(chunk)); - await new Promise((done) => setTimeout(done, 8000)); - const start = Date.now() / 1000; - const summaryFile = `${options.out}.k6.json`; - execFileSync( - "k6", - [ - "run", - "--quiet", - "-e", - `BASE=${site}`, - "-e", - `TARGET_PATH=${spec.path(paths)}`, - "-e", - "STATUS=200", - "-e", - `MARKER=${spec.marker}`, - "-e", - `FETCH_MODE=${spec.fetchMode}`, - "-e", - `RATE=${options.rate}`, - "-e", - `DURATION=${options.duration}`, - "-e", - `OUT=${summaryFile}`, - join(BENCH, "load.js"), - ], - { stdio: "inherit" }, - ); - const end = Date.now() / 1000; - // Logs arrive a few seconds after the executions. - await new Promise((done) => setTimeout(done, 15000)); - logs.kill(); - writeFileSync(logFile, Buffer.concat(chunks)); - - const entries: LogEntry[] = Buffer.concat(chunks) - .toString("utf8") - .split("\n") - .flatMap((line) => { - try { - const entry = JSON.parse(line); - return entry?.kind === "Completion" ? [entry] : []; - } catch { - return []; - } - }) - .filter((entry) => entry.timestamp >= start - 1 && entry.timestamp <= end + 10); - const unique = [...new Map(entries.map((entry) => [entry.executionId, entry])).values()]; - const http = unique.filter((entry) => entry.udfType === "HttpAction"); - const requestIds = new Set(http.map((entry) => entry.requestId)); - const inner = unique.filter( - (entry) => entry.udfType !== "HttpAction" && requestIds.has(entry.requestId), - ); - const byFunction: Record = {}; - for (const entry of [...http, ...inner]) { - const key = `${entry.udfType} ${entry.componentPath ? `${entry.componentPath}/` : ""}${entry.identifier}`; - byFunction[key] = (byFunction[key] ?? 0) + 1; - } - const k6 = JSON.parse(readFileSync(summaryFile, "utf8")); - const metric = (name: string) => k6.metrics[name]?.values ?? {}; - const requests = metric("http_reqs").count ?? 0; - const checks = metric("checks"); - const executionsPerRequest = - http.length === 0 ? null : (http.length + inner.length) / http.length; - const passRate = checks.rate ?? 0; - return { - case: caseName, - path: spec.path(paths), - client: { - requests, - rate: metric("http_reqs").rate, - checksPassed: passRate, - failed: metric("http_req_failed").rate, - dropped: metric("dropped_iterations").count ?? 0, - latencyMs: { - median: metric("http_req_duration").med, - p90: metric("http_req_duration")["p(90)"], - p95: metric("http_req_duration")["p(95)"], - p99: metric("http_req_duration")["p(99)"], - max: metric("http_req_duration").max, - }, - }, - server: { - httpActionsLogged: http.length, - logCompleteness: requests === 0 ? null : http.length / requests, - functionsPerRequest: executionsPerRequest, - downloadsPerRequest: spec.download ? 1 : 0, - billedCallsPerRequest: - executionsPerRequest === null ? null : executionsPerRequest + (spec.download ? 1 : 0), - byFunction, - httpActionMs: { - median: median(http.map((entry) => entry.executionTime * 1000)), - p95: quantile( - http.map((entry) => entry.executionTime * 1000), - 0.95, - ), - }, - innerFunctionMs: { - median: median(inner.map((entry) => entry.executionTime * 1000)), - p95: quantile( - inner.map((entry) => entry.executionTime * 1000), - 0.95, - ), - }, - }, - }; -} - -async function main() { - const { values, positionals } = parseArgs({ - allowPositionals: true, - options: { - run: { type: "string" }, - files: { type: "string", default: "400" }, - rate: { type: "string", default: "25" }, - duration: { type: "string", default: "60s" }, - cases: { type: "string" }, - "no-deploy": { type: "boolean", default: false }, - }, - }); - const [name] = positionals; - const make = targets[name ?? ""]; - if (make === undefined || values.run === undefined) { - throw new Error( - `Usage: node bench/run.ts <${Object.keys(targets).join(" | ")}> --run [options]`, - ); - } - const target = make(); - const files = Number(values.files); - const { cwd, paths } = setUp(name, target, files); - let deploySeconds: number | null = null; - if (!values["no-deploy"]) { - const started = Date.now(); - target.deploy(cwd); - deploySeconds = (Date.now() - started) / 1000; - console.error(`Deployed ${files} files in ${deploySeconds.toFixed(0)} s.`); - } - const { deployment, site } = convexEnv(cwd); - const cases = (values.cases?.split(",") ?? target.cases) as CaseName[]; - const outDir = join(BENCH, "results", values.run); - mkdirSync(outDir, { recursive: true }); - const commit = execFileSync("git", ["rev-parse", "HEAD"], { cwd: REPO, encoding: "utf8" }).trim(); - for (const caseName of cases) { - const out = join(outDir, `${name}-${files}-${caseName}`); - console.error( - `${name}, ${files} files, ${caseName}: ${values.rate}/s for ${values.duration} on ${site}`, - ); - const result = await runCase(cwd, site, caseName, paths, { - rate: Number(values.rate), - duration: values.duration, - out, - }); - const record = { - target: name, - // The packed branch build lives in bench/.work/pack, whatever the checkout's path. - dependencies: Object.fromEntries( - Object.entries(target.dependencies).map(([name, spec]) => [ - name, - spec.replace(`file:${BENCH}/`, "file:bench/"), - ]), - ), - convex: CONVEX, - commit, - deployment, - files, - deploySeconds, - rate: Number(values.rate), - duration: values.duration, - date: new Date().toISOString(), - ...result, - }; - writeFileSync(`${out}.json`, `${JSON.stringify(record, null, 2)}\n`); - console.error( - JSON.stringify({ case: caseName, client: result.client, server: result.server }, null, 2), - ); - } -} - -await main(); diff --git a/bench/site.ts b/bench/site.ts deleted file mode 100644 index 7c0462f5..00000000 --- a/bench/site.ts +++ /dev/null @@ -1,39 +0,0 @@ -// Writes a synthetic built site to `/site`: an index page, a 404 page, and `count` scripts of -// about 2 KB, named the way Vite names chunks. Every file has its own bytes, so every file is stored -// once. The path of a script in the middle goes to `/paths.json`, outside the site. -// node site.ts -import { createHash } from "node:crypto"; -import { mkdirSync, rmSync, writeFileSync } from "node:fs"; -import { join } from "node:path"; - -export function writeSite(count: number, dir: string) { - const site = join(dir, "site"); - rmSync(site, { recursive: true, force: true }); - mkdirSync(join(site, "assets"), { recursive: true }); - const names: string[] = []; - for (let i = 0; i < count; i++) { - const body = `export const chunk${i} = ${JSON.stringify("x".repeat(2000))}; // chunk ${i}\n`; - const hash = createHash("sha256").update(body).digest("base64url").slice(0, 8); - const name = `/assets/chunk-${i}-${hash}.js`; - writeFileSync(join(site, name), body); - names.push(name); - } - const page = (title: string) => - `${title}` + - `

${title}

\n`; - writeFileSync(join(site, "index.html"), page("Benchmark site")); - writeFileSync(join(site, "404.html"), page("Not found")); - const paths = { asset: names[Math.floor(count / 2)] }; - writeFileSync(join(dir, "paths.json"), `${JSON.stringify(paths)}\n`); - return paths; -} - -if (import.meta.main) { - const count = Number(process.argv[2]); - const dir = process.argv[3]; - if (!Number.isInteger(count) || count < 1 || dir === undefined) { - throw new Error("Usage: node site.ts "); - } - writeSite(count, dir); - console.log(`Wrote ${count} scripts, index.html and 404.html to ${join(dir, "site")}.`); -} From 6c2a31ca6544d406c74e49e65c5bcf6e523cf7bc Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 15:06:18 +0200 Subject: [PATCH 10/20] routeAll takes one object, and version.js exports assets 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. --- README.md | 12 +- docs/design.md | 25 ++- docs/development.md | 2 +- docs/from-static-hosting.md | 4 +- docs/serving.md | 26 +-- .../hello-world-assets-only-workers.patch | 6 +- .../hello-world-assets-only/convex/http.ts | 4 +- examples/tanstack-spa/convex/http.ts | 4 +- examples/tanstack-ssr-workers.patch | 6 +- examples/tanstack-ssr/convex/http.ts | 4 +- .../convex-hosting-tanstack-start/README.md | 3 +- packages/convex-hosting/CHANGELOG.md | 29 +++- packages/convex-hosting/src/cli/main.test.ts | 34 ++-- packages/convex-hosting/src/cli/main.ts | 48 +++--- .../convex-hosting/src/client/answer.test.ts | 10 +- packages/convex-hosting/src/client/answer.ts | 74 +++++++++ .../convex-hosting/src/client/index.test.ts | 47 +++--- packages/convex-hosting/src/client/index.ts | 157 +++++------------- .../src/client/manifest.test.ts | 28 ++-- .../convex-hosting/src/client/manifest.ts | 37 +++-- .../src/client/version-module.d.ts | 2 +- .../shared/src/run-wrangler-long-lived.ts | 4 +- 22 files changed, 303 insertions(+), 263 deletions(-) create mode 100644 packages/convex-hosting/src/client/answer.ts diff --git a/README.md b/README.md index b1dafaa8..cefa8c6d 100644 --- a/README.md +++ b/README.md @@ -56,14 +56,14 @@ server build for every other request, as a Cloudflare Worker with static assets import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { site } from "../.convex-hosting/version.js"; +import { assets } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; const http = httpRouter(); -routeAll(http, components.hosting, site, server); +routeAll({ http, component: components.hosting, assets, worker: server }); export default http; ``` @@ -106,10 +106,10 @@ wires both. ## Files only -A site without a server leaves the fourth argument out, `routeAll(http, components.hosting, site)`, -needs no adapter package, and deploys its build directory: `--dist dist` after a `vite build`, or -`--dist public` with no `--build` at all. A single-page app adds -`--not-found-handling single-page-application`. The +A site without a server leaves `worker` out, +`routeAll({ http, component: components.hosting, assets })`, needs no adapter package, and deploys +its build directory: `--dist dist` after a `vite build`, or `--dist public` with no `--build` at +all. A single-page app adds `--not-found-handling single-page-application`. The [tanstack-spa](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-spa) and [hello-world-assets-only](https://github.com/samebase/convex-hosting/tree/main/examples/hello-world-assets-only) examples are such sites. diff --git a/docs/design.md b/docs/design.md index 6187df36..bc982b4f 100644 --- a/docs/design.md +++ b/docs/design.md @@ -95,11 +95,11 @@ Bristol's production used it while hosting 0.3 and 0.4 ran side by side under tw 6. reads the storage URL of every entry, with the deployment's `CONVEX_CLOUD_URL`, through inline queries in the component (`npx convex run --component --inline-query`), which run whatever release of this package the component is, so an upgrade's upload works before its - push installs the new functions; then writes `.convex-hosting/version.js` with the site: the - id, a random mark token, and the files (see Serve), in the CLI's state folder at the project - root, like Wrangler's `.wrangler/`. It writes a temporary file and renames it, so a running - `npx convex dev` never reads half of it; the folder carries its own `.gitignore`, so nothing - of it reaches git and no tool writes into `convex/`. The file is a build artifact that + push installs the new functions; then writes `.convex-hosting/version.js` with the version's + `assets`: the id, a random mark token, and the files (see Serve), in the CLI's state folder at + the project root, like Wrangler's `.wrangler/`. It writes a temporary file and renames it, so + a running `npx convex dev` never reads half of it; the folder carries its own `.gitignore`, so + nothing of it reaches git and no tool writes into `convex/`. The file is a build artifact that `http.ts` imports, as a server-rendered app's `http.ts` already imports its server build; the package ships the declaration of that module (an ambient wildcard module in a script `.d.ts` that the package's types entry references), so a fresh clone typechecks with nothing added. @@ -206,11 +206,17 @@ picks the longest matching prefix, so only an exact route reaches the app there. ```ts import { routeAll } from "@samebase/convex-hosting"; -import { site } from "../.convex-hosting/version.js"; +import { assets } from "../.convex-hosting/version.js"; -routeAll(http, components.hosting, site, server); +routeAll({ http, component: components.hosting, assets, worker: server }); ``` +Every input is named, after Cloudflare where Cloudflare has a name: `assets` is the static assets of +Workers Static Assets (its `assets` setting and `ASSETS` binding), and `worker` is the Worker script +(`has_user_worker`, `run_worker_first`). The export is not `site`, the setting of Workers Sites, +which Cloudflare deprecated for Static Assets. The file stays `version.js`, since it holds one +version, Cloudflare's unit of a deploy. + `serveSite` answers with the file when one matches. Otherwise it answers with the page that the optional `worker.fetch()` returns, else 404, both with `Cache-Control: no-store`; the page keeps every other header, several `Set-Cookie` included. Measured on 2026-10-14: the deployment's @@ -548,8 +554,9 @@ or ChessMerge goes; the list is checked at every release. At 0.8.0 and 0.5.0 tha - `packages/convex-hosting` - `src/component`: `schema.ts`, `lib.ts`, `convex.config.ts`, and its generated files. - - `src/client`: `routeAll`, the site's files (`manifest.ts`: the builder that the CLI runs and the - lookup that the action runs), and the shipped declaration of the version module. + - `src/client`: `routeAll`, Cloudflare's handler run against the assets (`answer.ts`), the assets' + files (`manifest.ts`: the builder that the CLI runs and the lookup that the action runs), and + the shipped declaration of the version module. - `src/cli`: the `convex-hosting` command: `deploy`, and `upload`, the inner step that `npx convex deploy --cmd` has to call as a program. - `src/workers-sdk`: Cloudflare's asset worker, its tests, and its html_handling and encoding diff --git a/docs/development.md b/docs/development.md index a6211aaa..b9306fce 100644 --- a/docs/development.md +++ b/docs/development.md @@ -46,7 +46,7 @@ Two cases are transient: vi.mock("../dist/server/server.js", () => ({ default: { fetch: async () => new Response() } })); vi.mock("../.convex-hosting/version.js", () => ({ versionId: "test", - site: { format: 1, versionId: "test", markToken: "test", files: null }, + assets: { format: 1, versionId: "test", markToken: "test", files: null }, })); ``` diff --git a/docs/from-static-hosting.md b/docs/from-static-hosting.md index cc189b7a..19ba6aa8 100644 --- a/docs/from-static-hosting.md +++ b/docs/from-static-hosting.md @@ -31,9 +31,9 @@ and source on 2026-10-18, version 0.2.1. `httpPrefix: "/api"` from `defineApp`, and add `/api` to the paths of your own routes whose URLs must stay. 3. In `convex/http.ts`, replace `registerStaticRoutes(...)` with - `routeAll(http, components.hosting, site)`, and import `site` from + `routeAll({ http, component: components.hosting, assets })`, and import `assets` from `../.convex-hosting/version.js`. Your exact routes keep winning. A server-rendered app passes its - server entry as the fourth argument. + server entry as `worker`. 4. In the deploy scripts, replace `@convex-dev/static-hosting deploy`, or the pair `npx convex deploy` and `upload --prod`, with `convex-hosting deploy --build "" --dist `, which builds, uploads, and pushes diff --git a/docs/serving.md b/docs/serving.md index 0ae660fd..4a9c51d4 100644 --- a/docs/serving.md +++ b/docs/serving.md @@ -26,20 +26,20 @@ the file when the page reloads. A local deployment, which has no front, sends th ## Routing -`routeAll(http, component, site, worker?)` routes the site's HTTP action for every method at every -path, and returns it. The action answers with the file that matches, else with what `worker` answers -(see [Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or HEAD on -a path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, +`routeAll({ http, component, assets, worker? })` routes the site's HTTP action for every method at +every path, and returns it. The action answers with the file that matches, else with what `worker` +answers (see [Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or +HEAD on a path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, else 404. `worker` is the Worker script, an object with `fetch(request)`: the code that runs on a miss. Everything it returns gets `Cache-Control: no-store`, and so does a 404, because the `*.convex.site` front caches paths with an extension. The front keeps `no-store` for a path without an extension and replaces it with a four-hour browser `max-age` for a path with one, so a browser that asks for a script before its upload ended keeps the 404; the deploy order prevents that case, -because no page refers to a file that is not uploaded yet. The site's files come with the pushed -code, in `.convex-hosting/version.js`, so a request reads no database: it costs one function call, -the HTTP action, and a file adds the download of its bytes, which Convex counts as a call too. A -redirect, a 304, a miss, and a rendered page download nothing. Until a first install's upload ends, -the site answers 404 naming the version. +because no page refers to a file that is not uploaded yet. The `assets` of the version come with the +pushed code, in `.convex-hosting/version.js`, so a request reads no database: it costs one function +call, the HTTP action, and a file adds the download of its bytes, which Convex counts as a call too. +A redirect, a 304, a miss, and a rendered page download nothing. Until a first install's upload +ends, the site answers 404 naming the version. As on Cloudflare, the presence of code decides where `not_found_handling` (the single-page fallback or the 404 page) applies: @@ -64,10 +64,10 @@ over an asset at the same path. The other differences are in ## Server-rendered pages -`routeAll` takes a fourth argument, `worker`, the object with `fetch(request)` that the app's server -entry exports, and calls it when no file matches. `convex/http.ts` imports the server build -directly, such as `../dist/server/server.js` for TanStack Start, so `npx convex dev` bundles it only -after a build: on a fresh clone, the first `deploy --dev` builds before the first push (see +`routeAll` takes a `worker`, the object with `fetch(request)` that the app's server entry exports, +and calls it when no file matches. `convex/http.ts` imports the server build directly, such as +`../dist/server/server.js` for TanStack Start, so `npx convex dev` bundles it only after a build: on +a fresh clone, the first `deploy --dev` builds before the first push (see [Quick start](../README.md#quick-start)). [`@samebase/convex-hosting-tanstack-start`](../packages/convex-hosting-tanstack-start) runs TanStack diff --git a/examples/hello-world-assets-only-workers.patch b/examples/hello-world-assets-only-workers.patch index 783ee851..45c17848 100644 --- a/examples/hello-world-assets-only-workers.patch +++ b/examples/hello-world-assets-only-workers.patch @@ -12,20 +12,20 @@ index 41a6c4afe86dc311eed5da6e75804b73bdc4462f..00000000000000000000000000000000 -export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index f71716a43c9d61ec1f5faf1c1165548296d1386f..0000000000000000000000000000000000000000 +index 51996727a045edbc5b84557709e31b07a62c3bfb..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; --import { site } from "../.convex-hosting/version.js"; +-import { assets } from "../.convex-hosting/version.js"; - -const http = httpRouter(); - -// Every method, every path, as a Cloudflare Worker without a script: a file for a path that has -// one, else 404; another method than GET or HEAD on a file answers 405. --routeAll(http, components.hosting, site); +-routeAll({ http, component: components.hosting, assets }); - -export default http; diff --git a/convex/tsconfig.json b/convex/tsconfig.json diff --git a/examples/hello-world-assets-only/convex/http.ts b/examples/hello-world-assets-only/convex/http.ts index f71716a4..51996727 100644 --- a/examples/hello-world-assets-only/convex/http.ts +++ b/examples/hello-world-assets-only/convex/http.ts @@ -1,12 +1,12 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { site } from "../.convex-hosting/version.js"; +import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else 404; another method than GET or HEAD on a file answers 405. -routeAll(http, components.hosting, site); +routeAll({ http, component: components.hosting, assets }); export default http; diff --git a/examples/tanstack-spa/convex/http.ts b/examples/tanstack-spa/convex/http.ts index 61b5a7e4..229ed7c7 100644 --- a/examples/tanstack-spa/convex/http.ts +++ b/examples/tanstack-spa/convex/http.ts @@ -1,12 +1,12 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { site } from "../.convex-hosting/version.js"; +import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else the single-page fallback; another method than GET or HEAD on a file answers 405. -routeAll(http, components.hosting, site); +routeAll({ http, component: components.hosting, assets }); export default http; diff --git a/examples/tanstack-ssr-workers.patch b/examples/tanstack-ssr-workers.patch index 058a9d89..43250147 100644 --- a/examples/tanstack-ssr-workers.patch +++ b/examples/tanstack-ssr-workers.patch @@ -18,14 +18,14 @@ index 1831f4b4fa5703fe1332d9cf45fb2308a57be703..dcc4d5f09735722e1164710651a0c69d export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index a8989b93e04e6fc60bbf5577c7ffc5ea39a4015d..0000000000000000000000000000000000000000 +index 4ae60e6c413b09f9d22481a9cba1b67b633b2529..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; --import { site } from "../.convex-hosting/version.js"; +-import { assets } from "../.convex-hosting/version.js"; -// Type only, nothing is bundled: the server build imported below. -import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; -import server from "../dist/server/server.js"; @@ -35,7 +35,7 @@ index a8989b93e04e6fc60bbf5577c7ffc5ea39a4015d..00000000000000000000000000000000 -// Every method, every path: a file for a path that has one (another method than GET or HEAD on it -// answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with -// static assets does. --const handler = routeAll(http, components.hosting, site, server); +-const handler = routeAll({ http, component: components.hosting, assets, worker: server }); -// Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it -// serves the key set, and the longest prefix wins, so the catch-all above never sees them. -for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { diff --git a/examples/tanstack-ssr/convex/http.ts b/examples/tanstack-ssr/convex/http.ts index a8989b93..4ae60e6c 100644 --- a/examples/tanstack-ssr/convex/http.ts +++ b/examples/tanstack-ssr/convex/http.ts @@ -1,7 +1,7 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; import { components } from "./_generated/api.js"; -import { site } from "../.convex-hosting/version.js"; +import { assets } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; @@ -11,7 +11,7 @@ const http = httpRouter(); // Every method, every path: a file for a path that has one (another method than GET or HEAD on it // answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with // static assets does. -const handler = routeAll(http, components.hosting, site, server); +const handler = routeAll({ http, component: components.hosting, assets, worker: server }); // Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it // serves the key set, and the longest prefix wins, so the catch-all above never sees them. for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { diff --git a/packages/convex-hosting-tanstack-start/README.md b/packages/convex-hosting-tanstack-start/README.md index 1efe029f..9999a624 100644 --- a/packages/convex-hosting-tanstack-start/README.md +++ b/packages/convex-hosting-tanstack-start/README.md @@ -29,11 +29,12 @@ other request goes to the server, as it goes to a Cloudflare Worker: ```ts import { routeAll } from "@samebase/convex-hosting"; +import { assets } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; -routeAll(http, components.hosting, site, server); +routeAll({ http, component: components.hosting, assets, worker: server }); ``` Import `@samebase/convex-hosting` before the server build: it defines `queueMicrotask` when it diff --git a/packages/convex-hosting/CHANGELOG.md b/packages/convex-hosting/CHANGELOG.md index 5df6977f..38f15987 100644 --- a/packages/convex-hosting/CHANGELOG.md +++ b/packages/convex-hosting/CHANGELOG.md @@ -2,15 +2,26 @@ ## 0.15.0 -- A request reads no database. The deploy writes the site's files into `.convex-hosting/version.js` - (each path's content hash, content type, and stored file, in the layout of Cloudflare's asset - manifest), and the HTTP action answers from them. A page, a miss, a redirect, a 304, and a session - refresh cost one function call, the HTTP action, where they cost two; an answer with a body costs - two, the action and the download of the file, where it cost three. The component's `route` query - is gone. -- Breaking: `routeAll` takes the site, `import { site } from "../.convex-hosting/version.js"` and - `routeAll(http, components.hosting, site, server)`. `versionId` stays exported for the query that - reloads open tabs. +- A request reads no database. The deploy writes the version's assets into + `.convex-hosting/version.js` (each path's content hash, content type, and stored file, in the + layout of Cloudflare's asset manifest), and the HTTP action answers from them. A page, a miss, a + redirect, a 304, and a session refresh cost one function call, the HTTP action, where they cost + two; an answer with a body costs two, the action and the download of the file, where it cost + three. The component's `route` query is gone. +- Breaking: `routeAll` takes one object, with every input named, and the assets in place of the + version id: + + ```ts + import { assets } from "../.convex-hosting/version.js"; + + routeAll({ http, component: components.hosting, assets, worker: server }); + ``` + + A files-only site leaves `worker` out. `assets` and `worker` are Cloudflare's names: the static + assets of a Worker, and the Worker script. `versionId` stays exported for the query that reloads + open tabs. A test that mocks the version module adds + `assets: { format: 1, versionId: "test", markToken: "test", files: null }`. + - After the push, `deploy` sends one request with the version's mark token, and the code that answers marks its version live; before, the first request did. `markLive` answers what it did and never throws. diff --git a/packages/convex-hosting/src/cli/main.test.ts b/packages/convex-hosting/src/cli/main.test.ts index 05ebcfc5..efee6786 100644 --- a/packages/convex-hosting/src/cli/main.test.ts +++ b/packages/convex-hosting/src/cli/main.test.ts @@ -12,7 +12,7 @@ import { import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { describe, expect, test } from "vite-plus/test"; -import { lookup, MARK_HEADER, MARK_PATH, storageUrl, type Site } from "../client/manifest.js"; +import { lookup, MARK_HEADER, MARK_PATH, storageUrl, type Assets } from "../client/manifest.js"; import { deploymentSelector, type Cli } from "./convex.js"; import { main, VERSION_FILE } from "./main.js"; @@ -155,9 +155,9 @@ function fake( events.push("mark"); const token = new Headers(init?.headers).get(MARK_HEADER); if (options.mark !== undefined) return await options.mark(token, init); - const site = writtenSite(cwd); - return token === site.markToken - ? Response.json({ versionId: site.versionId, result: "marked" }) + const assets = writtenAssets(cwd); + return token === assets.markToken + ? Response.json({ versionId: assets.versionId, result: "marked" }) : new Response("

Home

"); } const storageId = `storage-${stored.size}`; @@ -184,12 +184,12 @@ function innerUpload(cli: Cli, args: string[]) { const versionFile = (cwd: string) => readFileSync(join(cwd, VERSION_FILE), "utf8"); const writtenVersionId = (cwd: string) => /"([^"]+)"/.exec(versionFile(cwd))?.[1]; -/** The site of the version file, as `convex/http.ts` imports it. */ -function writtenSite(cwd: string): Site { +/** The assets of the version file, as `convex/http.ts` imports them. */ +function writtenAssets(cwd: string): Assets { const line = versionFile(cwd) .split("\n") - .find((text) => text.startsWith("export const site = ")); - return JSON.parse(line?.slice("export const site = ".length, -1) ?? "null"); + .find((text) => text.startsWith("export const assets = ")); + return JSON.parse(line?.slice("export const assets = ".length, -1) ?? "null"); } const site = { @@ -266,7 +266,7 @@ describe("deploy --dev", () => { const { cli, events, callArgs } = fake(cwd, { installed: () => pushed, push: async () => { - pushedFiles.push(writtenSite(cwd).files !== null); + pushedFiles.push(writtenAssets(cwd).files !== null); pushed = true; return 0; }, @@ -399,11 +399,11 @@ describe("deploy reports", () => { push: innerUpload, mark: async (token) => { tokens.push(token); - return Response.json({ versionId: writtenSite(cwd).versionId, result: "marked" }); + return Response.json({ versionId: writtenAssets(cwd).versionId, result: "marked" }); }, }); expect(await main(DEPLOY, cli)).toBe(0); - expect(tokens).toEqual([writtenSite(cwd).markToken]); + expect(tokens).toEqual([writtenAssets(cwd).markToken]); expect(logs[logs.length - 1]).toMatch(/^Deployed version /); }); @@ -441,7 +441,7 @@ describe("deploy reports", () => { const { cli, logs } = fake(cwd, { push: innerUpload, mark: async () => - Response.json({ versionId: writtenSite(cwd).versionId, result: "superseded" }), + Response.json({ versionId: writtenAssets(cwd).versionId, result: "superseded" }), }); expect(await main(DEPLOY, cli)).toBe(0); expect(logs.some((line) => line.includes("a deploy overlapped this one"))).toBe(true); @@ -529,11 +529,11 @@ describe("deploy", () => { if (args.includes("--cmd")) { const exitCode = await innerUpload(cli, args); expect(existsSync(join(cwd, ".convex-hosting", "first-install"))).toBe(true); - pushedFiles.push(writtenSite(cwd).files !== null); + pushedFiles.push(writtenAssets(cwd).files !== null); pushed = true; return exitCode; } - pushedFiles.push(writtenSite(cwd).files !== null); + pushedFiles.push(writtenAssets(cwd).files !== null); return 0; }, }); @@ -669,9 +669,9 @@ describe("upload", () => { expect(versionFile(cwd).split("\n").slice(0, 2)).toEqual([ 'export const versionId = "v1";', // tsc reads the file itself in an app whose convex/tsconfig.json sets allowJs. - '/** @type {import("@samebase/convex-hosting").Site} */', + '/** @type {import("@samebase/convex-hosting").Assets} */', ]); - const written = writtenSite(cwd); + const written = writtenAssets(cwd); expect(written).toMatchObject({ format: 1, versionId: "v1", markToken: expect.any(String) }); const files = written.files; if (files === null) throw new Error("The version file has no files."); @@ -705,7 +705,7 @@ describe("upload", () => { const { cli, calls } = fake(cwd); expect(await main(upload(), cli)).toBe(0); expect(calls().filter((name) => name === "urls")).toHaveLength(2); - const written = writtenSite(cwd).files; + const written = writtenAssets(cwd).files; if (written === null) throw new Error("The version file has no files."); for (const i of [0, 1999, 2000, 2499]) { expect(await lookup(written, `/assets/${i}.js`)).not.toBeNull(); diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index ec73254c..28212c62 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -13,12 +13,12 @@ import { fileURLToPath } from "node:url"; import { parseArgs } from "node:util"; import { z } from "zod"; import { - buildSiteFiles, + ASSETS_FORMAT, + buildAssetFiles, MARK_HEADER, MARK_PATH, - SITE_FORMAT, - type Site, - type SiteFiles, + type AssetFiles, + type Assets, } from "../client/manifest.js"; import { internal } from "../component/_generated/api.js"; import type { Config } from "../component/lib.js"; @@ -388,7 +388,7 @@ async function upload( const markToken = randomUUID(); const missing = await probeComponent(cli, target); if (missing !== undefined) { - writeVersionFile(cli, { format: SITE_FORMAT, versionId, markToken, files: null }); + writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, markToken, files: null }); return missing; } @@ -477,8 +477,8 @@ async function upload( await record(uploaded); } await runComponent(cli, target, internal.lib.finishVersion, { versionId }, z.null()); - const files = await siteFiles(cli, target, versionId, config, entries); - writeVersionFile(cli, { format: SITE_FORMAT, versionId, markToken, files }); + const files = await assetFiles(cli, target, versionId, config, entries); + writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, markToken, files }); cli.log(`Uploaded version ${versionId} and wrote ${VERSION_FILE}.`); return undefined; } @@ -488,13 +488,13 @@ async function upload( * component can make, read with inline queries in the component, which work whatever release of * this package its functions are, and the deployment's `CONVEX_CLOUD_URL`, their origin. */ -async function siteFiles( +async function assetFiles( cli: Cli, target: Target, versionId: string, config: Config, entries: DistEntry[], -): Promise { +): Promise { const urls = new Map(); let cloudUrl = ""; let after = ""; @@ -523,7 +523,7 @@ async function siteFiles( if (page.files.length < URL_PAGE) break; after = page.files[page.files.length - 1][0]; } - return await buildSiteFiles( + return await buildAssetFiles( cloudUrl, siteConfig(config), entries.map(({ path, sha256, contentType }) => { @@ -534,34 +534,34 @@ async function siteFiles( ); } -/** The line of the version file that holds the site. */ -const SITE_LINE = "export const site = "; +/** The line of the version file that holds the assets. */ +const ASSETS_LINE = "export const assets = "; /** * Writes the version file. `versionId` is its own export too, for the app query that reloads - * pages on a new version. The site carries its type as JSDoc: Convex's default + * pages on a new version. The assets carry their type as JSDoc: Convex's default * `convex/tsconfig.json` sets `allowJs`, so tsc reads this file instead of the package's - * declaration, and would infer `string` where `Site` has a union of literals. + * declaration, and would infer `string` where `Assets` has a union of literals. */ -function writeVersionFile(cli: Cli, site: Site) { +function writeVersionFile(cli: Cli, assets: Assets) { writeStateFile( cli, VERSION_FILE, - `export const versionId = ${JSON.stringify(site.versionId)};\n` + - `/** @type {import("@samebase/convex-hosting").Site} */\n` + - `${SITE_LINE}${JSON.stringify(site)};\n`, + `export const versionId = ${JSON.stringify(assets.versionId)};\n` + + `/** @type {import("@samebase/convex-hosting").Assets} */\n` + + `${ASSETS_LINE}${JSON.stringify(assets)};\n`, ); } -/** The id and the mark token of the site in the version file that the upload wrote. */ -function readVersionFile(cli: Cli): Pick { +/** The id and the mark token of the assets in the version file that the upload wrote. */ +function readVersionFile(cli: Cli): Pick { const line = readFileSync(join(cli.cwd, VERSION_FILE), "utf8") .split("\n") - .find((text) => text.startsWith(SITE_LINE)); - if (line === undefined) throw new Error(`${VERSION_FILE} has no site.`); + .find((text) => text.startsWith(ASSETS_LINE)); + if (line === undefined) throw new Error(`${VERSION_FILE} has no assets.`); return z .object({ versionId: z.string(), markToken: z.string() }) - .parse(JSON.parse(line.slice(SITE_LINE.length, -1))); + .parse(JSON.parse(line.slice(ASSETS_LINE.length, -1))); } /** @@ -572,7 +572,7 @@ function readVersionFile(cli: Cli): Pick { async function markServedVersion( cli: Cli, url: string, - site: Pick, + site: Pick, ) { const later = `Version ${site.versionId} serves, and the next deploy deletes the files of the versions before it.`; let answer: unknown; diff --git a/packages/convex-hosting/src/client/answer.test.ts b/packages/convex-hosting/src/client/answer.test.ts index c5e9c0e8..d1c8ecce 100644 --- a/packages/convex-hosting/src/client/answer.test.ts +++ b/packages/convex-hosting/src/client/answer.test.ts @@ -3,8 +3,8 @@ import { siteConfig } from "../cli/site-config.js"; import type { Config } from "../component/lib.js"; import { encodingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/encoding-test-cases.js"; import { htmlHandlingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/html-handling-test-cases.js"; -import { answer } from "./index.js"; -import { buildSiteFiles, storageUrl, type SiteFiles } from "./manifest.js"; +import { answer } from "./answer.js"; +import { buildAssetFiles, storageUrl, type AssetFiles } from "./manifest.js"; type Files = Record; @@ -31,12 +31,12 @@ async function siteFiles(files: Files, config: Config = {}) { url: await bodyUrl(body), })), ); - return await buildSiteFiles(CLOUD_URL, siteConfig(config), entries); + return await buildAssetFiles(CLOUD_URL, siteConfig(config), entries); } /** Cloudflare's answer to one request, with the storage URL of its body, or `null` for a miss. */ async function route( - files: SiteFiles, + files: AssetFiles, path: string, headers: Record = {}, hasUserWorker = true, @@ -189,7 +189,7 @@ describe("answer", () => { // asset Worker with `exists` mocked; here the files are a site's manifest. describe("Cloudflare's conformance cases", () => { /** Requests `path` and follows redirects, as the upstream test's `fetch` does. */ - async function follow(files: SiteFiles, path: string) { + async function follow(files: AssetFiles, path: string) { let url = ORIGIN + path; for (let hop = 0; hop < 8; hop++) { const asset = await answer(files, new Request(url), false); diff --git a/packages/convex-hosting/src/client/answer.ts b/packages/convex-hosting/src/client/answer.ts new file mode 100644 index 00000000..a00ac46c --- /dev/null +++ b/packages/convex-hosting/src/client/answer.ts @@ -0,0 +1,74 @@ +import { Analytics } from "../workers-sdk/packages/workers-shared/asset-worker/src/analytics.js"; +import { + canFetch, + handleRequest, +} from "../workers-sdk/packages/workers-shared/asset-worker/src/handler.js"; +import { mockJaegerBinding } from "../workers-sdk/packages/workers-shared/utils/tracing.js"; +import { lookup, type AssetFiles, type ManifestHit } from "./manifest.js"; + +/** An answer of Cloudflare's handler, and the stored file of its body, if it has one. */ +export type Answer = { status: number; headers: Headers; file: number | null }; + +/** + * Runs Cloudflare's asset handler for `request` against the version's files, or returns `null` when + * no asset answers. `hasUserWorker` is Cloudflare's `has_user_worker`: whether the app has code that + * answers a miss. With it, Cloudflare's router asks `canFetch` first, which keeps + * `not_found_handling` for navigations only, and the app answers the other misses. Without it, + * every request goes to `handleRequest`, so `not_found_handling` applies to all of them, and an + * asset always answers. + */ +export async function answer( + files: AssetFiles, + request: Request, + hasUserWorker: boolean, +): Promise { + const env = { JAEGER: mockJaegerBinding() }; + // `exists` returns an ETag; `getByETag` gets the entry back for that ETag. The ETag is the content + // hash and a short hash of the content type, so identical bytes under two types stay distinct. + const found = new Map(); + const exists = async (pathname: string) => { + const hit = await lookup(files, pathname); + if (hit === null) return null; + const eTag = hit.contentHash + (await shortHash(hit.contentType ?? "")); + found.set(eTag, hit); + return eTag; + }; + let body: ManifestHit | undefined; + const getByETag = async (eTag: string) => { + body = found.get(eTag); + if (body === undefined) throw new Error(`No entry has the ETag ${eTag}.`); + return { + // `withBody` replaces this placeholder with the stored file. + readableStream: new ReadableStream(), + contentType: body.contentType, + cacheStatus: "MISS" as const, + }; + }; + + if (hasUserWorker && !(await canFetch(request, env, files.config, exists))) return null; + const response = await handleRequest( + request, + env, + files.config, + exists, + getByETag, + new Analytics(), + ); + // It describes Cloudflare's cache, which does not exist here. + response.headers.delete("CF-Cache-Status"); + // The deployment's Cloudflare front caches 404 answers on static paths. + if (response.status === 404) response.headers.set("Cache-Control", "no-store"); + return { + status: response.status, + headers: response.headers, + file: response.body !== null && body !== undefined ? body.file : null, + }; +} + +/** The first 8 hex digits of the SHA-256 of `text`. */ +async function shortHash(text: string) { + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)); + return Array.from(new Uint8Array(digest, 0, 4), (byte) => + byte.toString(16).padStart(2, "0"), + ).join(""); +} diff --git a/packages/convex-hosting/src/client/index.test.ts b/packages/convex-hosting/src/client/index.test.ts index 31670dea..42531778 100644 --- a/packages/convex-hosting/src/client/index.test.ts +++ b/packages/convex-hosting/src/client/index.test.ts @@ -7,7 +7,7 @@ import type { Config } from "../component/lib.js"; import { internal } from "../component/_generated/api.js"; import schema from "../component/schema.js"; import { routeAll } from "./index.js"; -import { buildSiteFiles, MARK_HEADER, type Site } from "./manifest.js"; +import { buildAssetFiles, MARK_HEADER, type Assets } from "./manifest.js"; const modules = import.meta.glob(["../component/**/*.ts", "!../component/**/*.test.ts"]); @@ -17,7 +17,7 @@ const component = { lib: { markLive: anyApi.lib.markLive } }; const CLOUD_URL = "https://example.convex.cloud"; /** - * Version `v1` with `/index.html` and `config`, ready, and its site as the upload writes it. The + * Version `v1` with `/index.html` and `config`, ready, and its assets as the upload writes them. The * site's action runs in an HTTP action, an action context where `fetch` is allowed; convex-test * refuses `fetch` in `t.run`, which is a mutation. The response comes back as its parts, with the * number of functions that the action called. @@ -41,11 +41,11 @@ async function setup(config: Config = {}) { entries: [{ ...entry, storageId }], }); await t.mutation(internal.lib.finishVersion, { versionId: "v1" }); - const site: Site = { + const assets: Assets = { format: 1, versionId: "v1", markToken: "token-1", - files: await buildSiteFiles(CLOUD_URL, siteConfig(config), [ + files: await buildAssetFiles(CLOUD_URL, siteConfig(config), [ { ...entry, url: `${CLOUD_URL}/api/storage/${storageId}` }, ]), }; @@ -53,7 +53,7 @@ async function setup(config: Config = {}) { const serve = ( path: string, options: { - site?: Site; + assets?: Assets; render?: () => Promise; headers?: Record; method?: string; @@ -64,7 +64,12 @@ async function setup(config: Config = {}) { const runQuery = vi.spyOn(ctx, "runQuery"); const url = `https://example.convex.site${path}`; const worker = options.render === undefined ? undefined : { fetch: options.render }; - const action = routeAll(httpRouter(), component, options.site ?? site, worker); + const action = routeAll({ + http: httpRouter(), + component, + assets: options.assets ?? assets, + worker, + }); const request = new Request(url, { method: options.method, headers: options.headers }); // @ts-expect-error httpActionGeneric keeps the function as _handler; PublicHttpAction does not declare it. const response: Response = await action._handler(ctx, request); @@ -88,7 +93,7 @@ async function setup(config: Config = {}) { )?.state.kind, ); const finish = () => t.finishAllScheduledFunctions(vi.runAllTimers); - return { site, serve, state, finish }; + return { assets, serve, state, finish }; } afterEach(() => { @@ -99,9 +104,9 @@ afterEach(() => { describe("routeAll", () => { test("routes the action for every method Convex routes, at every path, and returns it", async () => { - const { site } = await setup(); + const { assets } = await setup(); const http = httpRouter(); - const action = routeAll(http, component, site); + const action = routeAll({ http, component, assets }); for (const method of ROUTABLE_HTTP_METHODS) { expect(http.lookup("/any/path", method)).toEqual([action, method, "/*"]); } @@ -121,19 +126,19 @@ describe("the site's action", () => { }); test("the request with the site's mark token marks the version live and answers the result", async () => { - const { site, serve, state, finish } = await setup(); + const { assets, serve, state, finish } = await setup(); const render = vi.fn(async () => new Response("page")); const marked = await serve("/.convex-hosting/mark", { render, method: "POST", - headers: { [MARK_HEADER]: site.markToken }, + headers: { [MARK_HEADER]: assets.markToken }, }); expect(marked.calls).toBe(1); expect(JSON.parse(marked.body)).toEqual({ versionId: "v1", result: "marked" }); expect(marked.cacheControl).toBe("no-store"); expect(render).not.toHaveBeenCalled(); expect(await state()).toBe("live"); - const again = await serve("/", { headers: { [MARK_HEADER]: site.markToken } }); + const again = await serve("/", { headers: { [MARK_HEADER]: assets.markToken } }); expect(JSON.parse(again.body)).toEqual({ versionId: "v1", result: "live" }); await finish(); expect(await state()).toBe("live"); @@ -149,30 +154,30 @@ describe("the site's action", () => { expect(await state()).toBe("ready"); }); - test("a first install's site, before its upload, answers 404 naming the version, without rendering", async () => { - const { site, serve } = await setup(); + test("a first install's assets, before its upload, answer 404 naming the version, without rendering", async () => { + const { assets, serve } = await setup(); const render = vi.fn(async () => new Response("page")); - const early = await serve("/", { site: { ...site, files: null }, render }); + const early = await serve("/", { assets: { ...assets, files: null }, render }); expect(early.status).toBe(404); expect(early.body).toBe("Version v1 of the site is not uploaded yet."); expect(early.cacheControl).toBe("no-store"); expect(render).not.toHaveBeenCalled(); }); - test("a site uploaded to another deployment answers 404 naming it, without rendering", async () => { - const { site, serve } = await setup(); + test("assets uploaded to another deployment answer 404 naming it, without rendering", async () => { + const { assets, serve } = await setup(); vi.stubEnv("CONVEX_CLOUD_URL", "https://other-dog-456.convex.cloud"); const render = vi.fn(async () => new Response("page")); - const elsewhere = await serve("/", { site, render }); + const elsewhere = await serve("/", { assets, render }); expect(elsewhere.status).toBe(404); expect(elsewhere.body).toContain(`was uploaded to ${CLOUD_URL}, not to this deployment`); expect(render).not.toHaveBeenCalled(); }); - test("a site of another format answers 500 and asks for a deploy", async () => { - const { site, serve } = await setup(); + test("assets of another format answer 500 and ask for a deploy", async () => { + const { assets, serve } = await setup(); // A version file that another release wrote. - const answer = await serve("/", { site: { ...site, format: 0 } }); + const answer = await serve("/", { assets: { ...assets, format: 0 } }); expect(answer.status).toBe(500); expect(answer.body).toContain("Deploy again."); }); diff --git a/packages/convex-hosting/src/client/index.ts b/packages/convex-hosting/src/client/index.ts index 3699c9da..1cfff1d6 100644 --- a/packages/convex-hosting/src/client/index.ts +++ b/packages/convex-hosting/src/client/index.ts @@ -6,74 +6,77 @@ import { type PublicHttpAction, } from "convex/server"; import type { ComponentApi } from "../component/_generated/component.js"; -import { Analytics } from "../workers-sdk/packages/workers-shared/asset-worker/src/analytics.js"; +import { answer, type Answer } from "./answer.js"; import { - canFetch, - handleRequest, -} from "../workers-sdk/packages/workers-shared/asset-worker/src/handler.js"; -import { mockJaegerBinding } from "../workers-sdk/packages/workers-shared/utils/tracing.js"; -import { - lookup, + ASSETS_FORMAT, MARK_HEADER, - SITE_FORMAT, storageUrl, - type ManifestHit, - type Site, - type SiteFiles, + type AssetFiles, + type Assets, } from "./manifest.js"; -export type { Site } from "./manifest.js"; +export type { Assets } from "./manifest.js"; + +/** What `routeAll` routes, each named as Cloudflare and Convex name it. */ +export type RouteAllOptions = { + /** The app's router, from `httpRouter()`. */ + http: HttpRouter; + /** The installed component: `components.hosting`. */ + component: ComponentApi; + /** `assets` from `.convex-hosting/version.js`, which `convex-hosting deploy` writes. */ + assets: Assets; + /** + * The Worker script: the object with `fetch(request)` that the app's server entry exports, the + * code that runs on a miss. Without it, the site is assets only. + */ + worker?: { fetch(request: Request): Promise }; +}; /** - * The HTTP action that serves the site, for `routeAll`: it answers a request with the file of the - * site (another method than GET or HEAD on a file answers 405), else with what `worker` answers, - * else 404. `worker` is the Worker script, the object with `fetch(request)` that the app's server - * entry exports: the code that runs on a miss. As on Cloudflare, the presence of code decides how - * `not_found_handling` applies: with `worker`, it applies to navigations only and `worker` answers - * the other misses; without it, the site is files only, so it applies to every request. + * The HTTP action that serves the site, for `routeAll`: it answers a request with an asset (another + * method than GET or HEAD on an asset answers 405), else with what `worker` answers, else 404. As on + * Cloudflare, the presence of a Worker script decides how `not_found_handling` applies: with + * `worker`, it applies to navigations only and `worker` answers the other misses; without it, it + * applies to every request. * - * The site's files are in the pushed code, so a request calls no function of the component: a file - * costs this action and the download of its bytes, any other answer this action alone. + * The assets are in the pushed code, so a request calls no function of the component: a file costs + * this action and the download of its bytes, any other answer this action alone. * * A page and a 404 answer `Cache-Control: no-store`. The deployment's Cloudflare front keeps that * for a path without an extension and replaces it with a four-hour browser `max-age` for a path * with one, so a browser that asks for a script before its upload ended keeps the 404; the deploy * order prevents that case, because no page refers to a file that is not uploaded yet. */ -function serveSite( - component: ComponentApi, - site: Site, - worker?: { fetch(request: Request): Promise }, -): PublicHttpAction { +function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAction { return httpActionGeneric(async (ctx, request) => { - if (site.format !== SITE_FORMAT) { + if (assets.format !== ASSETS_FORMAT) { return notServed( 500, - `.convex-hosting/version.js has format ${site.format}, and this release of ` + - `@samebase/convex-hosting reads format ${SITE_FORMAT}. Deploy again.`, + `.convex-hosting/version.js has format ${assets.format}, and this release of ` + + `@samebase/convex-hosting reads format ${ASSETS_FORMAT}. Deploy again.`, ); } - if (request.headers.get(MARK_HEADER) === site.markToken) { - const result = await ctx.runMutation(component.lib.markLive, { versionId: site.versionId }); - return Response.json({ versionId: site.versionId, result }, { headers: NO_STORE }); + if (request.headers.get(MARK_HEADER) === assets.markToken) { + const result = await ctx.runMutation(component.lib.markLive, { versionId: assets.versionId }); + return Response.json({ versionId: assets.versionId, result }, { headers: NO_STORE }); } - const { files } = site; + const { files } = assets; // A first install pushes before its upload; the deploy pushes again when the upload ends. if (files === null) { - return notServed(404, `Version ${site.versionId} of the site is not uploaded yet.`); + return notServed(404, `Version ${assets.versionId} of the site is not uploaded yet.`); } // The storage URLs name the deployment they were taken from. if (files.cloudUrl !== process.env.CONVEX_CLOUD_URL) { return notServed( 404, - `Version ${site.versionId} of the site was uploaded to ${files.cloudUrl}, not to this ` + + `Version ${assets.versionId} of the site was uploaded to ${files.cloudUrl}, not to this ` + `deployment. Deploy to this deployment with convex-hosting deploy.`, ); } const asset = await answer(files, request, worker !== undefined); if (asset !== null) return await withBody(files, asset); - // `answer` answers every files-only request itself, so this 404 only fails closed. + // `answer` answers every assets-only request itself, so this 404 only fails closed. if (worker === undefined) return new Response(null, { status: 404, headers: NO_STORE }); const page = await worker.fetch(request); const headers = new Headers(page.headers); @@ -87,84 +90,24 @@ function serveSite( * every path, as every request reaches a Cloudflare Worker with static assets. Convex answers HEAD * through GET. * + * ```ts + * routeAll({ http, component: components.hosting, assets, worker: server }); + * ``` + * * Returns the action, for the paths that a component's HTTP prefix would otherwise take: Convex * picks an exact route first, then the longest prefix, so an app whose session routes sit under a * component's prefix registers them with `http.route({ path, method, handler })`. */ -export function routeAll( - http: HttpRouter, - component: ComponentApi, - site: Site, - worker?: { fetch(request: Request): Promise }, -): PublicHttpAction { - const action = serveSite(component, site, worker); +export function routeAll(options: RouteAllOptions): PublicHttpAction { + const action = serveSite(options); for (const method of ROUTABLE_HTTP_METHODS) { - http.route({ pathPrefix: "/", method, handler: action }); + options.http.route({ pathPrefix: "/", method, handler: action }); } return action; } -/** An answer of Cloudflare's handler, and the stored file of its body, if it has one. */ -export type Asset = { status: number; headers: Headers; file: number | null }; - -/** - * Runs Cloudflare's asset handler for `request` against the site's files, or returns `null` when no - * asset answers. `hasUserWorker` is Cloudflare's `has_user_worker`: whether the app has code that - * answers a miss. With it, Cloudflare's router asks `canFetch` first, which keeps - * `not_found_handling` for navigations only, and the app answers the other misses. Without it, - * every request goes to `handleRequest`, so `not_found_handling` applies to all of them, and an - * asset always answers. - */ -export async function answer( - files: SiteFiles, - request: Request, - hasUserWorker: boolean, -): Promise { - const env = { JAEGER: mockJaegerBinding() }; - // `exists` returns an ETag; `getByETag` gets the entry back for that ETag. The ETag is the content - // hash and a short hash of the content type, so identical bytes under two types stay distinct. - const found = new Map(); - const exists = async (pathname: string) => { - const hit = await lookup(files, pathname); - if (hit === null) return null; - const eTag = hit.contentHash + (await shortHash(hit.contentType ?? "")); - found.set(eTag, hit); - return eTag; - }; - let body: ManifestHit | undefined; - const getByETag = async (eTag: string) => { - body = found.get(eTag); - if (body === undefined) throw new Error(`No entry has the ETag ${eTag}.`); - return { - // `withBody` replaces this placeholder with the stored file. - readableStream: new ReadableStream(), - contentType: body.contentType, - cacheStatus: "MISS" as const, - }; - }; - - if (hasUserWorker && !(await canFetch(request, env, files.config, exists))) return null; - const response = await handleRequest( - request, - env, - files.config, - exists, - getByETag, - new Analytics(), - ); - // It describes Cloudflare's cache, which does not exist here. - response.headers.delete("CF-Cache-Status"); - // The deployment's Cloudflare front caches 404 answers on static paths. - if (response.status === 404) response.headers.set("Cache-Control", "no-store"); - return { - status: response.status, - headers: response.headers, - file: response.body !== null && body !== undefined ? body.file : null, - }; -} - /** The response of `asset`, with the stored file as its body when it has one. */ -async function withBody(files: SiteFiles, asset: Asset): Promise { +async function withBody(files: AssetFiles, asset: Answer): Promise { if (asset.file === null) return new Response(null, { status: asset.status, headers: asset.headers }); // An app cannot read a component's storage, so the body comes from the storage URL. @@ -191,11 +134,3 @@ const NO_STORE = { "Cache-Control": "no-store" }; function notServed(status: number, message: string) { return new Response(message, { status, headers: NO_STORE }); } - -/** The first 8 hex digits of the SHA-256 of `text`. */ -async function shortHash(text: string) { - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)); - return Array.from(new Uint8Array(digest, 0, 4), (byte) => - byte.toString(16).padStart(2, "0"), - ).join(""); -} diff --git a/packages/convex-hosting/src/client/manifest.test.ts b/packages/convex-hosting/src/client/manifest.test.ts index acbf4938..75b3eb78 100644 --- a/packages/convex-hosting/src/client/manifest.test.ts +++ b/packages/convex-hosting/src/client/manifest.test.ts @@ -1,6 +1,12 @@ import { describe, expect, test } from "vite-plus/test"; import { siteConfig } from "../cli/site-config.js"; -import { buildSiteFiles, lookup, storageUrl, type SiteEntry, type SiteFiles } from "./manifest.js"; +import { + buildAssetFiles, + lookup, + storageUrl, + type AssetEntry, + type AssetFiles, +} from "./manifest.js"; const CLOUD_URL = "https://happy-cat-123.convex.cloud"; const config = siteConfig({}); @@ -17,7 +23,7 @@ function url(key: string) { /** `count` entries with distinct bytes; every third shares the bytes of the one before. */ async function entries(count: number, paths = (i: number) => `/assets/chunk-${i}.js`) { - const list: SiteEntry[] = []; + const list: AssetEntry[] = []; for (let i = 0; i < count; i++) { const body = `body ${i - (i % 3 === 2 ? 1 : 0)}`; const sha256 = await sha256Hex(body); @@ -35,7 +41,7 @@ async function entries(count: number, paths = (i: number) => `/assets/chunk-${i} * The reference reader: it decodes the whole manifest and reads every entry into a map by path * hash, the plain way, which `lookup` must agree with for every path and every miss. */ -async function reference(files: SiteFiles) { +async function reference(files: AssetFiles) { const bytes = Uint8Array.from(atob(files.manifest), (char) => char.charCodeAt(0)); const view = new DataView(bytes.buffer); const hex = (from: number, to: number) => @@ -52,12 +58,12 @@ async function reference(files: SiteFiles) { return async (path: string) => byPathHash.get((await sha256Hex(path)).slice(0, 32)) ?? null; } -describe("buildSiteFiles and lookup", () => { +describe("buildAssetFiles and lookup", () => { test("every path finds its entry, and the reference reader agrees, at every size up to 64", async () => { // Entries start 20 + 40i bytes in, so successive sizes put entries at every base64 alignment. for (let count = 0; count <= 64; count++) { const list = await entries(count); - const files = await buildSiteFiles(CLOUD_URL, config, list); + const files = await buildAssetFiles(CLOUD_URL, config, list); const read = await reference(files); for (const entry of list) { const hit = await lookup(files, entry.path); @@ -82,14 +88,14 @@ describe("buildSiteFiles and lookup", () => { "/emoji/🙂.svg", ]; const list = await entries(paths.length, (i) => paths[i]); - const files = await buildSiteFiles(CLOUD_URL, config, list); + const files = await buildAssetFiles(CLOUD_URL, config, list); for (const path of paths) expect(await lookup(files, path)).not.toBeNull(); expect(await lookup(files, "/caf%C3%A9/menu.html")).toBeNull(); }); test("a large site: 5,000 entries all found, and misses miss", async () => { const list = await entries(5000); - const files = await buildSiteFiles(CLOUD_URL, config, list); + const files = await buildAssetFiles(CLOUD_URL, config, list); const read = await reference(files); for (const entry of list.filter((_, i) => i % 97 === 0)) { expect(await lookup(files, entry.path)).toEqual(await read(entry.path)); @@ -100,7 +106,7 @@ describe("buildSiteFiles and lookup", () => { test("paths with the same bytes share one stored file and keep their own content types", async () => { const sha256 = await sha256Hex("same"); - const files = await buildSiteFiles(CLOUD_URL, config, [ + const files = await buildAssetFiles(CLOUD_URL, config, [ { path: "/a.txt", sha256, contentType: "text/plain", url: url("k1") }, { path: "/a.js", sha256, contentType: "text/javascript", url: url("k1") }, ]); @@ -118,7 +124,7 @@ describe("buildSiteFiles and lookup", () => { const keys = ["a", "bcd", "efghij", "klmnopqrstuvwxyz0123456789abcdef0123"]; const list = await entries(keys.length); keys.forEach((key, i) => (list[i].url = url(key))); - const files = await buildSiteFiles(CLOUD_URL, config, list); + const files = await buildAssetFiles(CLOUD_URL, config, list); expect(files.storage.prefix).toBe(`${CLOUD_URL}/api/storage/`); expect(files.storage.suffix).toBe("?component=m026ambq8g7g5yxf42tb4d4tfx8hg303"); for (const entry of list) { @@ -129,9 +135,9 @@ describe("buildSiteFiles and lookup", () => { test("a site with one file or no file", async () => { const [one] = await entries(1); - const single = await buildSiteFiles(CLOUD_URL, config, [one]); + const single = await buildAssetFiles(CLOUD_URL, config, [one]); expect(storageUrl(single.storage, (await lookup(single, one.path))?.file ?? -1)).toBe(one.url); - const empty = await buildSiteFiles(CLOUD_URL, config, []); + const empty = await buildAssetFiles(CLOUD_URL, config, []); expect(await lookup(empty, "/index.html")).toBeNull(); }); }); diff --git a/packages/convex-hosting/src/client/manifest.ts b/packages/convex-hosting/src/client/manifest.ts index 314bb257..85e0c218 100644 --- a/packages/convex-hosting/src/client/manifest.ts +++ b/packages/convex-hosting/src/client/manifest.ts @@ -9,10 +9,10 @@ import { } from "../workers-sdk/packages/workers-shared/utils/constants.js"; /** - * The format of `Site`. `serveSite` refuses a site of another format, which only a deploy with + * The format of `Assets`. `serveSite` refuses assets of another format, which only a deploy with * another release of this package writes. */ -export const SITE_FORMAT = 1; +export const ASSETS_FORMAT = 1; /** * The header with which the CLI, after the push, asks the served code to mark its version live. Its @@ -24,12 +24,13 @@ export const MARK_HEADER = "Convex-Hosting-Mark"; export const MARK_PATH = "/.convex-hosting/mark"; /** - * The site that one deploy pushes, as `.convex-hosting/version.js` exports it: the version's id, - * and everything that serving reads, so that a request reads no database. `files` is `null` in the - * code that a first install pushes before its upload, which serves nothing. + * The static assets of one version, as `.convex-hosting/version.js` exports them under `assets`, + * Cloudflare's name for them: the version's id, and everything that serving reads, so that a + * request reads no database. `files` is `null` in the code that a first install pushes before its + * upload, which serves nothing. */ -export type Site = { - /** `SITE_FORMAT` of the release that wrote it. */ +export type Assets = { + /** `ASSETS_FORMAT` of the release that wrote it. */ format: number; versionId: string; /** @@ -37,15 +38,15 @@ export type Site = { * live; another request with the header pays nothing more than any other request. */ markToken: string; - files: SiteFiles | null; + files: AssetFiles | null; }; -export type SiteFiles = { +export type AssetFiles = { /** The deployment's `CONVEX_CLOUD_URL` at the upload: the origin of every storage URL. */ cloudUrl: string; /** Cloudflare's normalized `AssetConfig` for the version, as its handler takes it. */ config: NormalizedAssetConfig; - /** The base64 of the manifest bytes; see `buildSiteFiles`. */ + /** The base64 of the manifest bytes; see `buildAssetFiles`. */ manifest: string; /** The content types of the entries, sorted; an entry holds an index into it. */ contentTypes: string[]; @@ -57,7 +58,7 @@ export type SiteFiles = { }; /** One file of a version, as the upload knows it. */ -export type SiteEntry = { +export type AssetEntry = { /** The URL path, such as `/assets/index-a1b2.js`. */ path: string; /** The hex SHA-256 of the bytes. */ @@ -78,7 +79,7 @@ const NO_CONTENT_TYPE = 0xffff; export type ManifestHit = { /** The hex of the manifest's content hash: the first 16 bytes of the SHA-256 of the bytes. */ contentHash: string; - /** The index of the stored file in `SiteFiles.storage`. */ + /** The index of the stored file in `AssetFiles.storage`. */ file: number; /** The entry's content type, if it has one. */ contentType: string | undefined; @@ -135,7 +136,7 @@ function commonSuffixLength(a: string, b: string): number { * differ only in the file's key, but that is Convex's choice, so the split is computed, and every * URL is rebuilt from it and compared before it is used. */ -function compressUrls(urls: string[]): SiteFiles["storage"] { +function compressUrls(urls: string[]): AssetFiles["storage"] { if (urls.length === 0) return { prefix: "", suffix: "", width: 0, keys: "" }; let prefixLength = urls[0].length; for (const url of urls) prefixLength = Math.min(prefixLength, commonPrefixLength(urls[0], url)); @@ -167,11 +168,11 @@ function compressUrls(urls: string[]): SiteFiles["storage"] { * binary search. An entry is the path hash, the content hash, and a tail, which here holds the * index of the stored file and the index of the content type. */ -export async function buildSiteFiles( +export async function buildAssetFiles( cloudUrl: string, config: NormalizedAssetConfig, - entries: SiteEntry[], -): Promise { + entries: AssetEntry[], +): Promise { const urls = [...new Set(entries.map(({ url }) => url))].sort(); const contentTypes = [ ...new Set( @@ -233,7 +234,7 @@ function entryCount(manifest: string): number { } /** Finds the entry of `path` by binary search over the path hashes, or returns `null`. */ -export async function lookup(files: SiteFiles, path: string): Promise { +export async function lookup(files: AssetFiles, path: string): Promise { const pathHash = await hashPath(path); let low = 0; let high = entryCount(files.manifest) - 1; @@ -263,7 +264,7 @@ export async function lookup(files: SiteFiles, path: string): Promise Date: Tue, 10 Nov 2026 15:30:45 +0200 Subject: [PATCH 11/20] Read the manifest with Cloudflare's own reader 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. --- docs/design.md | 39 ++- .../scripts/sync-workers-sdk.ts | 1 + packages/convex-hosting/src/cli/main.test.ts | 24 +- packages/convex-hosting/src/cli/main.ts | 4 +- .../convex-hosting/src/cli/manifest.test.ts | 69 +++++ packages/convex-hosting/src/cli/manifest.ts | 75 ++++++ .../convex-hosting/src/client/answer.test.ts | 19 +- packages/convex-hosting/src/client/answer.ts | 27 +- .../convex-hosting/src/client/index.test.ts | 5 +- packages/convex-hosting/src/client/index.ts | 16 +- .../src/client/manifest.test.ts | 143 ---------- .../convex-hosting/src/client/manifest.ts | 253 +++--------------- .../convex-hosting/src/workers-sdk/UPSTREAM | 2 +- .../asset-worker/src/assets-manifest.ts | 125 +++++++++ 14 files changed, 373 insertions(+), 429 deletions(-) create mode 100644 packages/convex-hosting/src/cli/manifest.test.ts create mode 100644 packages/convex-hosting/src/cli/manifest.ts delete mode 100644 packages/convex-hosting/src/client/manifest.test.ts create mode 100644 packages/convex-hosting/src/workers-sdk/packages/workers-shared/asset-worker/src/assets-manifest.ts diff --git a/docs/design.md b/docs/design.md index bc982b4f..0cccf0f2 100644 --- a/docs/design.md +++ b/docs/design.md @@ -290,24 +290,22 @@ can call only a component's public functions; clients cannot call it at all. The functions, which are internal, with `npx convex run --component`. The two callbacks that Cloudflare's code takes map to the site's manifest: `exists(path)` finds the -path's entry and returns its ETag, the content hash followed by a short hash of the content type, so -that identical bytes stored under two content types stay distinct; `getByETag` returns the content -type of the entry that `exists` found and a placeholder stream, which `serveSite` replaces with the -body. Nothing is added to Cloudflare's headers besides `no-store` on a 404. Long caching of hashed -files is a `_headers` rule, as on Cloudflare. - -**The site's files** (`src/client/manifest.ts`). The manifest is Cloudflare's: a 20-byte header, -zero and unused as in Cloudflare's, then one 40-byte entry per path, sorted by the path hash, the -first 16 bytes of the SHA-256 of the path, so a lookup is a binary search. An entry is the path -hash, the content hash (the first 16 bytes of the SHA-256 of the bytes), and a tail that holds the -index of the stored file (a big-endian u32) and of the content type (a big-endian u16, `0xffff` for -none). The manifest is one base64 string, and a lookup decodes only the bytes it compares, so its -cost does not grow with the site. The storage URLs are one prefix and one suffix around one key per -stored file, each padded to one width; the CLI rebuilds every URL from them before it writes the -file. Convex evaluates the HTTP module for every request, so the site is a few string literals and -nothing is parsed or decoded when the module loads. Measured on a cloud deployment on 2026-11-04: a -site of 100,000 files is a module of 8.9 MB, which adds about 2 ms to each request; a site of 400 -files is about 35 KB. +path's entry and returns its ETag, the content hash, as on Cloudflare; `getByETag` returns the +content type of the entry that `exists` found and a placeholder stream, which `serveSite` replaces +with the body. Nothing is added to Cloudflare's headers besides `no-store` on a 404. Long caching of +hashed files is a `_headers` rule, as on Cloudflare. + +**The site's files.** The manifest is Cloudflare's asset manifest, and Cloudflare's own reader +(`asset-worker/src/assets-manifest.ts`, vendored) searches it: a 20-byte header, then one 40-byte +entry per path, sorted by the path hash, the first 16 bytes of the SHA-256 of the path. The CLI +(`src/cli/manifest.ts`) encodes it as Miniflare does for `wrangler dev`. The content hash covers the +bytes and the content type, as Cloudflare's covers the bytes and the extension, so the same bytes +under two types have two ETags. The tail, which Cloudflare leaves zero, holds the index of the +storage URL (a big-endian u32) and of the content type (a big-endian u16, `0xffff` for none). Convex +modules carry no binary data, so the manifest is a base64 string, decoded once per request with +Convex's native `Uint8Array.fromBase64`; the storage URLs are a plain array. Measured on a cloud +deployment on 2026-11-10, against 3.8 ms for an empty action: 4.2 ms per request at 10,000 files (a +1.9 MB module), 12.4 ms at 100,000 (18.8 MB). Other HTTP routes of the app (auth, APIs) win over the site route when they are exact paths or longer prefixes, by Convex's router rules for the same method. @@ -555,10 +553,9 @@ or ChessMerge goes; the list is checked at every release. At 0.8.0 and 0.5.0 tha - `packages/convex-hosting` - `src/component`: `schema.ts`, `lib.ts`, `convex.config.ts`, and its generated files. - `src/client`: `routeAll`, Cloudflare's handler run against the assets (`answer.ts`), the assets' - files (`manifest.ts`: the builder that the CLI runs and the lookup that the action runs), and - the shipped declaration of the version module. + types and lookup (`manifest.ts`), and the shipped declaration of the version module. - `src/cli`: the `convex-hosting` command: `deploy`, and `upload`, the inner step that - `npx convex deploy --cmd` has to call as a program. + `npx convex deploy --cmd` has to call as a program; `manifest.ts` encodes the manifest. - `src/workers-sdk`: Cloudflare's asset worker, its tests, and its html_handling and encoding cases, copied by `scripts/sync-workers-sdk.ts` from cloudflare/workers-sdk at the commit in `UPSTREAM`, each file at its upstream path, so the folder mirrors that repository. Only the sync diff --git a/packages/convex-hosting/scripts/sync-workers-sdk.ts b/packages/convex-hosting/scripts/sync-workers-sdk.ts index a06e525f..02f71b38 100644 --- a/packages/convex-hosting/scripts/sync-workers-sdk.ts +++ b/packages/convex-hosting/scripts/sync-workers-sdk.ts @@ -40,6 +40,7 @@ const UPSTREAM_FILES = [ "fixtures/workers-shared-asset-config/test-cases/encoding-test-cases.ts", "fixtures/workers-shared-asset-config/test-cases/html-handling-test-cases.ts", "packages/workers-shared/asset-worker/src/analytics.ts", + "packages/workers-shared/asset-worker/src/assets-manifest.ts", "packages/workers-shared/asset-worker/src/compatibility-flags.ts", "packages/workers-shared/asset-worker/src/configuration.ts", "packages/workers-shared/asset-worker/src/constants.ts", diff --git a/packages/convex-hosting/src/cli/main.test.ts b/packages/convex-hosting/src/cli/main.test.ts index efee6786..aac70db7 100644 --- a/packages/convex-hosting/src/cli/main.test.ts +++ b/packages/convex-hosting/src/cli/main.test.ts @@ -12,7 +12,7 @@ import { import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { describe, expect, test } from "vite-plus/test"; -import { lookup, MARK_HEADER, MARK_PATH, storageUrl, type Assets } from "../client/manifest.js"; +import { manifestLookup, MARK_HEADER, MARK_PATH, type Assets } from "../client/manifest.js"; import { deploymentSelector, type Cli } from "./convex.js"; import { main, VERSION_FILE } from "./main.js"; @@ -685,15 +685,20 @@ describe("upload", () => { "text/html; charset=utf-8", "text/javascript; charset=utf-8", ]); - // Every path finds its stored file and its type; the two copies share one stored file. - const found = await lookup(files, "/copy.html"); + // Every path finds its stored file and its type; the two copies share one stored file and ETag. + const contentType = "text/html; charset=utf-8"; + const lookup = manifestLookup(files); + const found = await lookup("/copy.html"); expect(found).toEqual({ - contentHash: home.sha256.slice(0, 32), - file: (await lookup(files, "/index.html"))?.file, - contentType: "text/html; charset=utf-8", + eTag: createHash("sha256") + .update(`${home.sha256}\n${contentType}`) + .digest("hex") + .slice(0, 32), + url: fileUrl(home.storageId), + contentType, }); - expect(storageUrl(files.storage, found?.file ?? -1)).toBe(fileUrl(home.storageId)); - expect(await lookup(files, "/private/notes.txt")).toBeNull(); + expect(await lookup("/index.html")).toEqual(found); + expect(await lookup("/private/notes.txt")).toBeNull(); expect(readFileSync(join(cwd, ".convex-hosting", ".gitignore"), "utf8")).toBe("*\n"); }); @@ -707,8 +712,9 @@ describe("upload", () => { expect(calls().filter((name) => name === "urls")).toHaveLength(2); const written = writtenAssets(cwd).files; if (written === null) throw new Error("The version file has no files."); + const lookup = manifestLookup(written); for (const i of [0, 1999, 2000, 2499]) { - expect(await lookup(written, `/assets/${i}.js`)).not.toBeNull(); + expect(await lookup(`/assets/${i}.js`)).not.toBeNull(); } }); diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index 28212c62..cf3e4818 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -14,7 +14,6 @@ import { parseArgs } from "node:util"; import { z } from "zod"; import { ASSETS_FORMAT, - buildAssetFiles, MARK_HEADER, MARK_PATH, type AssetFiles, @@ -36,6 +35,7 @@ import { type Target, } from "./convex.js"; import { readDist, type DistEntry, type HandlingOptions } from "./files.js"; +import { buildAssetFiles } from "./manifest.js"; import { siteConfig } from "./site-config.js"; const USAGE = `Usage: @@ -523,7 +523,7 @@ async function assetFiles( if (page.files.length < URL_PAGE) break; after = page.files[page.files.length - 1][0]; } - return await buildAssetFiles( + return buildAssetFiles( cloudUrl, siteConfig(config), entries.map(({ path, sha256, contentType }) => { diff --git a/packages/convex-hosting/src/cli/manifest.test.ts b/packages/convex-hosting/src/cli/manifest.test.ts new file mode 100644 index 00000000..f576d6a2 --- /dev/null +++ b/packages/convex-hosting/src/cli/manifest.test.ts @@ -0,0 +1,69 @@ +import { createHash } from "node:crypto"; +import { describe, expect, test } from "vite-plus/test"; +import { manifestLookup } from "../client/manifest.js"; +import { buildAssetFiles, type AssetEntry } from "./manifest.js"; +import { siteConfig } from "./site-config.js"; + +const CLOUD_URL = "https://happy-cat-123.convex.cloud"; +const config = siteConfig({}); +const sha256Hex = (text: string) => createHash("sha256").update(text).digest("hex"); +const url = (key: string) => + `${CLOUD_URL}/api/storage/${key}?component=m026ambq8g7g5yxf42tb4d4tfx8hg303`; + +/** `count` entries; every third shares the bytes of the one before, and every fifth has no type. */ +function entries(count: number, paths = (i: number) => `/assets/chunk-${i}.js`): AssetEntry[] { + return Array.from({ length: count }, (_, i) => { + const sha256 = sha256Hex(`body ${i - (i % 3 === 2 ? 1 : 0)}`); + const contentType = i % 5 === 4 ? undefined : i % 2 === 0 ? "text/javascript" : "text/html"; + return { path: paths(i), sha256, contentType, url: url(sha256.slice(0, 36)) }; + }); +} + +describe("buildAssetFiles, read with Cloudflare's lookup", () => { + test.each([0, 1, 2, 64, 5000])("%i entries: every path finds its URL and type", async (count) => { + const list = entries(count); + const lookup = manifestLookup(buildAssetFiles(CLOUD_URL, config, list)); + for (const entry of list) { + const hit = await lookup(entry.path); + expect(hit).toEqual({ + eTag: sha256Hex(`${entry.sha256}\n${entry.contentType ?? ""}`).slice(0, 32), + url: entry.url, + contentType: entry.contentType, + }); + } + expect(await lookup("/assets/missing.js")).toBeNull(); + }); + + test("paths with Unicode, spaces, and percent signs are found as the handler decodes them", async () => { + const paths = [ + "/café/menu.html", + "/a b/c.txt", + "/100%.html", + "/日本語/索引.html", + "/emoji/🙂.svg", + ]; + const lookup = manifestLookup( + buildAssetFiles( + CLOUD_URL, + config, + entries(paths.length, (i) => paths[i]), + ), + ); + for (const path of paths) expect(await lookup(path)).not.toBeNull(); + expect(await lookup("/caf%C3%A9/menu.html")).toBeNull(); + }); + + test("the same bytes under two content types share one stored file and have two ETags", async () => { + const sha256 = sha256Hex("same"); + const files = buildAssetFiles(CLOUD_URL, config, [ + { path: "/a.txt", sha256, contentType: "text/plain", url: url("k1") }, + { path: "/a.js", sha256, contentType: "text/javascript", url: url("k1") }, + ]); + const lookup = manifestLookup(files); + const txt = await lookup("/a.txt"); + const js = await lookup("/a.js"); + expect(files.urls).toEqual([url("k1")]); + expect(txt?.eTag).not.toBe(js?.eTag); + expect([txt?.contentType, js?.contentType]).toEqual(["text/plain", "text/javascript"]); + }); +}); diff --git a/packages/convex-hosting/src/cli/manifest.ts b/packages/convex-hosting/src/cli/manifest.ts new file mode 100644 index 00000000..cfcbeb87 --- /dev/null +++ b/packages/convex-hosting/src/cli/manifest.ts @@ -0,0 +1,75 @@ +import { createHash } from "node:crypto"; +import type { NormalizedAssetConfig } from "../workers-sdk/packages/workers-shared/asset-worker/src/types.js"; +import { + CONTENT_HASH_OFFSET, + CONTENT_HASH_SIZE, + ENTRY_SIZE, + HEADER_SIZE, + PATH_HASH_OFFSET, + PATH_HASH_SIZE, +} from "../workers-sdk/packages/workers-shared/utils/constants.js"; +import { + NO_CONTENT_TYPE, + TAIL_CONTENT_TYPE, + TAIL_URL, + type AssetFiles, +} from "../client/manifest.js"; + +/** One file of a version, as the upload knows it. */ +export type AssetEntry = { + /** The URL path, such as `/assets/index-a1b2.js`. */ + path: string; + /** The hex SHA-256 of the bytes. */ + sha256: string; + contentType: string | undefined; + /** The storage URL of the bytes. */ + url: string; +}; + +const sha256 = (text: string) => createHash("sha256").update(text).digest(); + +/** + * Builds the files that serving reads. The manifest is encoded as Miniflare encodes it for + * `wrangler dev`: a 20-byte header, then one 40-byte entry per path, sorted by the path hash. The + * content hash covers the bytes and the content type, as Cloudflare's covers the bytes and the + * extension, so the same bytes under two types are two entries with two ETags. + */ +export function buildAssetFiles( + cloudUrl: string, + config: NormalizedAssetConfig, + entries: AssetEntry[], +): AssetFiles { + // Sorted, so the same files write the same version file. + const urls = [...new Set(entries.map(({ url }) => url))].sort(); + const contentTypes = [ + ...new Set( + entries.flatMap(({ contentType }) => (contentType === undefined ? [] : [contentType])), + ), + ].sort(); + const urlIndex = new Map(urls.map((url, index) => [url, index])); + const contentTypeIndex = new Map(contentTypes.map((type, index) => [type, index])); + + const sorted = entries + .map((entry) => ({ entry, pathHash: sha256(entry.path).subarray(0, PATH_HASH_SIZE) })) + .sort((a, b) => Buffer.compare(a.pathHash, b.pathHash)); + const manifest = Buffer.alloc(HEADER_SIZE + sorted.length * ENTRY_SIZE); + sorted.forEach(({ entry, pathHash }, i) => { + const offset = HEADER_SIZE + i * ENTRY_SIZE; + pathHash.copy(manifest, offset + PATH_HASH_OFFSET); + sha256(`${entry.sha256}\n${entry.contentType ?? ""}`).copy( + manifest, + offset + CONTENT_HASH_OFFSET, + 0, + CONTENT_HASH_SIZE, + ); + const tail = offset + CONTENT_HASH_OFFSET + CONTENT_HASH_SIZE; + manifest.writeUInt32BE(urlIndex.get(entry.url) ?? 0, tail + TAIL_URL); + manifest.writeUInt16BE( + entry.contentType === undefined + ? NO_CONTENT_TYPE + : (contentTypeIndex.get(entry.contentType) ?? 0), + tail + TAIL_CONTENT_TYPE, + ); + }); + return { cloudUrl, config, manifest: manifest.toString("base64"), contentTypes, urls }; +} diff --git a/packages/convex-hosting/src/client/answer.test.ts b/packages/convex-hosting/src/client/answer.test.ts index d1c8ecce..c9b843a5 100644 --- a/packages/convex-hosting/src/client/answer.test.ts +++ b/packages/convex-hosting/src/client/answer.test.ts @@ -4,7 +4,8 @@ import type { Config } from "../component/lib.js"; import { encodingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/encoding-test-cases.js"; import { htmlHandlingTestCases } from "../workers-sdk/fixtures/workers-shared-asset-config/test-cases/html-handling-test-cases.js"; import { answer } from "./answer.js"; -import { buildAssetFiles, storageUrl, type AssetFiles } from "./manifest.js"; +import { buildAssetFiles } from "../cli/manifest.js"; +import type { AssetFiles } from "./manifest.js"; type Files = Record; @@ -16,6 +17,11 @@ async function sha256Hex(body: string) { return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); } +/** The ETag of `body` under `contentType`: the content hash, which covers both. */ +async function eTagOf(body: string, contentType?: string) { + return (await sha256Hex(`${await sha256Hex(body)}\n${contentType ?? ""}`)).slice(0, 32); +} + /** The stored file's URL of `body`: it names the bytes, so a test can tell which file answered. */ async function bodyUrl(body: string) { return `${CLOUD_URL}/api/storage/${await sha256Hex(body)}`; @@ -31,7 +37,7 @@ async function siteFiles(files: Files, config: Config = {}) { url: await bodyUrl(body), })), ); - return await buildAssetFiles(CLOUD_URL, siteConfig(config), entries); + return buildAssetFiles(CLOUD_URL, siteConfig(config), entries); } /** Cloudflare's answer to one request, with the storage URL of its body, or `null` for a miss. */ @@ -47,7 +53,7 @@ async function route( return { status: asset.status, headers: Object.fromEntries(asset.headers), - bodyUrl: asset.file === null ? null : storageUrl(files.storage, asset.file), + bodyUrl: asset.url, }; } @@ -66,8 +72,7 @@ describe("answer", () => { expect(hit?.headers["cache-control"]).toBe("public, max-age=0, must-revalidate"); expect(hit?.headers["cf-cache-status"]).toBeUndefined(); const eTag = hit?.headers.etag; - const sha256 = await sha256Hex("console.log(1)"); - expect(eTag).toMatch(new RegExp(`^"${sha256.slice(0, 32)}[0-9a-f]{8}"$`)); + expect(eTag).toBe(`"${await eTagOf("console.log(1)", "text/javascript; charset=utf-8")}"`); expect(hit?.bodyUrl).toBe(await bodyUrl("console.log(1)")); const revalidated = await route(files, "/assets/app-a1.js", { "if-none-match": eTag ?? "" }); @@ -222,9 +227,7 @@ describe("Cloudflare's conformance cases", () => { expect(response.status).toBe(200); expect(response.url).toBe(ORIGIN + finalPath); expect(response.redirected).toBe(requestPath !== finalPath); - expect(response.eTag).toMatch( - new RegExp(`^"${(await sha256Hex(matchedFile)).slice(0, 32)}`), - ); + expect(response.eTag).toBe(`"${await eTagOf(matchedFile)}"`); } else { expect(response.status).toBe(404); } diff --git a/packages/convex-hosting/src/client/answer.ts b/packages/convex-hosting/src/client/answer.ts index a00ac46c..e69223be 100644 --- a/packages/convex-hosting/src/client/answer.ts +++ b/packages/convex-hosting/src/client/answer.ts @@ -4,10 +4,10 @@ import { handleRequest, } from "../workers-sdk/packages/workers-shared/asset-worker/src/handler.js"; import { mockJaegerBinding } from "../workers-sdk/packages/workers-shared/utils/tracing.js"; -import { lookup, type AssetFiles, type ManifestHit } from "./manifest.js"; +import { manifestLookup, type AssetFiles, type ManifestHit } from "./manifest.js"; -/** An answer of Cloudflare's handler, and the stored file of its body, if it has one. */ -export type Answer = { status: number; headers: Headers; file: number | null }; +/** An answer of Cloudflare's handler, and the storage URL of its body, if it has one. */ +export type Answer = { status: number; headers: Headers; url: string | null }; /** * Runs Cloudflare's asset handler for `request` against the version's files, or returns `null` when @@ -23,15 +23,14 @@ export async function answer( hasUserWorker: boolean, ): Promise { const env = { JAEGER: mockJaegerBinding() }; - // `exists` returns an ETag; `getByETag` gets the entry back for that ETag. The ETag is the content - // hash and a short hash of the content type, so identical bytes under two types stay distinct. + // `exists` returns the entry's ETag; `getByETag` gets the entry back for that ETag. + const lookup = manifestLookup(files); const found = new Map(); const exists = async (pathname: string) => { - const hit = await lookup(files, pathname); + const hit = await lookup(pathname); if (hit === null) return null; - const eTag = hit.contentHash + (await shortHash(hit.contentType ?? "")); - found.set(eTag, hit); - return eTag; + found.set(hit.eTag, hit); + return hit.eTag; }; let body: ManifestHit | undefined; const getByETag = async (eTag: string) => { @@ -61,14 +60,6 @@ export async function answer( return { status: response.status, headers: response.headers, - file: response.body !== null && body !== undefined ? body.file : null, + url: response.body !== null && body !== undefined ? body.url : null, }; } - -/** The first 8 hex digits of the SHA-256 of `text`. */ -async function shortHash(text: string) { - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)); - return Array.from(new Uint8Array(digest, 0, 4), (byte) => - byte.toString(16).padStart(2, "0"), - ).join(""); -} diff --git a/packages/convex-hosting/src/client/index.test.ts b/packages/convex-hosting/src/client/index.test.ts index 42531778..bf086c70 100644 --- a/packages/convex-hosting/src/client/index.test.ts +++ b/packages/convex-hosting/src/client/index.test.ts @@ -7,7 +7,8 @@ import type { Config } from "../component/lib.js"; import { internal } from "../component/_generated/api.js"; import schema from "../component/schema.js"; import { routeAll } from "./index.js"; -import { buildAssetFiles, MARK_HEADER, type Assets } from "./manifest.js"; +import { buildAssetFiles } from "../cli/manifest.js"; +import { MARK_HEADER, type Assets } from "./manifest.js"; const modules = import.meta.glob(["../component/**/*.ts", "!../component/**/*.test.ts"]); @@ -45,7 +46,7 @@ async function setup(config: Config = {}) { format: 1, versionId: "v1", markToken: "token-1", - files: await buildAssetFiles(CLOUD_URL, siteConfig(config), [ + files: buildAssetFiles(CLOUD_URL, siteConfig(config), [ { ...entry, url: `${CLOUD_URL}/api/storage/${storageId}` }, ]), }; diff --git a/packages/convex-hosting/src/client/index.ts b/packages/convex-hosting/src/client/index.ts index 1cfff1d6..464896a7 100644 --- a/packages/convex-hosting/src/client/index.ts +++ b/packages/convex-hosting/src/client/index.ts @@ -7,13 +7,7 @@ import { } from "convex/server"; import type { ComponentApi } from "../component/_generated/component.js"; import { answer, type Answer } from "./answer.js"; -import { - ASSETS_FORMAT, - MARK_HEADER, - storageUrl, - type AssetFiles, - type Assets, -} from "./manifest.js"; +import { ASSETS_FORMAT, MARK_HEADER, type Assets } from "./manifest.js"; export type { Assets } from "./manifest.js"; @@ -75,7 +69,7 @@ function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAc } const asset = await answer(files, request, worker !== undefined); - if (asset !== null) return await withBody(files, asset); + if (asset !== null) return await withBody(asset); // `answer` answers every assets-only request itself, so this 404 only fails closed. if (worker === undefined) return new Response(null, { status: 404, headers: NO_STORE }); const page = await worker.fetch(request); @@ -107,13 +101,13 @@ export function routeAll(options: RouteAllOptions): PublicHttpAction { } /** The response of `asset`, with the stored file as its body when it has one. */ -async function withBody(files: AssetFiles, asset: Answer): Promise { - if (asset.file === null) +async function withBody(asset: Answer): Promise { + if (asset.url === null) return new Response(null, { status: asset.status, headers: asset.headers }); // An app cannot read a component's storage, so the body comes from the storage URL. let stored: Response; try { - stored = await fetch(storageUrl(files.storage, asset.file)); + stored = await fetch(asset.url); } catch { return new Response(null, { status: 502, headers: NO_STORE }); } diff --git a/packages/convex-hosting/src/client/manifest.test.ts b/packages/convex-hosting/src/client/manifest.test.ts deleted file mode 100644 index 75b3eb78..00000000 --- a/packages/convex-hosting/src/client/manifest.test.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { describe, expect, test } from "vite-plus/test"; -import { siteConfig } from "../cli/site-config.js"; -import { - buildAssetFiles, - lookup, - storageUrl, - type AssetEntry, - type AssetFiles, -} from "./manifest.js"; - -const CLOUD_URL = "https://happy-cat-123.convex.cloud"; -const config = siteConfig({}); - -async function sha256Hex(text: string) { - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)); - return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); -} - -/** A storage URL as Convex makes them, with a key of the given length. */ -function url(key: string) { - return `${CLOUD_URL}/api/storage/${key}?component=m026ambq8g7g5yxf42tb4d4tfx8hg303`; -} - -/** `count` entries with distinct bytes; every third shares the bytes of the one before. */ -async function entries(count: number, paths = (i: number) => `/assets/chunk-${i}.js`) { - const list: AssetEntry[] = []; - for (let i = 0; i < count; i++) { - const body = `body ${i - (i % 3 === 2 ? 1 : 0)}`; - const sha256 = await sha256Hex(body); - list.push({ - path: paths(i), - sha256, - contentType: i % 5 === 4 ? undefined : i % 2 === 0 ? "text/javascript" : "text/html", - url: url(sha256.slice(0, 36)), - }); - } - return list; -} - -/** - * The reference reader: it decodes the whole manifest and reads every entry into a map by path - * hash, the plain way, which `lookup` must agree with for every path and every miss. - */ -async function reference(files: AssetFiles) { - const bytes = Uint8Array.from(atob(files.manifest), (char) => char.charCodeAt(0)); - const view = new DataView(bytes.buffer); - const hex = (from: number, to: number) => - Array.from(bytes.subarray(from, to), (byte) => byte.toString(16).padStart(2, "0")).join(""); - const byPathHash = new Map(); - for (let offset = 20; offset < bytes.length; offset += 40) { - const contentType = view.getUint16(offset + 36); - byPathHash.set(hex(offset, offset + 16), { - contentHash: hex(offset + 16, offset + 32), - file: view.getUint32(offset + 32), - contentType: contentType === 0xffff ? undefined : files.contentTypes[contentType], - }); - } - return async (path: string) => byPathHash.get((await sha256Hex(path)).slice(0, 32)) ?? null; -} - -describe("buildAssetFiles and lookup", () => { - test("every path finds its entry, and the reference reader agrees, at every size up to 64", async () => { - // Entries start 20 + 40i bytes in, so successive sizes put entries at every base64 alignment. - for (let count = 0; count <= 64; count++) { - const list = await entries(count); - const files = await buildAssetFiles(CLOUD_URL, config, list); - const read = await reference(files); - for (const entry of list) { - const hit = await lookup(files, entry.path); - expect(hit).toEqual(await read(entry.path)); - expect(hit).toEqual({ - contentHash: entry.sha256.slice(0, 32), - file: hit?.file, - contentType: entry.contentType, - }); - expect(storageUrl(files.storage, hit?.file ?? -1)).toBe(entry.url); - } - expect(await lookup(files, "/assets/missing.js")).toBeNull(); - } - }); - - test("paths with Unicode, spaces, and percent signs are found as the handler decodes them", async () => { - const paths = [ - "/café/menu.html", - "/a b/c.txt", - "/100%.html", - "/日本語/索引.html", - "/emoji/🙂.svg", - ]; - const list = await entries(paths.length, (i) => paths[i]); - const files = await buildAssetFiles(CLOUD_URL, config, list); - for (const path of paths) expect(await lookup(files, path)).not.toBeNull(); - expect(await lookup(files, "/caf%C3%A9/menu.html")).toBeNull(); - }); - - test("a large site: 5,000 entries all found, and misses miss", async () => { - const list = await entries(5000); - const files = await buildAssetFiles(CLOUD_URL, config, list); - const read = await reference(files); - for (const entry of list.filter((_, i) => i % 97 === 0)) { - expect(await lookup(files, entry.path)).toEqual(await read(entry.path)); - } - for (let i = 5000; i < 5100; i++) - expect(await lookup(files, `/assets/chunk-${i}.js`)).toBeNull(); - }); - - test("paths with the same bytes share one stored file and keep their own content types", async () => { - const sha256 = await sha256Hex("same"); - const files = await buildAssetFiles(CLOUD_URL, config, [ - { path: "/a.txt", sha256, contentType: "text/plain", url: url("k1") }, - { path: "/a.js", sha256, contentType: "text/javascript", url: url("k1") }, - ]); - const txt = await lookup(files, "/a.txt"); - const js = await lookup(files, "/a.js"); - expect(txt?.file).toBe(js?.file); - expect(txt?.contentHash).toBe(js?.contentHash); - expect([txt?.contentType, js?.contentType]).toEqual(["text/plain", "text/javascript"]); - // One stored file: its whole URL is the shared part. - expect(files.storage).toEqual({ prefix: url("k1"), suffix: "", width: 0, keys: "" }); - expect(storageUrl(files.storage, txt?.file ?? -1)).toBe(url("k1")); - }); - - test("storage keys of different lengths are padded, and every URL is rebuilt exactly", async () => { - const keys = ["a", "bcd", "efghij", "klmnopqrstuvwxyz0123456789abcdef0123"]; - const list = await entries(keys.length); - keys.forEach((key, i) => (list[i].url = url(key))); - const files = await buildAssetFiles(CLOUD_URL, config, list); - expect(files.storage.prefix).toBe(`${CLOUD_URL}/api/storage/`); - expect(files.storage.suffix).toBe("?component=m026ambq8g7g5yxf42tb4d4tfx8hg303"); - for (const entry of list) { - const hit = await lookup(files, entry.path); - expect(storageUrl(files.storage, hit?.file ?? -1)).toBe(entry.url); - } - }); - - test("a site with one file or no file", async () => { - const [one] = await entries(1); - const single = await buildAssetFiles(CLOUD_URL, config, [one]); - expect(storageUrl(single.storage, (await lookup(single, one.path))?.file ?? -1)).toBe(one.url); - const empty = await buildAssetFiles(CLOUD_URL, config, []); - expect(await lookup(empty, "/index.html")).toBeNull(); - }); -}); diff --git a/packages/convex-hosting/src/client/manifest.ts b/packages/convex-hosting/src/client/manifest.ts index 85e0c218..a3600187 100644 --- a/packages/convex-hosting/src/client/manifest.ts +++ b/packages/convex-hosting/src/client/manifest.ts @@ -1,12 +1,9 @@ -import type { NormalizedAssetConfig } from "../workers-sdk/packages/workers-shared/asset-worker/src/types.js"; import { - CONTENT_HASH_OFFSET, - CONTENT_HASH_SIZE, - ENTRY_SIZE, - HEADER_SIZE, - PATH_HASH_OFFSET, - PATH_HASH_SIZE, -} from "../workers-sdk/packages/workers-shared/utils/constants.js"; + binarySearch, + hashPath, +} from "../workers-sdk/packages/workers-shared/asset-worker/src/assets-manifest.js"; +import type { NormalizedAssetConfig } from "../workers-sdk/packages/workers-shared/asset-worker/src/types.js"; +import { CONTENT_HASH_SIZE } from "../workers-sdk/packages/workers-shared/utils/constants.js"; /** * The format of `Assets`. `serveSite` refuses assets of another format, which only a deploy with @@ -46,225 +43,53 @@ export type AssetFiles = { cloudUrl: string; /** Cloudflare's normalized `AssetConfig` for the version, as its handler takes it. */ config: NormalizedAssetConfig; - /** The base64 of the manifest bytes; see `buildAssetFiles`. */ - manifest: string; - /** The content types of the entries, sorted; an entry holds an index into it. */ - contentTypes: string[]; /** - * The storage URL of each stored file, sorted: `prefix`, then the file's `width` characters of - * `keys`, then `suffix`. Convex's storage URLs of one component share all but the file's key. + * Cloudflare's asset manifest, in base64, which Cloudflare's own reader searches. The tail of an + * entry, which Cloudflare leaves zero, holds the indexes of its URL and its content type. */ - storage: { prefix: string; suffix: string; width: number; keys: string }; -}; - -/** One file of a version, as the upload knows it. */ -export type AssetEntry = { - /** The URL path, such as `/assets/index-a1b2.js`. */ - path: string; - /** The hex SHA-256 of the bytes. */ - sha256: string; - contentType: string | undefined; - /** The storage URL of the bytes. */ - url: string; + manifest: string; + /** The content types of the entries. */ + contentTypes: string[]; + /** The storage URL of each stored file. */ + urls: string[]; }; -/** Where an entry's tail keeps the index of its stored file (a big-endian u32). */ -const FILE_OFFSET = CONTENT_HASH_OFFSET + CONTENT_HASH_SIZE; -/** Where an entry's tail keeps the index of its content type (a big-endian u16). */ -const CONTENT_TYPE_OFFSET = FILE_OFFSET + 4; +/** Where an entry's tail, after the content hash, keeps the index of its URL (a big-endian u32). */ +export const TAIL_URL = 0; +/** Where the tail keeps the index of the content type (a big-endian u16). */ +export const TAIL_CONTENT_TYPE = 4; /** The content type index of an entry without a content type. */ -const NO_CONTENT_TYPE = 0xffff; +export const NO_CONTENT_TYPE = 0xffff; -/** One entry that `lookup` found. */ +/** The entry of a path. */ export type ManifestHit = { - /** The hex of the manifest's content hash: the first 16 bytes of the SHA-256 of the bytes. */ - contentHash: string; - /** The index of the stored file in `AssetFiles.storage`. */ - file: number; - /** The entry's content type, if it has one. */ + /** The hex of the content hash, which is the ETag, as on Cloudflare. */ + eTag: string; + url: string; contentType: string | undefined; }; -/** The first 16 bytes of the SHA-256 of the UTF-8 of `path`: Cloudflare's path hash. */ -async function hashPath(path: string): Promise { - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(path)); - return new Uint8Array(digest, 0, PATH_HASH_SIZE); -} - -function hexToBytes(hex: string): Uint8Array { - const bytes = new Uint8Array(hex.length / 2); - for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16); - return bytes; -} - -function bytesToHex(bytes: Uint8Array): string { - return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(""); -} - -function compareBytes(a: Uint8Array, b: Uint8Array): number { - for (let i = 0; i < a.length; i++) { - if (a[i] !== b[i]) return a[i] - b[i]; - } - return 0; -} - -/** The position of each value of `values`, which has no repeats. */ -function indexOf(values: string[]): (value: string) => number { - const positions = new Map(values.map((value, index) => [value, index])); - return (value) => { - const position = positions.get(value); - if (position === undefined) throw new Error(`${value} is not in the list it was taken from.`); - return position; - }; -} - -function commonPrefixLength(a: string, b: string): number { - let i = 0; - while (i < a.length && i < b.length && a[i] === b[i]) i++; - return i; -} - -function commonSuffixLength(a: string, b: string): number { - let i = 0; - while (i < a.length && i < b.length && a[a.length - 1 - i] === b[b.length - 1 - i]) i++; - return i; -} - /** - * The storage URLs as one shared prefix and suffix around one key per file, each key padded with - * spaces to the width of the longest, since a URL has no space. Convex's URLs of one component - * differ only in the file's key, but that is Convex's choice, so the split is computed, and every - * URL is rebuilt from it and compared before it is used. + * Decodes the manifest once, like Cloudflare's `AssetsManifest`, and returns its lookup: it finds the + * entry of a path with Cloudflare's binary search, or returns `null`. */ -function compressUrls(urls: string[]): AssetFiles["storage"] { - if (urls.length === 0) return { prefix: "", suffix: "", width: 0, keys: "" }; - let prefixLength = urls[0].length; - for (const url of urls) prefixLength = Math.min(prefixLength, commonPrefixLength(urls[0], url)); - const rests = urls.map((url) => url.slice(prefixLength)); - let suffixLength = rests[0].length; - for (const rest of rests) - suffixLength = Math.min(suffixLength, commonSuffixLength(rests[0], rest)); - const keys = rests.map((rest) => rest.slice(0, rest.length - suffixLength)); - // A loop, since a spread passes one argument per stored file, more than V8 allows on a large site. - let width = 0; - for (const key of keys) width = Math.max(width, key.length); - const storage = { - prefix: urls[0].slice(0, prefixLength), - suffix: rests[0].slice(rests[0].length - suffixLength), - width, - keys: keys.map((key) => key.padEnd(width, " ")).join(""), +export function manifestLookup(files: AssetFiles) { + const manifest = fromBase64(files.manifest); + return async (path: string): Promise => { + const contentHash = binarySearch(manifest, await hashPath(path)); + if (contentHash === false) return null; + const tail = new DataView(contentHash.buffer, contentHash.byteOffset + CONTENT_HASH_SIZE); + const contentType = tail.getUint16(TAIL_CONTENT_TYPE); + return { + eTag: Array.from(contentHash, (byte) => byte.toString(16).padStart(2, "0")).join(""), + url: files.urls[tail.getUint32(TAIL_URL)], + contentType: contentType === NO_CONTENT_TYPE ? undefined : files.contentTypes[contentType], + }; }; - urls.forEach((url, file) => { - if (storageUrl(storage, file) !== url) { - throw new Error(`The storage URL ${url} does not survive its compression.`); - } - }); - return storage; -} - -/** - * Builds the files of a site. The manifest is Cloudflare's: a 20-byte header (zero, unused, as in - * Cloudflare's) and one 40-byte entry per path, sorted by the path hash, so that a lookup is a - * binary search. An entry is the path hash, the content hash, and a tail, which here holds the - * index of the stored file and the index of the content type. - */ -export async function buildAssetFiles( - cloudUrl: string, - config: NormalizedAssetConfig, - entries: AssetEntry[], -): Promise { - const urls = [...new Set(entries.map(({ url }) => url))].sort(); - const contentTypes = [ - ...new Set( - entries.flatMap(({ contentType }) => (contentType === undefined ? [] : [contentType])), - ), - ].sort(); - if (contentTypes.length >= NO_CONTENT_TYPE) - throw new Error("The site has too many content types."); - const fileIndex = indexOf(urls); - const contentTypeIndex = indexOf(contentTypes); - - const hashed = await Promise.all( - entries.map(async (entry) => ({ entry, pathHash: await hashPath(entry.path) })), - ); - hashed.sort((a, b) => compareBytes(a.pathHash, b.pathHash)); - const bytes = new Uint8Array(HEADER_SIZE + hashed.length * ENTRY_SIZE); - const view = new DataView(bytes.buffer); - hashed.forEach(({ entry, pathHash }, i) => { - if (i > 0 && compareBytes(hashed[i - 1].pathHash, pathHash) === 0) { - throw new Error(`${hashed[i - 1].entry.path} and ${entry.path} have the same path hash.`); - } - const offset = HEADER_SIZE + i * ENTRY_SIZE; - bytes.set(pathHash, offset + PATH_HASH_OFFSET); - bytes.set( - hexToBytes(entry.sha256).subarray(0, CONTENT_HASH_SIZE), - offset + CONTENT_HASH_OFFSET, - ); - view.setUint32(offset + FILE_OFFSET, fileIndex(entry.url)); - view.setUint16( - offset + CONTENT_TYPE_OFFSET, - entry.contentType === undefined ? NO_CONTENT_TYPE : contentTypeIndex(entry.contentType), - ); - }); - - let binary = ""; - for (let i = 0; i < bytes.length; i += 0x8000) { - binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000)); - } - return { cloudUrl, config, manifest: btoa(binary), contentTypes, storage: compressUrls(urls) }; -} - -/** - * `length` bytes of the base64 `text` from byte `offset`, decoding only the base64 groups that hold - * them, so that a lookup costs the same for any size of manifest. - */ -function bytesAt(text: string, offset: number, length: number): Uint8Array { - const start = Math.floor(offset / 3); - const end = Math.ceil((offset + length) / 3); - const decoded = atob(text.slice(start * 4, end * 4)); - const bytes = new Uint8Array(length); - for (let i = 0; i < length; i++) bytes[i] = decoded.charCodeAt(offset - start * 3 + i); - return bytes; -} - -/** The number of entries of a base64 manifest. */ -function entryCount(manifest: string): number { - const padding = manifest.endsWith("==") ? 2 : manifest.endsWith("=") ? 1 : 0; - return ((manifest.length / 4) * 3 - padding - HEADER_SIZE) / ENTRY_SIZE; -} - -/** Finds the entry of `path` by binary search over the path hashes, or returns `null`. */ -export async function lookup(files: AssetFiles, path: string): Promise { - const pathHash = await hashPath(path); - let low = 0; - let high = entryCount(files.manifest) - 1; - while (low <= high) { - const middle = (low + high) >> 1; - const offset = HEADER_SIZE + middle * ENTRY_SIZE; - const order = compareBytes( - pathHash, - bytesAt(files.manifest, offset + PATH_HASH_OFFSET, PATH_HASH_SIZE), - ); - if (order < 0) { - high = middle - 1; - } else if (order > 0) { - low = middle + 1; - } else { - const entry = bytesAt(files.manifest, offset, ENTRY_SIZE); - const view = new DataView(entry.buffer); - const contentType = view.getUint16(CONTENT_TYPE_OFFSET); - return { - contentHash: bytesToHex(entry.subarray(CONTENT_HASH_OFFSET, FILE_OFFSET)), - file: view.getUint32(FILE_OFFSET), - contentType: contentType === NO_CONTENT_TYPE ? undefined : files.contentTypes[contentType], - }; - } - } - return null; } -/** The storage URL of stored file `file`. */ -export function storageUrl(storage: AssetFiles["storage"], file: number): string { - const key = storage.keys.slice(file * storage.width, (file + 1) * storage.width).trimEnd(); - return storage.prefix + key + storage.suffix; +/** Convex's runtime decodes base64 natively; Node before 25, where tests run, does not. */ +function fromBase64(text: string): Uint8Array { + const decoded = (Uint8Array as { fromBase64?: (text: string) => Uint8Array }).fromBase64?.(text); + return decoded ?? Uint8Array.from(atob(text), (char) => char.charCodeAt(0)); } diff --git a/packages/convex-hosting/src/workers-sdk/UPSTREAM b/packages/convex-hosting/src/workers-sdk/UPSTREAM index 7b51b863..51eff88b 100644 --- a/packages/convex-hosting/src/workers-sdk/UPSTREAM +++ b/packages/convex-hosting/src/workers-sdk/UPSTREAM @@ -2,7 +2,7 @@ Copied from https://github.com/cloudflare/workers-sdk, at the paths the files ha packages/workers-shared, and the test cases of fixtures/workers-shared-asset-config. License: MIT OR Apache-2.0 (LICENSE-MIT, LICENSE-APACHE). commit: 855812b79fcb8ee77cac5ab0b01ebc167741951d -synced: 2026-10-16 +synced: 2026-11-10 Run `node scripts/sync-workers-sdk.ts []` from packages/convex-hosting to update. Relative import and export specifiers without an extension get .js, for Node's ESM loader. diff --git a/packages/convex-hosting/src/workers-sdk/packages/workers-shared/asset-worker/src/assets-manifest.ts b/packages/convex-hosting/src/workers-sdk/packages/workers-shared/asset-worker/src/assets-manifest.ts new file mode 100644 index 00000000..6499707d --- /dev/null +++ b/packages/convex-hosting/src/workers-sdk/packages/workers-shared/asset-worker/src/assets-manifest.ts @@ -0,0 +1,125 @@ +import { + CONTENT_HASH_OFFSET, + CONTENT_HASH_SIZE, + ENTRY_SIZE, + HEADER_SIZE, + PATH_HASH_OFFSET, + PATH_HASH_SIZE, +} from "../../utils/constants.js"; + +export class AssetsManifest { + private data: Uint8Array; + + constructor(data: ArrayBuffer) { + this.data = new Uint8Array(data); + } + + async get(pathname: string) { + const pathHash = await hashPath(pathname); + const entry = binarySearch(this.data, pathHash); + return entry ? Uint8ToHexString(entry) : null; + } +} + +export const hashPath = async (path: string) => { + const encoder = new TextEncoder(); + const data = encoder.encode(path); + const hashBuffer = await crypto.subtle.digest( + "SHA-256", + data.buffer as ArrayBuffer + ); + return new Uint8Array(hashBuffer, 0, PATH_HASH_SIZE); +}; + +/** + * Search for an entry with the given hash path. + * + * @param manifest the manifest bytes + * @param pathHash the path hash to find in the manifest + * @returns The content hash when the entry is found and `false` otherwise + */ +export const binarySearch = ( + manifest: Uint8Array, + pathHash: Uint8Array +): Uint8Array | false => { + if (pathHash.byteLength !== PATH_HASH_SIZE) { + throw new TypeError( + `Search value should have a length of ${PATH_HASH_SIZE}` + ); + } + + const numberOfEntries = (manifest.byteLength - HEADER_SIZE) / ENTRY_SIZE; + + if (numberOfEntries === 0) { + return false; + } + + let lowIndex = 0; + let highIndex = numberOfEntries - 1; + + while (lowIndex <= highIndex) { + const middleIndex = (lowIndex + highIndex) >> 1; + + const cmp = comparePathHashWithEntry(pathHash, manifest, middleIndex); + + if (cmp < 0) { + highIndex = middleIndex - 1; + continue; + } + + if (cmp > 0) { + lowIndex = middleIndex + 1; + continue; + } + + return new Uint8Array( + manifest.buffer, + HEADER_SIZE + middleIndex * ENTRY_SIZE + CONTENT_HASH_OFFSET, + CONTENT_HASH_SIZE + ); + } + + return false; +}; + +/** + * Compares a search value with a path hash in the manifest + * + * @param searchValue a `Uint8Array` of size `PATH_HASH_SIZE` + * @param manifest the manifest bytes + * @param entryIndex the index in the manifest of the entry to compare + */ +function comparePathHashWithEntry( + searchValue: Uint8Array, + manifest: Uint8Array, + entryIndex: number +) { + let pathHashOffset = HEADER_SIZE + entryIndex * ENTRY_SIZE + PATH_HASH_OFFSET; + for (let offset = 0; offset < PATH_HASH_SIZE; offset++, pathHashOffset++) { + const s = searchValue[offset]; + const e = manifest[pathHashOffset]; + if (s === undefined || e === undefined) { + throw new TypeError( + `Unexpected undefined value at offset ${offset} during path hash comparison` + ); + } + if (s < e) { + return -1; + } + if (s > e) { + return 1; + } + } + + return 0; +} + +/** + * Converts an Uint8Array to an hex string + * + * @param array The content hash + * @returns padded hex string + */ +const Uint8ToHexString = (array: Uint8Array) => { + return [...array].map((b) => b.toString(16).padStart(2, "0")).join(""); +}; From aeb384a82930105c21525ae86ce81c2860d6ae7a Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 16:55:03 +0200 Subject: [PATCH 12/20] Mark live from the CLI, keep the storage URLs as one string of keys, and test the manifest with properties routeAll no longer takes the component: the serving path calls none of its functions, and markLive is internal. The mark token, its request, and the branch for it in the site's action are gone. The storage URLs share a start and an end, written once; the keys are one fixed-width string, which at 100,000 files takes a request from 12.4 ms to 7.5 ms and the assets from about 16 MB to about 7 MB. A fast-check property reads what the CLI writes back with Cloudflare's reader. --- README.md | 18 +-- docs/deploy.md | 5 +- docs/design.md | 142 +++++++++--------- docs/development.md | 2 +- docs/from-static-hosting.md | 7 +- docs/serving.md | 28 ++-- .../hello-world-assets-only/convex/http.ts | 3 +- examples/tanstack-spa/convex/http.ts | 3 +- examples/tanstack-ssr/convex/http.ts | 3 +- .../convex-hosting-tanstack-start/README.md | 2 +- packages/convex-hosting/CHANGELOG.md | 11 +- packages/convex-hosting/package.json | 1 + packages/convex-hosting/src/cli/main.test.ts | 91 ++++------- packages/convex-hosting/src/cli/main.ts | 83 +++------- .../convex-hosting/src/cli/manifest.test.ts | 96 +++++++----- packages/convex-hosting/src/cli/manifest.ts | 31 +++- .../convex-hosting/src/client/index.test.ts | 83 ++-------- packages/convex-hosting/src/client/index.ts | 20 +-- .../convex-hosting/src/client/manifest.ts | 31 ++-- .../src/component/_generated/component.ts | 12 +- .../convex-hosting/src/component/lib.test.ts | 4 +- packages/convex-hosting/src/component/lib.ts | 19 +-- .../shared/src/run-wrangler-long-lived.ts | 3 +- pnpm-lock.yaml | 19 +++ pnpm-workspace.yaml | 1 + 25 files changed, 319 insertions(+), 399 deletions(-) diff --git a/README.md b/README.md index cefa8c6d..52216adc 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,6 @@ server build for every other request, as a Cloudflare Worker with static assets ```ts import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; @@ -63,7 +62,7 @@ import server from "../dist/server/server.js"; const http = httpRouter(); -routeAll({ http, component: components.hosting, assets, worker: server }); +routeAll({ http, assets, worker: server }); export default http; ``` @@ -106,10 +105,9 @@ wires both. ## Files only -A site without a server leaves `worker` out, -`routeAll({ http, component: components.hosting, assets })`, needs no adapter package, and deploys -its build directory: `--dist dist` after a `vite build`, or `--dist public` with no `--build` at -all. A single-page app adds `--not-found-handling single-page-application`. The +A site without a server leaves `worker` out, `routeAll({ http, assets })`, needs no adapter package, +and deploys its build directory: `--dist dist` after a `vite build`, or `--dist public` with no +`--build` at all. A single-page app adds `--not-found-handling single-page-application`. The [tanstack-spa](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-spa) and [hello-world-assets-only](https://github.com/samebase/convex-hosting/tree/main/examples/hello-world-assets-only) examples are such sites. @@ -190,10 +188,10 @@ Cloudflare's asset manifest) to `.convex-hosting/version.js`, and then pushes th imports the file. The push is the switch: no pointer moves in a second step, so there is no moment when new code serves old files, and no page refers to a file that is not uploaded yet. A request reads no database: it costs one function call, the HTTP action, and a file adds the download of its -bytes, which Convex counts as a call too. After the push, `deploy` asks the served code to mark its -version live, which deletes the versions that were live before it. A version whose push never came -is deleted at a later switch, once it is a day old; nothing is deleted by the clock alone. The one -rule: run one deploy at a time per deployment. The +bytes, which Convex counts as a call too. After the push, `deploy` marks its version live, which +deletes the versions that were live before it. A version whose push never came is deleted at a later +switch, once it is a day old; nothing is deleted by the clock alone. The one rule: run one deploy at +a time per deployment. The [design](https://github.com/samebase/convex-hosting/blob/main/docs/design.md#orderings-and-timing) works through every interleaving. diff --git a/docs/deploy.md b/docs/deploy.md index 8f24f7c7..6c57d8d3 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -2,9 +2,8 @@ `deploy` runs `npx convex deploy` with your build and the upload of `--dist` as its `--cmd`. The pushed code carries the version it was built with and that version's files, so the push switches the -site. Then the command reads the site URL from the deployment (`CONVEX_SITE_URL`), sends one request -to it with the version's mark token, which makes the code that answers mark its version live and -delete the versions that were live before it, prints the site URL, and ends. When that request +site. Then the command marks its version live, which deletes the versions that were live before it, +reads the site URL from the deployment (`CONVEX_SITE_URL`), prints it, and ends. When the mark fails, the deploy still succeeds and says so; the old versions then stay until the next deploy's mark. A version that never becomes live, from a deploy that failed, is deleted at the first switch after it is a day old, and the stored files that no version uses go at the switch after that. diff --git a/docs/design.md b/docs/design.md index 0cccf0f2..89a7ed84 100644 --- a/docs/design.md +++ b/docs/design.md @@ -29,22 +29,22 @@ no pointer that a second step must move, so there is no moment when new code ser request reads no database: the HTTP action answers from the files in its own code, and downloads the bytes of a file from storage. -Only the pushed code knows which version a deployment runs, so the serving code reports it: after -the push, the CLI sends one request with the version's mark token, which only that version's code -holds, and the code that answers marks its version `live`. An older upload never goes live over a -newer one: a version is marked only when no live version was created after it, so a request still -running on replaced code cannot take the site back. Marking a version live deletes the versions that -were live before it, because their code is gone by definition. Nothing is deleted by the clock -alone: deletion runs only at a switch, when a new version becomes live, so a version stays intact -until a newer one has served. At a switch, a version that never became live is dead too, from a push -that failed, with one exception: a slower deploy whose push has not landed yet. So a never-live -version is deleted at a switch only when it is more than a day old; the day bounds how late a push -may follow its upload, and it is the only time constant in the design. +After its push, the CLI marks its version `live`, with `markLive` in the component. An older upload +never goes live over a newer one: a version is marked only when no live version was created after +it. Marking a version live deletes the versions that were live before it, because their code is gone +by definition. Nothing is deleted by the clock alone: deletion runs only at a switch, when a new +version becomes live, so a version stays intact until a newer one has served. At a switch, a version +that never became live is dead too, from a push that failed, with one exception: a slower deploy +whose push has not landed yet. So a never-live version is deleted at a switch only when it is more +than a day old; the day bounds how late a push may follow its upload, and it is the only time +constant in the design. The precondition: deploys to one deployment do not overlap. When two overlap and the older upload is -pushed last, its mark is refused like a mark of replaced code: its version serves, but it never -becomes live, and nothing is deleted until the next deploy. So run one deploy at a time per -deployment; the example workflows queue them, with one `concurrency` group per deployment. +pushed last, its mark is refused: its version serves, but it never becomes live, and nothing is +deleted until the next deploy. If its mark lands before the newer version's, both are marked in +turn, and the newer version's mark deletes the rows of the version that serves; its stored files +stay until the next deploy's switch. So run one deploy at a time per deployment; the example +workflows queue them, with one `concurrency` group per deployment. ## Deploy @@ -96,10 +96,10 @@ Bristol's production used it while hosting 0.3 and 0.4 ran side by side under tw queries in the component (`npx convex run --component --inline-query`), which run whatever release of this package the component is, so an upgrade's upload works before its push installs the new functions; then writes `.convex-hosting/version.js` with the version's - `assets`: the id, a random mark token, and the files (see Serve), in the CLI's state folder at - the project root, like Wrangler's `.wrangler/`. It writes a temporary file and renames it, so - a running `npx convex dev` never reads half of it; the folder carries its own `.gitignore`, so - nothing of it reaches git and no tool writes into `convex/`. The file is a build artifact that + `assets`: the id and the files (see Serve), in the CLI's state folder at the project root, + like Wrangler's `.wrangler/`. It writes a temporary file and renames it, so a running + `npx convex dev` never reads half of it; the folder carries its own `.gitignore`, so nothing + of it reaches git and no tool writes into `convex/`. The file is a build artifact that `http.ts` imports, as a server-rendered app's `http.ts` already imports its server build; the package ships the declaration of that module (an ambient wildcard module in a script `.d.ts` that the package's types entry references), so a fresh clone typechecks with nothing added. @@ -109,11 +109,10 @@ Bristol's production used it while hosting 0.3 and 0.4 ran side by side under tw deployment's URL from `.env.local`, so no nesting is needed), uploads, writes the version file, and pushes with `npx convex run --push`. -**The mark.** When the last push has ended, the CLI reads the site URL (below) and sends -`POST /.convex-hosting/mark` with the header `Convex-Hosting-Mark: `. The code -that answers calls `markLive` for its own version and answers the result. A failure, or an answer -from other code, is reported, and the deploy succeeds: nothing is deleted until a later version is -marked, so the cost is old files kept until the next deploy. +**The mark.** When the last push has ended, the CLI calls `markLive` for its version, with +`npx convex run --component lib:markLive`, as it calls the upload's functions. A failure is +reported, and the deploy succeeds: nothing is deleted until a later version is marked, so the cost +is old files kept until the next deploy. **The site URL.** When the push, and on a first install the upload and the push after it, have ended, the CLI asks the deployment for its site URL: @@ -208,7 +207,7 @@ picks the longest matching prefix, so only an exact route reaches the app there. import { routeAll } from "@samebase/convex-hosting"; import { assets } from "../.convex-hosting/version.js"; -routeAll({ http, component: components.hosting, assets, worker: server }); +routeAll({ http, assets, worker: server }); ``` Every input is named, after Cloudflare where Cloudflare has a name: `assets` is the static assets of @@ -276,18 +275,12 @@ keeps `no-store` for a path without an extension and gives a path with one a fou `max-age` anyway; the deploy order keeps that moot, because no page refers to a file that is not uploaded yet. A `null` asset means one thing: no asset matched, and `worker` answers. -A request with the header `Convex-Hosting-Mark` set to the site's mark token is the CLI's mark: -before anything else, `serveSite` calls `markLive` for its version and answers the result as JSON, -with `Cache-Control: no-store`. `markLive` marks the version only when no live version was created -after it, inside its own transaction, so code that was replaced cannot make its version newest, and -a repeated mark changes nothing. It never throws: it answers `marked`, `live`, `superseded`, -`uploading`, `deleting`, or `missing`, and the CLI reports the last four. That is the only write the -serving path ever makes, once per deploy. Any other request, with another token or none, calls no -function. - -`markLive` is the component's only public function, because `serveSite` runs in the app and an app -can call only a component's public functions; clients cannot call it at all. The CLI calls the other -functions, which are internal, with `npx convex run --component`. +The serving path calls no function of the component and writes nothing, so `routeAll` does not take +the component. Every function of the component is internal, and the CLI calls each with +`npx convex run --component`. `markLive` marks the version only when no live version was created +after it, inside its own transaction, and a repeated mark changes nothing. It never throws: it +answers `marked`, `live`, `superseded`, `uploading`, `deleting`, or `missing`, and the CLI reports +the last four. The two callbacks that Cloudflare's code takes map to the site's manifest: `exists(path)` finds the path's entry and returns its ETag, the content hash, as on Cloudflare; `getByETag` returns the @@ -303,9 +296,12 @@ bytes and the content type, as Cloudflare's covers the bytes and the extension, under two types have two ETags. The tail, which Cloudflare leaves zero, holds the index of the storage URL (a big-endian u32) and of the content type (a big-endian u16, `0xffff` for none). Convex modules carry no binary data, so the manifest is a base64 string, decoded once per request with -Convex's native `Uint8Array.fromBase64`; the storage URLs are a plain array. Measured on a cloud -deployment on 2026-11-10, against 3.8 ms for an empty action: 4.2 ms per request at 10,000 files (a -1.9 MB module), 12.4 ms at 100,000 (18.8 MB). +Convex's native `Uint8Array.fromBase64`. The storage URLs differ only in a key, so the start and the +end that they share are written once, and the keys are one string of 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. Measured on a cloud deployment on 2026-11-10, against 3.8 ms for an empty action: 4.2 ms per +request at 10,000 files (a 0.9 MB module), 7.5 ms at 100,000 (8.9 MB), where the assets take about 7 +MB of the 64 MB that an action has, which the app's `worker` shares. Other HTTP routes of the app (auth, APIs) win over the site route when they are exact paths or longer prefixes, by Convex's router rules for the same method. @@ -339,30 +335,30 @@ result sizes) shape the batches. Every interleaving worked through for 0.4, what happens, and what checks it. "Component test" is a convex-test run of the exact order of transactions; "runtime" is a run against a local backend. -| What happens | Outcome | Checked by | -| --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | -| A deploy pushes; the CLI's mark reaches the new code | The version is marked live; the versions live before it are deleted | Component test, runtime | -| Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | -| Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy | Component test (stale request) | -| A mark for an older version reaches its code after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | -| Two marks of one version | One mark; the second answers `live` | Component test | -| Two marks in one millisecond | The second is strictly later | Component test | -| A deploy dies before its push | A never-live version; deleted at a later switch when a day old | Component test (age rule) | -| An upload dies midway | An `uploading` version; same fate; a retry reuses its recorded files | Component test, runtime (reuse) | -| The push is reported as failed but landed | The version serves, `ready`, since the CLI sent no mark; the next deploy's mark deletes the versions before it | Inherent; stated | -| No request for days, weeks | Nothing changes: the deploy marked its version, and deletion waits for the next mark | Inherent: deletion runs only at a switch | -| Many deploys in a row | Each deploy marks its version; the one before goes at that mark, never-live versions when a day old | Component test (age rule) | -| A push lands more than a day after its upload, after another switch | Its files are gone: pages render, and its files answer 404 from storage; redeploy | Stated | -| An upload borrows a stored file; a switch deletes the lending version | The file survives: files go only when unreferenced, a day old, and already unreferenced when the chain started | Component test (sweep order) | -| Two switches during one upload | The borrowed file can go; `recordFiles` says so; a retry works | Stated | -| A request on replaced code reaches a version while it is being deleted | Its files answer 404 from storage; a mark answers `deleting` | Component test, client test | -| Documents share a creation time at a page boundary | The cursor carries the ids seen at that time; none is skipped | Component test (crafted cursor) | -| The CLI's mark fails, or other code answers it | Reported; the deploy succeeds; nothing is deleted until the next deploy's mark | CLI test | -| First install: the component does not exist yet | Push a site without files, upload, push the site; 404 naming the version until the second push | CLI test, runtime (both flows) | -| Two first installs at once | Outside the precondition. Both push and upload; the last push serves | Stated | -| Two commands from one checkout at once | They overwrite each other's build output and version file | Stated, unsupported | -| A production deploy from a checkout where `npx convex dev` runs | Production's site is pushed to development, which answers 404 naming production's deployment until the next `deploy --dev` | Client test; stated | -| `deploy --dev` against an anonymous local deployment without `npx convex dev` | Each Convex CLI call starts and stops its own backend; the upload fails with `fetch failed` | Runtime; stated in the README | +| What happens | Outcome | Checked by | +| ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | +| A deploy pushes; the CLI marks its version | The version is marked live; the versions live before it are deleted | Component test, runtime | +| Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | +| Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy. If its mark lands first, the newer version's mark deletes its rows, and its stored files stay until the next deploy's switch | Component test (stale request) | +| A mark for an older version comes after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | +| Two marks of one version | One mark; the second answers `live` | Component test | +| Two marks in one millisecond | The second is strictly later | Component test | +| A deploy dies before its push | A never-live version; deleted at a later switch when a day old | Component test (age rule) | +| An upload dies midway | An `uploading` version; same fate; a retry reuses its recorded files | Component test, runtime (reuse) | +| The push is reported as failed but landed | The version serves, `ready`, since the CLI sent no mark; the next deploy's mark deletes the versions before it | Inherent; stated | +| No request for days, weeks | Nothing changes: the deploy marked its version, and deletion waits for the next mark | Inherent: deletion runs only at a switch | +| Many deploys in a row | Each deploy marks its version; the one before goes at that mark, never-live versions when a day old | Component test (age rule) | +| A push lands more than a day after its upload, after another switch | Its files are gone: pages render, and its files answer 404 from storage; redeploy | Stated | +| An upload borrows a stored file; a switch deletes the lending version | The file survives: files go only when unreferenced, a day old, and already unreferenced when the chain started | Component test (sweep order) | +| Two switches during one upload | The borrowed file can go; `recordFiles` says so; a retry works | Stated | +| A request on replaced code reaches a version while it is being deleted | Its files answer 404 from storage; a mark answers `deleting` | Component test, client test | +| Documents share a creation time at a page boundary | The cursor carries the ids seen at that time; none is skipped | Component test (crafted cursor) | +| The CLI's mark fails | Reported; the deploy succeeds; nothing is deleted until the next deploy's mark | CLI test | +| First install: the component does not exist yet | Push a site without files, upload, push the site; 404 naming the version until the second push | CLI test, runtime (both flows) | +| Two first installs at once | Outside the precondition. Both push and upload; the last push serves | Stated | +| Two commands from one checkout at once | They overwrite each other's build output and version file | Stated, unsupported | +| A production deploy from a checkout where `npx convex dev` runs | Production's site is pushed to development, which answers 404 naming production's deployment until the next `deploy --dev` | Client test; stated | +| `deploy --dev` against an anonymous local deployment without `npx convex dev` | Each Convex CLI call starts and stops its own backend; the upload fails with `fetch failed` | Runtime; stated in the README | Not reproducible in the test runtime and not yet run against a cloud deployment: two real pushes in a chosen order, a preview deployment, an old HTTP action kept running across a push. A smoke script @@ -372,8 +368,9 @@ place for those. ## Stated, not solved - Deploys to one deployment do not overlap. When two overlap and the older upload is pushed last, - its mark is refused like a mark of replaced code, so its version serves but is never marked live, - and nothing is deleted until the next deploy. + its mark is refused, so its version serves but is never marked live, and nothing is deleted until + the next deploy. If its mark lands first, the newer version's mark deletes the rows of the version + that serves; serving reads no rows, and its stored files stay until the next deploy's switch. - An upload that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it fails with a message that says so, and a retry works. - No `run_worker_first`, no `base_path`, no selectable compatibility date: an app that needs its @@ -384,7 +381,7 @@ place for those. ## Not here, and why - No live pointer that a command moves, no `activate`, no `getLiveVersion`: the pushed code carries - its version, and the served code marks it when the CLI asks. + its version, and the CLI marks it after the push. - No lock, no heartbeat, no cron, no call after the push besides the read of the site URL and the mark: a version is deleted only after another version has served in its place. A one-day age bounds garbage from failed deploys; it decides nothing about what is served. @@ -413,10 +410,15 @@ are not proposed again. every request: on a cloud deployment on 2026-11-04, a module-level counter read 1 on every one of 52 requests, 40 of them concurrent, while the module's own random id stayed the same. A module-level flag would have called `markLive` on every request. -- **Marking live from the CLI with `npx convex run lib:markLive`.** When deploys overlap, the CLI - can mark a version whose code does not serve, and the mark deletes the files of the code that - does. The mark request reaches the code that serves, and its token makes only that deploy's code - mark. +- **A mark request to the served code, with a per-version token (built for 0.15, cut before its + release).** After the push, the CLI sent the site a request with a random token from the version + file, and the code that answered marked its own version, so a mark proved which code served. It + cost about 150 lines: the token, a branch in every app's HTTP action, a public function, and the + reading of the answer. It protected one case, already outside the precondition: two overlapping + deploys whose pushes land in the reverse of creation order within about a second, with the marks + in the other order. The CLI now calls `markLive` itself; in that case the newer version's mark + deletes the rows of the version that serves, serving reads no rows, and the stored files stay + until the next deploy's switch. - **Marking live on a random share of requests.** It kept the mark in the serving code for about one call per hundred requests, but a site with little traffic would keep its old versions for days, and every request would pay the draw. diff --git a/docs/development.md b/docs/development.md index b9306fce..ade554b6 100644 --- a/docs/development.md +++ b/docs/development.md @@ -46,7 +46,7 @@ Two cases are transient: vi.mock("../dist/server/server.js", () => ({ default: { fetch: async () => new Response() } })); vi.mock("../.convex-hosting/version.js", () => ({ versionId: "test", - assets: { format: 1, versionId: "test", markToken: "test", files: null }, + assets: { format: 1, versionId: "test", files: null }, })); ``` diff --git a/docs/from-static-hosting.md b/docs/from-static-hosting.md index 19ba6aa8..462306fe 100644 --- a/docs/from-static-hosting.md +++ b/docs/from-static-hosting.md @@ -30,10 +30,9 @@ and source on 2026-10-18, version 0.2.1. as in [Quick start](../README.md#quick-start). If the component owned `/`, also remove `httpPrefix: "/api"` from `defineApp`, and add `/api` to the paths of your own routes whose URLs must stay. -3. In `convex/http.ts`, replace `registerStaticRoutes(...)` with - `routeAll({ http, component: components.hosting, assets })`, and import `assets` from - `../.convex-hosting/version.js`. Your exact routes keep winning. A server-rendered app passes its - server entry as `worker`. +3. In `convex/http.ts`, replace `registerStaticRoutes(...)` with `routeAll({ http, assets })`, and + import `assets` from `../.convex-hosting/version.js`. Your exact routes keep winning. A + server-rendered app passes its server entry as `worker`. 4. In the deploy scripts, replace `@convex-dev/static-hosting deploy`, or the pair `npx convex deploy` and `upload --prod`, with `convex-hosting deploy --build "" --dist `, which builds, uploads, and pushes diff --git a/docs/serving.md b/docs/serving.md index 4a9c51d4..eabd298e 100644 --- a/docs/serving.md +++ b/docs/serving.md @@ -26,20 +26,20 @@ the file when the page reloads. A local deployment, which has no front, sends th ## Routing -`routeAll({ http, component, assets, worker? })` routes the site's HTTP action for every method at -every path, and returns it. The action answers with the file that matches, else with what `worker` -answers (see [Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or -HEAD on a path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, -else 404. `worker` is the Worker script, an object with `fetch(request)`: the code that runs on a -miss. Everything it returns gets `Cache-Control: no-store`, and so does a 404, because the -`*.convex.site` front caches paths with an extension. The front keeps `no-store` for a path without -an extension and replaces it with a four-hour browser `max-age` for a path with one, so a browser -that asks for a script before its upload ended keeps the 404; the deploy order prevents that case, -because no page refers to a file that is not uploaded yet. The `assets` of the version come with the -pushed code, in `.convex-hosting/version.js`, so a request reads no database: it costs one function -call, the HTTP action, and a file adds the download of its bytes, which Convex counts as a call too. -A redirect, a 304, a miss, and a rendered page download nothing. Until a first install's upload -ends, the site answers 404 naming the version. +`routeAll({ http, assets, worker? })` routes the site's HTTP action for every method at every path, +and returns it. The action answers with the file that matches, else with what `worker` answers (see +[Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or HEAD on a +path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, else 404. +`worker` is the Worker script, an object with `fetch(request)`: the code that runs on a miss. +Everything it returns gets `Cache-Control: no-store`, and so does a 404, because the `*.convex.site` +front caches paths with an extension. The front keeps `no-store` for a path without an extension and +replaces it with a four-hour browser `max-age` for a path with one, so a browser that asks for a +script before its upload ended keeps the 404; the deploy order prevents that case, because no page +refers to a file that is not uploaded yet. The `assets` of the version come with the pushed code, in +`.convex-hosting/version.js`, so a request reads no database: it costs one function call, the HTTP +action, and a file adds the download of its bytes, which Convex counts as a call too. A redirect, a +304, a miss, and a rendered page download nothing. Until a first install's upload ends, the site +answers 404 naming the version. As on Cloudflare, the presence of code decides where `not_found_handling` (the single-page fallback or the 404 page) applies: diff --git a/examples/hello-world-assets-only/convex/http.ts b/examples/hello-world-assets-only/convex/http.ts index 51996727..d1037d72 100644 --- a/examples/hello-world-assets-only/convex/http.ts +++ b/examples/hello-world-assets-only/convex/http.ts @@ -1,12 +1,11 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else 404; another method than GET or HEAD on a file answers 405. -routeAll({ http, component: components.hosting, assets }); +routeAll({ http, assets }); export default http; diff --git a/examples/tanstack-spa/convex/http.ts b/examples/tanstack-spa/convex/http.ts index 229ed7c7..b79d158e 100644 --- a/examples/tanstack-spa/convex/http.ts +++ b/examples/tanstack-spa/convex/http.ts @@ -1,12 +1,11 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else the single-page fallback; another method than GET or HEAD on a file answers 405. -routeAll({ http, component: components.hosting, assets }); +routeAll({ http, assets }); export default http; diff --git a/examples/tanstack-ssr/convex/http.ts b/examples/tanstack-ssr/convex/http.ts index 4ae60e6c..9124b69f 100644 --- a/examples/tanstack-ssr/convex/http.ts +++ b/examples/tanstack-ssr/convex/http.ts @@ -1,6 +1,5 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; @@ -11,7 +10,7 @@ const http = httpRouter(); // Every method, every path: a file for a path that has one (another method than GET or HEAD on it // answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with // static assets does. -const handler = routeAll({ http, component: components.hosting, assets, worker: server }); +const handler = routeAll({ http, assets, worker: server }); // Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it // serves the key set, and the longest prefix wins, so the catch-all above never sees them. for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { diff --git a/packages/convex-hosting-tanstack-start/README.md b/packages/convex-hosting-tanstack-start/README.md index 9999a624..a87ae043 100644 --- a/packages/convex-hosting-tanstack-start/README.md +++ b/packages/convex-hosting-tanstack-start/README.md @@ -34,7 +34,7 @@ import { assets } from "../.convex-hosting/version.js"; import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; -routeAll({ http, component: components.hosting, assets, worker: server }); +routeAll({ http, assets, worker: server }); ``` Import `@samebase/convex-hosting` before the server build: it defines `queueMicrotask` when it diff --git a/packages/convex-hosting/CHANGELOG.md b/packages/convex-hosting/CHANGELOG.md index 38f15987..1bfb05cf 100644 --- a/packages/convex-hosting/CHANGELOG.md +++ b/packages/convex-hosting/CHANGELOG.md @@ -9,22 +9,21 @@ two; an answer with a body costs two, the action and the download of the file, where it cost three. The component's `route` query is gone. - Breaking: `routeAll` takes one object, with every input named, and the assets in place of the - version id: + component and the version id: ```ts import { assets } from "../.convex-hosting/version.js"; - routeAll({ http, component: components.hosting, assets, worker: server }); + routeAll({ http, assets, worker: server }); ``` A files-only site leaves `worker` out. `assets` and `worker` are Cloudflare's names: the static assets of a Worker, and the Worker script. `versionId` stays exported for the query that reloads open tabs. A test that mocks the version module adds - `assets: { format: 1, versionId: "test", markToken: "test", files: null }`. + `assets: { format: 1, versionId: "test", files: null }`. -- After the push, `deploy` sends one request with the version's mark token, and the code that - answers marks its version live; before, the first request did. `markLive` answers what it did and - never throws. +- After the push, `deploy` marks its version live; before, the first request did. The component has + no public function left. - A first install pushes twice: once to install the component, and once after the upload, to serve the site. - A version file uploaded to another deployment, such as production's pushed to development by a diff --git a/packages/convex-hosting/package.json b/packages/convex-hosting/package.json index 7ccea746..fc076b15 100644 --- a/packages/convex-hosting/package.json +++ b/packages/convex-hosting/package.json @@ -59,6 +59,7 @@ "@types/node": "catalog:", "convex": "catalog:", "convex-test": "catalog:", + "fast-check": "catalog:", "typescript": "catalog:", "undici": "catalog:", "vite-plus": "catalog:" diff --git a/packages/convex-hosting/src/cli/main.test.ts b/packages/convex-hosting/src/cli/main.test.ts index aac70db7..b4b47ddc 100644 --- a/packages/convex-hosting/src/cli/main.test.ts +++ b/packages/convex-hosting/src/cli/main.test.ts @@ -12,7 +12,7 @@ import { import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { describe, expect, test } from "vite-plus/test"; -import { manifestLookup, MARK_HEADER, MARK_PATH, type Assets } from "../client/manifest.js"; +import { manifestLookup, type Assets } from "../client/manifest.js"; import { deploymentSelector, type Cli } from "./convex.js"; import { main, VERSION_FILE } from "./main.js"; @@ -55,10 +55,9 @@ const callName = (args: string[]) => /** * A fake `Cli`: `npx convex run` answers like a deployment with the component, the build calls - * `build`, `npx convex deploy` or `npx convex run --push` calls `push`, and the site answers the - * mark request with `mark`. No processes, no network. `events` lists the builds, the probes, the - * site URL queries, the storage URL queries, the function calls, the pushes, and the marks in - * order. + * `build`, and `npx convex deploy` or `npx convex run --push` calls `push`. No processes, no + * network. `events` lists the builds, the probes, the site URL queries, the storage URL queries, + * the function calls, and the pushes in order. */ function fake( cwd: string, @@ -71,8 +70,8 @@ function fake( failing?: Record; build?: () => Promise; push?: (cli: Cli, args: string[]) => Promise; - /** The site's answer to the mark request; by default it marks the version of the file. */ - mark?: (token: string | null, init: RequestInit | undefined) => Promise; + /** What `markLive` answers; by default it marks the version. */ + mark?: string; } = {}, ) { const runs: string[][] = []; @@ -136,6 +135,8 @@ function fake( return storageId === undefined ? [] : [{ sha256, storageId }]; }), ); + case "lib:markLive": + return ok(options.mark ?? "marked"); default: return ok(null); } @@ -151,15 +152,6 @@ function fake( return (await options.build?.()) ?? 0; }, fetch: async (url, init) => { - if (url === SITE_URL + MARK_PATH) { - events.push("mark"); - const token = new Headers(init?.headers).get(MARK_HEADER); - if (options.mark !== undefined) return await options.mark(token, init); - const assets = writtenAssets(cwd); - return token === assets.markToken - ? Response.json({ versionId: assets.versionId, result: "marked" }) - : new Response("

Home

"); - } const storageId = `storage-${stored.size}`; stored.set(storageId, await new Response(init?.body).text()); return Response.json({ storageId }); @@ -235,7 +227,7 @@ describe("deploy --dev", () => { expect(await main(DEV, cli)).toBe(0); expect(builds).toEqual(["vite build"]); - // Only the site URL query runs after the push. + // Only the mark and the site URL query run after the push. expect(events).toEqual([ "build", "probe", @@ -247,8 +239,8 @@ describe("deploy --dev", () => { "lib:finishVersion", "urls", "push: run", + "lib:markLive", "site url", - "mark", ]); // An inline query at the app's root, which exists before a first install. expect(pushes).toEqual([["run", "--push", "--inline-query", "null"]]); @@ -283,8 +275,8 @@ describe("deploy --dev", () => { "lib:finishVersion", "urls", "push: run", + "lib:markLive", "site url", - "mark", ]); expect(pushedFiles).toEqual([false, true]); expect(existsSync(join(cwd, ".convex-hosting", "first-install"))).toBe(false); @@ -392,57 +384,28 @@ describe("deploy reports", () => { ); }); - test("the mark carries the site's token, so only the code of this deploy marks", async () => { - const tokens: (string | null)[] = []; + test("after the push, marks the version of this deploy live", async () => { const cwd = app(site); - const { cli, logs } = fake(cwd, { - push: innerUpload, - mark: async (token) => { - tokens.push(token); - return Response.json({ versionId: writtenAssets(cwd).versionId, result: "marked" }); - }, - }); + const { cli, callArgs, logs } = fake(cwd, { push: innerUpload }); expect(await main(DEPLOY, cli)).toBe(0); - expect(tokens).toEqual([writtenAssets(cwd).markToken]); + expect(callArgs("lib:markLive")).toEqual([{ versionId: writtenVersionId(cwd) }]); expect(logs[logs.length - 1]).toMatch(/^Deployed version /); }); - test("a mark that fails or reaches other code is reported, and the deploy succeeds", async () => { - const answers: Record Promise> = { - "failed: fetch failed": async () => { - throw new TypeError("fetch failed"); - }, - "did not answer as version": async () => new Response("

Home

"), - }; - for (const [message, answer] of Object.entries(answers)) { - const { cli, logs } = fake(app(site), { push: innerUpload, mark: answer }); - expect(await main(DEPLOY, cli)).toBe(0); - expect(logs.some((line) => line.includes(message))).toBe(true); - expect(logs[logs.length - 1]).toMatch(/^Deployed version /); - } - }); - - test("the mark follows no redirect, which would carry the token to another origin", async () => { - const redirects: (RequestRedirect | undefined)[] = []; + test("a mark that fails is reported, and the deploy succeeds", async () => { const { cli, logs } = fake(app(site), { push: innerUpload, - mark: async (_token, init) => { - redirects.push(init?.redirect); - return new Response(null, { status: 307, headers: { Location: "https://other.example/" } }); - }, + failing: { "lib:markLive": "✖ Not logged in." }, }); expect(await main(DEPLOY, cli)).toBe(0); - expect(redirects).toEqual(["manual"]); - expect(logs.some((line) => line.includes("did not answer as version"))).toBe(true); + expect( + logs.some((line) => /^Marking version .* live failed: ✖ Not logged in\./.test(line)), + ).toBe(true); + expect(logs[logs.length - 1]).toMatch(/^Deployed version /); }); test("a mark refused because a newer version is live says that deploys overlapped", async () => { - const cwd = app(site); - const { cli, logs } = fake(cwd, { - push: innerUpload, - mark: async () => - Response.json({ versionId: writtenAssets(cwd).versionId, result: "superseded" }), - }); + const { cli, logs } = fake(app(site), { push: innerUpload, mark: "superseded" }); expect(await main(DEPLOY, cli)).toBe(0); expect(logs.some((line) => line.includes("a deploy overlapped this one"))).toBe(true); }); @@ -486,7 +449,7 @@ describe("deploy without --build", () => { expect(await main(["deploy", "--dev", "--dist", "dist"], cli)).toBe(0); expect(builds).toEqual([]); expect(events[0]).toBe("probe"); - expect(events.slice(-3)).toEqual(["push: run", "site url", "mark"]); + expect(events.slice(-3)).toEqual(["push: run", "lib:markLive", "site url"]); }); test("production runs only the upload inside npx convex deploy --cmd", async () => { @@ -494,7 +457,7 @@ describe("deploy without --build", () => { expect(await main(["deploy", "--dist", "dist"], cli)).toBe(0); expect(pushes[0][2]).toMatch(/^'.+' '.+' 'upload' '--dist' 'dist' '--version-id' '/); expect(events[0]).toBe("push: deploy"); - expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "site url", "mark"]); + expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "lib:markLive", "site url"]); }); }); @@ -513,9 +476,9 @@ describe("deploy", () => { // `npx convex deploy` goes to production by default and has no --prod flag; every run gets it. expect(pushes[0]).not.toContain("--prod"); expect(runs.every((args) => args.includes("--prod"))).toBe(true); - // The upload runs inside the push; after it, the site URL query and the mark. + // The upload runs inside the push; after it, the mark and the site URL query. expect(events[0]).toBe("push: deploy"); - expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "site url", "mark"]); + expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "lib:markLive", "site url"]); expect(callArgs("lib:createVersion")[0].versionId).toBe(writtenVersionId(cwd)); }); @@ -540,7 +503,7 @@ describe("deploy", () => { expect(await main(DEPLOY, cli)).toBe(0); expect(calls().slice(0, 3)).toEqual(["probe", "probe", "lib:generateUploadUrls"]); - expect(calls().slice(-3)).toEqual(["lib:finishVersion", "urls", "site url"]); + expect(calls().slice(-4)).toEqual(["lib:finishVersion", "urls", "lib:markLive", "site url"]); expect(pushes.map((args) => args[0])).toEqual(["deploy", "deploy"]); expect(pushes[1]).toEqual(["deploy"]); expect(pushedFiles).toEqual([false, true]); @@ -672,7 +635,7 @@ describe("upload", () => { '/** @type {import("@samebase/convex-hosting").Assets} */', ]); const written = writtenAssets(cwd); - expect(written).toMatchObject({ format: 1, versionId: "v1", markToken: expect.any(String) }); + expect(written).toMatchObject({ format: 1, versionId: "v1" }); const files = written.files; if (files === null) throw new Error("The version file has no files."); expect(files.cloudUrl).toBe(CLOUD_URL); diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index cf3e4818..456eb77f 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -12,13 +12,7 @@ import { join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { parseArgs } from "node:util"; import { z } from "zod"; -import { - ASSETS_FORMAT, - MARK_HEADER, - MARK_PATH, - type AssetFiles, - type Assets, -} from "../client/manifest.js"; +import { ASSETS_FORMAT, type AssetFiles, type Assets } from "../client/manifest.js"; import { internal } from "../component/_generated/api.js"; import type { Config } from "../component/lib.js"; import type { Id } from "../component/_generated/dataModel.js"; @@ -185,9 +179,9 @@ function quote(arg: string): string { } /** - * Builds, uploads, writes the version file, and pushes. The push is the switch. Then it asks the - * served code to mark its version live, and reports the site URL, for a person and, through - * `$GITHUB_OUTPUT`, for the next step of a GitHub Actions job. + * Builds, uploads, writes the version file, and pushes. The push is the switch. Then it marks the + * version live, and reports the site URL, for a person and, through `$GITHUB_OUTPUT`, for the next + * step of a GitHub Actions job. */ async function deploy(cli: Cli, options: Options, build: string | undefined) { // A deploy key wins over every selector in the Convex CLI, so a production key in the environment @@ -236,6 +230,7 @@ async function deploy(cli: Cli, options: Options, build: string | undefined) { } else { await deployWithConvexDeploy(cli, options, target, versionId, build); } + await markLive(cli, target, versionId); let url: string; try { url = await siteUrl(cli, target.flags); @@ -244,7 +239,6 @@ async function deploy(cli: Cli, options: Options, build: string | undefined) { const message = error instanceof Error ? error.message : String(error); throw new Error(`Deployed version ${versionId}, but reading the site URL failed: ${message}`); } - await markServedVersion(cli, url, readVersionFile(cli)); cli.log(`Deployed version ${versionId} to ${url}.`); if (cli.env.GITHUB_OUTPUT) appendFileSync(cli.env.GITHUB_OUTPUT, `url=${url}\n`); } @@ -384,11 +378,9 @@ async function upload( z.array(z.string()).length(count), ); - // The CLI sends it after the push; see `MARK_HEADER`. - const markToken = randomUUID(); const missing = await probeComponent(cli, target); if (missing !== undefined) { - writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, markToken, files: null }); + writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, files: null }); return missing; } @@ -478,7 +470,7 @@ async function upload( } await runComponent(cli, target, internal.lib.finishVersion, { versionId }, z.null()); const files = await assetFiles(cli, target, versionId, config, entries); - writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, markToken, files }); + writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, files }); cli.log(`Uploaded version ${versionId} and wrote ${VERSION_FILE}.`); return undefined; } @@ -534,9 +526,6 @@ async function assetFiles( ); } -/** The line of the version file that holds the assets. */ -const ASSETS_LINE = "export const assets = "; - /** * Writes the version file. `versionId` is its own export too, for the app query that reloads * pages on a new version. The assets carry their type as JSDoc: Convex's default @@ -549,61 +538,37 @@ function writeVersionFile(cli: Cli, assets: Assets) { VERSION_FILE, `export const versionId = ${JSON.stringify(assets.versionId)};\n` + `/** @type {import("@samebase/convex-hosting").Assets} */\n` + - `${ASSETS_LINE}${JSON.stringify(assets)};\n`, + `export const assets = ${JSON.stringify(assets)};\n`, ); } -/** The id and the mark token of the assets in the version file that the upload wrote. */ -function readVersionFile(cli: Cli): Pick { - const line = readFileSync(join(cli.cwd, VERSION_FILE), "utf8") - .split("\n") - .find((text) => text.startsWith(ASSETS_LINE)); - if (line === undefined) throw new Error(`${VERSION_FILE} has no assets.`); - return z - .object({ versionId: z.string(), markToken: z.string() }) - .parse(JSON.parse(line.slice(ASSETS_LINE.length, -1))); -} - /** - * Asks the code that the deployment serves to mark its version live, with the site's mark token, - * which only the code of this deploy has. A failure deletes nothing: the versions live before stay - * until a later deploy marks its own, so it is reported, and the deploy succeeds. + * Marks the version live after the push that serves it, so the component deletes the versions + * before it. A failure deletes nothing: the versions live before stay until a later deploy marks + * its own, so it is reported, and the deploy succeeds. */ -async function markServedVersion( - cli: Cli, - url: string, - site: Pick, -) { - const later = `Version ${site.versionId} serves, and the next deploy deletes the files of the versions before it.`; - let answer: unknown; +async function markLive(cli: Cli, target: Target, versionId: string) { + const later = `Version ${versionId} serves, and the next deploy deletes the files of the versions before it.`; + let result: string; try { - // A redirect would carry the token to another origin, so it counts as other code answering. - const response = await cli.fetch(url + MARK_PATH, { - method: "POST", - headers: { [MARK_HEADER]: site.markToken }, - redirect: "manual", - }); - // Other code answers the path with a page or a 404, which is no mark. - answer = response.ok ? await response.json().catch(() => null) : null; + result = await runComponent( + cli, + target, + internal.lib.markLive, + { versionId }, + z.enum(["marked", "live", "superseded", "uploading", "deleting", "missing"]), + ); } catch (error) { const message = error instanceof Error ? error.message : String(error); - cli.log(`Asking the site to mark version ${site.versionId} live failed: ${message}. ${later}`); - return; - } - const parsed = z.object({ versionId: z.string(), result: z.string() }).safeParse(answer); - if (!parsed.success || parsed.data.versionId !== site.versionId) { - cli.log( - `The site did not answer as version ${site.versionId}, so its code is not this deploy's.`, - ); + cli.log(`Marking version ${versionId} live failed: ${message}. ${later}`); return; } - const { result } = parsed.data; if (result === "superseded") { cli.log( - `A version created after ${site.versionId} is live, so a deploy overlapped this one; ${later}`, + `A version created after ${versionId} is live, so a deploy overlapped this one; ${later}`, ); } else if (result !== "marked" && result !== "live") { - cli.log(`Version ${site.versionId} could not be marked live: it is ${result}.`); + cli.log(`Version ${versionId} could not be marked live: it is ${result}.`); } } diff --git a/packages/convex-hosting/src/cli/manifest.test.ts b/packages/convex-hosting/src/cli/manifest.test.ts index f576d6a2..30f3d0bc 100644 --- a/packages/convex-hosting/src/cli/manifest.test.ts +++ b/packages/convex-hosting/src/cli/manifest.test.ts @@ -1,4 +1,5 @@ import { createHash } from "node:crypto"; +import fc from "fast-check"; import { describe, expect, test } from "vite-plus/test"; import { manifestLookup } from "../client/manifest.js"; import { buildAssetFiles, type AssetEntry } from "./manifest.js"; @@ -10,46 +11,58 @@ const sha256Hex = (text: string) => createHash("sha256").update(text).digest("he const url = (key: string) => `${CLOUD_URL}/api/storage/${key}?component=m026ambq8g7g5yxf42tb4d4tfx8hg303`; -/** `count` entries; every third shares the bytes of the one before, and every fifth has no type. */ -function entries(count: number, paths = (i: number) => `/assets/chunk-${i}.js`): AssetEntry[] { - return Array.from({ length: count }, (_, i) => { - const sha256 = sha256Hex(`body ${i - (i % 3 === 2 ? 1 : 0)}`); - const contentType = i % 5 === 4 ? undefined : i % 2 === 0 ? "text/javascript" : "text/html"; - return { path: paths(i), sha256, contentType, url: url(sha256.slice(0, 36)) }; - }); -} +/** What the lookup finds for an entry. */ +const hit = (entry: AssetEntry) => ({ + eTag: sha256Hex(`${entry.sha256}\n${entry.contentType ?? ""}`).slice(0, 32), + url: entry.url, + contentType: entry.contentType, +}); + +/** A file of any path, Unicode included, whose storage key has any length. */ +const anyEntry = fc.record({ + path: fc.string({ unit: "grapheme" }).map((path) => `/${path}`), + sha256: fc.uint8Array({ minLength: 32, maxLength: 32 }).map((bytes) => { + return Buffer.from(bytes).toString("hex"); + }), + contentType: fc.option(fc.constantFrom("text/html; charset=utf-8", "text/css", "image/png"), { + nil: undefined, + }), + url: fc.stringMatching(/^[0-9a-z-]{1,40}$/).map(url), +}); describe("buildAssetFiles, read with Cloudflare's lookup", () => { - test.each([0, 1, 2, 64, 5000])("%i entries: every path finds its URL and type", async (count) => { - const list = entries(count); - const lookup = manifestLookup(buildAssetFiles(CLOUD_URL, config, list)); - for (const entry of list) { - const hit = await lookup(entry.path); - expect(hit).toEqual({ - eTag: sha256Hex(`${entry.sha256}\n${entry.contentType ?? ""}`).slice(0, 32), - url: entry.url, - contentType: entry.contentType, - }); - } + test("every path of any site finds its own entry, and any other path finds none", async () => { + await fc.assert( + fc.asyncProperty( + fc.uniqueArray(anyEntry, { selector: ({ path }) => path, maxLength: 40 }), + fc.string({ unit: "grapheme" }).map((path) => `/${path}`), + async (entries, other) => { + const lookup = manifestLookup(buildAssetFiles(CLOUD_URL, config, entries)); + for (const entry of entries) expect(await lookup(entry.path)).toEqual(hit(entry)); + if (entries.every(({ path }) => path !== other)) expect(await lookup(other)).toBeNull(); + }, + ), + ); + }); + + test("5,000 entries: every path finds its entry", async () => { + // Every third entry shares the bytes of the one before, and every fifth has no type. + const entries = Array.from({ length: 5000 }, (_, i) => { + const sha256 = sha256Hex(`body ${i - (i % 3 === 2 ? 1 : 0)}`); + const contentType = i % 5 === 4 ? undefined : i % 2 === 0 ? "text/javascript" : "text/html"; + return { path: `/assets/chunk-${i}.js`, sha256, contentType, url: url(sha256.slice(0, 36)) }; + }); + const lookup = manifestLookup(buildAssetFiles(CLOUD_URL, config, entries)); + for (const entry of entries) expect(await lookup(entry.path)).toEqual(hit(entry)); expect(await lookup("/assets/missing.js")).toBeNull(); }); - test("paths with Unicode, spaces, and percent signs are found as the handler decodes them", async () => { - const paths = [ - "/café/menu.html", - "/a b/c.txt", - "/100%.html", - "/日本語/索引.html", - "/emoji/🙂.svg", - ]; + test("a path is found as the handler decodes it, not percent-encoded", async () => { + const entry = { path: "/café/menu.html", sha256: sha256Hex("menu"), contentType: undefined }; const lookup = manifestLookup( - buildAssetFiles( - CLOUD_URL, - config, - entries(paths.length, (i) => paths[i]), - ), + buildAssetFiles(CLOUD_URL, config, [{ ...entry, url: url("k") }]), ); - for (const path of paths) expect(await lookup(path)).not.toBeNull(); + expect(await lookup("/café/menu.html")).not.toBeNull(); expect(await lookup("/caf%C3%A9/menu.html")).toBeNull(); }); @@ -62,8 +75,23 @@ describe("buildAssetFiles, read with Cloudflare's lookup", () => { const lookup = manifestLookup(files); const txt = await lookup("/a.txt"); const js = await lookup("/a.js"); - expect(files.urls).toEqual([url("k1")]); + expect([txt?.url, js?.url]).toEqual([url("k1"), url("k1")]); expect(txt?.eTag).not.toBe(js?.eTag); expect([txt?.contentType, js?.contentType]).toEqual(["text/plain", "text/javascript"]); }); + + test("the storage URLs are written as what they share and one string of keys", () => { + const entries = ["0c1f6a52", "5b7d2e11", "9e4a7c30"].map((key, i) => ({ + path: `/${i}.js`, + sha256: sha256Hex(key), + contentType: undefined, + url: url(key), + })); + expect(buildAssetFiles(CLOUD_URL, config, entries)).toMatchObject({ + urlPrefix: `${CLOUD_URL}/api/storage/`, + urlSuffix: "?component=m026ambq8g7g5yxf42tb4d4tfx8hg303", + urlKeys: "0c1f6a525b7d2e119e4a7c30", + urlKeyWidth: 8, + }); + }); }); diff --git a/packages/convex-hosting/src/cli/manifest.ts b/packages/convex-hosting/src/cli/manifest.ts index cfcbeb87..09b05d3d 100644 --- a/packages/convex-hosting/src/cli/manifest.ts +++ b/packages/convex-hosting/src/cli/manifest.ts @@ -32,7 +32,8 @@ const sha256 = (text: string) => createHash("sha256").update(text).digest(); * Builds the files that serving reads. The manifest is encoded as Miniflare encodes it for * `wrangler dev`: a 20-byte header, then one 40-byte entry per path, sorted by the path hash. The * content hash covers the bytes and the content type, as Cloudflare's covers the bytes and the - * extension, so the same bytes under two types are two entries with two ETags. + * extension, so the same bytes under two types are two entries with two ETags. The storage URLs + * differ only in a key, so what they share is written once. */ export function buildAssetFiles( cloudUrl: string, @@ -47,6 +48,10 @@ export function buildAssetFiles( ), ].sort(); const urlIndex = new Map(urls.map((url, index) => [url, index])); + const urlPrefix = sharedStart(urls); + const urlSuffix = reversed(sharedStart(urls.map((url) => reversed(url.slice(urlPrefix.length))))); + const keys = urls.map((url) => url.slice(urlPrefix.length, url.length - urlSuffix.length)); + const urlKeyWidth = keys.reduce((width, key) => Math.max(width, key.length), 0); const contentTypeIndex = new Map(contentTypes.map((type, index) => [type, index])); const sorted = entries @@ -71,5 +76,27 @@ export function buildAssetFiles( tail + TAIL_CONTENT_TYPE, ); }); - return { cloudUrl, config, manifest: manifest.toString("base64"), contentTypes, urls }; + return { + cloudUrl, + config, + manifest: manifest.toString("base64"), + contentTypes, + urlPrefix, + urlSuffix, + urlKeys: keys.map((key) => key.padEnd(urlKeyWidth)).join(""), + urlKeyWidth, + }; } + +/** The longest start that all of `texts` share. */ +function sharedStart(texts: string[]): string { + let start = texts[0] ?? ""; + for (const text of texts) { + let length = 0; + while (length < start.length && start[length] === text[length]) length++; + start = start.slice(0, length); + } + return start; +} + +const reversed = (text: string) => [...text].reverse().join(""); diff --git a/packages/convex-hosting/src/client/index.test.ts b/packages/convex-hosting/src/client/index.test.ts index bf086c70..d5ab911e 100644 --- a/packages/convex-hosting/src/client/index.test.ts +++ b/packages/convex-hosting/src/client/index.test.ts @@ -1,53 +1,40 @@ /// import { convexTest } from "convex-test"; -import { anyApi, httpRouter, ROUTABLE_HTTP_METHODS } from "convex/server"; +import { httpRouter, ROUTABLE_HTTP_METHODS } from "convex/server"; import { afterEach, describe, expect, test, vi } from "vite-plus/test"; import { siteConfig } from "../cli/site-config.js"; import type { Config } from "../component/lib.js"; -import { internal } from "../component/_generated/api.js"; import schema from "../component/schema.js"; import { routeAll } from "./index.js"; import { buildAssetFiles } from "../cli/manifest.js"; -import { MARK_HEADER, type Assets } from "./manifest.js"; +import type { Assets } from "./manifest.js"; const modules = import.meta.glob(["../component/**/*.ts", "!../component/**/*.test.ts"]); -/** The component's public functions, as an app reaches them through `components.hosting`. */ -const component = { lib: { markLive: anyApi.lib.markLive } }; - const CLOUD_URL = "https://example.convex.cloud"; /** - * Version `v1` with `/index.html` and `config`, ready, and its assets as the upload writes them. The - * site's action runs in an HTTP action, an action context where `fetch` is allowed; convex-test - * refuses `fetch` in `t.run`, which is a mutation. The response comes back as its parts, with the - * number of functions that the action called. + * The assets of version `v1` with `/index.html` and `config`, as the upload writes them. The site's + * action runs in an HTTP action, an action context where `fetch` is allowed. The response comes + * back as its parts, with the number of functions that the action called. */ async function setup(config: Config = {}) { - // `markLive` schedules `collect`; the tests run it with `finish`. - vi.useFakeTimers(); vi.stubEnv("CONVEX_CLOUD_URL", CLOUD_URL); const t = convexTest(schema, modules); - const body = "

Home

"; - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode("

Home

")); const sha256 = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join( "", ); - const configId = await t.run((ctx) => ctx.storage.store(new Blob([JSON.stringify(config)]))); - await t.action(internal.lib.createVersion, { versionId: "v1", configId }); - const storageId = await t.run((ctx) => ctx.storage.store(new Blob([body]))); - const entry = { path: "/index.html", sha256, contentType: "text/html" }; - await t.mutation(internal.lib.recordFiles, { - versionId: "v1", - entries: [{ ...entry, storageId }], - }); - await t.mutation(internal.lib.finishVersion, { versionId: "v1" }); const assets: Assets = { format: 1, versionId: "v1", - markToken: "token-1", files: buildAssetFiles(CLOUD_URL, siteConfig(config), [ - { ...entry, url: `${CLOUD_URL}/api/storage/${storageId}` }, + { + path: "/index.html", + sha256, + contentType: "text/html", + url: `${CLOUD_URL}/api/storage/stored-1`, + }, ]), }; @@ -67,7 +54,6 @@ async function setup(config: Config = {}) { const worker = options.render === undefined ? undefined : { fetch: options.render }; const action = routeAll({ http: httpRouter(), - component, assets: options.assets ?? assets, worker, }); @@ -83,31 +69,19 @@ async function setup(config: Config = {}) { body: await response.text(), }; }); - const state = () => - t.run( - async (ctx) => - ( - await ctx.db - .query("versions") - .withIndex("by_versionId", (q) => q.eq("versionId", "v1")) - .unique() - )?.state.kind, - ); - const finish = () => t.finishAllScheduledFunctions(vi.runAllTimers); - return { assets, serve, state, finish }; + return { assets, serve }; } afterEach(() => { vi.unstubAllGlobals(); vi.unstubAllEnvs(); - vi.useRealTimers(); }); describe("routeAll", () => { test("routes the action for every method Convex routes, at every path, and returns it", async () => { const { assets } = await setup(); const http = httpRouter(); - const action = routeAll({ http, component, assets }); + const action = routeAll({ http, assets }); for (const method of ROUTABLE_HTTP_METHODS) { expect(http.lookup("/any/path", method)).toEqual([action, method, "/*"]); } @@ -126,35 +100,6 @@ describe("the site's action", () => { expect(hit.calls).toBe(0); }); - test("the request with the site's mark token marks the version live and answers the result", async () => { - const { assets, serve, state, finish } = await setup(); - const render = vi.fn(async () => new Response("page")); - const marked = await serve("/.convex-hosting/mark", { - render, - method: "POST", - headers: { [MARK_HEADER]: assets.markToken }, - }); - expect(marked.calls).toBe(1); - expect(JSON.parse(marked.body)).toEqual({ versionId: "v1", result: "marked" }); - expect(marked.cacheControl).toBe("no-store"); - expect(render).not.toHaveBeenCalled(); - expect(await state()).toBe("live"); - const again = await serve("/", { headers: { [MARK_HEADER]: assets.markToken } }); - expect(JSON.parse(again.body)).toEqual({ versionId: "v1", result: "live" }); - await finish(); - expect(await state()).toBe("live"); - }); - - test("a request with another mark token is an ordinary request, which calls no function", async () => { - vi.stubGlobal("fetch", async () => new Response("

Home

")); - const { serve, state } = await setup(); - const other = await serve("/", { headers: { [MARK_HEADER]: "guess" } }); - expect(other.status).toBe(200); - expect(other.body).toBe("

Home

"); - expect(other.calls).toBe(0); - expect(await state()).toBe("ready"); - }); - test("a first install's assets, before its upload, answer 404 naming the version, without rendering", async () => { const { assets, serve } = await setup(); const render = vi.fn(async () => new Response("page")); diff --git a/packages/convex-hosting/src/client/index.ts b/packages/convex-hosting/src/client/index.ts index 464896a7..ad8a470e 100644 --- a/packages/convex-hosting/src/client/index.ts +++ b/packages/convex-hosting/src/client/index.ts @@ -5,9 +5,8 @@ import { type HttpRouter, type PublicHttpAction, } from "convex/server"; -import type { ComponentApi } from "../component/_generated/component.js"; import { answer, type Answer } from "./answer.js"; -import { ASSETS_FORMAT, MARK_HEADER, type Assets } from "./manifest.js"; +import { ASSETS_FORMAT, type Assets } from "./manifest.js"; export type { Assets } from "./manifest.js"; @@ -15,8 +14,6 @@ export type { Assets } from "./manifest.js"; export type RouteAllOptions = { /** The app's router, from `httpRouter()`. */ http: HttpRouter; - /** The installed component: `components.hosting`. */ - component: ComponentApi; /** `assets` from `.convex-hosting/version.js`, which `convex-hosting deploy` writes. */ assets: Assets; /** @@ -33,16 +30,17 @@ export type RouteAllOptions = { * `worker`, it applies to navigations only and `worker` answers the other misses; without it, it * applies to every request. * - * The assets are in the pushed code, so a request calls no function of the component: a file costs - * this action and the download of its bytes, any other answer this action alone. + * The assets are in the pushed code, so a request calls no function of the component, and + * `routeAll` does not take it: a file costs this action and the download of its bytes, any other + * answer this action alone. * * A page and a 404 answer `Cache-Control: no-store`. The deployment's Cloudflare front keeps that * for a path without an extension and replaces it with a four-hour browser `max-age` for a path * with one, so a browser that asks for a script before its upload ended keeps the 404; the deploy * order prevents that case, because no page refers to a file that is not uploaded yet. */ -function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAction { - return httpActionGeneric(async (ctx, request) => { +function serveSite({ assets, worker }: RouteAllOptions): PublicHttpAction { + return httpActionGeneric(async (_ctx, request) => { if (assets.format !== ASSETS_FORMAT) { return notServed( 500, @@ -50,10 +48,6 @@ function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAc `@samebase/convex-hosting reads format ${ASSETS_FORMAT}. Deploy again.`, ); } - if (request.headers.get(MARK_HEADER) === assets.markToken) { - const result = await ctx.runMutation(component.lib.markLive, { versionId: assets.versionId }); - return Response.json({ versionId: assets.versionId, result }, { headers: NO_STORE }); - } const { files } = assets; // A first install pushes before its upload; the deploy pushes again when the upload ends. if (files === null) { @@ -85,7 +79,7 @@ function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAc * through GET. * * ```ts - * routeAll({ http, component: components.hosting, assets, worker: server }); + * routeAll({ http, assets, worker: server }); * ``` * * Returns the action, for the paths that a component's HTTP prefix would otherwise take: Convex diff --git a/packages/convex-hosting/src/client/manifest.ts b/packages/convex-hosting/src/client/manifest.ts index a3600187..996c40ad 100644 --- a/packages/convex-hosting/src/client/manifest.ts +++ b/packages/convex-hosting/src/client/manifest.ts @@ -11,15 +11,6 @@ import { CONTENT_HASH_SIZE } from "../workers-sdk/packages/workers-shared/utils/ */ export const ASSETS_FORMAT = 1; -/** - * The header with which the CLI, after the push, asks the served code to mark its version live. Its - * value is the site's `markToken`; a request without it is an ordinary request. - */ -export const MARK_HEADER = "Convex-Hosting-Mark"; - -/** The path of that request, which names it in logs; the header alone decides. */ -export const MARK_PATH = "/.convex-hosting/mark"; - /** * The static assets of one version, as `.convex-hosting/version.js` exports them under `assets`, * Cloudflare's name for them: the version's id, and everything that serving reads, so that a @@ -30,11 +21,6 @@ export type Assets = { /** `ASSETS_FORMAT` of the release that wrote it. */ format: number; versionId: string; - /** - * The CLI sends it after the push, so that only the CLI makes the served code mark its version - * live; another request with the header pays nothing more than any other request. - */ - markToken: string; files: AssetFiles | null; }; @@ -50,8 +36,15 @@ export type AssetFiles = { manifest: string; /** The content types of the entries. */ contentTypes: string[]; - /** The storage URL of each stored file. */ - urls: string[]; + /** + * The storage URL of each stored file is `urlPrefix`, its key, and `urlSuffix`. The keys are one + * string, `urlKeyWidth` characters each, padded with spaces: Convex evaluates the module for + * every request, and one string costs less than an array of 100,000. + */ + urlPrefix: string; + urlSuffix: string; + urlKeys: string; + urlKeyWidth: number; }; /** Where an entry's tail, after the content hash, keeps the index of its URL (a big-endian u32). */ @@ -79,10 +72,14 @@ export function manifestLookup(files: AssetFiles) { const contentHash = binarySearch(manifest, await hashPath(path)); if (contentHash === false) return null; const tail = new DataView(contentHash.buffer, contentHash.byteOffset + CONTENT_HASH_SIZE); + const key = tail.getUint32(TAIL_URL) * files.urlKeyWidth; const contentType = tail.getUint16(TAIL_CONTENT_TYPE); return { eTag: Array.from(contentHash, (byte) => byte.toString(16).padStart(2, "0")).join(""), - url: files.urls[tail.getUint32(TAIL_URL)], + url: + files.urlPrefix + + files.urlKeys.slice(key, key + files.urlKeyWidth).trimEnd() + + files.urlSuffix, contentType: contentType === NO_CONTENT_TYPE ? undefined : files.contentTypes[contentType], }; }; diff --git a/packages/convex-hosting/src/component/_generated/component.ts b/packages/convex-hosting/src/component/_generated/component.ts index 44e4f586..638c09a1 100644 --- a/packages/convex-hosting/src/component/_generated/component.ts +++ b/packages/convex-hosting/src/component/_generated/component.ts @@ -22,14 +22,4 @@ import type { FunctionReference } from "convex/server"; * ``` */ export type ComponentApi = - { - lib: { - markLive: FunctionReference< - "mutation", - "internal", - { versionId: string }, - "marked" | "live" | "superseded" | "uploading" | "deleting" | "missing", - Name - >; - }; - }; + {}; diff --git a/packages/convex-hosting/src/component/lib.test.ts b/packages/convex-hosting/src/component/lib.test.ts index 196512dc..e28fb2e9 100644 --- a/packages/convex-hosting/src/component/lib.test.ts +++ b/packages/convex-hosting/src/component/lib.test.ts @@ -3,7 +3,7 @@ import { convexTest } from "convex-test"; import { afterEach, describe, expect, test, vi } from "vite-plus/test"; import type { Id } from "./_generated/dataModel.js"; import type { Config } from "./lib.js"; -import { api, internal } from "./_generated/api.js"; +import { internal } from "./_generated/api.js"; import schema from "./schema.js"; const modules = import.meta.glob(["./**/*.ts", "!./**/*.test.ts"]); @@ -72,7 +72,7 @@ const site: Files = { }; async function markLive(t: ReturnType, versionId: string) { - return await t.mutation(api.lib.markLive, { versionId }); + return await t.mutation(internal.lib.markLive, { versionId }); } /** The kind of each version's state, and the number of `collect` chains that `markLive` started. */ diff --git a/packages/convex-hosting/src/component/lib.ts b/packages/convex-hosting/src/component/lib.ts index de36eb89..a9be1a98 100644 --- a/packages/convex-hosting/src/component/lib.ts +++ b/packages/convex-hosting/src/component/lib.ts @@ -7,7 +7,6 @@ import { internalAction, internalMutation, internalQuery, - mutation, type QueryCtx, } from "./_generated/server.js"; @@ -233,19 +232,17 @@ export const finishVersion = internalMutation({ }); /** - * Marks a `ready` version `live` and schedules `collect`, and says what it did. `serveSite` calls - * it for the request that the CLI sends after the push, with the site's mark token, so only the - * code that serves marks its own version. An older upload never goes live over a newer one: the - * mark does nothing when a live version was created after this one. So a request that runs on - * replaced code cannot make the old version newest, and `collect` cannot delete the new version's - * files. A version that is already live stays as it is, so a repeated mark is fine. It never - * throws, so the CLI reads every outcome from the answer. + * Marks a `ready` version `live` and schedules `collect`, and says what it did. The CLI calls it + * after the push that serves the version. An older upload never goes live over a newer one: the + * mark does nothing when a live version was created after this one, so `collect` cannot delete the + * new version's files. A version that is already live stays as it is, so a repeated mark is fine. + * It never throws, so the CLI reads every outcome from the answer. * * Precondition: deploys to one deployment do not overlap. When two overlap and the older upload is - * pushed last, its mark is refused like a mark of replaced code: its version serves but stays - * `ready`, and nothing is deleted until the next deploy. + * pushed last, its mark is refused: its version serves but stays `ready`, and nothing is deleted + * until the next deploy. */ -export const markLive = mutation({ +export const markLive = internalMutation({ args: { versionId: v.string() }, returns: v.union( /** It was `ready` and is now the newest live version. */ diff --git a/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts b/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts index 978d2962..1712d14f 100644 --- a/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts +++ b/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts @@ -95,12 +95,11 @@ export default app; join(project, "convex/http.ts"), `import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; -import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); -routeAll({ http, component: components.hosting, assets }); +routeAll({ http, assets }); export default http; `, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f489e2a0..b56d40d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -200,6 +200,9 @@ catalogs: convex-test: specifier: 0.0.61 version: 0.0.61 + fast-check: + specifier: 4.10.2 + version: 4.10.2 ignore: specifier: 7.0.12 version: 7.0.12 @@ -482,6 +485,9 @@ importers: convex-test: specifier: 'catalog:' version: 0.0.61(convex@1.46.0(react@19.3.0)) + fast-check: + specifier: 'catalog:' + version: 4.10.2 typescript: specifier: 'catalog:' version: 7.0.2 @@ -2623,6 +2629,10 @@ packages: exsolve@1.1.3: resolution: {integrity: sha512-kuzL9zherLQoqDeQaS55AiiIg1kb4KYXaSusTtgZTPlvKP2gGCI82LNmBNh5RjDVUXIcmgx+/Mx7vPwRzBbhJA==} + fast-check@4.10.2: + resolution: {integrity: sha512-iK2f+YrcmoeGqk6fA0ea2bptcu/itMIm4NfEozq6N25+aG6h7s5HZbB/k1aV7b5w5sFLMCbbtRUsTVR+BgC3xw==} + engines: {node: '>=12.17.0'} + fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -3008,6 +3018,9 @@ packages: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} + pure-rand@8.4.2: + resolution: {integrity: sha512-vvuOGgcuPJAirlHvuQw1TrOiw7ptaIXXmIbNuiNOY6lNGJJH49PQ1Kj4nd783nPdQhQdicgOjVI2yI/9BD6/Ng==} + pvtsutils@1.3.6: resolution: {integrity: sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg==} @@ -5211,6 +5224,10 @@ snapshots: exsolve@1.1.3: {} + fast-check@4.10.2: + dependencies: + pure-rand: 8.4.2 + fast-deep-equal@3.1.3: {} fast-json-stable-stringify@2.1.0: {} @@ -5544,6 +5561,8 @@ snapshots: punycode@2.3.1: {} + pure-rand@8.4.2: {} + pvtsutils@1.3.6: dependencies: tslib: 2.8.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index b1dc42f5..0703b77f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -17,6 +17,7 @@ catalog: ignore: 7.0.12 mime: 4.1.1 convex-test: 0.0.61 + fast-check: 4.10.2 react: 19.3.0 react-dom: 19.3.0 typescript: 7.0.2 From 592d0e783b6887b86fc312cd8f6450339dd7f884 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 16:55:10 +0200 Subject: [PATCH 13/20] Refresh the example patches for routeAll without the component --- examples/hello-world-assets-only-workers.patch | 7 +++---- examples/tanstack-ssr-workers.patch | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/hello-world-assets-only-workers.patch b/examples/hello-world-assets-only-workers.patch index 45c17848..ece50f57 100644 --- a/examples/hello-world-assets-only-workers.patch +++ b/examples/hello-world-assets-only-workers.patch @@ -12,20 +12,19 @@ index 41a6c4afe86dc311eed5da6e75804b73bdc4462f..00000000000000000000000000000000 -export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index 51996727a045edbc5b84557709e31b07a62c3bfb..0000000000000000000000000000000000000000 +index d1037d726e70fbc4e75a7b2761bf64770e84adea..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null -@@ -1,12 +0,0 @@ +@@ -1,11 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; --import { components } from "./_generated/api.js"; -import { assets } from "../.convex-hosting/version.js"; - -const http = httpRouter(); - -// Every method, every path, as a Cloudflare Worker without a script: a file for a path that has -// one, else 404; another method than GET or HEAD on a file answers 405. --routeAll({ http, component: components.hosting, assets }); +-routeAll({ http, assets }); - -export default http; diff --git a/convex/tsconfig.json b/convex/tsconfig.json diff --git a/examples/tanstack-ssr-workers.patch b/examples/tanstack-ssr-workers.patch index 43250147..54171c53 100644 --- a/examples/tanstack-ssr-workers.patch +++ b/examples/tanstack-ssr-workers.patch @@ -18,13 +18,12 @@ index 1831f4b4fa5703fe1332d9cf45fb2308a57be703..dcc4d5f09735722e1164710651a0c69d export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index 4ae60e6c413b09f9d22481a9cba1b67b633b2529..0000000000000000000000000000000000000000 +index 9124b69fdf444c75f63d3335fdd805f0d1014c4f..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null -@@ -1,21 +0,0 @@ +@@ -1,20 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; --import { components } from "./_generated/api.js"; -import { assets } from "../.convex-hosting/version.js"; -// Type only, nothing is bundled: the server build imported below. -import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; @@ -35,7 +34,7 @@ index 4ae60e6c413b09f9d22481a9cba1b67b633b2529..00000000000000000000000000000000 -// Every method, every path: a file for a path that has one (another method than GET or HEAD on it -// answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with -// static assets does. --const handler = routeAll({ http, component: components.hosting, assets, worker: server }); +-const handler = routeAll({ http, assets, worker: server }); -// Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it -// serves the key set, and the longest prefix wins, so the catch-all above never sees them. -for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { From ef4a7aed8f4c95f6bfff14bbad8130a73bc41a62 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 16:55:34 +0200 Subject: [PATCH 14/20] Find the shared end of the storage URLs without reversing strings --- packages/convex-hosting/src/cli/manifest.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/convex-hosting/src/cli/manifest.ts b/packages/convex-hosting/src/cli/manifest.ts index 09b05d3d..d172950c 100644 --- a/packages/convex-hosting/src/cli/manifest.ts +++ b/packages/convex-hosting/src/cli/manifest.ts @@ -49,7 +49,7 @@ export function buildAssetFiles( ].sort(); const urlIndex = new Map(urls.map((url, index) => [url, index])); const urlPrefix = sharedStart(urls); - const urlSuffix = reversed(sharedStart(urls.map((url) => reversed(url.slice(urlPrefix.length))))); + const urlSuffix = sharedEnd(urls.map((url) => url.slice(urlPrefix.length))); const keys = urls.map((url) => url.slice(urlPrefix.length, url.length - urlSuffix.length)); const urlKeyWidth = keys.reduce((width, key) => Math.max(width, key.length), 0); const contentTypeIndex = new Map(contentTypes.map((type, index) => [type, index])); @@ -99,4 +99,13 @@ function sharedStart(texts: string[]): string { return start; } -const reversed = (text: string) => [...text].reverse().join(""); +/** The longest end that all of `texts` share. */ +function sharedEnd(texts: string[]): string { + let end = texts[0] ?? ""; + for (const text of texts) { + let length = 0; + while (length < end.length && end.at(-1 - length) === text.at(-1 - length)) length++; + end = end.slice(end.length - length); + } + return end; +} From 52dc5b74e84bd201852f5cf81947334a74393c57 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 16:55:56 +0200 Subject: [PATCH 15/20] Compare the URL ends by index: String.prototype.at is outside the package's lib --- packages/convex-hosting/src/cli/manifest.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/convex-hosting/src/cli/manifest.ts b/packages/convex-hosting/src/cli/manifest.ts index d172950c..b7e28bd5 100644 --- a/packages/convex-hosting/src/cli/manifest.ts +++ b/packages/convex-hosting/src/cli/manifest.ts @@ -104,7 +104,12 @@ function sharedEnd(texts: string[]): string { let end = texts[0] ?? ""; for (const text of texts) { let length = 0; - while (length < end.length && end.at(-1 - length) === text.at(-1 - length)) length++; + while ( + length < Math.min(end.length, text.length) && + end[end.length - 1 - length] === text[text.length - 1 - length] + ) { + length++; + } end = end.slice(end.length - length); } return end; From 62544224ad723c641fd9760a7f37af7cb4467f7b Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 17:52:23 +0200 Subject: [PATCH 16/20] Bring back the mark token; the version file exports only assets 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. --- README.md | 18 ++- docs/deploy.md | 5 +- docs/design.md | 137 +++++++++--------- docs/development.md | 7 +- docs/from-static-hosting.md | 7 +- docs/serving.md | 28 ++-- .../hello-world-assets-only-workers.patch | 7 +- .../hello-world-assets-only/convex/http.ts | 3 +- examples/tanstack-spa/convex/http.ts | 3 +- examples/tanstack-ssr-workers.patch | 7 +- examples/tanstack-ssr/convex/http.ts | 3 +- .../convex-hosting-tanstack-start/README.md | 2 +- packages/convex-hosting/CHANGELOG.md | 15 +- packages/convex-hosting/src/cli/main.test.ts | 100 +++++++++---- packages/convex-hosting/src/cli/main.ts | 89 ++++++++---- .../convex-hosting/src/client/index.test.ts | 83 +++++++++-- packages/convex-hosting/src/client/index.ts | 20 ++- .../convex-hosting/src/client/manifest.ts | 14 ++ .../src/client/version-module.d.ts | 1 - .../src/component/_generated/component.ts | 12 +- .../convex-hosting/src/component/lib.test.ts | 4 +- packages/convex-hosting/src/component/lib.ts | 19 ++- .../shared/src/run-wrangler-long-lived.ts | 3 +- 23 files changed, 377 insertions(+), 210 deletions(-) diff --git a/README.md b/README.md index 52216adc..cefa8c6d 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ server build for every other request, as a Cloudflare Worker with static assets ```ts import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; +import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; @@ -62,7 +63,7 @@ import server from "../dist/server/server.js"; const http = httpRouter(); -routeAll({ http, assets, worker: server }); +routeAll({ http, component: components.hosting, assets, worker: server }); export default http; ``` @@ -105,9 +106,10 @@ wires both. ## Files only -A site without a server leaves `worker` out, `routeAll({ http, assets })`, needs no adapter package, -and deploys its build directory: `--dist dist` after a `vite build`, or `--dist public` with no -`--build` at all. A single-page app adds `--not-found-handling single-page-application`. The +A site without a server leaves `worker` out, +`routeAll({ http, component: components.hosting, assets })`, needs no adapter package, and deploys +its build directory: `--dist dist` after a `vite build`, or `--dist public` with no `--build` at +all. A single-page app adds `--not-found-handling single-page-application`. The [tanstack-spa](https://github.com/samebase/convex-hosting/tree/main/examples/tanstack-spa) and [hello-world-assets-only](https://github.com/samebase/convex-hosting/tree/main/examples/hello-world-assets-only) examples are such sites. @@ -188,10 +190,10 @@ Cloudflare's asset manifest) to `.convex-hosting/version.js`, and then pushes th imports the file. The push is the switch: no pointer moves in a second step, so there is no moment when new code serves old files, and no page refers to a file that is not uploaded yet. A request reads no database: it costs one function call, the HTTP action, and a file adds the download of its -bytes, which Convex counts as a call too. After the push, `deploy` marks its version live, which -deletes the versions that were live before it. A version whose push never came is deleted at a later -switch, once it is a day old; nothing is deleted by the clock alone. The one rule: run one deploy at -a time per deployment. The +bytes, which Convex counts as a call too. After the push, `deploy` asks the served code to mark its +version live, which deletes the versions that were live before it. A version whose push never came +is deleted at a later switch, once it is a day old; nothing is deleted by the clock alone. The one +rule: run one deploy at a time per deployment. The [design](https://github.com/samebase/convex-hosting/blob/main/docs/design.md#orderings-and-timing) works through every interleaving. diff --git a/docs/deploy.md b/docs/deploy.md index 6c57d8d3..8f24f7c7 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -2,8 +2,9 @@ `deploy` runs `npx convex deploy` with your build and the upload of `--dist` as its `--cmd`. The pushed code carries the version it was built with and that version's files, so the push switches the -site. Then the command marks its version live, which deletes the versions that were live before it, -reads the site URL from the deployment (`CONVEX_SITE_URL`), prints it, and ends. When the mark +site. Then the command reads the site URL from the deployment (`CONVEX_SITE_URL`), sends one request +to it with the version's mark token, which makes the code that answers mark its version live and +delete the versions that were live before it, prints the site URL, and ends. When that request fails, the deploy still succeeds and says so; the old versions then stay until the next deploy's mark. A version that never becomes live, from a deploy that failed, is deleted at the first switch after it is a day old, and the stored files that no version uses go at the switch after that. diff --git a/docs/design.md b/docs/design.md index 89a7ed84..3c402fdc 100644 --- a/docs/design.md +++ b/docs/design.md @@ -29,22 +29,22 @@ no pointer that a second step must move, so there is no moment when new code ser request reads no database: the HTTP action answers from the files in its own code, and downloads the bytes of a file from storage. -After its push, the CLI marks its version `live`, with `markLive` in the component. An older upload -never goes live over a newer one: a version is marked only when no live version was created after -it. Marking a version live deletes the versions that were live before it, because their code is gone -by definition. Nothing is deleted by the clock alone: deletion runs only at a switch, when a new -version becomes live, so a version stays intact until a newer one has served. At a switch, a version -that never became live is dead too, from a push that failed, with one exception: a slower deploy -whose push has not landed yet. So a never-live version is deleted at a switch only when it is more -than a day old; the day bounds how late a push may follow its upload, and it is the only time -constant in the design. +Only the pushed code knows which version a deployment runs, so the serving code reports it: after +the push, the CLI sends one request with the version's mark token, which only that version's code +holds, and the code that answers marks its version `live`. An older upload never goes live over a +newer one: a version is marked only when no live version was created after it, so a request still +running on replaced code cannot take the site back. Marking a version live deletes the versions that +were live before it, because their code is gone by definition. Nothing is deleted by the clock +alone: deletion runs only at a switch, when a new version becomes live, so a version stays intact +until a newer one has served. At a switch, a version that never became live is dead too, from a push +that failed, with one exception: a slower deploy whose push has not landed yet. So a never-live +version is deleted at a switch only when it is more than a day old; the day bounds how late a push +may follow its upload, and it is the only time constant in the design. The precondition: deploys to one deployment do not overlap. When two overlap and the older upload is -pushed last, its mark is refused: its version serves, but it never becomes live, and nothing is -deleted until the next deploy. If its mark lands before the newer version's, both are marked in -turn, and the newer version's mark deletes the rows of the version that serves; its stored files -stay until the next deploy's switch. So run one deploy at a time per deployment; the example -workflows queue them, with one `concurrency` group per deployment. +pushed last, its mark is refused like a mark of replaced code: its version serves, but it never +becomes live, and nothing is deleted until the next deploy. So run one deploy at a time per +deployment; the example workflows queue them, with one `concurrency` group per deployment. ## Deploy @@ -96,10 +96,10 @@ Bristol's production used it while hosting 0.3 and 0.4 ran side by side under tw queries in the component (`npx convex run --component --inline-query`), which run whatever release of this package the component is, so an upgrade's upload works before its push installs the new functions; then writes `.convex-hosting/version.js` with the version's - `assets`: the id and the files (see Serve), in the CLI's state folder at the project root, - like Wrangler's `.wrangler/`. It writes a temporary file and renames it, so a running - `npx convex dev` never reads half of it; the folder carries its own `.gitignore`, so nothing - of it reaches git and no tool writes into `convex/`. The file is a build artifact that + `assets`: the id, a random mark token, and the files (see Serve), in the CLI's state folder at + the project root, like Wrangler's `.wrangler/`. It writes a temporary file and renames it, so + a running `npx convex dev` never reads half of it; the folder carries its own `.gitignore`, so + nothing of it reaches git and no tool writes into `convex/`. The file is a build artifact that `http.ts` imports, as a server-rendered app's `http.ts` already imports its server build; the package ships the declaration of that module (an ambient wildcard module in a script `.d.ts` that the package's types entry references), so a fresh clone typechecks with nothing added. @@ -109,10 +109,11 @@ Bristol's production used it while hosting 0.3 and 0.4 ran side by side under tw deployment's URL from `.env.local`, so no nesting is needed), uploads, writes the version file, and pushes with `npx convex run --push`. -**The mark.** When the last push has ended, the CLI calls `markLive` for its version, with -`npx convex run --component lib:markLive`, as it calls the upload's functions. A failure is -reported, and the deploy succeeds: nothing is deleted until a later version is marked, so the cost -is old files kept until the next deploy. +**The mark.** When the last push has ended, the CLI reads the site URL (below) and sends +`POST /.convex-hosting/mark` with the header `Convex-Hosting-Mark: `. The code +that answers calls `markLive` for its own version and answers the result. A failure, or an answer +from other code, is reported, and the deploy succeeds: nothing is deleted until a later version is +marked, so the cost is old files kept until the next deploy. **The site URL.** When the push, and on a first install the upload and the push after it, have ended, the CLI asks the deployment for its site URL: @@ -190,8 +191,8 @@ precondition rules out: both push and upload, and the last push serves. **Browsers.** A page opened before a deploy keeps asking for its hashed files, which the new version does not have, exactly as on Cloudflare: they answer 404, or the shell on a files-only single-page app. An app that wants to reload on a new version adds one query that returns the bundled -`versionId` and reloads when its value changes. The README shows it. The component has no part in -it. +`assets.versionId` and reloads when its value changes. The README shows it. The component has no +part in it. ## Serve @@ -207,7 +208,7 @@ picks the longest matching prefix, so only an exact route reaches the app there. import { routeAll } from "@samebase/convex-hosting"; import { assets } from "../.convex-hosting/version.js"; -routeAll({ http, assets, worker: server }); +routeAll({ http, component: components.hosting, assets, worker: server }); ``` Every input is named, after Cloudflare where Cloudflare has a name: `assets` is the static assets of @@ -275,12 +276,18 @@ keeps `no-store` for a path without an extension and gives a path with one a fou `max-age` anyway; the deploy order keeps that moot, because no page refers to a file that is not uploaded yet. A `null` asset means one thing: no asset matched, and `worker` answers. -The serving path calls no function of the component and writes nothing, so `routeAll` does not take -the component. Every function of the component is internal, and the CLI calls each with -`npx convex run --component`. `markLive` marks the version only when no live version was created -after it, inside its own transaction, and a repeated mark changes nothing. It never throws: it -answers `marked`, `live`, `superseded`, `uploading`, `deleting`, or `missing`, and the CLI reports -the last four. +A request with the header `Convex-Hosting-Mark` set to the site's mark token is the CLI's mark: +before anything else, `serveSite` calls `markLive` for its version and answers the result as JSON, +with `Cache-Control: no-store`. `markLive` marks the version only when no live version was created +after it, inside its own transaction, so code that was replaced cannot make its version newest, and +a repeated mark changes nothing. It never throws: it answers `marked`, `live`, `superseded`, +`uploading`, `deleting`, or `missing`, and the CLI reports the last four. That is the only write the +serving path ever makes, once per deploy. Any other request, with another token or none, calls no +function. + +`markLive` is the component's only public function, because `serveSite` runs in the app and an app +can call only a component's public functions; clients cannot call it at all. The CLI calls the other +functions, which are internal, with `npx convex run --component`. The two callbacks that Cloudflare's code takes map to the site's manifest: `exists(path)` finds the path's entry and returns its ETag, the content hash, as on Cloudflare; `getByETag` returns the @@ -335,30 +342,30 @@ result sizes) shape the batches. Every interleaving worked through for 0.4, what happens, and what checks it. "Component test" is a convex-test run of the exact order of transactions; "runtime" is a run against a local backend. -| What happens | Outcome | Checked by | -| ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | -| A deploy pushes; the CLI marks its version | The version is marked live; the versions live before it are deleted | Component test, runtime | -| Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | -| Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy. If its mark lands first, the newer version's mark deletes its rows, and its stored files stay until the next deploy's switch | Component test (stale request) | -| A mark for an older version comes after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | -| Two marks of one version | One mark; the second answers `live` | Component test | -| Two marks in one millisecond | The second is strictly later | Component test | -| A deploy dies before its push | A never-live version; deleted at a later switch when a day old | Component test (age rule) | -| An upload dies midway | An `uploading` version; same fate; a retry reuses its recorded files | Component test, runtime (reuse) | -| The push is reported as failed but landed | The version serves, `ready`, since the CLI sent no mark; the next deploy's mark deletes the versions before it | Inherent; stated | -| No request for days, weeks | Nothing changes: the deploy marked its version, and deletion waits for the next mark | Inherent: deletion runs only at a switch | -| Many deploys in a row | Each deploy marks its version; the one before goes at that mark, never-live versions when a day old | Component test (age rule) | -| A push lands more than a day after its upload, after another switch | Its files are gone: pages render, and its files answer 404 from storage; redeploy | Stated | -| An upload borrows a stored file; a switch deletes the lending version | The file survives: files go only when unreferenced, a day old, and already unreferenced when the chain started | Component test (sweep order) | -| Two switches during one upload | The borrowed file can go; `recordFiles` says so; a retry works | Stated | -| A request on replaced code reaches a version while it is being deleted | Its files answer 404 from storage; a mark answers `deleting` | Component test, client test | -| Documents share a creation time at a page boundary | The cursor carries the ids seen at that time; none is skipped | Component test (crafted cursor) | -| The CLI's mark fails | Reported; the deploy succeeds; nothing is deleted until the next deploy's mark | CLI test | -| First install: the component does not exist yet | Push a site without files, upload, push the site; 404 naming the version until the second push | CLI test, runtime (both flows) | -| Two first installs at once | Outside the precondition. Both push and upload; the last push serves | Stated | -| Two commands from one checkout at once | They overwrite each other's build output and version file | Stated, unsupported | -| A production deploy from a checkout where `npx convex dev` runs | Production's site is pushed to development, which answers 404 naming production's deployment until the next `deploy --dev` | Client test; stated | -| `deploy --dev` against an anonymous local deployment without `npx convex dev` | Each Convex CLI call starts and stops its own backend; the upload fails with `fetch failed` | Runtime; stated in the README | +| What happens | Outcome | Checked by | +| --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | +| A deploy pushes; the CLI's mark reaches the new code | The version is marked live; the versions live before it are deleted | Component test, runtime | +| Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | +| Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy | Component test (stale request) | +| A mark for an older version reaches its code after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | +| Two marks of one version | One mark; the second answers `live` | Component test | +| Two marks in one millisecond | The second is strictly later | Component test | +| A deploy dies before its push | A never-live version; deleted at a later switch when a day old | Component test (age rule) | +| An upload dies midway | An `uploading` version; same fate; a retry reuses its recorded files | Component test, runtime (reuse) | +| The push is reported as failed but landed | The version serves, `ready`, since the CLI sent no mark; the next deploy's mark deletes the versions before it | Inherent; stated | +| No request for days, weeks | Nothing changes: the deploy marked its version, and deletion waits for the next mark | Inherent: deletion runs only at a switch | +| Many deploys in a row | Each deploy marks its version; the one before goes at that mark, never-live versions when a day old | Component test (age rule) | +| A push lands more than a day after its upload, after another switch | Its files are gone: pages render, and its files answer 404 from storage; redeploy | Stated | +| An upload borrows a stored file; a switch deletes the lending version | The file survives: files go only when unreferenced, a day old, and already unreferenced when the chain started | Component test (sweep order) | +| Two switches during one upload | The borrowed file can go; `recordFiles` says so; a retry works | Stated | +| A request on replaced code reaches a version while it is being deleted | Its files answer 404 from storage; a mark answers `deleting` | Component test, client test | +| Documents share a creation time at a page boundary | The cursor carries the ids seen at that time; none is skipped | Component test (crafted cursor) | +| The CLI's mark fails, or other code answers it | Reported; the deploy succeeds; nothing is deleted until the next deploy's mark | CLI test | +| First install: the component does not exist yet | Push a site without files, upload, push the site; 404 naming the version until the second push | CLI test, runtime (both flows) | +| Two first installs at once | Outside the precondition. Both push and upload; the last push serves | Stated | +| Two commands from one checkout at once | They overwrite each other's build output and version file | Stated, unsupported | +| A production deploy from a checkout where `npx convex dev` runs | Production's site is pushed to development, which answers 404 naming production's deployment until the next `deploy --dev` | Client test; stated | +| `deploy --dev` against an anonymous local deployment without `npx convex dev` | Each Convex CLI call starts and stops its own backend; the upload fails with `fetch failed` | Runtime; stated in the README | Not reproducible in the test runtime and not yet run against a cloud deployment: two real pushes in a chosen order, a preview deployment, an old HTTP action kept running across a push. A smoke script @@ -368,9 +375,8 @@ place for those. ## Stated, not solved - Deploys to one deployment do not overlap. When two overlap and the older upload is pushed last, - its mark is refused, so its version serves but is never marked live, and nothing is deleted until - the next deploy. If its mark lands first, the newer version's mark deletes the rows of the version - that serves; serving reads no rows, and its stored files stay until the next deploy's switch. + its mark is refused like a mark of replaced code, so its version serves but is never marked live, + and nothing is deleted until the next deploy. - An upload that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it fails with a message that says so, and a retry works. - No `run_worker_first`, no `base_path`, no selectable compatibility date: an app that needs its @@ -381,7 +387,7 @@ place for those. ## Not here, and why - No live pointer that a command moves, no `activate`, no `getLiveVersion`: the pushed code carries - its version, and the CLI marks it after the push. + its version, and the served code marks it when the CLI asks. - No lock, no heartbeat, no cron, no call after the push besides the read of the site URL and the mark: a version is deleted only after another version has served in its place. A one-day age bounds garbage from failed deploys; it decides nothing about what is served. @@ -410,15 +416,10 @@ are not proposed again. every request: on a cloud deployment on 2026-11-04, a module-level counter read 1 on every one of 52 requests, 40 of them concurrent, while the module's own random id stayed the same. A module-level flag would have called `markLive` on every request. -- **A mark request to the served code, with a per-version token (built for 0.15, cut before its - release).** After the push, the CLI sent the site a request with a random token from the version - file, and the code that answered marked its own version, so a mark proved which code served. It - cost about 150 lines: the token, a branch in every app's HTTP action, a public function, and the - reading of the answer. It protected one case, already outside the precondition: two overlapping - deploys whose pushes land in the reverse of creation order within about a second, with the marks - in the other order. The CLI now calls `markLive` itself; in that case the newer version's mark - deletes the rows of the version that serves, serving reads no rows, and the stored files stay - until the next deploy's switch. +- **Marking live from the CLI with `npx convex run lib:markLive`.** When deploys overlap, the CLI + can mark a version whose code does not serve, and the mark deletes the files of the code that + does. The mark request reaches the code that serves, and its token makes only that deploy's code + mark. - **Marking live on a random share of requests.** It kept the mark in the serving code for about one call per hundred requests, but a site with little traffic would keep its old versions for days, and every request would pay the draw. diff --git a/docs/development.md b/docs/development.md index ade554b6..a66630c3 100644 --- a/docs/development.md +++ b/docs/development.md @@ -45,8 +45,7 @@ Two cases are transient: ```ts vi.mock("../dist/server/server.js", () => ({ default: { fetch: async () => new Response() } })); vi.mock("../.convex-hosting/version.js", () => ({ - versionId: "test", - assets: { format: 1, versionId: "test", files: null }, + assets: { format: 1, versionId: "test", markToken: "test", files: null }, })); ``` @@ -65,9 +64,9 @@ open tabs on a new version, add a query that returns the bundled version: // convex/siteVersion.ts import { v } from "convex/values"; import { query } from "./_generated/server.js"; -import { versionId } from "../.convex-hosting/version.js"; +import { assets } from "../.convex-hosting/version.js"; -export const get = query({ args: {}, returns: v.string(), handler: () => versionId }); +export const get = query({ args: {}, returns: v.string(), handler: () => assets.versionId }); ``` and reload when its value changes after the first one: diff --git a/docs/from-static-hosting.md b/docs/from-static-hosting.md index 462306fe..19ba6aa8 100644 --- a/docs/from-static-hosting.md +++ b/docs/from-static-hosting.md @@ -30,9 +30,10 @@ and source on 2026-10-18, version 0.2.1. as in [Quick start](../README.md#quick-start). If the component owned `/`, also remove `httpPrefix: "/api"` from `defineApp`, and add `/api` to the paths of your own routes whose URLs must stay. -3. In `convex/http.ts`, replace `registerStaticRoutes(...)` with `routeAll({ http, assets })`, and - import `assets` from `../.convex-hosting/version.js`. Your exact routes keep winning. A - server-rendered app passes its server entry as `worker`. +3. In `convex/http.ts`, replace `registerStaticRoutes(...)` with + `routeAll({ http, component: components.hosting, assets })`, and import `assets` from + `../.convex-hosting/version.js`. Your exact routes keep winning. A server-rendered app passes its + server entry as `worker`. 4. In the deploy scripts, replace `@convex-dev/static-hosting deploy`, or the pair `npx convex deploy` and `upload --prod`, with `convex-hosting deploy --build "" --dist `, which builds, uploads, and pushes diff --git a/docs/serving.md b/docs/serving.md index eabd298e..4a9c51d4 100644 --- a/docs/serving.md +++ b/docs/serving.md @@ -26,20 +26,20 @@ the file when the page reloads. A local deployment, which has no front, sends th ## Routing -`routeAll({ http, assets, worker? })` routes the site's HTTP action for every method at every path, -and returns it. The action answers with the file that matches, else with what `worker` answers (see -[Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or HEAD on a -path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, else 404. -`worker` is the Worker script, an object with `fetch(request)`: the code that runs on a miss. -Everything it returns gets `Cache-Control: no-store`, and so does a 404, because the `*.convex.site` -front caches paths with an extension. The front keeps `no-store` for a path without an extension and -replaces it with a four-hour browser `max-age` for a path with one, so a browser that asks for a -script before its upload ended keeps the 404; the deploy order prevents that case, because no page -refers to a file that is not uploaded yet. The `assets` of the version come with the pushed code, in -`.convex-hosting/version.js`, so a request reads no database: it costs one function call, the HTTP -action, and a file adds the download of its bytes, which Convex counts as a call too. A redirect, a -304, a miss, and a rendered page download nothing. Until a first install's upload ends, the site -answers 404 naming the version. +`routeAll({ http, component, assets, worker? })` routes the site's HTTP action for every method at +every path, and returns it. The action answers with the file that matches, else with what `worker` +answers (see [Server-rendered pages](#server-rendered-pages)), else 404. Another method than GET or +HEAD on a path that has a file answers 405, as on Cloudflare; on any other path it goes to `worker`, +else 404. `worker` is the Worker script, an object with `fetch(request)`: the code that runs on a +miss. Everything it returns gets `Cache-Control: no-store`, and so does a 404, because the +`*.convex.site` front caches paths with an extension. The front keeps `no-store` for a path without +an extension and replaces it with a four-hour browser `max-age` for a path with one, so a browser +that asks for a script before its upload ended keeps the 404; the deploy order prevents that case, +because no page refers to a file that is not uploaded yet. The `assets` of the version come with the +pushed code, in `.convex-hosting/version.js`, so a request reads no database: it costs one function +call, the HTTP action, and a file adds the download of its bytes, which Convex counts as a call too. +A redirect, a 304, a miss, and a rendered page download nothing. Until a first install's upload +ends, the site answers 404 naming the version. As on Cloudflare, the presence of code decides where `not_found_handling` (the single-page fallback or the 404 page) applies: diff --git a/examples/hello-world-assets-only-workers.patch b/examples/hello-world-assets-only-workers.patch index ece50f57..45c17848 100644 --- a/examples/hello-world-assets-only-workers.patch +++ b/examples/hello-world-assets-only-workers.patch @@ -12,19 +12,20 @@ index 41a6c4afe86dc311eed5da6e75804b73bdc4462f..00000000000000000000000000000000 -export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index d1037d726e70fbc4e75a7b2761bf64770e84adea..0000000000000000000000000000000000000000 +index 51996727a045edbc5b84557709e31b07a62c3bfb..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null -@@ -1,11 +0,0 @@ +@@ -1,12 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; +-import { components } from "./_generated/api.js"; -import { assets } from "../.convex-hosting/version.js"; - -const http = httpRouter(); - -// Every method, every path, as a Cloudflare Worker without a script: a file for a path that has -// one, else 404; another method than GET or HEAD on a file answers 405. --routeAll({ http, assets }); +-routeAll({ http, component: components.hosting, assets }); - -export default http; diff --git a/convex/tsconfig.json b/convex/tsconfig.json diff --git a/examples/hello-world-assets-only/convex/http.ts b/examples/hello-world-assets-only/convex/http.ts index d1037d72..51996727 100644 --- a/examples/hello-world-assets-only/convex/http.ts +++ b/examples/hello-world-assets-only/convex/http.ts @@ -1,11 +1,12 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; +import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else 404; another method than GET or HEAD on a file answers 405. -routeAll({ http, assets }); +routeAll({ http, component: components.hosting, assets }); export default http; diff --git a/examples/tanstack-spa/convex/http.ts b/examples/tanstack-spa/convex/http.ts index b79d158e..229ed7c7 100644 --- a/examples/tanstack-spa/convex/http.ts +++ b/examples/tanstack-spa/convex/http.ts @@ -1,11 +1,12 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; +import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); // Every method, every path, as a Cloudflare Worker without a script: a file for a path that has // one, else the single-page fallback; another method than GET or HEAD on a file answers 405. -routeAll({ http, assets }); +routeAll({ http, component: components.hosting, assets }); export default http; diff --git a/examples/tanstack-ssr-workers.patch b/examples/tanstack-ssr-workers.patch index 54171c53..43250147 100644 --- a/examples/tanstack-ssr-workers.patch +++ b/examples/tanstack-ssr-workers.patch @@ -18,12 +18,13 @@ index 1831f4b4fa5703fe1332d9cf45fb2308a57be703..dcc4d5f09735722e1164710651a0c69d export default app; diff --git a/convex/http.ts b/convex/http.ts deleted file mode 100644 -index 9124b69fdf444c75f63d3335fdd805f0d1014c4f..0000000000000000000000000000000000000000 +index 4ae60e6c413b09f9d22481a9cba1b67b633b2529..0000000000000000000000000000000000000000 --- a/convex/http.ts +++ /dev/null -@@ -1,20 +0,0 @@ +@@ -1,21 +0,0 @@ -import { httpRouter } from "convex/server"; -import { routeAll } from "@samebase/convex-hosting"; +-import { components } from "./_generated/api.js"; -import { assets } from "../.convex-hosting/version.js"; -// Type only, nothing is bundled: the server build imported below. -import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; @@ -34,7 +35,7 @@ index 9124b69fdf444c75f63d3335fdd805f0d1014c4f..00000000000000000000000000000000 -// Every method, every path: a file for a path that has one (another method than GET or HEAD on it -// answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with -// static assets does. --const handler = routeAll({ http, assets, worker: server }); +-const handler = routeAll({ http, component: components.hosting, assets, worker: server }); -// Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it -// serves the key set, and the longest prefix wins, so the catch-all above never sees them. -for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { diff --git a/examples/tanstack-ssr/convex/http.ts b/examples/tanstack-ssr/convex/http.ts index 9124b69f..4ae60e6c 100644 --- a/examples/tanstack-ssr/convex/http.ts +++ b/examples/tanstack-ssr/convex/http.ts @@ -1,5 +1,6 @@ import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; +import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; // Type only, nothing is bundled: the server build imported below. import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; @@ -10,7 +11,7 @@ const http = httpRouter(); // Every method, every path: a file for a path that has one (another method than GET or HEAD on it // answers 405), the app's server (src/server.ts) for every other path, as a Cloudflare Worker with // static assets does. -const handler = routeAll({ http, assets, worker: server }); +const handler = routeAll({ http, component: components.hosting, assets, worker: server }); // Exact routes for the three auth paths: the Convex Auth component holds the /auth prefix, where it // serves the key set, and the longest prefix wins, so the catch-all above never sees them. for (const path of ["/auth/signin", "/auth/refresh", "/auth/signout"]) { diff --git a/packages/convex-hosting-tanstack-start/README.md b/packages/convex-hosting-tanstack-start/README.md index a87ae043..9999a624 100644 --- a/packages/convex-hosting-tanstack-start/README.md +++ b/packages/convex-hosting-tanstack-start/README.md @@ -34,7 +34,7 @@ import { assets } from "../.convex-hosting/version.js"; import type {} from "@samebase/convex-hosting-tanstack-start/server-build"; import server from "../dist/server/server.js"; -routeAll({ http, assets, worker: server }); +routeAll({ http, component: components.hosting, assets, worker: server }); ``` Import `@samebase/convex-hosting` before the server build: it defines `queueMicrotask` when it diff --git a/packages/convex-hosting/CHANGELOG.md b/packages/convex-hosting/CHANGELOG.md index 1bfb05cf..6ffd60e5 100644 --- a/packages/convex-hosting/CHANGELOG.md +++ b/packages/convex-hosting/CHANGELOG.md @@ -9,21 +9,22 @@ two; an answer with a body costs two, the action and the download of the file, where it cost three. The component's `route` query is gone. - Breaking: `routeAll` takes one object, with every input named, and the assets in place of the - component and the version id: + version id: ```ts import { assets } from "../.convex-hosting/version.js"; - routeAll({ http, assets, worker: server }); + routeAll({ http, component: components.hosting, assets, worker: server }); ``` A files-only site leaves `worker` out. `assets` and `worker` are Cloudflare's names: the static - assets of a Worker, and the Worker script. `versionId` stays exported for the query that reloads - open tabs. A test that mocks the version module adds - `assets: { format: 1, versionId: "test", files: null }`. + assets of a Worker, and the Worker script. The file exports only `assets`: the query that reloads + open tabs reads `assets.versionId` in place of `versionId`. A test that mocks the version module + adds `assets: { format: 1, versionId: "test", markToken: "test", files: null }`. -- After the push, `deploy` marks its version live; before, the first request did. The component has - no public function left. +- After the push, `deploy` sends one request with the version's mark token, and the code that + answers marks its version live; before, the first request did. `markLive` answers what it did and + never throws. - A first install pushes twice: once to install the component, and once after the upload, to serve the site. - A version file uploaded to another deployment, such as production's pushed to development by a diff --git a/packages/convex-hosting/src/cli/main.test.ts b/packages/convex-hosting/src/cli/main.test.ts index b4b47ddc..5cfccf5c 100644 --- a/packages/convex-hosting/src/cli/main.test.ts +++ b/packages/convex-hosting/src/cli/main.test.ts @@ -12,7 +12,7 @@ import { import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { describe, expect, test } from "vite-plus/test"; -import { manifestLookup, type Assets } from "../client/manifest.js"; +import { manifestLookup, MARK_HEADER, MARK_PATH, type Assets } from "../client/manifest.js"; import { deploymentSelector, type Cli } from "./convex.js"; import { main, VERSION_FILE } from "./main.js"; @@ -55,9 +55,10 @@ const callName = (args: string[]) => /** * A fake `Cli`: `npx convex run` answers like a deployment with the component, the build calls - * `build`, and `npx convex deploy` or `npx convex run --push` calls `push`. No processes, no - * network. `events` lists the builds, the probes, the site URL queries, the storage URL queries, - * the function calls, and the pushes in order. + * `build`, `npx convex deploy` or `npx convex run --push` calls `push`, and the site answers the + * mark request with `mark`. No processes, no network. `events` lists the builds, the probes, the + * site URL queries, the storage URL queries, the function calls, the pushes, and the marks in + * order. */ function fake( cwd: string, @@ -70,8 +71,8 @@ function fake( failing?: Record; build?: () => Promise; push?: (cli: Cli, args: string[]) => Promise; - /** What `markLive` answers; by default it marks the version. */ - mark?: string; + /** The site's answer to the mark request; by default it marks the version of the file. */ + mark?: (token: string | null, init: RequestInit | undefined) => Promise; } = {}, ) { const runs: string[][] = []; @@ -135,8 +136,6 @@ function fake( return storageId === undefined ? [] : [{ sha256, storageId }]; }), ); - case "lib:markLive": - return ok(options.mark ?? "marked"); default: return ok(null); } @@ -152,6 +151,15 @@ function fake( return (await options.build?.()) ?? 0; }, fetch: async (url, init) => { + if (url === SITE_URL + MARK_PATH) { + events.push("mark"); + const token = new Headers(init?.headers).get(MARK_HEADER); + if (options.mark !== undefined) return await options.mark(token, init); + const assets = writtenAssets(cwd); + return token === assets.markToken + ? Response.json({ versionId: assets.versionId, result: "marked" }) + : new Response("

Home

"); + } const storageId = `storage-${stored.size}`; stored.set(storageId, await new Response(init?.body).text()); return Response.json({ storageId }); @@ -175,7 +183,7 @@ function innerUpload(cli: Cli, args: string[]) { } const versionFile = (cwd: string) => readFileSync(join(cwd, VERSION_FILE), "utf8"); -const writtenVersionId = (cwd: string) => /"([^"]+)"/.exec(versionFile(cwd))?.[1]; +const writtenVersionId = (cwd: string) => writtenAssets(cwd).versionId; /** The assets of the version file, as `convex/http.ts` imports them. */ function writtenAssets(cwd: string): Assets { const line = versionFile(cwd) @@ -227,7 +235,7 @@ describe("deploy --dev", () => { expect(await main(DEV, cli)).toBe(0); expect(builds).toEqual(["vite build"]); - // Only the mark and the site URL query run after the push. + // Only the site URL query runs after the push. expect(events).toEqual([ "build", "probe", @@ -239,8 +247,8 @@ describe("deploy --dev", () => { "lib:finishVersion", "urls", "push: run", - "lib:markLive", "site url", + "mark", ]); // An inline query at the app's root, which exists before a first install. expect(pushes).toEqual([["run", "--push", "--inline-query", "null"]]); @@ -275,8 +283,8 @@ describe("deploy --dev", () => { "lib:finishVersion", "urls", "push: run", - "lib:markLive", "site url", + "mark", ]); expect(pushedFiles).toEqual([false, true]); expect(existsSync(join(cwd, ".convex-hosting", "first-install"))).toBe(false); @@ -384,28 +392,57 @@ describe("deploy reports", () => { ); }); - test("after the push, marks the version of this deploy live", async () => { + test("the mark carries the site's token, so only the code of this deploy marks", async () => { + const tokens: (string | null)[] = []; const cwd = app(site); - const { cli, callArgs, logs } = fake(cwd, { push: innerUpload }); + const { cli, logs } = fake(cwd, { + push: innerUpload, + mark: async (token) => { + tokens.push(token); + return Response.json({ versionId: writtenAssets(cwd).versionId, result: "marked" }); + }, + }); expect(await main(DEPLOY, cli)).toBe(0); - expect(callArgs("lib:markLive")).toEqual([{ versionId: writtenVersionId(cwd) }]); + expect(tokens).toEqual([writtenAssets(cwd).markToken]); expect(logs[logs.length - 1]).toMatch(/^Deployed version /); }); - test("a mark that fails is reported, and the deploy succeeds", async () => { + test("a mark that fails or reaches other code is reported, and the deploy succeeds", async () => { + const answers: Record Promise> = { + "failed: fetch failed": async () => { + throw new TypeError("fetch failed"); + }, + "did not answer as version": async () => new Response("

Home

"), + }; + for (const [message, answer] of Object.entries(answers)) { + const { cli, logs } = fake(app(site), { push: innerUpload, mark: answer }); + expect(await main(DEPLOY, cli)).toBe(0); + expect(logs.some((line) => line.includes(message))).toBe(true); + expect(logs[logs.length - 1]).toMatch(/^Deployed version /); + } + }); + + test("the mark follows no redirect, which would carry the token to another origin", async () => { + const redirects: (RequestRedirect | undefined)[] = []; const { cli, logs } = fake(app(site), { push: innerUpload, - failing: { "lib:markLive": "✖ Not logged in." }, + mark: async (_token, init) => { + redirects.push(init?.redirect); + return new Response(null, { status: 307, headers: { Location: "https://other.example/" } }); + }, }); expect(await main(DEPLOY, cli)).toBe(0); - expect( - logs.some((line) => /^Marking version .* live failed: ✖ Not logged in\./.test(line)), - ).toBe(true); - expect(logs[logs.length - 1]).toMatch(/^Deployed version /); + expect(redirects).toEqual(["manual"]); + expect(logs.some((line) => line.includes("did not answer as version"))).toBe(true); }); test("a mark refused because a newer version is live says that deploys overlapped", async () => { - const { cli, logs } = fake(app(site), { push: innerUpload, mark: "superseded" }); + const cwd = app(site); + const { cli, logs } = fake(cwd, { + push: innerUpload, + mark: async () => + Response.json({ versionId: writtenAssets(cwd).versionId, result: "superseded" }), + }); expect(await main(DEPLOY, cli)).toBe(0); expect(logs.some((line) => line.includes("a deploy overlapped this one"))).toBe(true); }); @@ -449,7 +486,7 @@ describe("deploy without --build", () => { expect(await main(["deploy", "--dev", "--dist", "dist"], cli)).toBe(0); expect(builds).toEqual([]); expect(events[0]).toBe("probe"); - expect(events.slice(-3)).toEqual(["push: run", "lib:markLive", "site url"]); + expect(events.slice(-3)).toEqual(["push: run", "site url", "mark"]); }); test("production runs only the upload inside npx convex deploy --cmd", async () => { @@ -457,7 +494,7 @@ describe("deploy without --build", () => { expect(await main(["deploy", "--dist", "dist"], cli)).toBe(0); expect(pushes[0][2]).toMatch(/^'.+' '.+' 'upload' '--dist' 'dist' '--version-id' '/); expect(events[0]).toBe("push: deploy"); - expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "lib:markLive", "site url"]); + expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "site url", "mark"]); }); }); @@ -476,9 +513,9 @@ describe("deploy", () => { // `npx convex deploy` goes to production by default and has no --prod flag; every run gets it. expect(pushes[0]).not.toContain("--prod"); expect(runs.every((args) => args.includes("--prod"))).toBe(true); - // The upload runs inside the push; after it, the mark and the site URL query. + // The upload runs inside the push; after it, the site URL query and the mark. expect(events[0]).toBe("push: deploy"); - expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "lib:markLive", "site url"]); + expect(events.slice(-4)).toEqual(["lib:finishVersion", "urls", "site url", "mark"]); expect(callArgs("lib:createVersion")[0].versionId).toBe(writtenVersionId(cwd)); }); @@ -503,7 +540,7 @@ describe("deploy", () => { expect(await main(DEPLOY, cli)).toBe(0); expect(calls().slice(0, 3)).toEqual(["probe", "probe", "lib:generateUploadUrls"]); - expect(calls().slice(-4)).toEqual(["lib:finishVersion", "urls", "lib:markLive", "site url"]); + expect(calls().slice(-3)).toEqual(["lib:finishVersion", "urls", "site url"]); expect(pushes.map((args) => args[0])).toEqual(["deploy", "deploy"]); expect(pushes[1]).toEqual(["deploy"]); expect(pushedFiles).toEqual([false, true]); @@ -629,13 +666,12 @@ describe("upload", () => { home.storageId, ); - expect(versionFile(cwd).split("\n").slice(0, 2)).toEqual([ - 'export const versionId = "v1";', - // tsc reads the file itself in an app whose convex/tsconfig.json sets allowJs. + // tsc reads the file itself in an app whose convex/tsconfig.json sets allowJs. + expect(versionFile(cwd).split("\n")[0]).toBe( '/** @type {import("@samebase/convex-hosting").Assets} */', - ]); + ); const written = writtenAssets(cwd); - expect(written).toMatchObject({ format: 1, versionId: "v1" }); + expect(written).toMatchObject({ format: 1, versionId: "v1", markToken: expect.any(String) }); const files = written.files; if (files === null) throw new Error("The version file has no files."); expect(files.cloudUrl).toBe(CLOUD_URL); diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index 456eb77f..d27ece78 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -12,7 +12,13 @@ import { join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { parseArgs } from "node:util"; import { z } from "zod"; -import { ASSETS_FORMAT, type AssetFiles, type Assets } from "../client/manifest.js"; +import { + ASSETS_FORMAT, + MARK_HEADER, + MARK_PATH, + type AssetFiles, + type Assets, +} from "../client/manifest.js"; import { internal } from "../component/_generated/api.js"; import type { Config } from "../component/lib.js"; import type { Id } from "../component/_generated/dataModel.js"; @@ -179,9 +185,9 @@ function quote(arg: string): string { } /** - * Builds, uploads, writes the version file, and pushes. The push is the switch. Then it marks the - * version live, and reports the site URL, for a person and, through `$GITHUB_OUTPUT`, for the next - * step of a GitHub Actions job. + * Builds, uploads, writes the version file, and pushes. The push is the switch. Then it asks the + * served code to mark its version live, and reports the site URL, for a person and, through + * `$GITHUB_OUTPUT`, for the next step of a GitHub Actions job. */ async function deploy(cli: Cli, options: Options, build: string | undefined) { // A deploy key wins over every selector in the Convex CLI, so a production key in the environment @@ -230,7 +236,6 @@ async function deploy(cli: Cli, options: Options, build: string | undefined) { } else { await deployWithConvexDeploy(cli, options, target, versionId, build); } - await markLive(cli, target, versionId); let url: string; try { url = await siteUrl(cli, target.flags); @@ -239,6 +244,7 @@ async function deploy(cli: Cli, options: Options, build: string | undefined) { const message = error instanceof Error ? error.message : String(error); throw new Error(`Deployed version ${versionId}, but reading the site URL failed: ${message}`); } + await markServedVersion(cli, url, readVersionFile(cli)); cli.log(`Deployed version ${versionId} to ${url}.`); if (cli.env.GITHUB_OUTPUT) appendFileSync(cli.env.GITHUB_OUTPUT, `url=${url}\n`); } @@ -378,9 +384,11 @@ async function upload( z.array(z.string()).length(count), ); + // The CLI sends it after the push; see `MARK_HEADER`. + const markToken = randomUUID(); const missing = await probeComponent(cli, target); if (missing !== undefined) { - writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, files: null }); + writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, markToken, files: null }); return missing; } @@ -470,7 +478,7 @@ async function upload( } await runComponent(cli, target, internal.lib.finishVersion, { versionId }, z.null()); const files = await assetFiles(cli, target, versionId, config, entries); - writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, files }); + writeVersionFile(cli, { format: ASSETS_FORMAT, versionId, markToken, files }); cli.log(`Uploaded version ${versionId} and wrote ${VERSION_FILE}.`); return undefined; } @@ -526,9 +534,11 @@ async function assetFiles( ); } +/** The line of the version file that holds the assets. */ +const ASSETS_LINE = "export const assets = "; + /** - * Writes the version file. `versionId` is its own export too, for the app query that reloads - * pages on a new version. The assets carry their type as JSDoc: Convex's default + * Writes the version file. The assets carry their type as JSDoc: Convex's default * `convex/tsconfig.json` sets `allowJs`, so tsc reads this file instead of the package's * declaration, and would infer `string` where `Assets` has a union of literals. */ @@ -536,39 +546,62 @@ function writeVersionFile(cli: Cli, assets: Assets) { writeStateFile( cli, VERSION_FILE, - `export const versionId = ${JSON.stringify(assets.versionId)};\n` + - `/** @type {import("@samebase/convex-hosting").Assets} */\n` + - `export const assets = ${JSON.stringify(assets)};\n`, + `/** @type {import("@samebase/convex-hosting").Assets} */\n` + + `${ASSETS_LINE}${JSON.stringify(assets)};\n`, ); } +/** The id and the mark token of the assets in the version file that the upload wrote. */ +function readVersionFile(cli: Cli): Pick { + const line = readFileSync(join(cli.cwd, VERSION_FILE), "utf8") + .split("\n") + .find((text) => text.startsWith(ASSETS_LINE)); + if (line === undefined) throw new Error(`${VERSION_FILE} has no assets.`); + return z + .object({ versionId: z.string(), markToken: z.string() }) + .parse(JSON.parse(line.slice(ASSETS_LINE.length, -1))); +} + /** - * Marks the version live after the push that serves it, so the component deletes the versions - * before it. A failure deletes nothing: the versions live before stay until a later deploy marks - * its own, so it is reported, and the deploy succeeds. + * Asks the code that the deployment serves to mark its version live, with the site's mark token, + * which only the code of this deploy has. A failure deletes nothing: the versions live before stay + * until a later deploy marks its own, so it is reported, and the deploy succeeds. */ -async function markLive(cli: Cli, target: Target, versionId: string) { - const later = `Version ${versionId} serves, and the next deploy deletes the files of the versions before it.`; - let result: string; +async function markServedVersion( + cli: Cli, + url: string, + site: Pick, +) { + const later = `Version ${site.versionId} serves, and the next deploy deletes the files of the versions before it.`; + let answer: unknown; try { - result = await runComponent( - cli, - target, - internal.lib.markLive, - { versionId }, - z.enum(["marked", "live", "superseded", "uploading", "deleting", "missing"]), - ); + // A redirect would carry the token to another origin, so it counts as other code answering. + const response = await cli.fetch(url + MARK_PATH, { + method: "POST", + headers: { [MARK_HEADER]: site.markToken }, + redirect: "manual", + }); + // Other code answers the path with a page or a 404, which is no mark. + answer = response.ok ? await response.json().catch(() => null) : null; } catch (error) { const message = error instanceof Error ? error.message : String(error); - cli.log(`Marking version ${versionId} live failed: ${message}. ${later}`); + cli.log(`Asking the site to mark version ${site.versionId} live failed: ${message}. ${later}`); + return; + } + const parsed = z.object({ versionId: z.string(), result: z.string() }).safeParse(answer); + if (!parsed.success || parsed.data.versionId !== site.versionId) { + cli.log( + `The site did not answer as version ${site.versionId}, so its code is not this deploy's.`, + ); return; } + const { result } = parsed.data; if (result === "superseded") { cli.log( - `A version created after ${versionId} is live, so a deploy overlapped this one; ${later}`, + `A version created after ${site.versionId} is live, so a deploy overlapped this one; ${later}`, ); } else if (result !== "marked" && result !== "live") { - cli.log(`Version ${versionId} could not be marked live: it is ${result}.`); + cli.log(`Version ${site.versionId} could not be marked live: it is ${result}.`); } } diff --git a/packages/convex-hosting/src/client/index.test.ts b/packages/convex-hosting/src/client/index.test.ts index d5ab911e..bf086c70 100644 --- a/packages/convex-hosting/src/client/index.test.ts +++ b/packages/convex-hosting/src/client/index.test.ts @@ -1,40 +1,53 @@ /// import { convexTest } from "convex-test"; -import { httpRouter, ROUTABLE_HTTP_METHODS } from "convex/server"; +import { anyApi, httpRouter, ROUTABLE_HTTP_METHODS } from "convex/server"; import { afterEach, describe, expect, test, vi } from "vite-plus/test"; import { siteConfig } from "../cli/site-config.js"; import type { Config } from "../component/lib.js"; +import { internal } from "../component/_generated/api.js"; import schema from "../component/schema.js"; import { routeAll } from "./index.js"; import { buildAssetFiles } from "../cli/manifest.js"; -import type { Assets } from "./manifest.js"; +import { MARK_HEADER, type Assets } from "./manifest.js"; const modules = import.meta.glob(["../component/**/*.ts", "!../component/**/*.test.ts"]); +/** The component's public functions, as an app reaches them through `components.hosting`. */ +const component = { lib: { markLive: anyApi.lib.markLive } }; + const CLOUD_URL = "https://example.convex.cloud"; /** - * The assets of version `v1` with `/index.html` and `config`, as the upload writes them. The site's - * action runs in an HTTP action, an action context where `fetch` is allowed. The response comes - * back as its parts, with the number of functions that the action called. + * Version `v1` with `/index.html` and `config`, ready, and its assets as the upload writes them. The + * site's action runs in an HTTP action, an action context where `fetch` is allowed; convex-test + * refuses `fetch` in `t.run`, which is a mutation. The response comes back as its parts, with the + * number of functions that the action called. */ async function setup(config: Config = {}) { + // `markLive` schedules `collect`; the tests run it with `finish`. + vi.useFakeTimers(); vi.stubEnv("CONVEX_CLOUD_URL", CLOUD_URL); const t = convexTest(schema, modules); - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode("

Home

")); + const body = "

Home

"; + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); const sha256 = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join( "", ); + const configId = await t.run((ctx) => ctx.storage.store(new Blob([JSON.stringify(config)]))); + await t.action(internal.lib.createVersion, { versionId: "v1", configId }); + const storageId = await t.run((ctx) => ctx.storage.store(new Blob([body]))); + const entry = { path: "/index.html", sha256, contentType: "text/html" }; + await t.mutation(internal.lib.recordFiles, { + versionId: "v1", + entries: [{ ...entry, storageId }], + }); + await t.mutation(internal.lib.finishVersion, { versionId: "v1" }); const assets: Assets = { format: 1, versionId: "v1", + markToken: "token-1", files: buildAssetFiles(CLOUD_URL, siteConfig(config), [ - { - path: "/index.html", - sha256, - contentType: "text/html", - url: `${CLOUD_URL}/api/storage/stored-1`, - }, + { ...entry, url: `${CLOUD_URL}/api/storage/${storageId}` }, ]), }; @@ -54,6 +67,7 @@ async function setup(config: Config = {}) { const worker = options.render === undefined ? undefined : { fetch: options.render }; const action = routeAll({ http: httpRouter(), + component, assets: options.assets ?? assets, worker, }); @@ -69,19 +83,31 @@ async function setup(config: Config = {}) { body: await response.text(), }; }); - return { assets, serve }; + const state = () => + t.run( + async (ctx) => + ( + await ctx.db + .query("versions") + .withIndex("by_versionId", (q) => q.eq("versionId", "v1")) + .unique() + )?.state.kind, + ); + const finish = () => t.finishAllScheduledFunctions(vi.runAllTimers); + return { assets, serve, state, finish }; } afterEach(() => { vi.unstubAllGlobals(); vi.unstubAllEnvs(); + vi.useRealTimers(); }); describe("routeAll", () => { test("routes the action for every method Convex routes, at every path, and returns it", async () => { const { assets } = await setup(); const http = httpRouter(); - const action = routeAll({ http, assets }); + const action = routeAll({ http, component, assets }); for (const method of ROUTABLE_HTTP_METHODS) { expect(http.lookup("/any/path", method)).toEqual([action, method, "/*"]); } @@ -100,6 +126,35 @@ describe("the site's action", () => { expect(hit.calls).toBe(0); }); + test("the request with the site's mark token marks the version live and answers the result", async () => { + const { assets, serve, state, finish } = await setup(); + const render = vi.fn(async () => new Response("page")); + const marked = await serve("/.convex-hosting/mark", { + render, + method: "POST", + headers: { [MARK_HEADER]: assets.markToken }, + }); + expect(marked.calls).toBe(1); + expect(JSON.parse(marked.body)).toEqual({ versionId: "v1", result: "marked" }); + expect(marked.cacheControl).toBe("no-store"); + expect(render).not.toHaveBeenCalled(); + expect(await state()).toBe("live"); + const again = await serve("/", { headers: { [MARK_HEADER]: assets.markToken } }); + expect(JSON.parse(again.body)).toEqual({ versionId: "v1", result: "live" }); + await finish(); + expect(await state()).toBe("live"); + }); + + test("a request with another mark token is an ordinary request, which calls no function", async () => { + vi.stubGlobal("fetch", async () => new Response("

Home

")); + const { serve, state } = await setup(); + const other = await serve("/", { headers: { [MARK_HEADER]: "guess" } }); + expect(other.status).toBe(200); + expect(other.body).toBe("

Home

"); + expect(other.calls).toBe(0); + expect(await state()).toBe("ready"); + }); + test("a first install's assets, before its upload, answer 404 naming the version, without rendering", async () => { const { assets, serve } = await setup(); const render = vi.fn(async () => new Response("page")); diff --git a/packages/convex-hosting/src/client/index.ts b/packages/convex-hosting/src/client/index.ts index ad8a470e..464896a7 100644 --- a/packages/convex-hosting/src/client/index.ts +++ b/packages/convex-hosting/src/client/index.ts @@ -5,8 +5,9 @@ import { type HttpRouter, type PublicHttpAction, } from "convex/server"; +import type { ComponentApi } from "../component/_generated/component.js"; import { answer, type Answer } from "./answer.js"; -import { ASSETS_FORMAT, type Assets } from "./manifest.js"; +import { ASSETS_FORMAT, MARK_HEADER, type Assets } from "./manifest.js"; export type { Assets } from "./manifest.js"; @@ -14,6 +15,8 @@ export type { Assets } from "./manifest.js"; export type RouteAllOptions = { /** The app's router, from `httpRouter()`. */ http: HttpRouter; + /** The installed component: `components.hosting`. */ + component: ComponentApi; /** `assets` from `.convex-hosting/version.js`, which `convex-hosting deploy` writes. */ assets: Assets; /** @@ -30,17 +33,16 @@ export type RouteAllOptions = { * `worker`, it applies to navigations only and `worker` answers the other misses; without it, it * applies to every request. * - * The assets are in the pushed code, so a request calls no function of the component, and - * `routeAll` does not take it: a file costs this action and the download of its bytes, any other - * answer this action alone. + * The assets are in the pushed code, so a request calls no function of the component: a file costs + * this action and the download of its bytes, any other answer this action alone. * * A page and a 404 answer `Cache-Control: no-store`. The deployment's Cloudflare front keeps that * for a path without an extension and replaces it with a four-hour browser `max-age` for a path * with one, so a browser that asks for a script before its upload ended keeps the 404; the deploy * order prevents that case, because no page refers to a file that is not uploaded yet. */ -function serveSite({ assets, worker }: RouteAllOptions): PublicHttpAction { - return httpActionGeneric(async (_ctx, request) => { +function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAction { + return httpActionGeneric(async (ctx, request) => { if (assets.format !== ASSETS_FORMAT) { return notServed( 500, @@ -48,6 +50,10 @@ function serveSite({ assets, worker }: RouteAllOptions): PublicHttpAction { `@samebase/convex-hosting reads format ${ASSETS_FORMAT}. Deploy again.`, ); } + if (request.headers.get(MARK_HEADER) === assets.markToken) { + const result = await ctx.runMutation(component.lib.markLive, { versionId: assets.versionId }); + return Response.json({ versionId: assets.versionId, result }, { headers: NO_STORE }); + } const { files } = assets; // A first install pushes before its upload; the deploy pushes again when the upload ends. if (files === null) { @@ -79,7 +85,7 @@ function serveSite({ assets, worker }: RouteAllOptions): PublicHttpAction { * through GET. * * ```ts - * routeAll({ http, assets, worker: server }); + * routeAll({ http, component: components.hosting, assets, worker: server }); * ``` * * Returns the action, for the paths that a component's HTTP prefix would otherwise take: Convex diff --git a/packages/convex-hosting/src/client/manifest.ts b/packages/convex-hosting/src/client/manifest.ts index 996c40ad..1382a951 100644 --- a/packages/convex-hosting/src/client/manifest.ts +++ b/packages/convex-hosting/src/client/manifest.ts @@ -11,6 +11,15 @@ import { CONTENT_HASH_SIZE } from "../workers-sdk/packages/workers-shared/utils/ */ export const ASSETS_FORMAT = 1; +/** + * The header with which the CLI, after the push, asks the served code to mark its version live. Its + * value is the site's `markToken`; a request without it is an ordinary request. + */ +export const MARK_HEADER = "Convex-Hosting-Mark"; + +/** The path of that request, which names it in logs; the header alone decides. */ +export const MARK_PATH = "/.convex-hosting/mark"; + /** * The static assets of one version, as `.convex-hosting/version.js` exports them under `assets`, * Cloudflare's name for them: the version's id, and everything that serving reads, so that a @@ -21,6 +30,11 @@ export type Assets = { /** `ASSETS_FORMAT` of the release that wrote it. */ format: number; versionId: string; + /** + * The CLI sends it after the push, so that only the CLI makes the served code mark its version + * live; another request with the header pays nothing more than any other request. + */ + markToken: string; files: AssetFiles | null; }; diff --git a/packages/convex-hosting/src/client/version-module.d.ts b/packages/convex-hosting/src/client/version-module.d.ts index 7da0271e..6b549ecc 100644 --- a/packages/convex-hosting/src/client/version-module.d.ts +++ b/packages/convex-hosting/src/client/version-module.d.ts @@ -2,6 +2,5 @@ // fresh clone, before its first deploy. Script file on purpose: a wildcard module name is only allowed // in an ambient context. declare module "*/.convex-hosting/version.js" { - export const versionId: string; export const assets: import("./manifest.js").Assets; } diff --git a/packages/convex-hosting/src/component/_generated/component.ts b/packages/convex-hosting/src/component/_generated/component.ts index 638c09a1..44e4f586 100644 --- a/packages/convex-hosting/src/component/_generated/component.ts +++ b/packages/convex-hosting/src/component/_generated/component.ts @@ -22,4 +22,14 @@ import type { FunctionReference } from "convex/server"; * ``` */ export type ComponentApi = - {}; + { + lib: { + markLive: FunctionReference< + "mutation", + "internal", + { versionId: string }, + "marked" | "live" | "superseded" | "uploading" | "deleting" | "missing", + Name + >; + }; + }; diff --git a/packages/convex-hosting/src/component/lib.test.ts b/packages/convex-hosting/src/component/lib.test.ts index e28fb2e9..196512dc 100644 --- a/packages/convex-hosting/src/component/lib.test.ts +++ b/packages/convex-hosting/src/component/lib.test.ts @@ -3,7 +3,7 @@ import { convexTest } from "convex-test"; import { afterEach, describe, expect, test, vi } from "vite-plus/test"; import type { Id } from "./_generated/dataModel.js"; import type { Config } from "./lib.js"; -import { internal } from "./_generated/api.js"; +import { api, internal } from "./_generated/api.js"; import schema from "./schema.js"; const modules = import.meta.glob(["./**/*.ts", "!./**/*.test.ts"]); @@ -72,7 +72,7 @@ const site: Files = { }; async function markLive(t: ReturnType, versionId: string) { - return await t.mutation(internal.lib.markLive, { versionId }); + return await t.mutation(api.lib.markLive, { versionId }); } /** The kind of each version's state, and the number of `collect` chains that `markLive` started. */ diff --git a/packages/convex-hosting/src/component/lib.ts b/packages/convex-hosting/src/component/lib.ts index a9be1a98..de36eb89 100644 --- a/packages/convex-hosting/src/component/lib.ts +++ b/packages/convex-hosting/src/component/lib.ts @@ -7,6 +7,7 @@ import { internalAction, internalMutation, internalQuery, + mutation, type QueryCtx, } from "./_generated/server.js"; @@ -232,17 +233,19 @@ export const finishVersion = internalMutation({ }); /** - * Marks a `ready` version `live` and schedules `collect`, and says what it did. The CLI calls it - * after the push that serves the version. An older upload never goes live over a newer one: the - * mark does nothing when a live version was created after this one, so `collect` cannot delete the - * new version's files. A version that is already live stays as it is, so a repeated mark is fine. - * It never throws, so the CLI reads every outcome from the answer. + * Marks a `ready` version `live` and schedules `collect`, and says what it did. `serveSite` calls + * it for the request that the CLI sends after the push, with the site's mark token, so only the + * code that serves marks its own version. An older upload never goes live over a newer one: the + * mark does nothing when a live version was created after this one. So a request that runs on + * replaced code cannot make the old version newest, and `collect` cannot delete the new version's + * files. A version that is already live stays as it is, so a repeated mark is fine. It never + * throws, so the CLI reads every outcome from the answer. * * Precondition: deploys to one deployment do not overlap. When two overlap and the older upload is - * pushed last, its mark is refused: its version serves but stays `ready`, and nothing is deleted - * until the next deploy. + * pushed last, its mark is refused like a mark of replaced code: its version serves but stays + * `ready`, and nothing is deleted until the next deploy. */ -export const markLive = internalMutation({ +export const markLive = mutation({ args: { versionId: v.string() }, returns: v.union( /** It was `ready` and is now the newest live version. */ diff --git a/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts b/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts index 1712d14f..978d2962 100644 --- a/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts +++ b/packages/convex-hosting/src/workers-sdk/fixtures/shared/src/run-wrangler-long-lived.ts @@ -95,11 +95,12 @@ export default app; join(project, "convex/http.ts"), `import { httpRouter } from "convex/server"; import { routeAll } from "@samebase/convex-hosting"; +import { components } from "./_generated/api.js"; import { assets } from "../.convex-hosting/version.js"; const http = httpRouter(); -routeAll({ http, assets }); +routeAll({ http, component: components.hosting, assets }); export default http; `, From 55f41d6d07f3e961b8917198dd1d684e6a9308ce Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 19:38:35 +0200 Subject: [PATCH 17/20] Run every order of overlapping deploys on the real component and serving 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. --- docs/design.md | 17 +- .../convex-hosting/src/client/overlap.test.ts | 205 ++++++++++++++++++ packages/convex-hosting/src/component/lib.ts | 3 +- 3 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 packages/convex-hosting/src/client/overlap.test.ts diff --git a/docs/design.md b/docs/design.md index 3c402fdc..cfe19052 100644 --- a/docs/design.md +++ b/docs/design.md @@ -43,8 +43,9 @@ may follow its upload, and it is the only time constant in the design. The precondition: deploys to one deployment do not overlap. When two overlap and the older upload is pushed last, its mark is refused like a mark of replaced code: its version serves, but it never -becomes live, and nothing is deleted until the next deploy. So run one deploy at a time per -deployment; the example workflows queue them, with one `concurrency` group per deployment. +becomes live, and nothing is deleted until the next deploy, but for one order in "Stated, not +solved". So run one deploy at a time per deployment; the example workflows queue them, with one +`concurrency` group per deployment. ## Deploy @@ -347,6 +348,7 @@ convex-test run of the exact order of transactions; "runtime" is a run against a | A deploy pushes; the CLI's mark reaches the new code | The version is marked live; the versions live before it are deleted | Component test, runtime | | Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | | Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy | Component test (stale request) | +| Two deploys overlap; the newer one's mark is still running while the older one is pushed and marked | Outside the precondition. The version that serves loses its entries to the late mark; its files stay until the next switch | Stated; `overlap.test.ts` | | A mark for an older version reaches its code after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | | Two marks of one version | One mark; the second answers `live` | Component test | | Two marks in one millisecond | The second is strictly later | Component test | @@ -376,7 +378,13 @@ place for those. - Deploys to one deployment do not overlap. When two overlap and the older upload is pushed last, its mark is refused like a mark of replaced code, so its version serves but is never marked live, - and nothing is deleted until the next deploy. + and nothing is deleted until the next deploy. One order does delete: the newer upload's mark + request is still running while the older upload is pushed and marked, which takes seconds. The + older version becomes live, the late mark makes the newer one live over it, and the version that + serves loses its entries. Its stored files stay until the next switch, which follows the next + deploy's push. `src/client/overlap.test.ts` runs every order of the steps of two deploys, and of + three with each mark run as it arrives, on the real component and serving code, and finds this + order alone. - An upload that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it fails with a message that says so, and a retry works. - No `run_worker_first`, no `base_path`, no selectable compatibility date: an app that needs its @@ -419,7 +427,8 @@ are not proposed again. - **Marking live from the CLI with `npx convex run lib:markLive`.** When deploys overlap, the CLI can mark a version whose code does not serve, and the mark deletes the files of the code that does. The mark request reaches the code that serves, and its token makes only that deploy's code - mark. + mark. `src/client/overlap.test.ts` runs an order of two deploys in which the CLI's mark deletes + the entries of the version that serves, with no request still running. - **Marking live on a random share of requests.** It kept the mark in the serving code for about one call per hundred requests, but a site with little traffic would keep its old versions for days, and every request would pay the draw. diff --git a/packages/convex-hosting/src/client/overlap.test.ts b/packages/convex-hosting/src/client/overlap.test.ts new file mode 100644 index 00000000..ec0cc77e --- /dev/null +++ b/packages/convex-hosting/src/client/overlap.test.ts @@ -0,0 +1,205 @@ +/// +import { convexTest } from "convex-test"; +import { anyApi, httpRouter, type FunctionReference } from "convex/server"; +import { afterEach, describe, expect, test, vi } from "vite-plus/test"; +import { api, internal } from "../component/_generated/api.js"; +import type { Id } from "../component/_generated/dataModel.js"; +import schema from "../component/schema.js"; +import { routeAll } from "./index.js"; +import { ASSETS_FORMAT, MARK_HEADER, MARK_PATH, type Assets } from "./manifest.js"; + +const modules = import.meta.glob(["../component/**/*.ts", "!../component/**/*.test.ts"]); +const component = { lib: { markLive: anyApi.lib.markLive } }; +const DAY = 24 * 60 * 60 * 1000; + +/** + * The steps of a deploy that other deploys can come between. The mark is two: the request arrives + * at the code that serves at that moment, and the `markLive` that this code calls runs later, when + * other code may serve. + */ +const STEPS = ["upload", "push", "mark arrives", "mark runs"] as const; + +/** A call of `markLive` that is on its way. */ +type Call = { versionId: string }; + +/** What an upload leaves: the version file that the deploy pushes, and its stored files. */ +type Uploaded = { assets: Assets; storageIds: Id<"_storage">[] }; + +/** + * Every order of the steps of the deploys in `names`. An order names the deploy of each step. The + * uploads start in the order of `names`, which only names the deploys by creation time. With + * `atOnce`, every mark runs as it arrives, which leaves few enough orders for three deploys. + */ +function orders(names: string, atOnce: boolean, order = ""): string[] { + if (order.length === names.length * STEPS.length) return [order]; + const done = (name: string) => order.split(name).length - 1; + const last = order[order.length - 1]; + const next = + atOnce && last !== undefined && done(last) === 3 + ? [last] + : names + .split("") + .filter((name, i) => done(name) < STEPS.length && (i === 0 || done(names[i - 1]!) > 0)); + return next.flatMap((name) => orders(names, atOnce, order + name)); +} + +async function sha256Hex(body: string) { + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); + return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); +} + +type Run = { + /** The deploy of each step. */ + order: string; + /** + * `minutes`: a second passes after every step. `days`: a day passes after every step at which no + * deploy is between its upload and its push or has a mark on its way, the most that the + * precondition allows, so every file and every version that never became live is old enough to + * delete. + */ + pace: "minutes" | "days"; + /** + * Who marks a version live. `request` is the design: the deploy's request with its mark token, + * answered by the code that serves. `cli` is the rejected one: the deploy's own call of + * `markLive`. + */ + markBy: "request" | "cli"; +}; + +/** + * Runs the deploys on the real component and the real serving code, over a version `p` that was + * deployed a day before, and returns the first step after which the version that serves lacks an + * entry or a stored file, or `null`. A stored file goes only after its entries, at a later switch, + * so the entries are checked too. + */ +async function firstLoss({ order, pace, markBy }: Run) { + vi.useFakeTimers(); + const t = convexTest(schema, modules); + + /** The upload of a page that every version has, stored once, and a script of this version. */ + const upload = async (versionId: string): Promise => { + const configId = await t.run((ctx) => ctx.storage.store(new Blob(["{}"]))); + await t.action(internal.lib.createVersion, { versionId, configId }); + const entries = []; + for (const [path, body] of [ + ["/index.html", "

Home

"], + ["/assets/app.js", versionId], + ] as const) { + const sha256 = await sha256Hex(body); + const [known] = await t.query(internal.lib.knownFiles, { sha256s: [sha256] }); + const storageId = + known?.storageId ?? (await t.run((ctx) => ctx.storage.store(new Blob([body])))); + entries.push({ path, sha256, storageId }); + } + await t.mutation(internal.lib.recordFiles, { versionId, entries }); + await t.mutation(internal.lib.finishVersion, { versionId }); + return { + // The mark reads the id and the token alone. + assets: { format: ASSETS_FORMAT, versionId, markToken: `token of ${versionId}`, files: null }, + storageIds: entries.map(({ storageId }) => storageId), + }; + }; + + /** The call of `markLive` that the mark of `deploy` makes when `serving` is the code that serves. */ + const markArrives = async (deploy: Assets, serving: Assets): Promise => { + if (markBy === "cli") return { versionId: deploy.versionId }; + let call: Call | undefined; + const runMutation = async (_: FunctionReference<"mutation">, args: Call) => { + call = args; + return "marked"; + }; + const action = routeAll({ http: httpRouter(), component, assets: serving }); + const request = new Request(`https://example.convex.site${MARK_PATH}`, { + method: "POST", + headers: { [MARK_HEADER]: deploy.markToken }, + }); + // @ts-expect-error httpActionGeneric keeps the function as _handler; PublicHttpAction does not declare it. + await action._handler({ runMutation }, request); + return call; + }; + + const settle = async (pause: number) => { + await t.finishAllScheduledFunctions(vi.runAllTimers); + vi.advanceTimersByTime(pause); + }; + + let serving = await upload("p"); + await t.mutation(api.lib.markLive, { versionId: "p" }); + await settle(DAY + 1); + + const deploys = new Map(); + const steps: string[] = []; + for (const name of order) { + const deploy = deploys.get(name) ?? { ...(await upload(name)), done: 0 }; + deploys.set(name, deploy); + const step = STEPS[deploy.done++]!; + steps.push(`${step} ${name}`); + if (step === "push") serving = deploy; + if (step === "mark arrives") deploy.call = await markArrives(deploy.assets, serving.assets); + if (step === "mark runs" && deploy.call !== undefined) { + await t.mutation(api.lib.markLive, deploy.call); + } + const underway = [...deploys.values()].some(({ done }) => done === 1 || done === 3); + await settle(pace === "days" && !underway ? DAY + 1 : 1000); + + const { assets, storageIds } = serving; + const kept = await t.run(async (ctx) => { + const entries = await ctx.db + .query("entries") + .withIndex("by_version_path", (q) => q.eq("versionId", assets.versionId)) + .collect(); + const files = await Promise.all(storageIds.map((id) => ctx.db.system.get("_storage", id))); + return { entries: entries.length, files: files.filter((file) => file !== null).length }; + }); + if (kept.entries < 2 || kept.files < 2) { + return ( + `${assets.versionId} serves with ${kept.entries} of its 2 entries and ${kept.files} of ` + + `its 2 stored files: ${steps.join(", ")}` + ); + } + } + return null; +} + +afterEach(() => { + vi.useRealTimers(); +}); + +describe("deploys that overlap: the version that serves keeps its entries and its files", () => { + test.each(["minutes", "days"] as const)( + "three deploys, in every order of their steps with each mark run as it arrives, %s apart", + async (pace) => { + for (const order of orders("abc", true)) { + expect(await firstLoss({ order, pace, markBy: "request" })).toBeNull(); + } + }, + ); + + test.each(["minutes", "days"] as const)( + "two deploys, in every order of their steps, %s apart, but for the one order that is stated", + async (pace) => { + const losses = []; + for (const order of orders("ab", false)) { + const loss = await firstLoss({ order, pace, markBy: "request" }); + if (loss !== null) losses.push(loss); + } + // "Stated, not solved" in docs/design.md: the newer upload's mark is still on its way while + // the older upload is pushed and marked. + expect(losses).toEqual([ + "a serves with 0 of its 2 entries and 2 of its 2 stored files: upload a, upload b, " + + "push b, mark arrives b, push a, mark arrives a, mark runs a, mark runs b", + ]); + }, + ); + + test("marked from the CLI instead, a version that serves loses its entries with no mark on its way", async () => { + // The older upload is pushed last, so a serves. Each deploy's own call marks its version, and + // b's mark deletes a as the version that was live before it. + const run = { order: "abbaaabb", pace: "minutes" } as const; + expect(await firstLoss({ ...run, markBy: "cli" })).toBe( + "a serves with 0 of its 2 entries and 2 of its 2 stored files: upload a, upload b, " + + "push b, push a, mark arrives a, mark runs a, mark arrives b, mark runs b", + ); + expect(await firstLoss({ ...run, markBy: "request" })).toBeNull(); + }); +}); diff --git a/packages/convex-hosting/src/component/lib.ts b/packages/convex-hosting/src/component/lib.ts index de36eb89..f6a55265 100644 --- a/packages/convex-hosting/src/component/lib.ts +++ b/packages/convex-hosting/src/component/lib.ts @@ -243,7 +243,8 @@ export const finishVersion = internalMutation({ * * Precondition: deploys to one deployment do not overlap. When two overlap and the older upload is * pushed last, its mark is refused like a mark of replaced code: its version serves but stays - * `ready`, and nothing is deleted until the next deploy. + * `ready`, and nothing is deleted until the next deploy. The one order that deletes, a mark still + * running across the other deploy's push and mark, is in `docs/design.md`, "Stated, not solved". */ export const markLive = mutation({ args: { versionId: v.string() }, From 261947685b3e725f45fb42f907f2b4572d2df16a Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 20:19:47 +0200 Subject: [PATCH 18/20] State that the overlap order can also delete a stored file 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. --- docs/design.md | 12 +++++++----- packages/convex-hosting/src/client/overlap.test.ts | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/design.md b/docs/design.md index cfe19052..31df8361 100644 --- a/docs/design.md +++ b/docs/design.md @@ -348,7 +348,7 @@ convex-test run of the exact order of transactions; "runtime" is a run against a | A deploy pushes; the CLI's mark reaches the new code | The version is marked live; the versions live before it are deleted | Component test, runtime | | Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | | Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy | Component test (stale request) | -| Two deploys overlap; the newer one's mark is still running while the older one is pushed and marked | Outside the precondition. The version that serves loses its entries to the late mark; its files stay until the next switch | Stated; `overlap.test.ts` | +| Two deploys overlap; the newer one's mark is still running while the older one is pushed and marked | Outside the precondition. The version that serves loses its entries to the late mark, and a day-old file if the two cleanups interleave | Stated; `overlap.test.ts` | | A mark for an older version reaches its code after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | | Two marks of one version | One mark; the second answers `live` | Component test | | Two marks in one millisecond | The second is strictly later | Component test | @@ -381,10 +381,12 @@ place for those. and nothing is deleted until the next deploy. One order does delete: the newer upload's mark request is still running while the older upload is pushed and marked, which takes seconds. The older version becomes live, the late mark makes the newer one live over it, and the version that - serves loses its entries. Its stored files stay until the next switch, which follows the next - deploy's push. `src/client/overlap.test.ts` runs every order of the steps of two deploys, and of - three with each mark run as it arrives, on the real component and serving code, and finds this - order alone. + serves loses its entries. Its stored files stay, unless the two marks' cleanups interleave: 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. `src/client/overlap.test.ts` + runs every order of the steps of two deploys, and of three with each mark run as it arrives, on + the real component and serving code, each `collect` run to its end before the next step, and finds + this order alone. - An upload that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it fails with a message that says so, and a retry works. - No `run_worker_first`, no `base_path`, no selectable compatibility date: an app that needs its diff --git a/packages/convex-hosting/src/client/overlap.test.ts b/packages/convex-hosting/src/client/overlap.test.ts index ec0cc77e..2ced1305 100644 --- a/packages/convex-hosting/src/client/overlap.test.ts +++ b/packages/convex-hosting/src/client/overlap.test.ts @@ -69,8 +69,8 @@ type Run = { /** * Runs the deploys on the real component and the real serving code, over a version `p` that was * deployed a day before, and returns the first step after which the version that serves lacks an - * entry or a stored file, or `null`. A stored file goes only after its entries, at a later switch, - * so the entries are checked too. + * entry or a stored file, or `null`. A stored file goes only after its entries, so the entries are + * checked too. Every `collect` chain runs to its end before the next step. */ async function firstLoss({ order, pace, markBy }: Run) { vi.useFakeTimers(); From ef74582367904bb4ba9e9407baf402fad68a18c9 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 21:10:00 +0200 Subject: [PATCH 19/20] A mark carries its arrival time, and a late one is refused 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. --- docs/design.md | 64 ++--- packages/convex-hosting/CHANGELOG.md | 4 +- packages/convex-hosting/src/cli/main.ts | 2 +- packages/convex-hosting/src/client/index.ts | 7 +- .../convex-hosting/src/client/overlap.test.ts | 253 ++++++++++++------ .../src/component/_generated/component.ts | 2 +- .../convex-hosting/src/component/lib.test.ts | 20 +- packages/convex-hosting/src/component/lib.ts | 31 ++- 8 files changed, 250 insertions(+), 133 deletions(-) diff --git a/docs/design.md b/docs/design.md index 31df8361..f25699ed 100644 --- a/docs/design.md +++ b/docs/design.md @@ -32,20 +32,21 @@ bytes of a file from storage. Only the pushed code knows which version a deployment runs, so the serving code reports it: after the push, the CLI sends one request with the version's mark token, which only that version's code holds, and the code that answers marks its version `live`. An older upload never goes live over a -newer one: a version is marked only when no live version was created after it, so a request still -running on replaced code cannot take the site back. Marking a version live deletes the versions that -were live before it, because their code is gone by definition. Nothing is deleted by the clock -alone: deletion runs only at a switch, when a new version becomes live, so a version stays intact -until a newer one has served. At a switch, a version that never became live is dead too, from a push -that failed, with one exception: a slower deploy whose push has not landed yet. So a never-live -version is deleted at a switch only when it is more than a day old; the day bounds how late a push -may follow its upload, and it is the only time constant in the design. - -The precondition: deploys to one deployment do not overlap. When two overlap and the older upload is -pushed last, its mark is refused like a mark of replaced code: its version serves, but it never -becomes live, and nothing is deleted until the next deploy, but for one order in "Stated, not -solved". So run one deploy at a time per deployment; the example workflows queue them, with one -`concurrency` group per deployment. +newer one: a version is marked only when no live version was created after it. And a mark is late +when another version went live after its request arrived: the request carries its arrival time, and +that version's code has served since. So a request still running on replaced code cannot take the +site back. Marking a version live deletes the versions that were live before it, because their code +is gone by definition. Nothing is deleted by the clock alone: deletion runs only at a switch, when a +new version becomes live, so a version stays intact until a newer one has served. At a switch, a +version that never became live is dead too, from a push that failed, with one exception: a slower +deploy whose push has not landed yet. So a never-live version is deleted at a switch only when it is +more than a day old; the day bounds how late a push may follow its upload, and it is the only time +constant in the design. + +The precondition: deploys to one deployment do not overlap. When two overlap, the mark of the +version that serves may be refused: it then serves without being live. Its files stay, within the +two limits in "Stated, not solved". So run one deploy at a time per deployment; the example +workflows queue them, with one `concurrency` group per deployment. ## Deploy @@ -280,11 +281,11 @@ uploaded yet. A `null` asset means one thing: no asset matched, and `worker` ans A request with the header `Convex-Hosting-Mark` set to the site's mark token is the CLI's mark: before anything else, `serveSite` calls `markLive` for its version and answers the result as JSON, with `Cache-Control: no-store`. `markLive` marks the version only when no live version was created -after it, inside its own transaction, so code that was replaced cannot make its version newest, and -a repeated mark changes nothing. It never throws: it answers `marked`, `live`, `superseded`, -`uploading`, `deleting`, or `missing`, and the CLI reports the last four. That is the only write the -serving path ever makes, once per deploy. Any other request, with another token or none, calls no -function. +after it and none went live after the request arrived, inside its own transaction, so code that was +replaced cannot make its version newest, and a repeated mark changes nothing. It never throws: it +answers `marked`, `live`, `superseded`, `uploading`, `deleting`, or `missing`, and the CLI reports +the last four. That is the only write the serving path ever makes, once per deploy. Any other +request, with another token or none, calls no function. `markLive` is the component's only public function, because `serveSite` runs in the app and an app can call only a component's public functions; clients cannot call it at all. The CLI calls the other @@ -348,7 +349,7 @@ convex-test run of the exact order of transactions; "runtime" is a run against a | A deploy pushes; the CLI's mark reaches the new code | The version is marked live; the versions live before it are deleted | Component test, runtime | | Two deploys overlap; the pushes land in creation order | Both complete; the last push's version is marked live by its deploy's mark; the other was never live and goes at a later switch when a day old | Component test (age rule) | | Two deploys overlap; the earlier-created one pushes last | Outside the precondition. Its version serves but is never marked, because the other is newer and live; nothing is deleted until the next deploy | Component test (stale request) | -| Two deploys overlap; the newer one's mark is still running while the older one is pushed and marked | Outside the precondition. The version that serves loses its entries to the late mark, and a day-old file if the two cleanups interleave | Stated; `overlap.test.ts` | +| Two deploys overlap; the newer one's mark is still running while the older one is pushed and marked | The late mark is refused, because a version went live after its request arrived; the version that serves stays live | Component test, `overlap.test.ts` | | A mark for an older version reaches its code after the new version was marked, from an overlapping deploy | Its version is older than the live one, so the mark answers `superseded`; the new version stays live and keeps its files | Component test, CLI test | | Two marks of one version | One mark; the second answers `live` | Component test | | Two marks in one millisecond | The second is strictly later | Component test | @@ -376,17 +377,16 @@ place for those. ## Stated, not solved -- Deploys to one deployment do not overlap. When two overlap and the older upload is pushed last, - its mark is refused like a mark of replaced code, so its version serves but is never marked live, - and nothing is deleted until the next deploy. One order does delete: the newer upload's mark - request is still running while the older upload is pushed and marked, which takes seconds. The - older version becomes live, the late mark makes the newer one live over it, and the version that - serves loses its entries. Its stored files stay, unless the two marks' cleanups interleave: 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. `src/client/overlap.test.ts` - runs every order of the steps of two deploys, and of three with each mark run as it arrives, on - the real component and serving code, each `collect` run to its end before the next step, and finds - this order alone. +- Deploys to one deployment do not overlap. When two overlap, the mark of the version that serves + may be refused, so it serves without being live and nothing is deleted until the next deploy. + `src/client/overlap.test.ts` runs the deploys on the real component and serving code, and the + version that serves keeps its entries and its files in every order of two deploys' steps and + `collect` calls, every order of three deploys' steps, and random orders of three with their + `collect` calls. Two limits remain, both with overlapping deploys only. The arrival time is read + in the HTTP action and compared with a time set in the mutation, so a late mark is refused as far + as those two clocks agree. And the day is a bound, not a margin: 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. - An upload that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it fails with a message that says so, and a retry works. - No `run_worker_first`, no `base_path`, no selectable compatibility date: an app that needs its @@ -450,7 +450,7 @@ are not proposed again. between a request's lookup and its mark, not the gap between the request's start and its lookup: a request on replaced code whose lookup came after the new code's first mark passed it, made its old version newest, and `collect` deleted the new version's files. Creation order decides the mark - instead, and deploys that do not overlap are the precondition. + instead, with the arrival time of the mark's request, which needs no lookup. - **A committed version file in `convex/`.** Its value is set by the deploy that pushes it, so the committed value is never used by a correct deploy; it left stale ids and merge conflicts in git, and a plain `npx convex deploy` from a clean checkout would push a stale id and take the site diff --git a/packages/convex-hosting/CHANGELOG.md b/packages/convex-hosting/CHANGELOG.md index 6ffd60e5..b7631b4e 100644 --- a/packages/convex-hosting/CHANGELOG.md +++ b/packages/convex-hosting/CHANGELOG.md @@ -24,7 +24,9 @@ - After the push, `deploy` sends one request with the version's mark token, and the code that answers marks its version live; before, the first request did. `markLive` answers what it did and - never throws. + never throws. It takes the time the request arrived and refuses a mark when another version went + live after it: a mark that was still running when another deploy's push and mark landed deleted + the entries of the version that serves. - A first install pushes twice: once to install the component, and once after the upload, to serve the site. - A version file uploaded to another deployment, such as production's pushed to development by a diff --git a/packages/convex-hosting/src/cli/main.ts b/packages/convex-hosting/src/cli/main.ts index d27ece78..b78cff83 100644 --- a/packages/convex-hosting/src/cli/main.ts +++ b/packages/convex-hosting/src/cli/main.ts @@ -598,7 +598,7 @@ async function markServedVersion( const { result } = parsed.data; if (result === "superseded") { cli.log( - `A version created after ${site.versionId} is live, so a deploy overlapped this one; ${later}`, + `Another version went live over ${site.versionId}, so a deploy overlapped this one; ${later}`, ); } else if (result !== "marked" && result !== "live") { cli.log(`Version ${site.versionId} could not be marked live: it is ${result}.`); diff --git a/packages/convex-hosting/src/client/index.ts b/packages/convex-hosting/src/client/index.ts index 464896a7..0cdb10e0 100644 --- a/packages/convex-hosting/src/client/index.ts +++ b/packages/convex-hosting/src/client/index.ts @@ -43,6 +43,8 @@ export type RouteAllOptions = { */ function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAction { return httpActionGeneric(async (ctx, request) => { + // Read first: a mark says when its request reached this code. + const arrivedAt = Date.now(); if (assets.format !== ASSETS_FORMAT) { return notServed( 500, @@ -51,7 +53,10 @@ function serveSite({ component, assets, worker }: RouteAllOptions): PublicHttpAc ); } if (request.headers.get(MARK_HEADER) === assets.markToken) { - const result = await ctx.runMutation(component.lib.markLive, { versionId: assets.versionId }); + const result = await ctx.runMutation(component.lib.markLive, { + versionId: assets.versionId, + arrivedAt, + }); return Response.json({ versionId: assets.versionId, result }, { headers: NO_STORE }); } const { files } = assets; diff --git a/packages/convex-hosting/src/client/overlap.test.ts b/packages/convex-hosting/src/client/overlap.test.ts index 2ced1305..d3e83f55 100644 --- a/packages/convex-hosting/src/client/overlap.test.ts +++ b/packages/convex-hosting/src/client/overlap.test.ts @@ -1,6 +1,7 @@ /// import { convexTest } from "convex-test"; import { anyApi, httpRouter, type FunctionReference } from "convex/server"; +import fc from "fast-check"; import { afterEach, describe, expect, test, vi } from "vite-plus/test"; import { api, internal } from "../component/_generated/api.js"; import type { Id } from "../component/_generated/dataModel.js"; @@ -20,44 +21,22 @@ const DAY = 24 * 60 * 60 * 1000; const STEPS = ["upload", "push", "mark arrives", "mark runs"] as const; /** A call of `markLive` that is on its way. */ -type Call = { versionId: string }; +type Call = { versionId: string; arrivedAt: number }; /** What an upload leaves: the version file that the deploy pushes, and its stored files. */ type Uploaded = { assets: Assets; storageIds: Id<"_storage">[] }; -/** - * Every order of the steps of the deploys in `names`. An order names the deploy of each step. The - * uploads start in the order of `names`, which only names the deploys by creation time. With - * `atOnce`, every mark runs as it arrives, which leaves few enough orders for three deploys. - */ -function orders(names: string, atOnce: boolean, order = ""): string[] { - if (order.length === names.length * STEPS.length) return [order]; - const done = (name: string) => order.split(name).length - 1; - const last = order[order.length - 1]; - const next = - atOnce && last !== undefined && done(last) === 3 - ? [last] - : names - .split("") - .filter((name, i) => done(name) < STEPS.length && (i === 0 || done(names[i - 1]!) > 0)); - return next.flatMap((name) => orders(names, atOnce, order + name)); -} - -async function sha256Hex(body: string) { - const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); - return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); -} - type Run = { - /** The deploy of each step. */ - order: string; /** - * `minutes`: a second passes after every step. `days`: a day passes after every step at which no - * deploy is between its upload and its push or has a mark on its way, the most that the - * precondition allows, so every file and every version that never became live is old enough to - * delete. + * Picks what happens next among what can happen now, or nothing to end the run: a deploy's name + * for its next step, `cleanup N` for the next call of the Nth `collect` chain that waits, or `a + * day passes`. A day can pass when no deploy is between its upload and its push, no mark is on + * its way, and no `collect` waits: the day bounds how late a push may follow its upload, and the + * rest takes seconds. */ - pace: "minutes" | "days"; + pick: (events: string[]) => string | undefined; + /** The deploys that build the commit that serves, so their script is `p`'s, a day old. */ + rebuilds: string[]; /** * Who marks a version live. `request` is the design: the deploy's request with its mark token, * answered by the code that serves. `cli` is the rejected one: the deploy's own call of @@ -67,25 +46,29 @@ type Run = { }; /** - * Runs the deploys on the real component and the real serving code, over a version `p` that was - * deployed a day before, and returns the first step after which the version that serves lacks an - * entry or a stored file, or `null`. A stored file goes only after its entries, so the entries are - * checked too. Every `collect` chain runs to its end before the next step. + * Runs deploys a, b and c on the real component and the real serving code, over a version `p` that + * was deployed a day before, and returns the first event after which the version that serves lacks + * an entry or a stored file, or `null`. A stored file goes only after its entries, so the entries + * are checked too. */ -async function firstLoss({ order, pace, markBy }: Run) { +async function firstLoss({ pick, rebuilds, markBy }: Run) { vi.useFakeTimers(); const t = convexTest(schema, modules); - /** The upload of a page that every version has, stored once, and a script of this version. */ + /** The upload of a page that every commit has, stored once, and the commit's script. */ const upload = async (versionId: string): Promise => { const configId = await t.run((ctx) => ctx.storage.store(new Blob(["{}"]))); await t.action(internal.lib.createVersion, { versionId, configId }); + const commit = rebuilds.includes(versionId) ? "p" : versionId; const entries = []; for (const [path, body] of [ ["/index.html", "

Home

"], - ["/assets/app.js", versionId], + ["/assets/app.js", commit], ] as const) { - const sha256 = await sha256Hex(body); + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body)); + const sha256 = Array.from(new Uint8Array(digest), (byte) => + byte.toString(16).padStart(2, "0"), + ).join(""); const [known] = await t.query(internal.lib.knownFiles, { sha256s: [sha256] }); const storageId = known?.storageId ?? (await t.run((ctx) => ctx.storage.store(new Blob([body])))); @@ -102,7 +85,7 @@ async function firstLoss({ order, pace, markBy }: Run) { /** The call of `markLive` that the mark of `deploy` makes when `serving` is the code that serves. */ const markArrives = async (deploy: Assets, serving: Assets): Promise => { - if (markBy === "cli") return { versionId: deploy.versionId }; + if (markBy === "cli") return { versionId: deploy.versionId, arrivedAt: Date.now() }; let call: Call | undefined; const runMutation = async (_: FunctionReference<"mutation">, args: Call) => { call = args; @@ -118,29 +101,59 @@ async function firstLoss({ order, pace, markBy }: Run) { return call; }; - const settle = async (pause: number) => { - await t.finishAllScheduledFunctions(vi.runAllTimers); - vi.advanceTimersByTime(pause); + /** + * The `collect` calls that wait, oldest first. The clock moves without running the timers, so + * the scheduled calls never start by themselves: the run picks when each one does. + */ + const waiting: { step: (typeof internal.lib.collect)["_args"]["step"] }[] = []; + const seen = new Set(); + const readScheduled = async () => { + const jobs = await t.run((ctx) => ctx.db.system.query("_scheduled_functions").collect()); + for (const job of jobs) { + if (!seen.has(job._id)) waiting.push({ step: job.args[0].step }); + seen.add(job._id); + } }; let serving = await upload("p"); - await t.mutation(api.lib.markLive, { versionId: "p" }); - await settle(DAY + 1); + await t.mutation(api.lib.markLive, { versionId: "p", arrivedAt: Date.now() }); + for (await readScheduled(); waiting.length > 0; await readScheduled()) { + await t.mutation(internal.lib.collect, waiting.shift()!); + } + vi.setSystemTime(Date.now() + DAY + 1); const deploys = new Map(); - const steps: string[] = []; - for (const name of order) { - const deploy = deploys.get(name) ?? { ...(await upload(name)), done: 0 }; - deploys.set(name, deploy); - const step = STEPS[deploy.done++]!; - steps.push(`${step} ${name}`); - if (step === "push") serving = deploy; - if (step === "mark arrives") deploy.call = await markArrives(deploy.assets, serving.assets); - if (step === "mark runs" && deploy.call !== undefined) { - await t.mutation(api.lib.markLive, deploy.call); + const done = (name: string) => deploys.get(name)?.done ?? 0; + const happened: string[] = []; + for (;;) { + const underway = [...deploys.values()].some((deploy) => deploy.done === 1 || deploy.done === 3); + const event = pick([ + ...["a", "b", "c"].filter((name) => done(name) < STEPS.length), + ...waiting.map((_, i) => `cleanup ${i + 1}`), + ...(underway || waiting.length > 0 ? [] : ["a day passes"]), + ]); + if (event === undefined) return null; + + if (event === "a day passes") { + vi.setSystemTime(Date.now() + DAY); + happened.push(event); + } else if (event.startsWith("cleanup ")) { + const [call] = waiting.splice(Number(event.slice("cleanup ".length)) - 1, 1); + await t.mutation(internal.lib.collect, call!); + happened.push(`cleanup of ${call!.step.kind}`); + } else { + const deploy = deploys.get(event) ?? { ...(await upload(event)), done: 0 }; + deploys.set(event, deploy); + const step = STEPS[deploy.done++]!; + happened.push(`${step} ${event}`); + if (step === "push") serving = deploy; + if (step === "mark arrives") deploy.call = await markArrives(deploy.assets, serving.assets); + if (step === "mark runs" && deploy.call !== undefined) { + await t.mutation(api.lib.markLive, deploy.call); + } } - const underway = [...deploys.values()].some(({ done }) => done === 1 || done === 3); - await settle(pace === "days" && !underway ? DAY + 1 : 1000); + await readScheduled(); + vi.setSystemTime(Date.now() + 1000); const { assets, storageIds } = serving; const kept = await t.run(async (ctx) => { @@ -154,11 +167,72 @@ async function firstLoss({ order, pace, markBy }: Run) { if (kept.entries < 2 || kept.files < 2) { return ( `${assets.versionId} serves with ${kept.entries} of its 2 entries and ${kept.files} of ` + - `its 2 stored files: ${steps.join(", ")}` + `its 2 stored files: ${happened.join(", ")}` ); } } - return null; +} + +type Orders = { + /** The deploys that run, named in the order of their uploads. */ + deploys: string; + /** A day passes after every event that allows one, so everything is old enough to delete. */ + days: boolean; + /** + * Every mark runs as it arrives and every `collect` chain runs to its end before the next step, + * which leaves few enough orders for three deploys. + */ + atOnce: boolean; + markBy: Run["markBy"]; +}; + +/** + * Runs every order in which the deploys' steps and the calls of `collect` can happen, and returns + * the runs that lost something, with the number of runs. It walks the tree of choices: each run + * repeats the choices of the one before up to the deepest choice that has another option, and + * takes that one. + */ +async function everyOrder({ deploys, days, atOnce, markBy }: Orders) { + const losses: string[] = []; + const path: number[] = []; + let runs = 0; + do { + const sizes: number[] = []; + const steps = new Map(); + let rested = true; + let last: string | undefined; + const pick: Run["pick"] = (events) => { + if (days && !rested && events.includes("a day passes")) { + rested = true; + return "a day passes"; + } + rested = false; + const taken = (name: string) => steps.get(name) ?? 0; + const step = (name: string) => { + steps.set(name, taken(name) + 1); + last = name; + return name; + }; + if (atOnce && events.includes("cleanup 1")) return "cleanup 1"; + if (atOnce && last !== undefined && taken(last) === 3) return step(last); + // The uploads start in the order of `deploys`, which only names them by creation time. + const choices = events.filter((event) => { + const i = deploys.indexOf(event); + return event.startsWith("cleanup") || i === 0 || (i > 0 && taken(deploys[i - 1]!) > 0); + }); + if (choices.length === 0) return undefined; + const depth = sizes.push(choices.length) - 1; + const choice = choices[(path[depth] ??= 0)]!; + return choice.startsWith("cleanup") ? choice : step(choice); + }; + const loss = await firstLoss({ pick, rebuilds: [], markBy }); + if (loss !== null) losses.push(loss); + runs++; + path.length = sizes.length; + while (path.length > 0 && path[path.length - 1]! + 1 >= sizes[path.length - 1]!) path.pop(); + if (path.length > 0) path[path.length - 1]!++; + } while (path.length > 0); + return { runs, losses }; } afterEach(() => { @@ -166,40 +240,51 @@ afterEach(() => { }); describe("deploys that overlap: the version that serves keeps its entries and its files", () => { - test.each(["minutes", "days"] as const)( - "three deploys, in every order of their steps with each mark run as it arrives, %s apart", - async (pace) => { - for (const order of orders("abc", true)) { - expect(await firstLoss({ order, pace, markBy: "request" })).toBeNull(); - } + test.each([false, true])( + "two deploys, their steps and every call of collect in every order (a day between them: %s)", + async (days) => { + const orders = { deploys: "ab", days, atOnce: false, markBy: "request" } as const; + expect(await everyOrder(orders)).toEqual({ runs: 221, losses: [] }); }, + 60_000, ); - test.each(["minutes", "days"] as const)( - "two deploys, in every order of their steps, %s apart, but for the one order that is stated", - async (pace) => { - const losses = []; - for (const order of orders("ab", false)) { - const loss = await firstLoss({ order, pace, markBy: "request" }); - if (loss !== null) losses.push(loss); - } - // "Stated, not solved" in docs/design.md: the newer upload's mark is still on its way while - // the older upload is pushed and marked. - expect(losses).toEqual([ - "a serves with 0 of its 2 entries and 2 of its 2 stored files: upload a, upload b, " + - "push b, mark arrives b, push a, mark arrives a, mark runs a, mark runs b", - ]); + test.each([false, true])( + "three deploys, their steps in every order, each mark and collect run at once (a day between them: %s)", + async (days) => { + const orders = { deploys: "abc", days, atOnce: true, markBy: "request" } as const; + expect(await everyOrder(orders)).toEqual({ runs: 280, losses: [] }); }, + 60_000, ); + test("three deploys, their steps and every call of collect in any order, days between them or not", async () => { + await fc.assert( + fc.asyncProperty( + // Always 40 events: enough for the three deploys and their collect calls. + fc.array(fc.nat(), { minLength: 40, maxLength: 40 }), + fc.subarray(["a", "b", "c"]), + async (picks, rebuilds) => { + let taken = 0; + const pick: Run["pick"] = (events) => + taken < picks.length ? events[picks[taken++]! % events.length] : undefined; + expect(await firstLoss({ pick, rebuilds, markBy: "request" })).toBeNull(); + }, + ), + { numRuns: 300 }, + ); + }, 60_000); + test("marked from the CLI instead, a version that serves loses its entries with no mark on its way", async () => { + const orders = { deploys: "ab", days: false, atOnce: true } as const; + const { losses } = await everyOrder({ ...orders, markBy: "cli" }); // The older upload is pushed last, so a serves. Each deploy's own call marks its version, and // b's mark deletes a as the version that was live before it. - const run = { order: "abbaaabb", pace: "minutes" } as const; - expect(await firstLoss({ ...run, markBy: "cli" })).toBe( + expect(losses).toEqual([ "a serves with 0 of its 2 entries and 2 of its 2 stored files: upload a, upload b, " + - "push b, push a, mark arrives a, mark runs a, mark arrives b, mark runs b", - ); - expect(await firstLoss({ ...run, markBy: "request" })).toBeNull(); + "push b, push a, mark arrives a, mark runs a, cleanup of files, cleanup of versions, " + + "mark arrives b, mark runs b, cleanup of files, cleanup of versions", + ]); + expect((await everyOrder({ ...orders, markBy: "request" })).losses).toEqual([]); }); }); diff --git a/packages/convex-hosting/src/component/_generated/component.ts b/packages/convex-hosting/src/component/_generated/component.ts index 44e4f586..d925e227 100644 --- a/packages/convex-hosting/src/component/_generated/component.ts +++ b/packages/convex-hosting/src/component/_generated/component.ts @@ -27,7 +27,7 @@ export type ComponentApi = markLive: FunctionReference< "mutation", "internal", - { versionId: string }, + { arrivedAt: number; versionId: string }, "marked" | "live" | "superseded" | "uploading" | "deleting" | "missing", Name >; diff --git a/packages/convex-hosting/src/component/lib.test.ts b/packages/convex-hosting/src/component/lib.test.ts index 196512dc..d2a858e4 100644 --- a/packages/convex-hosting/src/component/lib.test.ts +++ b/packages/convex-hosting/src/component/lib.test.ts @@ -72,7 +72,7 @@ const site: Files = { }; async function markLive(t: ReturnType, versionId: string) { - return await t.mutation(api.lib.markLive, { versionId }); + return await t.mutation(api.lib.markLive, { versionId, arrivedAt: Date.now() }); } /** The kind of each version's state, and the number of `collect` chains that `markLive` started. */ @@ -222,6 +222,24 @@ describe("markLive", () => { expect((await tables(t)).entries).toContain("b/assets/app-a1.js"); }); + test("a mark whose request arrived before another version went live is late, and refused", async () => { + vi.useFakeTimers(); + const t = convexTest(schema, modules); + await uploadVersion(t, "a", site); + vi.advanceTimersByTime(1000); + await uploadVersion(t, "b", site); + // B's code serves when B's mark request arrives. Then A is pushed and marked, and B's mark + // runs last, on replaced code. + const arrivedAt = Date.now(); + vi.advanceTimersByTime(1000); + expect(await markLive(t, "a")).toBe("marked"); + vi.advanceTimersByTime(1000); + expect(await t.mutation(api.lib.markLive, { versionId: "b", arrivedAt })).toBe("superseded"); + await t.finishAllScheduledFunctions(vi.runAllTimers); + expect((await liveness(t)).versions).toEqual({ a: "live", b: "ready" }); + expect((await tables(t)).entries).toContain("a/assets/app-a1.js"); + }); + test("a mark in the same millisecond as the newest is still strictly newer", async () => { vi.useFakeTimers(); const t = convexTest(schema, modules); diff --git a/packages/convex-hosting/src/component/lib.ts b/packages/convex-hosting/src/component/lib.ts index f6a55265..0bb960a2 100644 --- a/packages/convex-hosting/src/component/lib.ts +++ b/packages/convex-hosting/src/component/lib.ts @@ -235,35 +235,42 @@ export const finishVersion = internalMutation({ /** * Marks a `ready` version `live` and schedules `collect`, and says what it did. `serveSite` calls * it for the request that the CLI sends after the push, with the site's mark token, so only the - * code that serves marks its own version. An older upload never goes live over a newer one: the - * mark does nothing when a live version was created after this one. So a request that runs on - * replaced code cannot make the old version newest, and `collect` cannot delete the new version's - * files. A version that is already live stays as it is, so a repeated mark is fine. It never - * throws, so the CLI reads every outcome from the answer. + * code that serves marks its own version. A version that is already live stays as it is, so a + * repeated mark is fine. It never throws, so the CLI reads every outcome from the answer. * - * Precondition: deploys to one deployment do not overlap. When two overlap and the older upload is - * pushed last, its mark is refused like a mark of replaced code: its version serves but stays - * `ready`, and nothing is deleted until the next deploy. The one order that deletes, a mark still - * running across the other deploy's push and mark, is in `docs/design.md`, "Stated, not solved". + * The request may still run when its code is replaced, so two rules refuse a mark of replaced code. + * An older upload never goes live over a newer one: the mark does nothing when a live version was + * created after this one. And a mark is late when another version went live after its request + * arrived, at `arrivedAt`: that version's code has served since. `arrivedAt` is the HTTP action's + * clock and the live time is this mutation's, so the rule holds as far as the two agree. + * + * Precondition: deploys to one deployment do not overlap. When two overlap, the mark of the + * version that serves may be refused: it then stays `ready`, and nothing is deleted until the next + * deploy. The limits are in `docs/design.md`, "Stated, not solved". */ export const markLive = mutation({ - args: { versionId: v.string() }, + args: { + versionId: v.string(), + /** `Date.now()` when the mark's request reached the code that serves. */ + arrivedAt: v.number(), + }, returns: v.union( /** It was `ready` and is now the newest live version. */ v.literal("marked"), v.literal("live"), - /** A live version was created after it, so it stays as it is. */ + /** A live version was created after it, or went live after `arrivedAt`: it stays as it is. */ v.literal("superseded"), v.literal("uploading"), v.literal("deleting"), v.literal("missing"), ), - handler: async (ctx, { versionId }) => { + handler: async (ctx, { versionId, arrivedAt }) => { const version = await getVersion(ctx, versionId); if (version === null) return "missing"; if (version.state.kind !== "ready") return version.state.kind; const newest = await getNewestLive(ctx); if (newest !== null && newest.createdAt > version._creationTime) return "superseded"; + if (newest !== null && newest.at > arrivedAt) return "superseded"; // Later than every live `at`, also within one millisecond or when the clock moves back, so that // `at` follows creation order and `collect` deletes the versions live before this one. const at = newest === null ? Date.now() : Math.max(Date.now(), newest.at + 1); From edd691c5d7be6c8eea2c1bf11eaa455d9e010091 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Tue, 10 Nov 2026 23:55:05 +0200 Subject: [PATCH 20/20] Cut a duplicate test, five comments that restate their names, and a sentence that restates the overlap test --- docs/design.md | 15 ++++++--------- packages/convex-hosting/src/cli/manifest.test.ts | 14 -------------- packages/convex-hosting/src/cli/manifest.ts | 3 --- packages/convex-hosting/src/client/manifest.ts | 2 -- 4 files changed, 6 insertions(+), 28 deletions(-) diff --git a/docs/design.md b/docs/design.md index f25699ed..7b1091a2 100644 --- a/docs/design.md +++ b/docs/design.md @@ -378,15 +378,12 @@ place for those. ## Stated, not solved - Deploys to one deployment do not overlap. When two overlap, the mark of the version that serves - may be refused, so it serves without being live and nothing is deleted until the next deploy. - `src/client/overlap.test.ts` runs the deploys on the real component and serving code, and the - version that serves keeps its entries and its files in every order of two deploys' steps and - `collect` calls, every order of three deploys' steps, and random orders of three with their - `collect` calls. Two limits remain, both with overlapping deploys only. The arrival time is read - in the HTTP action and compared with a time set in the mutation, so a late mark is refused as far - as those two clocks agree. And the day is a bound, not a margin: 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. + may be refused, so it serves without being live and nothing is deleted until the next deploy. The + version that serves keeps its entries and its files (`src/client/overlap.test.ts`), within two + limits. The arrival time is read in the HTTP action and compared with a time set in the mutation, + so a late mark is refused as far as those two clocks agree. And the day is a bound, not a margin: + 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. - An upload that took a stored file from `knownFiles` loses it only if two switches happen during that one upload; it fails with a message that says so, and a retry works. - No `run_worker_first`, no `base_path`, no selectable compatibility date: an app that needs its diff --git a/packages/convex-hosting/src/cli/manifest.test.ts b/packages/convex-hosting/src/cli/manifest.test.ts index 30f3d0bc..aec782aa 100644 --- a/packages/convex-hosting/src/cli/manifest.test.ts +++ b/packages/convex-hosting/src/cli/manifest.test.ts @@ -66,20 +66,6 @@ describe("buildAssetFiles, read with Cloudflare's lookup", () => { expect(await lookup("/caf%C3%A9/menu.html")).toBeNull(); }); - test("the same bytes under two content types share one stored file and have two ETags", async () => { - const sha256 = sha256Hex("same"); - const files = buildAssetFiles(CLOUD_URL, config, [ - { path: "/a.txt", sha256, contentType: "text/plain", url: url("k1") }, - { path: "/a.js", sha256, contentType: "text/javascript", url: url("k1") }, - ]); - const lookup = manifestLookup(files); - const txt = await lookup("/a.txt"); - const js = await lookup("/a.js"); - expect([txt?.url, js?.url]).toEqual([url("k1"), url("k1")]); - expect(txt?.eTag).not.toBe(js?.eTag); - expect([txt?.contentType, js?.contentType]).toEqual(["text/plain", "text/javascript"]); - }); - test("the storage URLs are written as what they share and one string of keys", () => { const entries = ["0c1f6a52", "5b7d2e11", "9e4a7c30"].map((key, i) => ({ path: `/${i}.js`, diff --git a/packages/convex-hosting/src/cli/manifest.ts b/packages/convex-hosting/src/cli/manifest.ts index b7e28bd5..fb6a2866 100644 --- a/packages/convex-hosting/src/cli/manifest.ts +++ b/packages/convex-hosting/src/cli/manifest.ts @@ -22,7 +22,6 @@ export type AssetEntry = { /** The hex SHA-256 of the bytes. */ sha256: string; contentType: string | undefined; - /** The storage URL of the bytes. */ url: string; }; @@ -88,7 +87,6 @@ export function buildAssetFiles( }; } -/** The longest start that all of `texts` share. */ function sharedStart(texts: string[]): string { let start = texts[0] ?? ""; for (const text of texts) { @@ -99,7 +97,6 @@ function sharedStart(texts: string[]): string { return start; } -/** The longest end that all of `texts` share. */ function sharedEnd(texts: string[]): string { let end = texts[0] ?? ""; for (const text of texts) { diff --git a/packages/convex-hosting/src/client/manifest.ts b/packages/convex-hosting/src/client/manifest.ts index 1382a951..3acb0659 100644 --- a/packages/convex-hosting/src/client/manifest.ts +++ b/packages/convex-hosting/src/client/manifest.ts @@ -48,7 +48,6 @@ export type AssetFiles = { * entry, which Cloudflare leaves zero, holds the indexes of its URL and its content type. */ manifest: string; - /** The content types of the entries. */ contentTypes: string[]; /** * The storage URL of each stored file is `urlPrefix`, its key, and `urlSuffix`. The keys are one @@ -68,7 +67,6 @@ export const TAIL_CONTENT_TYPE = 4; /** The content type index of an entry without a content type. */ export const NO_CONTENT_TYPE = 0xffff; -/** The entry of a path. */ export type ManifestHit = { /** The hex of the content hash, which is the ETag, as on Cloudflare. */ eTag: string;