Skip to content

feat(batch,snapshot): add --runtime workerd - #134

Merged
yusukebe merged 1 commit into
nextfrom
feat/batch-snapshot-runtime
Sep 18, 2026
Merged

yusukebe merged 1 commit into
nextfrom
feat/batch-snapshot-runtime

Conversation

@yusukebe

Copy link
Copy Markdown
Member

`batch` and `snapshot` take `--runtime workerd`, like `request`. One workerd starts from the wrangler config and every step runs in it, so a flow over the real bindings (put to KV, then get; D1; an AI binding) runs in one call with `save` and `expect`. Until now the only way was `request --runtime workerd` per step, which starts workerd each time and cannot carry values between steps. Asked by a user trying an AI-binding middleware.

The workerd code moves to `src/utils/workerd.ts` and splits into a target that can be started once, asked many times, and disposed; `request` keeps using the one-shot form. `runBatch` and `snapshotLines` send to any target with a `request()` method, so a Hono app and a running workerd look the same to them. `snapshot` reads the routes from `main` in-process and sends the requests to workerd. Only `node` and `workerd` are accepted here; `bun`/`deno` point at `request`.

Checked on a real wrangler project: `snapshot --runtime workerd` reports `Cloudflare-Workers` as the user agent, and a KV put-then-get batch passes on one workerd. Known limit, not new: an app that imports `cloudflare:*` modules cannot be imported in-process, so `snapshot` (any runtime) and `routes` fail on it with a build error.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • pnpm run format:fix && pnpm run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@yusukebe
yusukebe force-pushed the feat/batch-snapshot-runtime branch from 463e71e to aa0e430 Compare September 18, 2026 01:45
@yusukebe
yusukebe merged commit 8eea046 into next Sep 18, 2026
4 checks passed
@yusukebe
yusukebe deleted the feat/batch-snapshot-runtime branch September 18, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant