Skip to content

feat(sites): migrate - #209

Merged
jamie-at-bunny merged 4 commits into
mainfrom
sites-migrate
Sep 3, 2026
Merged

feat(sites): migrate#209
jamie-at-bunny merged 4 commits into
mainfrom
sites-migrate

Conversation

@jamie-at-bunny

Copy link
Copy Markdown
Member

Temp migrate command for early sites users to use to migrate to routerless setup.

@bunnynet-devops

Copy link
Copy Markdown

@codex review

@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cd75e41

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

This PR includes changesets to release 6 packages
Name Type
@bunny.net/cli Patch
@bunny.net/cli-darwin-arm64 Patch
@bunny.net/cli-darwin-x64 Patch
@bunny.net/cli-linux-arm64 Patch
@bunny.net/cli-linux-x64 Patch
@bunny.net/cli-windows-x64 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-03T06:58:49.122782Z 6d96851 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a hidden migration command that converts router-era site state to the edge-rule architecture and cleans up the former middleware script.

  • Parses and converts version-1 site state into version 2.
  • Detaches middleware, applies site rules and cache settings, republishes the current deploy, and conditionally removes the router script.
  • Adds migration coverage and a patch changeset.

Confidence Score: 3/5

The PR is not yet safe to merge because migration can still modify a sibling pull zone sharing the same origin and can permanently delete a same-named replacement middleware script.

The ownership check compares only the storage-zone ID, which is shared by valid sibling pull zones, while script cleanup treats the expected router name as sufficient identity even when the attached script ID differs from the legacy state.

Files Needing Attention: packages/cli/src/commands/sites/api.ts

Important Files Changed

Filename Overview
packages/cli/src/commands/sites/api.ts Adds legacy-state classification and the remote-resource migration sequence, including middleware cleanup.
packages/cli/src/commands/sites/migrate.ts Defines the hidden migration command, confirmation flow, progress reporting, and completion output.
packages/cli/src/commands/sites/constants.ts Adds the version-1 state schema, parser, and conversion into the current format.
packages/cli/src/commands/sites/api.test.ts Adds migration tests covering state conversion, conflict handling, ownership mismatch, and script cleanup.
packages/cli/src/commands/sites/index.ts Registers the hidden migration command in the sites namespace.

Sequence Diagram

sequenceDiagram
    participant CLI as sites migrate
    participant Storage as Site state
    participant Core as Core API
    participant Compute as Compute API
    CLI->>Storage: Read version-1 state
    CLI->>Core: Fetch and validate pull zone
    CLI->>Core: Detach middleware
    CLI->>Core: Apply edge rules and cache settings
    CLI->>Storage: Verify state and write version 2
    CLI->>Compute: Fetch detached script
    opt Expected router identity
        CLI->>Compute: Delete router script
    end
Loading

Reviews (4): Last reviewed commit: "fixes" | Re-trigger Greptile

Comment thread packages/cli/src/commands/sites/api.ts Outdated
Comment thread packages/cli/src/commands/sites/migrate.ts Outdated
Comment thread packages/cli/src/commands/sites/migrate.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d9685188b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/cli/src/commands/sites/api.ts Outdated
await applySiteCacheSettings(coreClient, state.pullZoneId);

step("Writing site state...");
await writeRemoteState(connection, state);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Revalidate legacy state before replacing it

When a router-era deploy or publish runs after this command selects the site—especially while the user is answering the confirmation—this unconditional write uses the stale snapshot and overwrites the new deploy record and current/previous pointers. That can silently roll production back and lose deploy history; carry the raw state's hash/etag through selection and abort or merge if it changed before writing version 2.

Useful? React with 👍 / 👎.

Comment thread packages/cli/src/commands/sites/api.ts Outdated
await applySiteCacheSettings(coreClient, state.pullZoneId);

step("Writing site state...");
await writeRemoteState(connection, state);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Finalize state only after fallible migration steps

If promoteDeploy throws after this version-2 write—for example because hostname resolution, an edge-rule request, or a purge fails—the next sites migrate run classifies the zone as already migrated and refuses to resume. Script deletion was never reached, and its ID has already been removed from state, so the automatic cleanup cannot be retried; leave the legacy marker in place until the remaining steps finish or preserve resumable migration metadata.

Useful? React with 👍 / 👎.

Comment thread packages/cli/src/commands/sites/api.ts
Comment thread packages/cli/src/commands/sites/api.ts
Comment thread packages/cli/src/commands/sites/api.ts Outdated
@jamie-at-bunny
jamie-at-bunny merged commit ffc2fb3 into main Sep 3, 2026
5 checks passed
@jamie-at-bunny
jamie-at-bunny deleted the sites-migrate branch September 3, 2026 15:50
@github-actions github-actions Bot mentioned this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants