Skip to content

[wrangler] Explain authentication required by remote bindings - #14806

Merged
petebacondarwin merged 3 commits into
cloudflare:mainfrom
akim136:agent/remote-binding-auth-context
Jul 27, 2026
Merged

[wrangler] Explain authentication required by remote bindings#14806
petebacondarwin merged 3 commits into
cloudflare:mainfrom
akim136:agent/remote-binding-auth-context

Conversation

@akim136

@akim136 akim136 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #14798.

When local development starts bindings that need to run remotely, Wrangler now explains why Cloudflare authentication is required before showing the existing API token or OAuth recovery guidance.

It also maps the edge-preview API's 10405 response into the same friendly remote-session authentication error. This preserves the original error cause, telemetry message, and remediation steps. Tests cover all three observed API authentication codes and snapshot the API token and OAuth messages.

Risk: error-handling/message-only. No authentication or remote-binding behavior changes.

Validation:

  • pnpm -w test:ci -F @cloudflare/remote-bindings — 5 files and 18 tests passed
  • pnpm check — 197 tasks passed, including build, lint, formatting, typechecks, and type tests
  • pnpm changeset status --since=upstream/main — Wrangler patch changeset detected

  • Tests
    • Tests included/updated
  • Public documentation
    • Cloudflare docs PR(s): N/A
    • Documentation not necessary because: This only clarifies an existing Wrangler error message.

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dced430

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@akim136
akim136 marked this pull request as ready for review July 22, 2026 15:44
@akim136
akim136 requested a review from workers-devprod as a code owner July 22, 2026 15:44
@workers-devprod
workers-devprod requested review from a team and penalosa and removed request for a team July 22, 2026 15:45
@workers-devprod

workers-devprod commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@allocsys

Copy link
Copy Markdown
Contributor

Nice fix for the messaging! One gap I found while digging into #14798 that this PR doesn't cover yet: the handleUserFriendlyError() switch still only matches case 9106: case 10000:, so it won't catch the actual failure mode reported in the issue.

I ran a curl matrix directly against /accounts/{id}/workers/subdomain/edge-preview (the endpoint createPreviewSession() hits) with a few auth states:

  • No Authorization header at all → code 9106 (already handled)
  • Empty/garbage Authorization → code 9106 (already handled)
  • A well-formed-but-invalid Bearer token → code 10405, "Method not allowed for this authentication scheme" (405) — not in the switch, falls through to default and dumps the raw APIError

The reason this matters for the reported bug specifically: requireAuth() (packages/workers-auth/src/core/factory.ts) can succeed purely from local cached state — getActiveAccountId() returns a cached id with no network call, and loginOrRefreshIfRequired() only checks local token expiry, never server-side revocation. So a stale/revoked token sails through requireAuth() and only gets validated for real when the edge-preview request goes out — which returns 10405, not 9106/10000.

So even with this PR's improved copy, a user with a stale/revoked token would still see the raw, unexplained APIError — the exact symptom in the original report — since it never reaches the code path that throws RemoteSessionAuthenticationError.

Suggest widening the switch to also catch 10405:

case 9106:
case 10000:
case 10405: {
  throw new RemoteSessionAuthenticationError(error);
}

Happy to share the repro workflow (live curl matrix + a small unit test suite covering this) if useful.

@akim136
akim136 force-pushed the agent/remote-binding-auth-context branch from 9910b05 to ab4ffff Compare July 22, 2026 21:39
@akim136

akim136 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Great catch @allocsys! I’ve added 10405 to the remote-session authentication cases and covered it with an API error using HTTP 405. I kept the change scoped to remote-binding session errors rather than widening Wrangler’s global authentication classifier. The remote-bindings tests and repository checks pass.

@petebacondarwin
petebacondarwin removed the request for review from penalosa July 27, 2026 09:04
@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 27, 2026

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jul 27, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14806

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@14806

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14806

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14806

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14806

miniflare

npm i https://pkg.pr.new/miniflare@14806

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14806

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14806

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14806

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14806

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14806

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14806

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14806

wrangler

npm i https://pkg.pr.new/wrangler@14806

commit: dced430

@petebacondarwin
petebacondarwin enabled auto-merge (squash) July 27, 2026 09:16
@petebacondarwin
petebacondarwin merged commit e8b3a9d into cloudflare:main Jul 27, 2026
73 of 75 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

unclear error message when developing with remote bindings and not logged in

4 participants