fix(engine): persist the selfhost plan for self-hosted workspaces

Closed
WI
4d ago
+321-8

Self-hosted workspaces persist the selfhost plan. The Node adapter writes selfhost on POST /v1/workspaces and, on startup, promotes rows still on the schema default free. Those workspaces use unlimited API calls and a 30,000 request per minute ceiling. Hosted workspace creation leaves defaultWorkspacePlan unset and continues to store free. Embedders select free, pro, or enterprise with EngineConfig.defaultWorkspacePlan. Workspace.plan includes selfhost.

Fixes #432.


[!NOTE]
Medium Risk
Changes default entitlements and performs a one-time SQLite plan migration on first self-host boot; wrong defaultWorkspacePlan config could leave embedders on unintended quotas, but hosted paths are unchanged.

Overview
Self-hosted engines now persist and enforce the selfhost entitlement tier instead of leaving workspaces on the schema default free (which could hit API-call quotas).

With the built-in static entitlements provider and no custom entitlements injection, the Node adapter sets EngineConfig.defaultWorkspacePlan to selfhost, so POST /v1/workspaces stores plan: selfhost (unlimited API calls, 30,000 requests/minute reflected in X-RateLimit-Limit). Embedders can override with defaultWorkspacePlan: 'free' | 'pro' | 'enterprise'. Hosted creation still omits the config and keeps storing free.

One-time legacy upgrade: on first startup when the default is selfhost, settleLegacySelfHostPlans promotes existing free rows to selfhost and records the decision in node_selfhost_plan_upgrade; later restarts do not rewrite plans. Workspaces explicitly created as free before a restart that defaults to selfhost are not promoted if the decision was already recorded under a free default.

Workspace create validates plan against PLAN_LIMITS; @relaycast/types and OpenAPI add selfhost to Workspace.plan. Docs and changelogs describe the self-host tier.

Reviewed by Cursor Bugbot for commit 9d007b048f555516a2d34e8b7fb7d0983776bd42. Bugbot is set up for automated code reviews on this repo. Configure here.