feat(desktop): v1→v2 auto-migration boot trigger, migrate-then-flip gate, continuity restore

Merged
KI
4mo ago
+1350-54

Summary

PR 4 of SUPER-1534/SUPER-1577 — the PR that turns the dormant machinery (PRs #5814/#5816/#5818) on.

  • V1AutoMigration (mounted in the authenticated layout only while on the v1 surface): once per boot, when signed in + active org + onboarded + local host-service up, acquires the run lock and executes runV1Migration() with the real targets (presets collection, pending-terminals queue, sidebar/finalize callbacks). Failures log and retry next boot; ledger keeps partial progress.
  • Single-flight lock: migration.acquireRunLock/releaseRunLock — pid+timestamp lock file in SUPERSET_HOME_DIR (stale/dead-pid locks stolen; instances sharing the home dir share local.db, so one runner suffices). Closes the concurrency finding from PR 1 review.
  • Migrate-then-flip gate: on gateComplete (all v1 projects+workspaces success/linked) the org is marked complete in localStorage; useIsV2CloudEnabled returns v2 when the marker exists — read boot-stable so completion mid-session flips the NEXT launch, never the live one. Per D5, completion overrides an explicit optInV2 === false.
  • V1MigrationContinuity (v2 surface, one-shot per org): first v2 launch after the flip navigates to the ledger-mapped counterpart of v1's lastActiveWorkspaceId instead of the dashboard.

Existing v2 users: the marker never gets written (no v1 data → but also V1AutoMigration never mounts since they're already on v2), so nothing changes. v1 users: silent background pass each boot until complete, then next launch lands on v2 with projects/workspaces/settings/presets/terminals already in place.

Test Plan

  • 21 unit tests, desktop typecheck, root lint clean
  • CDP E2E full loop: fresh v1 fixture → boots on v1 → auto pass runs → marker written → relaunch lands on v2 in the last-active workspace (running next)

Summary by cubic

Enables v1→v2 auto-migration: runs once per boot, flips to v2 after the migrate-then-flip gate, restores the user’s last v1 workspace on their first v2 launch, and emits rollout telemetry. Adds a hardened single-flight lock, a forced-flip backstop, and a first‑v2 catch‑up pass to sync the final v1 session. Supports SUPER-1534/SUPER-1577.

  • New Features
    • Boot-time headless V1AutoMigration with cross-instance atomic lock and ledgered progress; runs on v1, and on v2 only while follow-up work remains or on forced-flip machines.
    • Gate: only failures + deferred items block; unmapped workspaces now count as skipped; completion overrides optInV2 === false; optional forced-flip version flips even if the gate never completes.
    • Continuity: first v2 launch opens the ledger-mapped counterpart of v1’s last active workspace; the one-shot flag is consumed only after a successful restore (retries on failure).
    • Post-flip retries: first gate completion always arms one v2 catch-up pass; best-effort kinds (settings/presets/terminals) retry after flip until clean.
    • Telemetry: emits v1_auto_migration_completed with per-kind counts, gate status, trigger, first_completion, duration, and up to 5 failure reasons; emits v1_auto_migration_failed on errors.

Summary by CodeRabbit

  • New Features

    • Added automatic background migration from v1 to v2.
    • Prevented simultaneous migrations across app instances.
    • Automatically switches to v2 after successful migration, including for opted-out users.
    • Restores the most recently active migrated workspace on first v2 launch.
    • Supports retrying migration after errors or interrupted sessions.
    • Reports migration progress and outcomes for improved reliability monitoring.
  • Documentation

    • Added guidance for the v1-to-v2 migration and transition flow.
  • Tests

    • Added coverage for migration completion, forced switching, continuity, and retry behavior.