fix(cloudflare): warn when the default SESSION KV binding will be auto-provisioned - #17641
Open
edwardwc wants to merge 1 commit into
Open
fix(cloudflare): warn when the default SESSION KV binding will be auto-provisioned#17641edwardwc wants to merge 1 commit into
edwardwc wants to merge 1 commit into
Conversation
…o-provisioned The adapter injects a SESSION KV binding without an `id`, which wrangler reads as a request to provision a new namespace on deploy. That requires a token with "Workers KV Storage: Edit", so deploys without it fail with an opaque `Authentication error [code: 10000]` well after the build succeeded, naming neither sessions nor the available opt-outs. Warn at build time instead, pointing at both escape hatches. Silent when the user declared the binding, when sessions are disabled, and in dev. The emitted Wrangler config is unchanged.
🦋 Changeset detectedLatest commit: a72f3c2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 43 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
The adapter injects a
SESSIONKV binding with noid, which Wrangler treats as arequest to auto-provision a namespace on deploy. That needs an API token with
Workers KV Storage: Edit, so deploys without it fail with a genericAuthentication error [code: 10000]against/storage/kv/namespaces— after thebuild already succeeded, and with nothing in the message pointing back at sessions.
astro buildnow warns when that binding is about to be provisioned, naming thepermission and both escape hatches:
Silent when the user already declared the binding, when
session: false, and duringdev(which never provisions anything). Deduplicated to one warning per build, sincethe customizer runs once per worker (entry, prerender, previews).
No change to the emitted Wrangler config. The existing
!needsSessionKVBinding || hasSessionBindingternary is extracted into a namedinjectsSessionBindingso the warning condition and the emission condition can'tdrift apart, but the output is identical.
The warning lives in
cloudflareConfigCustomizerrather than theastro:config:setuphook because that's the only place that knows whether an id-less binding is actually
being emitted — warning from
index.tswould also fire for users who correctlydeclared
SESSIONwith anid.Closes #17640
Testing
Five cases added to the existing
test/session-false.test.ts, which already covers thesibling
session: falsebehavior: warns with both key phrases, dedupes across workers,silent when user-declared, silent when sessions disabled, and doesn't throw without a
logger.
Being upfront about verification: the suite imports from
dist/, so it needs a fullmonorepo install and build, which I did not run locally. I verified the logic by
compiling
wrangler.tsstandalone and running the same assertions plus threeregressions asserting binding emission is unchanged (8/8 passing). The committed test
file itself has therefore not been executed, and
tsc -bis unconfirmed — I'dappreciate CI confirming both.
Docs
No docs change needed: this adds no API or config surface, and the new
loggeroptionis internal to the customizer.
That said, the underlying gotcha — that a default-on adapter feature makes
deployrequire
Workers KV Storage: Edit— isn't currently called out on the Cloudflaresessions docs page, and arguably should be.
/cc @withastro/maintainers-docs for feedback!