Repository navigation
void deploy in CI fails when the project build opens a Cloudflare remote session (Astro prerender with ai) #425
Description
Problem
A direct Cloudflare app whose build opens a remote-bindings session cannot be
deployed from CI, even with CLOUDFLARE_API_TOKEN set. Known cases:
- Astro (
@astrojs/cloudflare14.x) with at least one prerendered page and an
aibinding (Void writesai: { binding, remote: true }into the project
config during dev for apps that importvoid/ai). - SvelteKit 2 with
adapter-cloudflare7.x and prerendered pages (code only;
kit 3 / adapter 8 has no build-time platform emulation).
The build stops with:
Establishing remote connection...
Failed to start the remote proxy session. ... In a non-interactive environment,
it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for cf to work.
The user did set the token, so the message is misleading.
Locally this is fixed by #424: the Void plugin selects the void cloudflare login
session for direct Cloudflare apps, so a local build's remote session uses the
same login as void deploy. CI has no stored login, and the deploy build removes
the token from the project build on purpose (see Cause).
Repro
- Astro 7 app with
@astrojs/cloudflare14.3.4,voidPlugin(),.void/project.json
{ "platform": "cloudflare" }, a route importingvoid/ai, and one page with
export const prerender = true. Runvp devonce (adds the remoteaibinding). - In CI (no cf login,
CI=1), setCLOUDFLARE_API_TOKENand run
void deploy --platform cloudflare. - The build fails as above. A plain
astro buildwith the token in the
environment should work, because nothing removes the token there (expected
from the auth order, not run).
The void deploy path is traced in code, not run. A plain astro build with no
token and CI=1 shows the same failure live.
Cause
packages/void/src/cli/deploy-cloudflare-build.ts:76-78builds the child env
withscrubWranglerAuthCredentials(deployChildEnv(...))and runs the project
build with it (:103).packages/void/src/cli/deploy-transport.ts:225-235deletes every name in
WRANGLER_AUTH_CREDENTIAL_ENV_VARS(packages/void/src/shared/untrusted-env.ts:4-17),
includingCLOUDFLARE_API_TOKEN. This is on purpose: the build runs project
code (Vite config, plugins, adapters), and the orchestrator keeps its API
credentials away from it (buildCloudflareWorkerdoc comment,:43).@astrojs/cloudflaredist/prerenderer.js:107-121startsvite.preview()
with the Cloudflare plugin;@cloudflare/vite-plugin1.64.0
dist/index.mjs:96433 -> 95823 -> 92706starts a remote session becauseai
is never local (pickRemoteBindings,:92698). With no token and no stored
login in CI, authentication fails.
Options
- Pass the token to the build only when needed. Simple, but it hands the
deploy credential to project code, which the build isolation exists to prevent.
Not recommended. - Turn off remote bindings for the deploy build when the deploy uses an
environment token. SetCLOUDFLARE_VITE_FORCE_LOCAL=trueinbuildChildEnv
(@cloudflare/vite-plugindist/index.mjs:71972maps it to
remoteBindings: false). Pages that do not call AI at build time would
prerender. Gaps: Wrangler'sgetPlatformProxy(SvelteKit 2) has no env
switch, only aremoteBindingsoption the adapter owns; a page that calls
AI while prerendering would fail with a missing-binding error instead.
Needs a check of how the plugin treats a never-local binding when remote
bindings are off. - Strip
remote: true/ the dev-onlyaibinding from the config the
deploy build reads. Void writes that binding for dev; the build does not
need it, because production gets the binding at upload. Needs care: the
adapter copiesaiinto the prerender Worker, and AI is remote even
without the flag, so the binding itself would have to be dropped for the
build and restored for dev. - Document it. In CI, run the deploy from a job that does not prerender
pages needing remote bindings, or mark such pages dynamic.
Recommendation: try option 2 behind a test that runs the Astro prerender with
the deploy build env, and keep option 4 as the interim docs note.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix: use the Void Cloudflare login in dev and unblock self-hosted pla…