fix(host-service): pin detached-HEAD v1 imports as non-blocking
The cohort
About 8 external users a week run the v1→v2 auto-migration on a machine where a v1 project's checkout sits on a detached HEAD (bisecting, a CI-style checkout, a tag). The repo is otherwise valid. Until #7485, project.create {importLocal} and project.setup {import} both ended in ensureMainWorkspaceStrict, which threw PRECONDITION_FAILED "Repository is in detached-HEAD state…". The migrator ledgers a throwing project import as error, so the flip gate never completed for that machine and those users stayed on v1 until they happened to check out a branch. Where the migration stands overall: https://app.superset.sh/page/v1-v2-migration-where-we-stand-yxfx0w
What this PR does
#7485 (already on main) removed the implicit main workspace and with it the strict HEAD check from both import paths, so the cohort is unblocked on main today. Nothing guarded that, though, and the branch requirement still exists one step later in createLocalWorkspace. This PR pins the whole path with host-service regression tests against a real temp git repo (git init, commit, git checkout --detach):
importLocalon a detached HEAD returnscreated: true, the project row exists, and no workspace row is created.project.setupwithmode.kind = "import"on a detached HEAD links the project the same way.listProjectWorktreesomits the detached main checkout and reports it again oncegit checkout mainruns. This is what keeps the migrator off the branch requirement:planWorkspaceAdoptionsonly routes a v1 workspace toworkspaces.createLocalwhen the main worktree's branch matches, so a detached main lands inmissingWorktreeand is ledgeredskipped(no-worktree-on-disk), which does not block the gate.createLocalWorkspacestill refuses a detached HEAD withPRECONDITION_FAILEDand succeeds after a branch is checked out. Clone and new-repo creation always produce a branch, so they are unaffected.
Also fixes the initLocalRepoInPlace comment that still named the deleted strict helper. A temporary mutation that re-added the branch check to createFromImportLocal made three of the four new tests fail, so they do guard the behaviour.
What it deliberately does not do
- No source change to the import paths: they already tolerate a detached HEAD after #7485.
- The v1 "main" workspace of a detached-HEAD project is skipped, not created, and the ledger treats
skippedas terminal. There is no boot-time sweep any more (#7485 removedrunMainWorkspaceSweep), so nothing creates that local workspace later; the user creates one from the sidebar once they are on a branch. If we want the migrator to retry that workspace after a branch appears, that is a ledger-classification change and belongs with #7480. - Desktop side untouched:
importV1Projectno longer carries amainWorkspaceId, so there is nothing to accept as null.
Checks
bun test packages/host-service/src/trpc/router/project/project-import.test.ts: 7 passbun run typecheckinpackages/host-service: cleanbiome checkon the two touched files: cleanbun testinpackages/host-service: see the first comment for the aggregate result
https://claude.ai/code/session_01YJ7iF8hZHKfEjmvzs1RYz3
Summary by cubic
Adds host-service regression tests pinning that v1 project imports succeed on detached-HEAD checkouts, so the v1→v2 auto-migration no longer stalls on machines at a tag or bisect. Also fixes a stale comment in initLocalRepoInPlace that referenced a removed strict-HEAD check.
importLocalandproject.setup(mode=import) persist the project row with no workspace row when HEAD is detached.listProjectWorktreesomits the detached main checkout and reports it again once a branch is checked out, keeping the importer from hittingcreateLocalWorkspace's branch requirement.createLocalWorkspacestill rejects a detached HEAD withPRECONDITION_FAILEDand succeeds after a branch is checked out; tests restore the repo's real initial branch rather than assumingmain.
Summary by CodeRabbit
-
Bug Fixes
- Projects in detached-HEAD repositories can now be imported and linked without automatically creating a workspace.
- Worktree discovery no longer includes detached main checkouts.
- Local workspace creation now rejects detached repositories and succeeds once the repository’s initial branch is checked out.
- Repository initialization now records the active branch and HEAD consistently.
-
Tests
- Added coverage for detached repository imports, worktree discovery, and local workspace creation behavior.