Skip to content

[wrangler] Widen agent Pages-to-Workers delegation for new projects - #15004

Open
MattieTK wants to merge 3 commits into
mainfrom
fix/pages-delegation-branch-flags
Open

[wrangler] Widen agent Pages-to-Workers delegation for new projects#15004
MattieTK wants to merge 3 commits into
mainfrom
fix/pages-delegation-branch-flags

Conversation

@MattieTK

@MattieTK MattieTK commented Aug 3, 2026

Copy link
Copy Markdown
Member

Two related changes that widen the agent Pages-to-Workers delegation so the common "brand-new static project" case lands on Workers instead of falling through to a direct Pages deploy. Both remain agent-only.

Branch flags no longer disqualify delegation

wrangler pages deploy --branch <name> and wrangler pages project create --production-branch <name> are now eligible for delegation. A branch flag was implicitly treated as evidence that an established Pages project already existed, so its presence bypassed delegation. But delegation only ever fires for a brand-new project, where a branch flag merely names the production branch – exactly what a Workers static-assets deploy targets. There are no preview-deployment semantics to preserve, so the flag no longer needs to disqualify the command. Genuinely Pages-only flags (--commit-hash, --commit-message, --commit-dirty, --skip-caching) still disqualify a deploy.

Per-project delegation gate

The gate is now per-project rather than per-account. Previously an account that already had any Pages project was never delegated; now a brand-new project is delegated even when the account has other Pages projects, while a deploy to an existing project stays on Pages. This also drops the paginated list-projects API call from the delegation path in favour of the project-existence signal the deploy command already computes.

The experimental rationale telemetry and the opt-out-flag rename from the same research branch are intentionally not included here.


  • 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: this refines the internal, agent-only Pages-to-Workers delegation heuristic. The opt-out flag and the delegation itself are hidden and not part of user-facing documented behaviour, so there is no public documentation to update.

A --branch (deploy) or --production-branch (project create) flag no longer
disqualifies an agent command from Pages-to-Workers delegation. Delegation
only fires for a brand-new project, where a branch flag merely names the
production branch — exactly what a Workers deploy targets — so there are no
preview-deployment semantics to preserve. Genuinely Pages-only flags
(--commit-*, --skip-caching) still disqualify a deploy.

(cherry picked from commit 26d0988)
@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 56f973d

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 3, 2026
@workers-devprod
workers-devprod requested review from a team and dario-piotrowicz and removed request for a team August 3, 2026 18:10
@workers-devprod

workers-devprod commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@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 potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@ask-bonk

ask-bonk Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

These tests run in a non-agent environment (no agent mocked), so delegation short-circuits at the detectAgent() check and these tests remain unaffected. The change is safe.

I've completed a thorough review:

  • Logic: The core reasoning is sound. The accountHasPagesProjects gate (delegate-to-workers.ts:210-227) guarantees delegation only fires for brand-new projects, so a branch flag genuinely just names the production branch. Removing --branch/--production-branch from the unsupported-args list is correct.
  • getUnsupportedDeployDelegateArgs: The filter value !== undefined && value !== false still correctly disqualifies the genuinely-Pages-only flags. Exporting it for testing is fine.
  • Tests: The deploy-side tests are thorough. The delegate-to-workers.test.ts swap from --branch to --commit-hash correctly preserves the unsupported-args coverage.
  • No regressions: Existing project-create tests run in non-agent mode, so they're unaffected.
  • Backward compatibility: This is a hidden, agent-only heuristic; no user-facing behavior changes for humans.

The only minor observations (test-coverage gap for the projects.ts delegation path, and the branch name not being carried into the Workers deploy) are not bugs — the latter is intentional since a delegated Workers static deploy is always a production deploy.

LGTM

github run

@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15004

@cloudflare/config

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

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15004

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 56f973d

@MattieTK MattieTK changed the title [wrangler] Delegate agent Pages deploys that target a production branch [wrangler] Widen agent Pages-to-Workers delegation for new projects Aug 3, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

…r-account

Replace the per-account `accountHasPagesProjects` check with a per-project
`projectExists` gate, so an agent deploying or creating a brand-new static
Pages project is delegated to a Workers static-assets deploy even when the
account already has other Pages projects. A command targeting a project that
already exists stays on Pages: `pages deploy` reuses the existence lookup it
already performs, and `pages project create` resolves it lazily (agents only)
so a name clash is left on Pages instead of being deployed to Workers under
that name.
@MattieTK
MattieTK force-pushed the fix/pages-delegation-branch-flags branch from 58cb354 to b72720f Compare August 3, 2026 23:38

@dario-piotrowicz dario-piotrowicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with a minor nit

Comment on lines +100 to +107
/**
* Whether a Pages project with the given name already exists on the account.
*
* Returns false for a missing name or a not-found project; any other API error
* propagates so the caller can decide how to treat a failed lookup (the
* delegation gate skips delegation rather than risk delegating over a project
* that may already exist).
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: personally I love using @params and @returns as they make the comment more readable and clear

@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 Aug 4, 2026
Convert the pagesProjectExists and getUnsupportedDeployDelegateArgs doc comments to @param/@returns/@throws form for readability, per review feedback. Comment-only; no behaviour change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

3 participants