Skip to content

Align preview port APIs with forwarding#709

Draft
ghostwriternr wants to merge 1 commit into
preview-stack-v2/01-preview-runtime-activationfrom
preview-stack-v2/02-preview-port-state
Draft

Align preview port APIs with forwarding#709
ghostwriternr wants to merge 1 commit into
preview-stack-v2/01-preview-runtime-activationfrom
preview-stack-v2/02-preview-port-state

Conversation

@ghostwriternr
Copy link
Copy Markdown
Member

@ghostwriternr ghostwriternr commented May 19, 2026

After preview forwarding becomes current-runtime scoped, the public preview-port APIs need to report the same state that forwarding uses. Otherwise users can see a port reported as exposed even though its preview URL is stale and cannot forward without an explicit exposePort() call in the current runtime.

In this stack, persistent token authorization means the preview token is still valid, while current-runtime activation means exposePort() has been called for that port in the currently running container runtime.

This change aligns the public preview-port surface with that model.

getExposedPorts(hostname) now reports only ports whose preview URLs can be used without another exposePort() call: a valid token exists, the sandbox has a current runtime, and the port activation was created for that runtime.

isPortExposed(port) now answers the same question for one port. It no longer treats persistent token authorization alone as proof that the preview URL can forward.

unexposePort(port) is now idempotent Durable Object-owned revocation. It clears token authorization and runtime activation without waking or reaching the container.

exposePort() and unexposePort() no longer depend on the old container-local exposed-port registry RPCs. The Sandbox Durable Object’s token and activation records are now the source of truth for deciding whether preview traffic may forward.

The desktop preview integration now also obtains URLs through exposePort(). It can no longer synthesize a URL from a persisted token when exposePort() fails to create current-runtime activation.

This PR intentionally does not delete the old container-local registry. It only stops the public Sandbox preview-port surface from relying on it. The registry deletion happens in the next PR once the new source of truth is in place.


This is part 2 of 3 in the preview URL lifecycle stack:

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

⚠️ No Changeset found

Latest commit: 651f1ad

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox Minor

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@709

commit: 651f1ad

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

📦 Preview Build

Version: 0.0.0-pr-709-651f1ad

Install the SDK preview:

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@709

🐳 Docker images were not rebuilt — no container changes detected. Use the latest release images from Docker Hub.

Copy link
Copy Markdown
Contributor

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

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

@ghostwriternr ghostwriternr force-pushed the preview-stack-v2/01-preview-runtime-activation branch from ccfb032 to 61c6d64 Compare May 20, 2026 10:36
@ghostwriternr ghostwriternr force-pushed the preview-stack-v2/02-preview-port-state branch 3 times, most recently from 4de3df0 to 41402d2 Compare May 20, 2026 15:24
@ghostwriternr ghostwriternr force-pushed the preview-stack-v2/02-preview-port-state branch from 41402d2 to 651f1ad Compare May 21, 2026 12:17
Copy link
Copy Markdown
Contributor

@scuffi scuffi left a comment

Choose a reason for hiding this comment

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

really cool approach 🫶

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.

2 participants