Title: feat(admin): move a workspace between organizations by mzxchandra · Pull Request #7254 · simstudioai/sim · GitHub
Open Graph Title: feat(admin): move a workspace between organizations by mzxchandra · Pull Request #7254 · simstudioai/sim
X Title: feat(admin): move a workspace between organizations by mzxchandra · Pull Request #7254 · simstudioai/sim
Description: Summary Lets the admin panel move a workspace from one organization to another. The move was restricted to personal/grandfathered sources — assertWorkspaceMovable threw "Inter-organization workspace transfers are not supported" — so support could only re-home a workspace with manual SQL. Most of the machinery already existed: durable operation IDs, seat-capacity checks, and changeWorkspaceStoragePayerInTx, which already accepted an arbitrary source payer, so the storage-ledger rebalance between two orgs needed no change. The work is a guard relaxation plus handling what the source organization loses. Two invariants this feature could break, now enforced here Moving a workspace between organizations is the first operation in the product capable of separating an artifact from the org that owns it. Two invariants nothing has ever had to defend: A custom block and its bound workflow always share an organization. publishCustomBlock refuses a workflow outside the target org, so the pair has always been co-located. getCustomBlockAuthority resolves by the consumer's org, and admitCustomBlockChildExecution deliberately skips its concurrency reservation because "the consumer and source workspaces are always in the same organization". A stranded row would run a foreign tenant's workflow under its owner's credentials, billed to the wrong payer. The move unpublishes those blocks through the product's own deleteCustomBlock, and records CUSTOM_BLOCK_DELETED in the source org's audit view. A fork parent and child always share an organization. assertCanFork pins the child to the source's org and resolveForkEdge has no org check at all. The move refuses while a cross-org edge would result; the fork must be disconnected first. Three blockers Each is evaluated in preflight and re-checked inside the transaction, because a subscription can lapse, a fork can be created, and an invitation can arrive in between. Blocker Code Why Cross-org fork edge fork-lineage-conflict Unlinking destroys promote history irreversibly; that call belongs to the customer, not a support admin mid-dialog Live pending invitation pending-invitations-present Re-stamping an org-scoped invitation converts a pending membership in the source org into one in the destination, consuming a seat for an invitation the destination never issued. Expired invitations do not block Entitlement downgrade destination-entitlement-downgrade Silent capability loss with no cleanup available and no signal to affected users Blocking on invitations deleted the most intricate part of the design — no cross-org invitation migration, no intent resolver, no sibling-invitation creation. invitation-migration-plan.ts is untouched and the shipped personal→org invitation path is not modified at all. Concurrency Both organizations are now locked, ascending by id, mirroring acquireOrganizationUserMutationLocks. The source id is read optimistically before the transaction and re-verified under the locks, retrying through the existing loop via SourceOrganizationChangedError. Lock order is unchanged: invitation/workspace advisory locks → org locks → workspace row. Audit The workspace-scoped move entry resolves to the destination after the move, because buildOrgScopeCondition scopes org audit reads by the org's current workspaces. Without more, the org that lost the workspace would have no record. Adds an org-level entry (workspaceId: null + metadata.organizationId, that condition's other branch) so the loss is diagnosable from the side that incurred it. Type of Change New feature Testing Automated: full apps/sim suite — 37,306 tests across 2,669 files, zero failures. turbo run type-check clean across all 26 workspaces. check:api-validation:strict, check:boundaries, check:client-boundary, check:route-verbs, check:api-contract-routes, check:utils, check:import-specifiers, and the 39-audit check:audits bundle all pass. 11 new tests cover the org→org path: both org locks acquired in sorted order after the invitation locks and before the row lock; the payer transfer fenced on the source org read under those locks (the assertion that makes the whole move safe); each blocker refusing without mutating anything; custom blocks unpublished; the source-org audit entry landing in the source and not the destination; and the personal source path unchanged, as a regression fence. End to end against a real database, two orgs and a workspace with content on both sides. Verified: org-owned workspaces appear as candidates with their source org named; every blocker refuses and mutates nothing; the happy path re-homes org, payer, and organizationAssignedAt; the move is reversible; replaying an operationId is idempotent; and both invariant post-conditions hold (zero cross-org custom blocks, zero cross-org fork edges). E2E surfaced two defects the unit tests missed, both now with regression tests: getMovedWorkspaceSummary took an appliedContext parameter no call site passed, so every applied move reported sourceOrganization: null; and the source-org audit entries were specified but never implemented. Reviewers should focus on the lock ordering in moveWorkspaceToOrganization and the expectedCurrentPayer fence — that optimistic check is what makes the payer transfer safe under concurrency. Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA) Notes for reviewers Not verifiable on a local deployment. resolveOrganizationEnterprisePlan short-circuits on isAccessControlEnabled && !isHosted, so every org resolves as entitled locally and the downgrade blocker cannot fire. That is correct — the gates it protects also all-pass there, so nothing is lost — but it means the blocker needs a hosted deployment to exercise. Related: isOrganizationOnEnterprisePlan is really "is on a paid org plan" (isOrgPlan = isTeam || isEnterprise), so Team is not a downgrade from Enterprise for these capabilities. The blocker reuses that same predicate deliberately, so it can never disagree with the gates it protects. Companion PR in simstudioai/admin adds the review modal that presents all of this before the admin confirms. Review history Supersedes #7243, which is closed. That PR carried the same file state but had accumulated ~45 review threads across 10 rounds, and the bots had started re-reviewing the thread history rather than the diff — re-raising findings already fixed and regressing the score on unchanged code. This is a clean slate on identical code. 23 findings were fixed there before this PR was opened, every one a real bug except a single false positive that was pushed back on with the type definitions. The substantive ones: Writer races. Enforcing the invariants at move time was never sufficient — publishCustomBlock and fork creation wrote without the lock the move holds, so either could commit after its scans. Both now serialize with it. The first fix for the fork was itself racy (the policy organization is captured before the transaction, and the lock is skipped entirely when it is null), so the parent is now row-locked instead, which also removed a lock-order inversion against invitation acceptance, a 5s timeout overwriting the fork's 10s, and an organization-wide lock held across the whole content copy. Fork blocker gated on an organization source, so a personal workspace whose parent had since moved into one was blocked by preflight but not by the transaction. Durable payload parser validated sourceOrganizationId then dropped it, so every reload would have claimed the source was not persisted. usageCount is a union of live and deployed placements, so subtracting a live-only count misattributed blocks; both figures are now measured with identical predicates. Entitlement fence, in four passes. Absence of a subscription row read as a pass; the plan was never checked; the fence rejected every move in the two deployment modes where entitlement is not subscription-backed; and billing-blocked organizations read as entitled. It now evaluates both organizations under the locks through a shared isSubscriptionBackedEntitlement predicate exported alongside the short-circuits it mirrors. EMPTY_CREDENTIAL_SUMMARY omitted two newly required contract fields, which would have failed validation on every successful move. Truncation was silent, then inconsistent: lists are now bounded with disclosed counts and a notice that opens "This review is incomplete".
Open Graph Description: Summary Lets the admin panel move a workspace from one organization to another. The move was restricted to personal/grandfathered sources — assertWorkspaceMovable threw "Inter-organization wor...
X Description: Summary Lets the admin panel move a workspace from one organization to another. The move was restricted to personal/grandfathered sources — assertWorkspaceMovable threw "Inter-organization...
Opengraph URL: https://github.com/simstudioai/sim/pull/7254
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1b828725-b603-1ad4-5a12-30f7331eef50 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AAA0:EE197:368E24:4BA6ED:6AFB35AF |
| html-safe-nonce | 2fc041c4e36b770cde865c05dccd365e289e0f97ccec1549ea9116bd72bbe35c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUEwOkVFMTk3OjM2OEUyNDo0QkE2RUQ6NkFGQjM1QUYiLCJ2aXNpdG9yX2lkIjoiODY3NTcwMTQzOTk3Mzc2NjU3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f3d10a04387981fa201e25657dadbc54a72c90b051f60350b72a10c072e20e25 |
| hovercard-subject-tag | pull_request:4389594884 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/7254/files |
| twitter:image | https://avatars.githubusercontent.com/u/129460234?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/129460234?s=400&v=4 |
| og:image:alt | Summary Lets the admin panel move a workspace from one organization to another. The move was restricted to personal/grandfathered sources — assertWorkspaceMovable threw "Inter-organization wor... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | efe184de15c1d8c1107a340cfc27bf7187b458dc07687ee1fa51f035148fb3d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f567cf3af46b50a3211fb5dab569a9d6a7b58025 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width