feat(desktop): move a project to another organization
Closes #6063.
What this does
Adds Move to organization to a project's right-click menu. The repo lands in the other org with its worktrees, its branches and its place in the sidebar intact. Nothing is re-cloned and nothing on disk moves.
Why it needs three parts
Which org a repo belongs to is recorded in three places, and a move that touches only one of them half-works:
| Where | What it holds | What happens if you skip it |
|---|---|---|
Cloud (v2_projects + friends) | the org id on the project, its workspaces, chat sessions, automations | workspaces end up in a different org from their project, and nothing in the database objects |
| Local host database, one per org | the project row the sidebar actually reads — there is no org column, the file is the org | the repo simply doesn't appear in the destination |
| Sidebar state, stored per org | collapse, order, groups, pane layout, pins | the repo arrives stripped of everything you'd arranged |
So the move is: start the destination host, move the cloud rows, re-register the project and each worktree, copy the sidebar state, then detach from the source.
The order matters
sequenceDiagram
autonumber
actor U as You
participant App as Superset
participant HB as Destination host
participant DB as Cloud
participant HA as Source host
U->>App: Move to organization → picks one
App->>HB: start host for that org
Note over HB,DB: starting it registers this machine<br/>in the destination org — the cloud step<br/>can't re-point workspaces without that
App->>DB: one transaction: project, workspaces,<br/>chat sessions, attachments, automations, runs
App->>HB: re-register project (same id)
App->>HB: adopt each worktree (same ids, same paths)
App->>App: copy sidebar state (same group ids)
App->>HA: detach — rows only
Note over HA: never git worktree remove:<br/>those worktrees now belong to the other org
- Start the destination host first. That registers this machine in the destination org, which the cloud step needs before it can re-point the workspaces — otherwise it fails on the
(organization_id, host_id)foreign key. - Move the cloud rows — project, workspaces, chat sessions, attachments, automations and their runs, in one transaction.
- Re-register on the destination host, keeping the project id and each workspace id. Worktrees live under
~/.superset/worktrees/<projectId>/, so keeping the id means nothing on disk has to move. - Copy the sidebar state, ids intact.
- Detach from the source last, through a new
project.detachthat removes rows only. The existing remove runsgit worktree remove, which would delete the worktrees just adopted.
Ids: what has to stay the same, and why
Nothing here is copied. The same rows are re-registered somewhere else, because four different ids are load-bearing and each one strands something different if it changes.
flowchart LR
P["project id"] --> D["worktrees on disk<br/>~/.superset/worktrees/<projectId>/…"]
P --> CW["cloud workspaces<br/>v2_workspaces.project_id"]
P --> SR["sidebar project row"]
W["worktree workspace id"] --> PL["pane layout, open tabs"]
W --> PIN["pinned state"]
W --> HR["host workspace row"]
M["checkout workspace id"] --> PL
M --> MC["its cloud row"]
S["group id"] --> GRP["which group each workspace sits in"]
| Id | Kept by | What breaks if it changes |
|---|---|---|
| Project | passing it to project.setup on the destination | every worktree on disk is orphaned — they're stored under the project id |
| Worktree workspace | workspaceCreation.adopt with existingWorkspaceId and the explicit path | the worktree comes back as if new: no tabs, no layout, unpinned |
| The repo's own checkout | the fix in this PR — project.setup now takes mainWorkspaceId | same loss, plus its cloud row points at a workspace no host serves |
| Group (section) | copied verbatim, ids and all | every workspace lands ungrouped in the destination |
Two more subtleties that only show up when you actually run it:
Removals are tombstones, not deletions. Two reconcilers re-add a worktree that has no local row, so removing a project marks its worktrees hidden instead of deleting them. That means moving a project back to an org meets its own tombstones — the host serves the worktrees, the sidebar suppresses them, and the repo arrives looking half-empty. The move now heals a tombstone for any workspace it's bringing in.
Pins are org-wide ordering, not a flag. pinnedAt orders the Pinned section across the whole org, so carrying the number over would jump a moved workspace ahead of pins already there. It's re-based against the destination.
Tasks stay behind. They're scoped to the org, not the project, so a moved workspace's task_id is cleared rather than left pointing across an org boundary.
What survives, and what doesn't
Survives: the repo, every worktree and its branch, the sidebar arrangement, per-project settings (worktree location, branch prefix).
Doesn't: running terminals and agent sessions — they belong to the source org's daemon and can't be re-parented. The dialog says so before you commit. The GitHub link is re-resolved in the destination org, or dropped if that org doesn't have the repo — a repo row is unique across the whole database and belongs to whichever org installed the app on it.
Only the machine you run it on moves. The host database is per machine, so another device keeps showing the repo under the old org until it runs the move too.
Walk-through
Before — side-project in the first org, with a feature/demo-move worktree:
Right-click gives the new item:
It lists the orgs you belong to, minus the one you're in:
Confirm step, saying plainly what happens:
After — the repo in the destination org:
Needs the API deployed
Worth flagging for anyone trying this from a client build: the two halves ship separately. The desktop side (menu, host re-registration, worktree adoption, sidebar state) is in the app, but v2Project.moveToOrganization runs on the API server. Until this is merged and deployed, a packaged client pointed at production gets No procedure found on path from that call — which is also a clean failure, since it happens before anything local is touched.
Projects created on a host have no cloud row and don't need the server at all; those move purely locally.
Testing
Driven through the real menus in a dev build, moving a project with a worktree between two orgs and back again, checking both host databases, the git worktree registrations and the sidebar state at each step.
Three bugs came out of running it, each fixed here with the reasoning in the commit:
- Projects created on a host are local-first and have no cloud row at all, so the move failed before doing any of the local work. It now reports the missing row and carries on.
- Re-registering minted a new id for the repo's own checkout, stranding the pane layout and pins keyed to the old one. The id is now carried across.
- Moving a project back to an org met the tombstones the earlier move left, so it arrived with its worktrees hidden. Those are now healed.
Unit tests: 8 on the sidebar state copy, 5 on the host detach — the detach tests use mocks that throw if git or the cloud is touched, so a regression fails loudly rather than quietly deleting a worktree.
bun run lint, bun run typecheck and the affected suites pass.
Not in this PR
- Moving a whole folder of projects at once (folders are #5981).
- Moving other devices — each machine runs its own move.
- An undo. Moving it back is the way back, and it's the same path.
Summary by cubic
Adds a "Move to organization" option to a project's right-click menu. The move re-registers the project on the destination host and rows-only detaches it from the source, leaving worktrees and files on disk untouched — no reclone, no cloud dependency, and no server deploy required.
- The destination host starts only if it's down; target orgs come from
cloudTrpc.organization.listand exclude the active one. project.detachdrops the source host's rows in one transaction without calling git or the cloud, disposes PTYs, and is idempotent. It deliberately avoids main's new soft delete (restore/purge): a moved project must leave no restorable row behind.- The move keeps
projectId, re-creates each local workspace under its existing id, adopts worktrees in place, preserves section ids, rebasespinnedAt, heals tombstones, and queues fresh terminals to reopen with empty panes. - The confirmation names running terminals per workspace; only the current device moves, and other devices keep the old org until moved there.
- Failures unwind a half-registered destination, and a source cleanup miss surfaces as "moved, but not cleared from the old organization".
Summary by CodeRabbit
-
New Features
- Added “Move to organization” to the project context menu with destination selection.
- Preserves project settings, workspace layout, and sidebar placement in the destination.
- Includes confirmation, progress handling, and notifications for completed moves or skipped workspaces.
- Disables the move option while an operation is in progress.
-
Bug Fixes
- Improved cross-organization moves, including hidden workspace restoration and reliable cleanup.
- Prevented duplicate sidebar entries during repeated move operations.