[codex] Reapply optimistic workspace Electric transaction work
Merged
SA
6mo ago+730+730+012345678901234567890123456789-719-719-012345678901234567890123456789
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
v2Workspacesinserts 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:fixbun run lint
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
v2Workspacesinserts with host create executed via mutation metadata; sync confirmation uses Electric txids. - Added local
failedWorkspaceCreatescollection to surface create errors on the workspace route. - Sidebar and routes use
$syncedasisSyncedfor “creating” state; deletion waits viawaitForWorkspaceDeleted. - Submit API returns a handle
{ workspaceId, completed }to react to final outcome. - Electric shape-stream: added onError handler with JWT refresh on 401.
electric-proxynow usesELECTRIC_PROTOCOL_QUERY_PARAMS.
- Optimistic
-
Refactors
- Removed renderer in-flight workspace store and cloud-row fallback; replaced with optimistic insert + sync waits.
- Unified pane layout writes with
writeWorkspacePaneLayout. - Replaced
creationStatusUI withisSynced; updated sidebar, title, and shortcuts logic. getCurrentTxidnow returns a numeric txid; TRPC/host-service mutations wrap writes in transactions and return txids.- Dependencies: added
@electric-sql/clienttoapps/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