[codex] Reapply optimistic workspace Electric transaction work

Merged
SA
6mo ago
+730-719

Summary

Reverts #4744, which reverted #4707. This restores the TanStack DB optimistic workspace creation and Electric txid-confirmed sync work from feat: optimistic workspace creation + Electric write-sync correctness.

Why

The revert PR was needed for the release handoff. With that release path handled elsewhere, this PR reapplies the transaction work on top of current main.

Impact

  • Restores optimistic v2Workspaces inserts and the failed-workspace-create local collection.
  • Restores Electric shape-stream retry handling and JWT refresh on 401.
  • Restores the txid/no-op write-path correctness changes across desktop, trpc, host-service, db utils, and electric-proxy.
  • Restores Electric-confirmed workspace deletion wait behavior.

Validation

  • bun run lint:fix
  • bun run lint

Open in Stage

Summary by cubic

Reapplies optimistic workspace creation with Electric txid-confirmed write sync. The app now shows “Creating…” until rows are synced, and waits for confirmed deletion before clearing UI state.

  • New Features

    • Optimistic v2Workspaces inserts with host create executed via mutation metadata; sync confirmation uses Electric txids.
    • Added local failedWorkspaceCreates collection to surface create errors on the workspace route.
    • Sidebar and routes use $synced as isSynced for “creating” state; deletion waits via waitForWorkspaceDeleted.
    • Submit API returns a handle { workspaceId, completed } to react to final outcome.
    • Electric shape-stream: added onError handler with JWT refresh on 401.
    • electric-proxy now uses ELECTRIC_PROTOCOL_QUERY_PARAMS.
  • Refactors

    • Removed renderer in-flight workspace store and cloud-row fallback; replaced with optimistic insert + sync waits.
    • Unified pane layout writes with writeWorkspacePaneLayout.
    • Replaced creationStatus UI with isSynced; updated sidebar, title, and shortcuts logic.
    • getCurrentTxid now returns a numeric txid; TRPC/host-service mutations wrap writes in transactions and return txids.
    • Dependencies: added @electric-sql/client to apps/electric-proxy.

Summary by CodeRabbit

  • Bug Fixes

    • Improved workspace creation and deletion reliability through database-backed state tracking
    • Enhanced workspace synchronization status display for more accurate UI feedback
  • Improvements

    • Optimized workspace operations handling for more responsive interactions
    • Strengthened error handling and recovery for failed workspace operations

Review Change Stack