Skip to content

Better organize runtime modules - #841

Merged
cpojer merged 2 commits into
mainfrom
codex/organize-runtime-modules
Nov 16, 2026
Merged

cpojer merged 2 commits into
mainfrom
codex/organize-runtime-modules

Conversation

@yangshun

@yangshun yangshun commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Issue

Group the mostly flat runtime helpers into feature directories. The runtime root now contains only directories, with standalone public features using <feature>/index.ts. Retain descriptive engine, handler, and client/server roles in filenames. Update imports, generated-code paths, build entries, package exports and tests while preserving public void/* import names.

Before: 76 direct files and 3 directories under packages/void/src/runtime/. Filename patterns below summarize related files.

runtime/
├── ai*.ts
├── auth*.ts, better-auth*.ts
├── client*.ts, fetch*.ts
├── db*.ts, pg.ts, seed.ts
├── schema*.ts, drizzle*.ts
├── migration*.ts, mysql-migration-sql.ts
├── env*.ts
├── handler*.ts, response.ts, validator.ts
├── routing*.ts, route-url.ts, prerender-path.ts, static-asset-marker.ts
├── live*.ts
├── sandbox*.ts
├── sse*.ts
├── ws*.ts
├── durable.ts, isr.ts, kv.ts, limits.ts, log.ts, queues.ts, storage.ts
├── email.ts, email-protocol.ts
├── base64.ts
├── email/
├── error-pages/
└── remote/

After: Feature directories.

runtime/
├── ai/
├── auth/                 # index.ts, better-auth-*, client*, migrations, response
├── client/               # index.ts, framework clients, fetch helpers
├── db/
│   ├── migrations/       # *-handler, mysql-lock, mysql-sql
│   ├── schema/
│   ├── validators/       # drizzle-*
│   └── index.ts, postgres.ts, mysql.ts, pgpass.ts, seed.ts
├── durable/              # index.ts
├── email/                # index.ts, protocol.ts, testing.ts, existing helpers
├── env/                  # runtime, public, public-client, helpers, raw
├── handler/              # index.ts, composition, response, validator
├── isr/                  # index.ts
├── kv/                   # index.ts
├── limits/               # index.ts
├── live/
├── log/                  # index.ts
├── queues/               # index.ts
├── remote/
├── routing/
│   └── error-pages/
├── sandbox/
├── sse/
├── storage/              # index.ts
└── ws/

I think some files could be better categorized but I didn't want to make that many changes yet, mainly focused on organization of the runtime directory. Feel free to move more files.

Keep the email protocol beside its runtime in email/protocol.ts, and move the cross-feature base64 helper to src/shared/base64.ts. Extract email pattern compilation and dispatch ordering into src/shared/email-pattern.ts. The file scanner and runtime email test harness share this dependency-free module, removing filesystem discovery from the harness dependency graph.

Notes

  • All 57 existing package export paths and their conditions are preserved.
  • No new behavior, simply moving files around for better scannability.

Validation

  • Package/playground builds, artifact checks, formatting, lint and vp run check.
  • CI=true vp run test: full 811-file selection, with 17,326 passing tests (35 skipped).
  • Full packed-consumer acceptance with npm and pnpm across React, Vue, Svelte and Solid.
  • Email test harness bundles with filesystem imports rejected.

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://codex-organize-runtime-modules-void-cloud.voidzero-docs.workers.dev (commit db1a52c)

This URL reflects your latest Preview deployment

Preview Deployments by commit

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

View logs ↗
https://03a974d2-void-cloud.voidzero-docs.workers.dev db1a52c 2026-11-16T03:49:39.127Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://beb32ab9-void-cloud.voidzero-docs.workers.dev 3e60005 2026-11-16T03:34:31.003Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c7963d28-void-cloud.voidzero-docs.workers.dev 966fd65 2026-11-16T03:04:48.922Z Visit the dashboard ↗

Move runtime files with git mv without changing their contents. Keep import
and packaging updates in the following commit so small entry files retain
a clear rename history.
Update imports, generated-code paths, package exports, build entries and
tests for the feature directories while preserving public import names.
Share pure email pattern compilation and ordering between the filesystem
scanner and runtime email test harness, and retain descriptive role names.
@yangshun
yangshun force-pushed the codex/organize-runtime-modules branch from 3e60005 to db1a52c Compare November 16, 2026 03:47
@yangshun
yangshun marked this pull request as ready for review November 16, 2026 04:05
@yangshun
yangshun requested a review from a team as a code owner November 16, 2026 04:05
@yangshun yangshun changed the title Organize runtime modules by feature Organize runtime modules Nov 16, 2026
@yangshun yangshun changed the title Organize runtime modules Better organize runtime modules Nov 16, 2026

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanups!

@cpojer
cpojer merged commit 38db82c into main Nov 16, 2026
19 checks passed
@cpojer
cpojer deleted the codex/organize-runtime-modules branch November 16, 2026 04:17
kossnocorp added a commit that referenced this pull request Nov 16, 2026
kossnocorp added a commit that referenced this pull request Nov 16, 2026
morinokami added a commit to morinokami/void that referenced this pull request Nov 16, 2026
voidzero-dev#841 moved void/env from dist/runtime/env-public.mjs to
dist/runtime/env/public.mjs. The transform's filter still matched only
the old name, so the transform stopped running and Astro builds again
copied private .env and build-shell values into the server output.

- Match env/public.mjs in the filter.
- Run the filter in the unit tests, and check that it matches the file
  void/env resolves to.
- Replace the build-shell canary: void/env no longer names
  validatedCache, so that check passed without testing anything. The
  test now first checks that void/env names every canary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8F8mZTJoFUM6ZN2xrVDx9
kossnocorp added a commit that referenced this pull request Nov 17, 2026
kossnocorp added a commit that referenced this pull request Nov 17, 2026
cpojer pushed a commit to konaito/void that referenced this pull request Dec 6, 2026
…dzero-dev#1059)

The [Sandboxes guide](https://void.cloud/guide/sandboxes#run-a-command)
starts with a route that runs a command, and says that importing from
`void/sandbox` enables the required resources:

```ts
// routes/api/sandbox.ts
import { defineHandler } from 'void';
import { getSandbox } from 'void/sandbox';

export const POST = defineHandler(async (c) => {
  const sandbox = await getSandbox('default');
  const result = await sandbox.run(['node', '--version']);
  return c.json({
    exitCode: result.exitCode,
    stdout: new TextDecoder().decode(result.stdout),
  });
});
```

An app with this route and no `sandbox.image` gets a default image that
does not exist:

| | 1.13.1 | This PR |
| --- | --- | --- |
| `vp build` | Exits 0 and records
`node_modules/void/dist/sandbox.Dockerfile`, which does not exist |
Records `node_modules/void/sandbox.Dockerfile`, the file the package
ships |
| `vp dev` | Stops before it serves anything: `ENOENT: no such file or
directory, open '<app>/node_modules/void/dist/sandbox.Dockerfile'` |
Builds the image and serves. The route answers
`{"exitCode":0,"stdout":"v26.12.1\n"}` |
| Image build of `void deploy --platform cloudflare` | `docker build`
cannot read the Dockerfile, and the deploy says "Sandbox image
preparation failed. Start Docker and retry the deployment." while Docker
is running | Builds the image |

`main` has the same code as 1.13.1 here. A deploy to a Void platform
takes a different path: its manifest carries `sandbox.platformImage`,
not the Dockerfile.

`getDefaultSandboxImage()` finds the file relative to the `void/sandbox`
entry, as `../../sandbox.Dockerfile`. 38db82c (voidzero-dev#841), first released
in 1.10.0, moved that entry from `dist/runtime/sandbox.mjs` to
`dist/runtime/sandbox/index.mjs`, so the same relative URL now ends in
`dist/`. The default-image test checked only the file name.

The deploy's message hid the cause. Every failed `docker build` of a
Sandbox image got the "Start Docker" advice, also while Docker was
running:

| `docker build` | `main` | This PR |
| --- | --- | --- |
| Fails while Docker is running, for example on a missing Dockerfile |
"Sandbox image preparation failed. Start Docker and retry the
deployment." | "Sandbox image preparation failed: `docker build` exited
with code 1 for \<Dockerfile\>. See the Docker output above." |
| Fails because the daemon is not running | The same "Start Docker"
message | Unchanged |
| Is stopped by a signal | The same "Start Docker" message | "Sandbox
image preparation failed: `docker build` was stopped by SIGTERM for
\<Dockerfile\>." |
| Cannot start, because the Docker CLI is missing | `spawn docker
ENOENT` | "Sandbox image preparation failed: the Docker CLI could not be
started (spawn docker ENOENT). Check that Docker is installed and retry
the deployment." |

## Fix

- **Default image** (first commit): `package.json` names the Dockerfile
in the package's private `imports`, as `#self/sandbox.Dockerfile`, and
`getDefaultSandboxImage()` resolves it from there. The path no longer
depends on where a built module sits in `dist/`, and the packed checks
already verify that every `imports` target is in the tarball. The file
stays at the package root, so its path in an installed package does not
change.
- **Deploy message** (second and third commits): after a failed build,
the deploy asks the daemon with `docker info`. "Start Docker" stays for
a daemon that does not answer, when `docker info` exits with a non-zero
code. A build that succeeds runs no extra command.
- `docker info` gets 5 seconds, so a daemon that accepts the connection
and never answers cannot keep back the report. When the check does not
finish in time, or cannot run, the deploy reports the build failure,
whose cause Docker has printed above.
- At that deadline the deploy kills only the CLI process. `docker info`
starts the CLI plugins just to read their metadata, before it asks the
daemon, so it has no child process while it waits.

## Tests

- `packages/void/test/unit/config.test.ts`: the default-image case reads
the resolved path and compares it with the packaged Dockerfile. With
`main`'s `sandbox/config.ts` it fails with `ENOENT` for
`packages/void/dist/sandbox.Dockerfile`.
- `packages/void/test/integration/kitchen-sink-build.test.ts`: the
playground sets no `sandbox.image`, and the build case checks that the
Dockerfile recorded in `dist/ssr/wrangler.json` exists. With `main`'s
`sandbox/config.ts` it fails.
- `packages/void/test/unit/container-image.test.ts` (new, 6 cases):
`buildContainerImage()` with a stand-in Docker CLI.
- A build that succeeds: no daemon check, and `dispose()` removes the
local tag.
- A build that fails while the daemon answers, and one while it does
not.
- A `docker info` that hangs, with the deadline reached through fake
timers.
  - A build that a signal stops, and a CLI that cannot be started.

5 of the 6 `container-image` cases fail with `main`'s
`container-image.ts`; the first one checks what `main` already does. The
file is skipped on Windows, which does not launch the stand-in script by
path.

## Verification

- `vpr test:all`: builds the packages and playgrounds, runs `vp check`
and `check:types`, and runs the platform, unit and integration groups;
269/269 tasks pass.
- `node .github/scripts/packed-consumer.mjs` passes for npm and pnpm.
The `void` tarball contains `sandbox.Dockerfile`.
- By hand, in a new static Vue starter (`void init`, Vite+) with the
route above, no `sandbox` key in `void.config.ts`, and Docker 29.8.2
running:
- void 1.13.1 from npm: `vp build` and `vp dev` as in the 1.13.1 column.
- The packed build of this branch, installed with npm and with pnpm: `vp
build` and `vp dev` as in the "This PR" column. In the pnpm install, the
recorded path is under `node_modules/.pnpm/` and exists.
- By hand, `buildContainerImage()`, which the deploy runs for each
recorded Dockerfile, with the real Docker CLI (29.8.2):
- `main`'s version, with a Dockerfile that does not exist: the "Start
Docker" message, while `docker info` answers.
- This branch, with the Dockerfile that the npm app's build records: it
builds `void-sandbox-build:<uuid>` for `linux/amd64`, and `dispose()`
removes the tag.
  - A Dockerfile that does not exist: the "exited with code 1" message.
- `DOCKER_HOST` set to a socket that does not exist: the "Start Docker"
message.
- A failed build, with `docker info` sent to a socket that accepts
connections and never answers: the "exited with code 1" message after 5
seconds, and no Docker process is left.
  - A CLI path that does not exist: the "could not be started" message.
- By hand, `docker info` (29.8.2) against that socket: it runs each
plugin's metadata command when it starts, has no child process while it
waits, and leaves none when the CLI is killed.
- Not run: `void deploy --platform cloudflare` from start to end, a
deploy to a Void platform, `VOID_PACKED_SUITE=full`, a build that a
signal stops outside the unit test, and Windows.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants