fix(desktop): stop stale repos and stale ledger rows from stranding v1 users on v1
Why
The v1-auto-migration flag went to 100% on 12 Sep. What remains on v1 is mostly users the migrator can never move, per the 12 Sep status page and the 10 Sep issues tracker:
| Class | People / week | Tracker |
|---|---|---|
| Repo folder gone, not a git repo, or no longer a directory | ~140 | MIGR-04, MIGR-07 |
| Ledger points at a v2 project the host no longer has | 3 | MIGR-07 |
| Switch still works after a mid-session completion | any completer | MIGR-01 (P0) |
What changes
Stale repos are skips, not failures. computeGateComplete already says deliberate skips must not hold the flip hostage. A v1 project whose folder moved, was deleted, or stopped being a git checkout has nothing to migrate, so the three host errors for that (Path does not exist, Not a git repository, Project directory is no longer a directory on disk) and findByPath's needsGitInit now ledger as skipped with a reason. Skips stay non-terminal, so a restored folder still imports on a later pass. Their workspaces already fall into the unmapped-project skip path; a workspace whose project directory vanished after the import is skipped the same way.
Stale ledger rows heal on the v1 surface. A done row whose v2 project or workspace is gone from this host (host.db wiped or rebuilt) is redone instead of trusted, so adoption stops failing with "Project is not set up on this host" forever. Scoped to the v1 surface via reconcileWithHost: after the flip, a missing row is the user's own deletion and the follow-up pass keeps trusting the ledger.
The flip lock is live, and the surface holds until relaunch. useIsV1FlipLocked subscribes to the completion event through useSyncExternalStore, so the Experimental switch hides the moment the gate completes. useIsV2CloudEnabled pins the opt-in value at the first render after completion and reads that until relaunch: a later opt-in does not flip forward, a later opt-out does not snap back, and the boot marker takes over on the next launch. The second commit replaced a first cut that fell through to the account default, which the dev-app reproduction showed moving the surface mid-session.
Telemetry. v1_auto_migration_completed now carries skip_reasons beside failure_reasons, so the watch automation can keep sizing the cohort.
Reproduced in the dev desktop app, before and after
Evidence page with screenshots and the exact pass summaries: see the PR comment below once published.
- Before: a v1 project at a missing path → pass
projects.failed=1,gateComplete=false, ledgererror | Path does not exist, no marker, user stays on v1 with the switch shown. With the gate allowed to complete on the old code, the switch stayed visible and a real click moved the surface to v2 mid-session, then back to v1. - After: same fixture →
projects.skipped=1,failed=0,gateComplete=true, ledgerskipped | repo-path-missing, marker written, flip notice shown, switch gone from Experimental in the same session, an opt-in written after completion leaves the surface on v1, and the next boot lands on v2.
Not in this PR
- Detached HEAD (8 people/week) still blocks the gate; the user can fix it and it is a real repo.
V1_FORCED_FLIP_VERSIONstays null. With this change the stuck cohort should drain without it.- The API
minimumVersiongate (PR #6704) is what reaches the 889 users below 1.19.
Verification
- 9 new tests: stale path skipped and later restored, non-git folder skipped with no create call, vanished directory skips the workspace, v1-surface re-import after a host wipe, no re-import after the flip, mid-session completion locks the switch at once, and surface frozen against a later opt-in and a later opt-out. All failed against
mainbefore the fix. bun testin apps/desktop: 3765 pass, 0 fail.tsc --noEmitclean. Biome clean.
https://claude.ai/code/session_016NkfQLLDdHvrPS1BRJtfhj
Summary by CodeRabbit
- Bug Fixes
- Improved v1-to-v2 migration behavior so completed migrations remain stable during the current session and take effect consistently after relaunch.
- Missing project folders and folders that are not Git repositories are now skipped instead of reported as migration failures.
- Migration reconciliation can restore eligible projects and workspaces when host records are missing, while avoiding re-import of items removed after the v2 transition.
- Re-imported projects now retain their worktree and branch preferences.
- Migration completion reporting now distinguishes skipped items from actual failures.