Repository navigation
Description
Summary
When TablePro reopens multiple connections from the previous session, a connection that finishes connecting in the background can keep showing the “Preparing the session” screen after it is already connected.
The workspace rail and toolbar report that the connection is connected, including the server version, but the detail pane still shows:
- “Preparing the session”
- “This is taking longer than usual.”
- A Cancel button
Clicking Cancel and then Connect makes the content appear immediately because the database session was already connected. The second Connect does not need to establish a new session.
Environment
- TablePro: 0.68.1 (build 124)
- Platform: macOS
- Observed with: MySQL 8.0.x through Cloud SQL Auth Proxy
- Also present in the relevant connection and pane code on the current
upstream/main
The affected state-management path is not specific to MySQL or Cloud SQL. Those were the connection types used during reproduction.
Steps to reproduce
- Open multiple saved database connections in one TablePro window.
- Configure TablePro to reopen the last session at launch.
- Leave one connection selected.
- Quit and reopen TablePro.
- Wait until the workspace rail reports that the restored connections are connected.
- Select a connection that completed while another connection was selected.
Actual behavior
The selected connection has contradictory UI state:
- The workspace rail reports
Connected. - The toolbar displays the connection and database server version.
- The sidebar remains visible, which indicates that the logical window pane is content.
- The detail pane still displays
Preparing the session. - The detail pane still has a Cancel button.
- The stale preparation screen remains indefinitely.
Clicking Cancel and then Connect displays the connected workspace immediately.
Expected behavior
When a background connection finishes connecting, its cached panes should represent the final connected phase.
Selecting that connection later should display its content immediately, without showing a stale connection progress screen or a Cancel button.
Root cause
Each connection owns persistent NSHostingController instances through WorkspacePanes.
During connection reconciliation, MainSplitViewController.reconcileStatus(of:) currently performs the connected transition in this order:
adoptSession(session, into: workspace)
refreshPanes(of: workspace)
transition(to: nextPhase, for: connectionId)Relevant code:
TablePro/Core/Services/Infrastructure/MainSplitViewController.swift,reconcileStatus(of:)TablePro/Core/Services/Infrastructure/MainSplitViewController.swift,transition(to:for:)TablePro/Core/Services/Infrastructure/MainSplitViewController.swift,refreshPanes(of:)TablePro/Core/Services/Infrastructure/MainSplitViewController.swift,applySelectedWorkspace()TablePro/Core/Services/Infrastructure/WorkspacePaneHost.swift
For a background workspace completing its initial connection:
nextPhaseis resolved as.connected.adoptSessioninstalls the connected session and coordinator.refreshPanesruns whileworkspace.phaseis still.connecting.buildDetailView(for:)therefore assignsConnectingStateViewto the workspace’s detail hosting controller.transition(to: .connected)updates the workspace phase.- Because the workspace is not selected,
transition(to:for:)does not callapplyPhase()and does not rebuild the cached pane. - Selecting the workspace later only swaps in the existing hosting controller through
showSelectedPanes(). It does not refresh the controller’s root view.
The resulting state is:
session.status = connected
workspace.phase = connected
logical pane = content
cached detail root = ConnectingStateView
A later status event may not repair the pane because reconcileStatus(of:) returns early when the session contents and phase are already current.
Why Cancel and Connect appear to fix it
Cancel changes the selected workspace phase and immediately rebuilds its pane.
The following Connect call finds an existing driver and returns early from ensureConnected(). The selected workspace then runs applyPhase() and rebuilds the detail pane from the connected state.
This repairs the stale UI without establishing a new database connection.
Additional affected transitions
The same cached-pane invariant can be violated by other background phase transitions:
| Background transition | Possible cached pane after transition | Required pane |
|---|---|---|
| Initial connection succeeds | Connecting | Content |
| Connection attempt fails | Connecting | Unavailable |
| Connected session disappears | Empty or stale content | Unavailable |
| Automatic reconnect starts | Content | Connecting |
| Automatic reconnect succeeds | Connecting | Content |
The fix should cover the shared transition invariant instead of only moving one refreshPanes call in the initial-success branch.
Suggested fix direction
Ensure that a background workspace’s cached panes are rendered from the final phase.
The state update order should be:
- Adopt or release the session state.
- Update
workspace.phase. - Let the selected workspace use the existing
applyPhase()path. - Refresh cached panes for a background workspace after its phase has been updated.
Refreshing every workspace unconditionally during selection would hide the symptom, but it may defeat the design of preserving one long-lived pane tree per connection. The root fix should keep the cached pane synchronized when the phase changes.
Acceptance criteria
- A connection that completes in the background displays content immediately when selected.
- The detail pane never shows
ConnectingStateViewwhen the live session is connected and the logical pane is content. - A background connection failure displays the unavailable state when selected.
- A background session loss displays the disconnected state when selected.
- A background reconnect displays the connecting state and later returns to content.
- Switching connections continues to preserve editor, grid, scroll, selection, and undo state.
- Repeated connected-status events do not leave or recreate a stale progress pane.
- Regression tests cover the final phase and the actual cached detail render state together.
Test coverage gap
Existing tests cover these pieces separately:
ConnectionWindowPhaseMachineConnectionWorkspaceRegistryConnectionWindowPaneResolverWorkspacePanesteardown
They do not cover this sequence as one test:
Workspace A selected
Workspace B connecting in the background
Workspace B receives a connected session
Workspace B is reconciled
Workspace B is selected later
Workspace B’s cached detail root is inspected
A regression test should assert both:
workspace.phase == connected
cached detail render state == content
Checking only the phase or pane resolver output will not detect this bug.
Regression source
The ordering was introduced with the per-connection pane ownership refactor:
486458a40c04b539738df84266911fed358f36a1refactor(connections): give each connection its own panes instead of rebuilding on switch (#2116)
Activity