Skip to content

[wrangler] Experiment: redirect agent-driven static Pages deploys to Workers#14312

Draft
MattieTK wants to merge 1 commit into
mainfrom
experiment/intercept-pages-deploy-redirect-to-workers
Draft

[wrangler] Experiment: redirect agent-driven static Pages deploys to Workers#14312
MattieTK wants to merge 1 commit into
mainfrom
experiment/intercept-pages-deploy-redirect-to-workers

Conversation

@MattieTK

Copy link
Copy Markdown
Member

Experiment — do not merge.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: experiment, not intended for release.

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6455144

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

This PR includes changesets to release 3 packages
Name Type
wrangler Minor
@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

@ask-bonk ask-bonk 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.

I'm Bonk, and I've done a quick review of your PR.

This adds an experimental path that, when Wrangler detects it is being driven by an AI agent, redirects brand-new static pages deploy / pages project create invocations to a Workers static-assets deploy (with fallback to Pages on failure).

Ranked issues:

  1. (High) The user-specified deploy directory is silently dropped on redirect — main(["deploy"]) ignores options.assetsDirectory, so a user running wrangler pages deploy ./dist gets autoconfig guessing the assets dir instead of using ./dist. This can deploy the wrong directory.
  2. (Low) getDetectedAgentId() re-invokes detectAgenticEnvironment a second time (once in isAgenticAgent, once here) per redirect. Minor, but the detection result could be computed once and threaded through.

Noting the PR is explicitly an experiment / do-not-merge, so I've kept this to behavioral correctness rather than polish.

// Passing no positional path is deliberate — it makes `wrangler deploy`
// run autoconfig, which detects the static assets directory and
// configures the project for Workers.
await main(["deploy"]);

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.

The user's requested assets directory is dropped here. For pages deploy <directory>, options.assetsDirectory holds the directory the user explicitly asked to deploy, but main(["deploy"]) is called with no path and no --assets, so autoconfig will re-detect the assets directory and may pick a different one than the user specified. Forward the directory so the redirect deploys what the user asked for:

Suggested change
await main(["deploy"]);
// Forward the user-specified assets directory (when present) so the
// Workers deploy targets the same files the Pages command would have.
// Without this, autoconfig re-detects the directory and may choose a
// different one than the user requested.
const deployArgs =
options.assetsDirectory !== undefined
? ["deploy", "--assets", options.assetsDirectory]
: ["deploy"];
await main(deployArgs);

@ask-bonk

ask-bonk Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully to PR #14312.

Summary of what I posted:

  • A high-severity inline suggestion on redirect-to-workers.ts:78: the user-specified deploy directory (options.assetsDirectory) is dropped when calling main(["deploy"]), so autoconfig re-detects the assets directory and may deploy the wrong one. Suggested forwarding it as --assets.
  • A low-severity note that detectAgenticEnvironment runs twice per redirect (once in isAgenticAgent, once in getDetectedAgentId).

I acknowledged the PR is an explicit experiment/do-not-merge and kept feedback focused on behavioral correctness.

github run

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@MattieTK MattieTK force-pushed the experiment/intercept-pages-deploy-redirect-to-workers branch from b241ef5 to 6455144 Compare June 16, 2026 00:57
@MattieTK MattieTK marked this pull request as ready for review June 16, 2026 00:59
@MattieTK MattieTK marked this pull request as draft June 16, 2026 01:00
@workers-devprod workers-devprod requested review from a team and NuroDev and removed request for a team June 16, 2026 01:00
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/agentic-pages-to-workers-redirect.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/pages/redirect-to-workers.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/utils/detect-agent.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/vitest.setup.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deploy/autoconfig.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/metrics/send-event.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/pages/deploy.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/pages/projects.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/pages/redirect-to-workers.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/utils/detect-agent.ts: [@cloudflare/wrangler]

@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 found 1 potential issue.

Open in Devin Review

Comment on lines +144 to +150
const redirect = await maybeRedirectPagesToWorkers({
command: "create",
projectPath: process.cwd(),
});
if (redirect.handled) {
return;
}

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.

🚩 Redirect from pages project create silently discards user-provided project name

When an AI agent runs wrangler pages project create my-app, the handler at packages/wrangler/src/pages/projects.ts:144-150 calls maybeRedirectPagesToWorkers({ command: "create", projectPath: process.cwd() }) — the projectName argument (which is demandOption: true) is not forwarded. The redirect then invokes main(["deploy"]) (redirect-to-workers.ts:78), which runs autoconfig. Autoconfig derives the project name from the directory name, not from the agent's requested name. So wrangler pages project create my-api in a directory named my-project would create a Workers project named my-project, not my-api. This also changes semantics from "create project only" to "create AND deploy". This appears intentional per the changeset description but is worth noting as a potential source of agent confusion.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

Copy link
Copy Markdown
create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 6455144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants