Repository navigation
Pause items above the plan's caps on a downgrade and restore them - #1602
Open
helpcodeai wants to merge 3 commits into
Open
helpcodeai wants to merge 3 commits into
helpcodeai wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Cloud trial now has the Team limits (#1599). A workspace that then buys Starter must end up within Starter's limits without losing anything for good, and without a surprise. This PR adds the automatic downgrade, its undo, and the caps that keep a paid workspace within its plan. It is switched by
PLAN_CAPS_ENFORCE, which defaults todry-run: on the first deploy nothing is refused or paused, and the backend only logs what it would do.Stacked on #1601 (plan fit), whose ranking it uses, so the paywall warning and the downgrade name the same items.
Changes
LicenseService. Every Cloud licence write goes throughverifyLicenseorsetLicenseKey: checkout, card-trial conversion, a billing-portal change reported by the site, a key entered by hand. These compare the workspace's current plan before and after and callonPlanChangelisteners (fire and forget: a listener never fails or delays the write). Nothing changes on self-hosted. When nothing listens, no extra query runs.PlanCapsService(newplan-capsmodule):isActive=false) the connectors, MCP servers and File Search folders above the caps, least used first (tool calls in the last 30 days); reloads their tools; stores the ids in OrgSettingsplan_caps_paused; emails the admins (new transactional template); logsplan_caps_applied.LicenseGuardService), counting only active items:PLAN_LIMITcode); paid plans are refused only when enforcement ison;checkCanActivateConnector(File Search folders count against the File Search quota) andcheckCanActivateMcpServer, used byPUT /api/connectors/:idandPUT /api/mcp-servers/:idwhen switching an item back on;checkCanAddMember, on invitation and on acceptance (existing and new accounts).403 { code: 'PLAN_LIMIT', axis, max, current, message }.GET /api/license/usagereturnspausedByPlan: { connectors, mcpServers }with the items still paused, so the dashboard can mark them.anythingmcp_list_connectorslists the paused connectors with a hint (choose which stay active at /connectors, or upgrade).docs/cloud-plans.md;PLAN_CAPS_ENFORCEindocs/deployment.md; a CLI README note on swapping andPLAN_LIMIT.Cloud vs self-hosted: Cloud only. On self-hosted, every guard returns early, the listener is not registered and the env var is ignored.
No Prisma schema change: it uses
isActiveandorg_settings.Type
Testing
In
packages/backend, afternpx prisma generate:npx jest --maxWorkers=4 src/license src/plan-caps src/connectors src/mcp-servers src/mcp-server src/adapters/adapters.controller src/adapters/connector-setup src/auth src/settings src/audit: 4,792 passed, 25 skipped, and 13 failed, all insrc/auth/jwt-or-management-key.guard.spec.ts. That spec needs a local Postgres and fails the same way onmainhere (baseline).plan-caps.service.spec.ts:plan-caps.guard.spec.ts:pausedByPlan.license.service.spec.ts.npm run lint: 0 errors. The 11 warnings already exist on main.npx tsc --noEmit -p tsconfig.json: clean.node scripts/generate-cli-operations.mjs: no change.Rollout
PLAN_CAPS_ENFORCEunset (dry-run). Watch[plan caps dry-run]log lines andplan_caps_appliedevents withstatus=dry-runfor a week, and compare them with what the paywall showed.PLAN_CAPS_ENFORCE=on.Checklist
npm test)Related Issues
Third step of the Team-trial plan: #1599 (trial limits), #1601 (plan fit), then this. The dashboard UI is a separate PR on top of #1601.