diff --git a/AGENTS.md b/AGENTS.md index 95204b5..e4ee8b5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,7 +5,7 @@ Guidance for agents working in this repository. Prefer the checked-in code and t ## 1. Project - Published on npm as one package, `serverless-objects` (0.13.x, pre-alpha). It contains the `sobjects` CLI, the native engine, and the `serverless-objects/hotcell` and `serverless-objects/autopilot` modules. There is no `@serverless-objects` npm scope; ship new modules as subpath exports of this package. -- Two engines: celld (external, pinned 0.6.2) and the native engine (`sobjects dev --engine native`: in-process, trusted code, node:sqlite per object). Conformance: Cloudflare 17/17 (`test:cloudflare`, deploys to the logged-in account and deletes afterwards), Wrangler 4.150.0 21/21, celld 0.6.2 24/24, native 23/23 (hibernation runs everywhere but Wrangler; facets pass on Wrangler and celld but not the native engine; a schedule across restart runs on celld and native; the PartyServer suite runs on Wrangler, celld and native but not Cloudflare). The Agents app also passes 6/6 through `sobjects deploy`/`up` (`test:product`, not in CI). +- Two engines: celld (external, pinned 0.6.2) and the native engine (`sobjects dev --engine native`: in-process, trusted code, node:sqlite per object). Conformance: Cloudflare 17/17 (`test:cloudflare`, deploys to the logged-in account and deletes afterwards), Wrangler 4.150.0 21/21, celld 0.6.2 24/24, native 23/23 (hibernation runs everywhere but Wrangler; facets pass on Wrangler and celld but not the native engine; a schedule across restart runs on celld and native; the PartyServer suite runs on Wrangler, celld and native but not Cloudflare). The Agents app also passes 6/6 through `sobjects deploy`/`up` (`test:product`, not in CI). A separate celld-only containers suite (`test:containers`, 8/8 on Linux arm64 in Docker Desktop's Linux VM) covers `ctx.container` start/exec/HTTP, `enableInternet: false`, sleep and restart; `S3Mount` and `DirectoryBackup` are unsupported because celld rejects `interceptOutboundHttp`. - ACME HTTP-01 is verified only against a local Pebble server. Point-in-time restore is not available on celld 0.6. The native engine has bucket backups (`--backup-bucket`; `--backup-mode durable` holds each result until its writes are in the bucket and adds Cloudflare's point-in-time recovery API, back `--backup-retention-days`), several nodes per bucket (`--node-name`, `--peer-listen`), and optional worker threads (`--threads`; fault and CPU isolation, not a security boundary). A `[native]` table in `sobjects.toml` (instead of `[celld]`) makes `sobjects up` run it as `sobjects dev --engine native` in a child process; `[admin]` isn't supported with it yet. Roadmap targets are not guarantees. Serverless Objects is a self-hostable operating layer for Cloudflare Workers and Durable Objects applications, aimed at coding-agent infrastructure. It is JavaScript (ES modules) on Node.js >=22, managed with npm workspaces; the product is the `sobjects` CLI (workspace package `serverless-objects`). The CLI supervises the external celld runtime (pinned v0.6.2) for production nodes and also ships a Node-native engine for trusted code. Cloudflare Workers/Wrangler APIs are the compatibility contract. The dashboard is plain HTML/CSS/JS; there is no application framework or TypeScript codebase. Status: pre-alpha. @@ -55,7 +55,7 @@ CI: `.github/workflows/ci.yml` runs `npm ci`, `npm test`, and the Wrangler and n | `packages/cli/autopilot/` | `serverless-objects/autopilot` (and `/autopilot/cell`): `RunObject`/`RunRegistry`/`AutopilotCellRun`. Runtime-independent logic in `run-store.js`, `run-host.js`, `registry-store.js` and `cell-executor.js` over an `{exec, transaction}` SQL adapter; tests (`test/autopilot-*.test.js`) use `node:sqlite`. | | `deploy/compose/` | Dockerfile and Compose bundle for a single node; pins the npm CLI version via `SOBJECTS_VERSION`. | | `examples/` | Runnable Wrangler projects (not workspaces) that import the packages through the root `node_modules`. | -| `packages/conformance/` | Private workspace: conformance apps (`app/` core, `agents-app/` Agents SDK, `party-app/` PartyServer), runners (`src/run.js` for Wrangler, celld and native; `src/product.js` for `sobjects deploy`/`up`), and runner tests. | +| `packages/conformance/` | Private workspace: conformance apps (`app/` core, `agents-app/` Agents SDK, `party-app/` PartyServer, `containers-app/` celld containers), runners (`src/run.js` for Wrangler, celld and native; `src/product.js` for `sobjects deploy`/`up`), and runner tests. | | `sobjects.example.toml` | Safe starter configuration; copy to the ignored, machine-specific `sobjects.toml`. | | `docs/conformance/` | Recorded Workers/celld compatibility findings (`m0-celld.md`) and conformance results (`results.md`); consult before changing runtime assumptions. | | `docs/install.md`, `docs/porting-from-cloudflare.md`, `docs/compatibility.md` | User guides and the supported/unsupported table; keep them in step with conformance results. | diff --git a/README.md b/README.md index 42663ba..771f53a 100644 --- a/README.md +++ b/README.md @@ -94,9 +94,9 @@ State survives `down` and `up` because it lives in the bucket. The [install guid ## Compatibility -Cloudflare's APIs are the contract. The current [conformance results](docs/conformance/results.md) pass every check on real Cloudflare (17/17), Wrangler 4.150.0 (21/21), celld 0.6.2 (24/24) and the native engine (23/23): the same apps, unchanged. They cover Durable Object IDs, KV and SQL storage, transactions, input gates, RPC, alarms (including across a restart), WebSockets with hibernation on celld, facets on Wrangler and celld, an Agents SDK suite (state, SQL, schedules including one across a restart, addressing and `@callable()` RPC), and a PartyServer suite (storage, alarms, room routing, broadcast and hibernation). The Cloudflare run predates the PartyServer suite. The Agents app also passes 6/6 through `sobjects deploy` and `sobjects up` behind TLS ingress (`test:product`). +Cloudflare's APIs are the contract. The current [conformance results](docs/conformance/results.md) pass every check on real Cloudflare (17/17), Wrangler 4.150.0 (21/21), celld 0.6.2 (24/24) and the native engine (23/23): the same apps, unchanged. They cover Durable Object IDs, KV and SQL storage, transactions, input gates, RPC, alarms (including across a restart), WebSockets with hibernation on celld, facets on Wrangler and celld, an Agents SDK suite (state, SQL, schedules including one across a restart, addressing and `@callable()` RPC), and a PartyServer suite (storage, alarms, room routing, broadcast and hibernation). The Cloudflare run predates the PartyServer suite. The Agents app also passes 6/6 through `sobjects deploy` and `sobjects up` behind TLS ingress (`test:product`). A separate celld-only containers suite (8/8 on Linux arm64 in Docker Desktop's Linux VM) covers `ctx.container`: start, exec, HTTP over a container port, `enableInternet: false`, sleep and restart; `S3Mount` and `DirectoryBackup` are unsupported because celld rejects `interceptOutboundHttp`. -Not covered yet: sockets across a cell move between nodes, PartyServer on Cloudflare or through `sobjects deploy`, Agents SDK chat, MCP and Workflows, and Cloudflare-hosted production behavior. Facets pass on Wrangler and celld but are not implemented by the native engine. Point-in-time restore isn't available on celld 0.6; the native engine has Cloudflare's point-in-time recovery API in durable mode. The [compatibility table](docs/compatibility.md) has the details, including Containers and `@cloudflare/sandbox` 1.0 on celld. The [porting guide](docs/porting-from-cloudflare.md) covers moving an existing project. +Not covered yet: sockets across a cell move between nodes, PartyServer on Cloudflare or through `sobjects deploy`, Agents SDK chat, MCP and Workflows, containers on a bare-metal Linux host or Linux x64, and Cloudflare-hosted production behavior. Facets pass on Wrangler and celld but are not implemented by the native engine. Point-in-time restore isn't available on celld 0.6; the native engine has Cloudflare's point-in-time recovery API in durable mode. The [compatibility table](docs/compatibility.md) has the details, including Containers and `@cloudflare/sandbox` 1.0 on celld. The [porting guide](docs/porting-from-cloudflare.md) covers moving an existing project. ## Repository layout @@ -104,7 +104,7 @@ Not covered yet: sockets across a cell move between nodes, PartyServer on Cloudf |---|---| | [`packages/cli`](packages/cli) | The `serverless-objects` npm package: the `sobjects` CLI (`src/`), the Hotcell Sandbox binding (`hotcell/`, imported as `serverless-objects/hotcell`) and Autopilot run objects (`autopilot/`, imported as `serverless-objects/autopilot`). Its README is the CLI reference. | | [`examples/autopilot-runs`](examples/autopilot-runs) | An HTTP demo of run objects: wake after restart, event streams, reconcile. | -| [`packages/conformance`](packages/conformance) | Conformance apps and the Wrangler, celld, native and product-path runners. | +| [`packages/conformance`](packages/conformance) | Conformance apps and the Wrangler, celld, native and product-path runners, including the celld-only containers suite. | | [`deploy/compose`](deploy/compose) | Dockerfile and Compose bundle for a single node, with an optional local SeaweedFS bucket. | | [`docs/`](docs) | Install, porting and compatibility guides, and recorded conformance results. | diff --git a/docs/compatibility.md b/docs/compatibility.md index eec3a81..63df39a 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -1,6 +1,6 @@ # Compatibility and support status -This table distinguishes behavior exercised by the project from functionality described by celld upstream. A celld capability is not automatically a Serverless Objects product guarantee. The conformance results are one local run on macOS arm64 using Wrangler 4.150.0, celld 0.6.2 and the native engine, plus one deployment to Cloudflare; they are not a cross-platform or Cloudflare production certification. CI runs the Wrangler and native suites on Ubuntu x64 but records no results, so the table is macOS arm64 evidence plus unrecorded Ubuntu x64 CI coverage. +This table distinguishes behavior exercised by the project from functionality described by celld upstream. A celld capability is not automatically a Serverless Objects product guarantee. The conformance results are one local run on macOS arm64 using Wrangler 4.150.0, celld 0.6.2 and the native engine, plus one deployment to Cloudflare, and a celld-only containers run on Linux arm64 in Docker Desktop's Linux VM; they are not a cross-platform or Cloudflare production certification. CI runs the Wrangler and native suites on Ubuntu x64 but records no results, so the table is macOS arm64 evidence plus unrecorded Ubuntu x64 CI coverage, with the Containers row from the Linux arm64 run. ## Product and runtime behavior @@ -27,7 +27,7 @@ This table distinguishes behavior exercised by the project from functionality de | Capability | Status | Notes | |---|---|---| | celld Durable Objects, KV, D1, R2, Queues, Workflows | Upstream-reported | Listed by celld 0.6.2; this conformance suite does not exercise every binding. Check celld's release documentation for exact feature limits. | -| Containers (`ctx.container`) and `@cloudflare/sandbox` 1.0 | Partial, one manual run on celld with Docker | celld 0.6.2 runs Wrangler `containers` classes on a local Docker or Podman engine. A DO using stock `@cloudflare/sandbox` 1.0.1 (`Files.writeFile`/`readFile`, `ctx.container.exec`) worked with an image built `FROM alpine` plus `sandbox-shim` copied from `cloudflare/sandbox:1.0.1`, which is a tools-only image with no command. That was a manual run on macOS through Docker Desktop, not an automated conformance case, and it exercises Docker's Linux VM rather than a Linux host. Gaps seen there: `exec()` straight after `start()` fails with "No such container" while the container is still being created, where Cloudflare's own example calls them back to back; `enableInternet: false` is not enforced (celld logs a warning); `container.images` is undefined. Not tested: a Linux host, `S3Mount`, `DirectoryBackup`, sleep and restart. | +| Containers (`ctx.container`) and `@cloudflare/sandbox` 1.0 | Partial, automated on Linux arm64 in Docker Desktop's Linux VM | celld 0.6.2 runs Wrangler `containers` classes on a local Docker or Podman engine. `npm run test:containers` (8/8) verified on Linux arm64 in Docker Desktop 4.75.0's Linux VM, with celld in a privileged container using the host Docker socket: `start()`, `exec()`, `getTcpPort().fetch()`, `enableInternet: false` (egress refused), idle eviction with the container kept alive and reattached, and a node restart destroying the container. `@cloudflare/sandbox` 1.0.1's `S3Mount.mount()` and `DirectoryBackup` are unsupported: both need `interceptOutboundHttp`, which celld rejects with "not implemented in celld"; `inspect()`, `snapshotDirectory()`, `snapshotContainer()` and `container.images` are also unavailable. `exec()` immediately after `start()` fails with "No such container" because celld's `start()` is fire-and-forget, while Cloudflare's `exec()` waits for a starting container; that is celld's behavior, not the CLI's, and the conformance app polls `exec()` for readiness. Not tested: a bare-metal Linux host, Linux x64, `@cloudflare/sandbox`'s `Files` API, and containers on Wrangler or Cloudflare. See [the containers record](conformance/containers.md). | | Workers AI, Vectorize, Hyperdrive, Browser Rendering, Email Workers | Not provided by celld 0.6.2 | Serverless Objects does not implement replacements. | | Single-host `sobjects up` | Implemented and smoke-tested | The current product is a single-host operating layer by default. Keep operator/admin listeners on loopback. | | Multi-node object placement | Native engine only | `--node-name` shares one bucket prefix between nodes, with leases, takeover, drain and call forwarding ([details](native-engine.md#several-nodes)). celld runs one node per bucket prefix. | diff --git a/docs/conformance/containers.md b/docs/conformance/containers.md new file mode 100644 index 0000000..3bae8d6 --- /dev/null +++ b/docs/conformance/containers.md @@ -0,0 +1,66 @@ +# Containers conformance — celld 0.6.2 + +Recorded 2 Nov 2026 on Linux arm64 in Docker Desktop 4.75.0's Linux VM, with +celld 0.6.2 and `@cloudflare/sandbox` 1.0.1. celld ran in a privileged +`node:22-bookworm` container with the host Docker socket and host network, so +the containers it created ran on the Docker Desktop Linux VM. That is a Linux +kernel and userspace, not a bare-metal Linux host; a bare-metal Linux host and +Linux x64 were not tested. + +Command: + +```sh +npm run test:containers --workspace=sobjects-conformance +``` + +The runner starts `celld dev` with `CELLD_IDLE_EVICT_S=2`, copies +`containers-app/` into a disposable `.runs/` directory, and drives the app over +HTTP. The image is `python:3.12-alpine` plus `fuse3`, `s3fs-fuse` and the +`sandbox-shim` copied from `cloudflare/sandbox:1.0.1` (a tools-only image with +no command). The shim is an x86-64 static binary; it ran under the host's +binfmt emulation. + +| Check | Result | Notes | +|---|---|---| +| `start()`, `exec()`, `getTcpPort().fetch()` | Pass | `exec()` ran `uname -s` (`Linux`) and read a marker file; `getTcpPort(8080).fetch()` returned the container's HTTP response. | +| `enableInternet: false` | Pass | A container started with `enableInternet: false` could not connect to `1.1.1.1:443` (`OSError: [Errno 101] Network unreachable`); a container started with `enableInternet: true` connected. | +| `exec()` immediately after `start()` | Divergence recorded | `exec()` failed with `create exec failed with [404] No such container: ...` while the container was still being created. See below. | +| `container.images` | Undefined | `ctx.container.images` is `undefined`. | +| `interceptOutboundHttp`, `interceptAllOutboundHttp` | Rejected | Both reject with `... is not implemented in celld`. | +| `inspect`, `snapshotDirectory`, `snapshotContainer` | Rejected | All three reject with `... is not implemented in celld`. | +| `S3Mount.mount()` | Unsupported | `@cloudflare/sandbox` 1.0.1's `S3Mount.mount()` failed with `interceptOutboundHttp() is not implemented in celld`. | +| `DirectoryBackup.intercept()` / `backup()` | Unsupported | `intercept()` failed with `interceptOutboundHttp() is not implemented in celld`; `backup()` then failed with `env.BACKUPS is not an R2 bucket binding` because the app has no R2 binding. | +| Sleep (idle eviction) | Pass | With `CELLD_IDLE_EVICT_S=2`, the object was evicted while idle. The next request reached a new object instance, and the same running container answered with its marker file and hostname intact. | +| Restart | Pass | Stopping and starting celld destroyed the container: the next request found `running` false and no marker file, and a new `start()` created a container with a different hostname. | + +## The `exec()`-after-`start()` race + +Cloudflare's `exec()` documentation says it "waits for a container that is +still starting". celld's `start()` is fire-and-forget: it returns before the +engine has created the container, and `exec()` rejects with +`create exec failed with [404] No such container: ...` until the container +exists. `container.running` is not a readiness signal either: celld sets it +when the run begins, before the engine has created the container, and the +value observed immediately after `start()` differed between the macOS and +Linux runs. + +This is celld's behavior, not the CLI's: the CLI does not wrap `ctx.container`. +The conformance app polls `exec()` for readiness, which is the workaround an +application needs on celld 0.6.2. Upstream celld would need to make `exec()` +wait for a starting container, as Cloudflare documents; the CLI cannot fix it +without replacing the runtime's `ctx.container`. + +## What remains unsupported + +- `S3Mount` and `DirectoryBackup` need `interceptOutboundHttp`, which celld + 0.6.2 rejects. `S3Mount` also needs FUSE and `s3fs` in the image; celld's + default runtime drops all Linux capabilities and does not pass `/dev/fuse`, + so a mount would not work even if the intercept existed. +- `inspect()`, `snapshotDirectory()`, `snapshotContainer()` and + `container.images` are not implemented. +- `enableInternet: false` is enforced on Linux; celld documents that it has no + effect on macOS, where the node reaches a container through a published port. +- A bare-metal Linux host, Linux x64, and containers on Wrangler or Cloudflare + were not tested. +- The earlier manual macOS run exercised `@cloudflare/sandbox`'s + `Files.writeFile`/`readFile`; this suite does not repeat that check. diff --git a/docs/conformance/results.md b/docs/conformance/results.md index 41dcec2..999e6ba 100644 --- a/docs/conformance/results.md +++ b/docs/conformance/results.md @@ -39,9 +39,13 @@ The Cloudflare column is from `npm run test:cloudflare` (20 Oct 2026): 17/17. Th The native engine column is from `npm run test:native` on the same host (29 Oct 2026): 23/23, with `--idle-evict-seconds 2` for the hibernation checks; see [the native engine](../native-engine.md). The PartyServer suite needed one engine fix: the global `WebSocket` now exposes workerd's `READY_STATE_*` ready-state constants, which PartyServer reads when it filters hibernatable sockets. +## Containers + +`npm run test:containers --workspace=sobjects-conformance` (2 Nov 2026) ran 8/8 checks on Linux arm64 in Docker Desktop 4.75.0's Linux VM with celld 0.6.2 and `@cloudflare/sandbox` 1.0.1. It covers `start()`, `exec()`, `getTcpPort().fetch()`, `enableInternet: false` (egress refused), idle eviction with the container kept alive and reattached, and a node restart destroying the container. `S3Mount` and `DirectoryBackup` are unsupported because celld rejects `interceptOutboundHttp`; `inspect()`, `snapshotDirectory()`, `snapshotContainer()` and `container.images` are also unavailable. The `exec()`-after-`start()` race is celld's fire-and-forget `start()`, not the CLI's. See [the containers record](containers.md). + ## Platforms -Every column above is one local run on macOS arm64. CI runs the Wrangler and native suites on Ubuntu x64 (Node 22) on every change, and builds the linux/amd64 Docker image and checks that `sobjects` and `celld` start in it; it does not run `test:celld` or `test:cloudflare`, and it records no results. Linux arm64 has no conformance evidence beyond the Compose stack on Docker Desktop. Treat the table as macOS arm64 evidence plus unrecorded Ubuntu x64 CI coverage, not as a cross-platform claim. +Every column in the table above is one local run on macOS arm64. CI runs the Wrangler and native suites on Ubuntu x64 (Node 22) on every change, and builds the linux/amd64 Docker image and checks that `sobjects` and `celld` start in it; it does not run `test:celld`, `test:containers` or `test:cloudflare`, and it records no results. Linux arm64 has containers evidence from the containers suite on Docker Desktop's Linux VM; no bare-metal Linux host or Linux x64 run is recorded. Treat the table as macOS arm64 evidence plus unrecorded Ubuntu x64 CI coverage, not as a cross-platform claim. ## Product path diff --git a/package-lock.json b/package-lock.json index 5b99fb1..aa8f8a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -421,6 +421,27 @@ "node": ">=22.0.0" } }, + "node_modules/@cloudflare/sandbox": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@cloudflare/sandbox/-/sandbox-1.0.1.tgz", + "integrity": "sha512-8Qvv2SbMGfDW+zo0AkwaDna+b+IbXPgMKjelu6UZla1jyTwt1Ye0Z4LEahwoXtIMbpQvopr9NvXtLm+abA7+Tw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "aws4fetch": "1.0.20", + "zod": "4.6.5" + } + }, + "node_modules/@cloudflare/sandbox/node_modules/zod": { + "version": "4.6.5", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.5.tgz", + "integrity": "sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, "node_modules/@cloudflare/unenv-preset": { "version": "2.16.2", "resolved": "https://registry.npmjs.org/@cloudflare/unenv-preset/-/unenv-preset-2.16.2.tgz", @@ -2248,6 +2269,13 @@ } } }, + "node_modules/aws4fetch": { + "version": "1.0.20", + "resolved": "https://registry.npmjs.org/aws4fetch/-/aws4fetch-1.0.20.tgz", + "integrity": "sha512-/djoAN709iY65ETD6LKCtyyEI04XIBP5xVvfmNxsEP0uJB5tyaGBztSryRr4HqMStr9R06PisQE7m9zDTXKu6g==", + "dev": true, + "license": "MIT" + }, "node_modules/baseline-browser-mapping": { "version": "2.11.29", "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.29.tgz", @@ -4392,6 +4420,7 @@ "name": "sobjects-conformance", "version": "0.1.0", "devDependencies": { + "@cloudflare/sandbox": "1.0.1", "agents": "0.28.1", "partyserver": "^0.5.10", "wrangler": "4.150.0" diff --git a/packages/conformance/README.md b/packages/conformance/README.md index 7428c3d..5f93489 100644 --- a/packages/conformance/README.md +++ b/packages/conformance/README.md @@ -6,11 +6,16 @@ return `{ pass, detail }` at `/case/`. `/cases` lists the cases. `nodejs_compat`); the runner also drives its WebSocket client protocol. `party-app/` does the same for PartyServer (pinned `partyserver` 0.5.10, with `nodejs_compat`): a `Server` with hibernation enabled, driven over -`/parties/chat/` and its WebSocket protocol. Select one with -`--suite core|agents|party|all` (default `all`). The +`/parties/chat/` and its WebSocket protocol. `containers-app/` is a +celld-only suite for `ctx.container` and `@cloudflare/sandbox` 1.0.1: it starts +a container, runs `exec()` and `getTcpPort().fetch()`, checks +`enableInternet: false`, records the `exec()`-after-`start()` race, attempts +`S3Mount` and `DirectoryBackup`, and drives sleep and restart checks. Select +one with `--suite core|agents|party|containers|all` (default `all`; `all` +excludes `containers`, which needs Docker and celld). The runner launches a disposable copy under the git-ignored `.runs/` directory, -so the Agents and PartyServer apps resolve the workspace's `node_modules`, and -removes it afterwards. +so the Agents, PartyServer and containers apps resolve the workspace's +`node_modules`, and removes it afterwards. Run the reference runner or celld runner from the repository root: @@ -33,6 +38,20 @@ The app uses compatibility date `2026-02-24`, when Cloudflare changed `deleteAll()` to clear a Durable Object alarm. This keeps the alarm case aligned with the documented Workers contract. +The containers suite is celld-only and needs a Docker or Podman engine on a +Linux host. Run it with: + +```sh +npm run test:containers --workspace=sobjects-conformance +``` + +It builds `containers-app/Dockerfile` (Python plus `fuse3`, `s3fs-fuse` and the +`sandbox-shim` from `cloudflare/sandbox:1.0.1`) and starts `celld dev` with +`CELLD_IDLE_EVICT_S=2`. On macOS celld reaches a container through a published +port, and the suite's `getTcpPort()` check fails; use a Linux host or a Linux +VM. The suite is not part of `--suite all` because it needs Docker and is +celld-only. + See [the recorded results](../../docs/conformance/results.md) for tested versions and coverage boundaries. A green result is evidence for these cases and versions only; it is not a claim of complete Workers compatibility. diff --git a/packages/conformance/containers-app/Dockerfile b/packages/conformance/containers-app/Dockerfile new file mode 100644 index 0000000..be4e1b8 --- /dev/null +++ b/packages/conformance/containers-app/Dockerfile @@ -0,0 +1,14 @@ +# A tiny HTTP server plus the sandbox tools that @cloudflare/sandbox 1.0.1 +# expects. The shim is copied from Cloudflare's tools-only image; it is an +# x86-64 static binary, so it runs under the host's binfmt emulation on arm64. +FROM python:3.12-alpine + +RUN apk add --no-cache fuse3 s3fs-fuse +COPY --from=cloudflare/sandbox:1.0.1 /usr/local/bin/sandbox-shim /usr/local/bin/sandbox-shim +RUN chmod +x /usr/local/bin/sandbox-shim + +WORKDIR /app +COPY server.py . +ENV PORT=8080 +EXPOSE 8080 +CMD ["python3", "server.py"] diff --git a/packages/conformance/containers-app/index.js b/packages/conformance/containers-app/index.js new file mode 100644 index 0000000..6a1698d --- /dev/null +++ b/packages/conformance/containers-app/index.js @@ -0,0 +1,284 @@ +// Containers conformance app: one Durable Object class with a container, and +// routes that exercise the parts of the Cloudflare Containers contract that +// celld 0.6.2 implements. The same bundle runs on celld; the runner drives the +// multi-step checks (sleep, restart) over HTTP. +import { DurableObject } from "cloudflare:workers"; +import { DirectoryBackup, S3Mount } from "@cloudflare/sandbox"; + +// The sandbox package reaches its gateways through ctx.exports, so the main +// module must re-export them. +export { DirectoryBackupGateway, S3Gateway } from "@cloudflare/sandbox"; + +const PORT = 8080; +const MARKER = "/tmp/conformance-marker"; + +const text = (value) => { + if (value == null) return ""; + if (value instanceof ArrayBuffer) return new TextDecoder().decode(new Uint8Array(value)); + return new TextDecoder().decode(value); +}; + +async function exec(container, command) { + const process = await container.exec(["sh", "-c", command]); + const output = await process.output(); + return { stdout: text(output.stdout), stderr: text(output.stderr), exitCode: output.exitCode }; +} + +// start() returns before the container exists, so exec() is the readiness +// probe: it fails with "No such container" until the engine has created it. +async function waitForExec(container, timeoutMs = 120_000) { + const deadline = Date.now() + timeoutMs; + let last; + while (Date.now() < deadline) { + try { + await exec(container, "true"); + return; + } catch (error) { + last = error; + } + await new Promise((resolve) => setTimeout(resolve, 500)); + } + throw new Error(`container did not accept exec within ${timeoutMs}ms: ${last?.message ?? last}`); +} + +async function waitForHttp(container, timeoutMs = 60_000) { + const deadline = Date.now() + timeoutMs; + let last; + while (Date.now() < deadline) { + try { + const response = await container.getTcpPort(PORT).fetch(`http://container/ready`); + if (response.ok) return JSON.parse(await response.text()); + last = new Error(`HTTP ${response.status}`); + } catch (error) { + last = error; + } + await new Promise((resolve) => setTimeout(resolve, 500)); + } + throw new Error(`container did not answer on port ${PORT} within ${timeoutMs}ms: ${last?.message ?? last}`); +} + +export class Box extends DurableObject { + // A new value means the runtime constructed a new instance, e.g. after idle + // eviction or a process restart. + instance = crypto.randomUUID(); + + async start({ enableInternet = true, marker = this.instance } = {}) { + const container = this.ctx.container; + if (!container.running) { + container.start({ enableInternet, env: { MESSAGE: "conformance" } }); + } + await waitForExec(container); + const ready = await waitForHttp(container); + await exec(container, `printf '%s' '${marker}' > ${MARKER}`); + return { instance: this.instance, hostname: ready.hostname, running: container.running }; + } + + async state() { + const container = this.ctx.container; + let marker = null; + let hostname = null; + if (container.running) { + try { + marker = (await exec(container, `cat ${MARKER} 2>/dev/null || true`)).stdout; + } catch { + // The container is running but exec is not available yet. + } + try { + hostname = (await waitForHttp(container, 5_000)).hostname; + } catch { + // The server is not answering; the container may still be starting. + } + } + return { instance: this.instance, running: container.running, marker, hostname }; + } + + async execCheck() { + const container = this.ctx.container; + await waitForExec(container); + const uname = await exec(container, "uname -s"); + const marker = await exec(container, `cat ${MARKER} 2>/dev/null || true`); + return { uname: uname.stdout.trim(), marker: marker.stdout, exitCode: uname.exitCode }; + } + + async httpCheck() { + const container = this.ctx.container; + return { ready: await waitForHttp(container) }; + } + + async egress() { + const container = this.ctx.container; + await waitForExec(container); + const result = await exec( + container, + "python3 -c \"import socket; socket.create_connection(('1.1.1.1', 443), 5); print('connected')\"", + ); + return { connected: result.exitCode === 0, stdout: result.stdout.trim(), stderr: result.stderr.trim() }; + } + + // The parts of the Containers API that celld 0.6.2 documents as rejected. + async unsupported() { + const container = this.ctx.container; + await waitForExec(container); + const attempt = async (operation) => { + try { + await operation(); + return { ok: true }; + } catch (error) { + return { ok: false, error: String(error?.message ?? error) }; + } + }; + return { + images: container.images === undefined ? null : Object.keys(container.images), + interceptOutboundHttp: await attempt(() => container.interceptOutboundHttp("example.com", this.ctx.exports.S3Gateway({ props: {} }))), + interceptAllOutboundHttp: await attempt(() => container.interceptAllOutboundHttp(this.ctx.exports.S3Gateway({ props: {} }))), + inspect: await attempt(() => container.inspect()), + snapshotDirectory: await attempt(() => container.snapshotDirectory("/tmp")), + snapshotContainer: await attempt(() => container.snapshotContainer()), + }; + } + + // S3Mount needs interceptOutboundHttp and a sandbox-shim image. The image + // here has the shim, so the failure names the missing runtime method. + async s3mount() { + const container = this.ctx.container; + await waitForExec(container); + const mounts = new S3Mount(container, this.ctx.exports.S3Gateway); + try { + await mounts.mount({ + mountPath: "/mnt/conformance", + source: { + type: "s3", + endpoint: "http://127.0.0.1:9000", + region: "us-east-1", + bucket: "conformance", + credentials: { type: "static", accessKeyId: "conformance", secretAccessKey: "conformance" }, + }, + access: "read-only", + }); + return { ok: true }; + } catch (error) { + return { ok: false, error: String(error?.message ?? error), code: error?.code ?? null }; + } + } + + // DirectoryBackup needs interceptOutboundHttp and an R2 binding. intercept() + // reaches the runtime method without touching R2. + async directoryBackup() { + const container = this.ctx.container; + await waitForExec(container); + const backups = new DirectoryBackup(container, this.ctx.exports.DirectoryBackupGateway, { + binding: "BACKUPS", + prefix: "conformance/", + }); + const attempt = async (operation) => { + try { + await operation(); + return { ok: true }; + } catch (error) { + return { ok: false, error: String(error?.message ?? error), code: error?.code ?? null }; + } + }; + return { + intercept: await attempt(() => backups.intercept()), + backup: await attempt(() => backups.backup({ dir: "/tmp" })), + }; + } + + // Cloudflare's exec() waits for a container that is still starting. celld's + // start() is fire-and-forget and exec() rejects until the engine has created + // the container, so this records the divergence rather than hiding it. + async execAfterStart() { + const container = this.ctx.container; + if (container.running) await container.destroy(); + container.start({ enableInternet: true }); + try { + await exec(container, "true"); + return { raced: false }; + } catch (error) { + return { raced: true, error: String(error?.message ?? error) }; + } + } + + async destroyContainer() { + if (this.ctx.container.running) await this.ctx.container.destroy(); + } +} + +const CASES = { + async "exec-after-start"(box) { + const result = await box.execAfterStart(); + if (!result.raced) throw new Error("exec() succeeded immediately after start(); the celld race was not observed"); + return `exec() immediately after start() failed as celld 0.6.2 documents: ${result.error}`; + }, + async "start-exec-http"(box) { + const started = await box.start({ marker: "start-exec-http" }); + const exec = await box.execCheck(); + const http = await box.httpCheck(); + if (exec.uname !== "Linux") throw new Error(`uname: ${JSON.stringify(exec)}`); + if (exec.marker !== "start-exec-http") throw new Error(`marker: ${JSON.stringify(exec)}`); + if (http.ready.hostname !== started.hostname) throw new Error(`hostname: ${JSON.stringify({ started, http })}`); + return `start(), exec() (${exec.uname}), and getTcpPort().fetch() (${http.ready.hostname})`; + }, + async egress(box, env) { + const online = env.BOX.get(env.BOX.idFromName("egress-online")); + const offline = env.BOX.get(env.BOX.idFromName("egress-offline")); + await online.start({ enableInternet: true, marker: "online" }); + await offline.start({ enableInternet: false, marker: "offline" }); + const onlineResult = await online.egress(); + const offlineResult = await offline.egress(); + if (!onlineResult.connected) throw new Error(`enableInternet: true did not reach the Internet: ${JSON.stringify(onlineResult)}`); + if (offlineResult.connected) throw new Error(`enableInternet: false still reached the Internet: ${JSON.stringify(offlineResult)}`); + return `enableInternet: true connected; enableInternet: false was refused (${offlineResult.stderr || offlineResult.stdout})`; + }, + async unsupported(box) { + const result = await box.unsupported(); + const rejected = ["interceptOutboundHttp", "interceptAllOutboundHttp", "inspect", "snapshotDirectory", "snapshotContainer"]; + for (const name of rejected) { + if (result[name].ok) throw new Error(`${name} unexpectedly succeeded`); + if (!/not implemented in celld/.test(result[name].error)) throw new Error(`${name}: ${result[name].error}`); + } + if (result.images !== null) throw new Error(`container.images is defined: ${JSON.stringify(result.images)}`); + return "interceptOutboundHttp, interceptAllOutboundHttp, inspect, snapshotDirectory and snapshotContainer reject; container.images is undefined"; + }, + async s3mount(box) { + const result = await box.s3mount(); + if (result.ok) throw new Error("S3Mount.mount() unexpectedly succeeded"); + return `S3Mount.mount() failed: ${result.error}`; + }, + async "directory-backup"(box) { + const result = await box.directoryBackup(); + if (result.intercept.ok) throw new Error("DirectoryBackup.intercept() unexpectedly succeeded"); + if (result.backup.ok) throw new Error("DirectoryBackup.backup() unexpectedly succeeded"); + return `DirectoryBackup.intercept() failed: ${result.intercept.error}; backup() failed: ${result.backup.error}`; + }, +}; + +export default { + async fetch(request, env) { + const url = new URL(request.url); + const name = url.searchParams.get("name") ?? "default"; + const box = env.BOX.get(env.BOX.idFromName(name)); + + if (url.pathname === "/cases") return Response.json(Object.keys(CASES)); + if (url.pathname === "/container/start") { + const enableInternet = url.searchParams.get("internet") !== "false"; + const marker = url.searchParams.get("marker") ?? undefined; + return Response.json(await box.start({ enableInternet, marker })); + } + if (url.pathname === "/container/state") return Response.json(await box.state()); + if (url.pathname === "/container/destroy") { + await box.destroyContainer(); + return Response.json({ ok: true }); + } + + const caseName = url.pathname.replace(/^\/case\//, ""); + if (url.pathname.startsWith("/case/") && CASES[caseName]) { + try { + return Response.json({ pass: true, detail: await CASES[caseName](box, env) }); + } catch (error) { + return Response.json({ pass: false, detail: String(error?.message ?? error) }); + } + } + return new Response("ok"); + }, +}; diff --git a/packages/conformance/containers-app/server.py b/packages/conformance/containers-app/server.py new file mode 100644 index 0000000..8435e91 --- /dev/null +++ b/packages/conformance/containers-app/server.py @@ -0,0 +1,32 @@ +# A tiny HTTP server: every response reports the container's hostname, the +# request path, and the MESSAGE environment variable the object passed in. +# The process is PID 1 in the container, and PID 1 ignores a signal it has +# no handler for. The object's destroy() sends SIGTERM, so exit on it. +import json +import os +import signal +import socket +import sys +from http.server import BaseHTTPRequestHandler, HTTPServer + +signal.signal(signal.SIGTERM, lambda *_: sys.exit(0)) + + +class Handler(BaseHTTPRequestHandler): + def do_GET(self): + body = json.dumps({ + "hostname": socket.gethostname(), + "path": self.path, + "message": os.environ.get("MESSAGE", ""), + }).encode() + self.send_response(200) + self.send_header("content-type", "application/json") + self.send_header("content-length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *args): + pass + + +HTTPServer(("0.0.0.0", int(os.environ["PORT"])), Handler).serve_forever() diff --git a/packages/conformance/containers-app/wrangler.json b/packages/conformance/containers-app/wrangler.json new file mode 100644 index 0000000..b15b461 --- /dev/null +++ b/packages/conformance/containers-app/wrangler.json @@ -0,0 +1,17 @@ +{ + "name": "sobjects-conformance-containers", + "main": "index.js", + "compatibility_date": "2026-02-24", + "compatibility_flags": ["nodejs_compat"], + "containers": [ + { + "class_name": "Box", + "image": "./Dockerfile", + "instance_type": "basic" + } + ], + "durable_objects": { + "bindings": [{ "name": "BOX", "class_name": "Box" }] + }, + "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Box"] }] +} diff --git a/packages/conformance/package.json b/packages/conformance/package.json index af1bca9..a33b4ed 100644 --- a/packages/conformance/package.json +++ b/packages/conformance/package.json @@ -7,12 +7,14 @@ "test": "node --test test/*.test.js", "test:wrangler": "node src/run.js --target wrangler", "test:celld": "node src/run.js --target celld", + "test:containers": "node src/run.js --target celld --suite containers", "test:native": "node src/run.js --target native", "test:product": "node src/product.js", "bench": "node src/bench.js", "test:cloudflare": "node src/run.js --target cloudflare" }, "devDependencies": { + "@cloudflare/sandbox": "1.0.1", "agents": "0.28.1", "partyserver": "^0.5.10", "wrangler": "4.150.0" diff --git a/packages/conformance/src/run.js b/packages/conformance/src/run.js index a45c734..490195d 100644 --- a/packages/conformance/src/run.js +++ b/packages/conformance/src/run.js @@ -10,6 +10,7 @@ const SUITES = { core: path.join(PACKAGE_DIR, "app"), agents: path.join(PACKAGE_DIR, "agents-app"), party: path.join(PACKAGE_DIR, "party-app"), + containers: path.join(PACKAGE_DIR, "containers-app"), }; const SOBJECTS_BIN = path.resolve(PACKAGE_DIR, "..", "cli", "bin", "sobjects.mjs"); const DEFAULT_CELLD_BIN = path.join(os.homedir(), ".local/share/serverless-objects/engines/celld-0.6.2/celld"); @@ -22,7 +23,7 @@ export function parseArgs(args) { alarmDelayMs: undefined, restartAfterAlarm: undefined, celldBin: process.env.CELLD_BIN ?? DEFAULT_CELLD_BIN, - suites: Object.keys(SUITES), + suites: ["core", "agents", "party"], }; for (let index = 0; index < args.length; index += 1) { @@ -34,7 +35,7 @@ export function parseArgs(args) { else if (arg === "--celld-bin") options.celldBin = args[++index]; else if (arg === "--suite") { const suite = args[++index]; - options.suites = suite === "all" ? Object.keys(SUITES) : [suite]; + options.suites = suite === "all" ? ["core", "agents", "party"] : [suite]; } else if (arg === "--restart-after-alarm") options.restartAfterAlarm = true; else if (arg === "--keep-deployment") options.keepDeployment = true; @@ -48,7 +49,8 @@ export function parseArgs(args) { if (options.help) return options; if (!["wrangler", "celld", "native", "cloudflare"].includes(options.target)) throw new Error("--target must be wrangler, celld, native or cloudflare"); if (options.target === "cloudflare" && options.restartAfterAlarm) throw new Error("--restart-after-alarm is not possible on Cloudflare"); - if (options.suites.some((suite) => !SUITES[suite])) throw new Error("--suite must be core, agents, party, or all"); + if (options.suites.some((suite) => !SUITES[suite])) throw new Error("--suite must be core, agents, party, containers, or all"); + if (options.suites.includes("containers") && options.target !== "celld") throw new Error("--suite containers requires --target celld"); if (!Number.isInteger(options.port) || options.port < 1 || options.port > 65_535) throw new Error("--port must be an integer from 1 to 65535"); if (!Number.isInteger(options.timeoutMs) || options.timeoutMs < 1_000) throw new Error("--timeout must be at least 1000 milliseconds"); if (options.alarmDelayMs !== undefined && (!Number.isInteger(options.alarmDelayMs) || options.alarmDelayMs < 1_000)) { @@ -76,7 +78,7 @@ function usage() { " --timeout MS Startup timeout (default: 60000)", " --alarm-delay MS Alarm delay (default: 2000; 30000 with restart)", " --celld-bin PATH celld executable (or set CELLD_BIN)", - " --suite SUITE core, agents, party, or all (default: all)", + " --suite SUITE core, agents, party, containers, or all (default: all)", " --keep-deployment cloudflare: leave the Workers deployed afterwards", " --native-threads N native: run the engine on N worker threads", " --native-arg ARG native: pass ARG to sobjects dev (repeatable)", @@ -151,7 +153,7 @@ export async function waitForServer(child, baseUrl, timeoutMs) { throw new Error(`Target did not become ready within ${timeoutMs}ms${lastError ? `: ${lastError.message}` : ""}`); } -export async function runCases(baseUrl) { +export async function runCases(baseUrl, timeoutMs = 30_000) { const listResponse = await fetch(`${baseUrl}/cases`, { signal: AbortSignal.timeout(5_000) }); if (!listResponse.ok) throw new Error(`/cases returned HTTP ${listResponse.status}`); const names = await listResponse.json(); @@ -161,7 +163,7 @@ export async function runCases(baseUrl) { const results = []; for (const name of names) { - const response = await fetch(`${baseUrl}/case/${encodeURIComponent(name)}`, { signal: AbortSignal.timeout(30_000) }); + const response = await fetch(`${baseUrl}/case/${encodeURIComponent(name)}`, { signal: AbortSignal.timeout(timeoutMs) }); const body = await response.json().catch(() => null); results.push(validateCaseResult(name, response, body)); } @@ -307,6 +309,48 @@ async function runPitrCheck(baseUrl) { return validateCaseResult("point-in-time-recovery", response, await response.json()); } +// Containers: the app's start() polls exec() for readiness because celld's +// start() returns before the container exists. The sleep check relies on +// CELLD_IDLE_EVICT_S (2s in the runner) and the container's inactivity window; +// the restart check relies on the runner's process restart. +async function containerJson(url, timeoutMs) { + const response = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) }); + const body = await response.text(); + if (!response.ok) throw new Error(`${url.pathname} returned HTTP ${response.status}: ${body.slice(0, 500)}`); + try { + return JSON.parse(body); + } catch { + throw new Error(`${url.pathname} returned non-JSON: ${body.slice(0, 500)}`); + } +} + +async function runContainerSleepCheck(baseUrl) { + const first = await containerJson(new URL("/container/start?name=sleep&marker=sleep-marker", baseUrl), 300_000); + if (!first.running) throw new Error(`container did not start: ${JSON.stringify(first)}`); + // The object is evicted after CELLD_IDLE_EVICT_S; the container's default + // inactivity window (10 minutes) keeps the container itself alive. + await new Promise((resolve) => setTimeout(resolve, 8_000)); + const after = await containerJson(new URL("/container/state?name=sleep", baseUrl), 60_000); + if (after.instance === first.instance) throw new Error("the object was not evicted while idle; sleep was not exercised"); + if (!after.running) throw new Error(`the container did not survive the idle eviction: ${JSON.stringify(after)}`); + if (after.marker !== "sleep-marker") throw new Error(`the container lost its filesystem: ${JSON.stringify(after)}`); + if (after.hostname !== first.hostname) throw new Error(`a different container answered: ${JSON.stringify({ first, after })}`); + return { pass: true, detail: "the object was evicted while idle; the next request reached a new instance and the same running container" }; +} + +async function runContainerRestartCheck(baseUrl, restart) { + const first = await containerJson(new URL("/container/start?name=restart&marker=restart-marker", baseUrl), 300_000); + if (!first.running) throw new Error(`container did not start: ${JSON.stringify(first)}`); + await restart(); + const after = await containerJson(new URL("/container/state?name=restart", baseUrl), 60_000); + if (after.running) throw new Error(`the container survived a node restart: ${JSON.stringify(after)}`); + if (after.marker !== null) throw new Error(`the container filesystem survived a node restart: ${JSON.stringify(after)}`); + const second = await containerJson(new URL("/container/start?name=restart&marker=restart-marker-2", baseUrl), 300_000); + if (!second.running) throw new Error(`the container did not start after the restart: ${JSON.stringify(second)}`); + if (second.hostname === first.hostname) throw new Error(`the same container answered after the restart: ${JSON.stringify({ first, second })}`); + return { pass: true, detail: "a node restart destroyed the container; the next start created a new one" }; +} + // Facets are part of the Durable Objects contract. workerd and celld 0.6.2 // implement them; the native engine has no ctx.facets, so it skips this. async function runFacetCheck(baseUrl) { @@ -483,7 +527,7 @@ async function runSuite(suite, options, scratchDir) { try { await start(); - const results = await runCases(baseUrl); + const results = await runCases(baseUrl, suite === "containers" ? 300_000 : 30_000); // A check that throws is a failed check, not a failed run. const record = async (name, check) => { try { @@ -505,6 +549,9 @@ async function runSuite(suite, options, scratchDir) { await record("client-protocol", () => runAgentsClientCheck(baseUrl)); await record("schedule-fires", () => runAgentsScheduleCheck(baseUrl)); if (options.restartAfterAlarm) await record("schedule-across-restart", () => runAgentsScheduleRestartCheck(baseUrl, restart)); + } else if (suite === "containers") { + await record("sleep", () => runContainerSleepCheck(baseUrl)); + if (options.restartAfterAlarm) await record("restart", () => runContainerRestartCheck(baseUrl, restart)); } else { await record("websocket-broadcast", () => runPartyWebSocketCheck(baseUrl)); // Wrangler's local runtime gives the runner no eviction control. diff --git a/packages/conformance/test/run.test.js b/packages/conformance/test/run.test.js index b724c7d..c2d8e4c 100644 --- a/packages/conformance/test/run.test.js +++ b/packages/conformance/test/run.test.js @@ -38,6 +38,12 @@ test("runs every suite unless one is selected", () => { assert.throws(() => parseArgs(["--suite", "partyserver"]), /--suite must be/); }); +test("containers is opt-in and needs celld", () => { + assert.deepEqual(parseArgs(["--target", "celld", "--suite", "containers"]).suites, ["containers"]); + assert.throws(() => parseArgs(["--suite", "containers"]), /requires --target celld/); + assert.throws(() => parseArgs(["--target", "native", "--suite", "containers"]), /requires --target celld/); +}); + test("native runs on this checkout's CLI and checks an alarm across restart", () => { const options = parseArgs(["--target", "native"]); assert.equal(options.restartAfterAlarm, true);