Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): refresh T3 Connect switch after startup reconcile #7193

Closedmaslinedwin(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/7193/headopened View on GitHub

Problem

Startup reconciliation applies T3 Connect relay config after routes are already live. Settings reads managedTunnelActive from useCloudLinkController → a shared SWR atom (staleTime: 5s). If the first read lands before applyRelayConfig, the atom caches managedTunnelActive: false and nothing invalidates it when the background reconcile finishes. The switch stays off even though the tunnel is up. Toggling later refreshes via the mutation path.

The always-mounted T3 Connect onboarding dialog keeps this atom subscribed from app start, so revalidateOnMount never runs again.

Fix

Display refresh only — no auto-link, no protocol change, and the managedTunnelActive ?? linked fallback for older servers is unchanged.

  • After the first settled link-state read, schedule one delayed refresh so a startup-stale inactive value can be replaced once reconcile has had a chance to finish.
  • Force-refresh when Settings → Connections opens, so a later visit also converges on post-reconcile server state.

Tests

  • apps/web/src/cloud/primaryCloudLinkState.test.ts — stale inactive snapshot becomes active after the follow-up refresh; one-shot per target; no schedule without a target
  • Existing linkEnvironment.test.ts still passes (read/reconcile mapping unchanged)

Fixes #6628

Model: grok-4 Harness: T3 Code


Note

Medium Risk Changes T3 Connect reconcile and toggle sync paths in onboarding and Connections; display-only refresh logic but incorrect reconcile could affect tunnel/publish state if helpers are wrong.

Overview Fixes stale managedTunnelActive: false in the shared cloud link SWR cache when startup reconcile finishes after the first read, so the T3 Connect switch and onboarding UI can catch up without a manual toggle.

Link-state refresh: After the first settled read with an inactive tunnel, usePrimaryCloudLinkState schedules bounded follow-up refreshes (2s / 5s / 10s) and cancels them once the tunnel is active. Connections forces a refresh on mount and retries every 2s for up to 15s while linked but still inactive.

Derived behavior: resolveManagedTunnelActive centralizes the managedTunnelActive ?? linked fallback (moved out of useCloudLinkController). isInitialCloudLinkStatePending only disables switches before the first snapshot, not during background revalidation.

Onboarding hardening: Toggles keep syncing from link state until the user touches them; reconcile uses resolveOnboardingReconcileDesired so stale prefill cannot tear down an active tunnel or submit publish-only when both toggles are off. Account-scoped helpers avoid applying another account’s cached tunnel state after a switch.

Unit tests cover the new helpers and refresh scheduling.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ee96d97bea90483a9862da7ddd53e20964f52725. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Refresh T3 Connect switch state after startup reconcile to fix stale inactive tunnel snapshots

  • After usePrimaryCloudLinkState settles, link state is refreshed at 2s, 5s, and 10s delays to correct a startup-stale managedTunnelActive=false snapshot left before reconcile completes.
  • The onboarding dialog in ConnectOnboardingDialog.tsx now continuously re-syncs toggles from link state until the user manually changes them, scoped to the current account only.
  • Reconcile submissions skip when both toggles are off, and no longer tear down an already-active tunnel when the expose toggle is turned off.
  • The T3 Connect switches on the Connections settings page are disabled only during the initial load, not during SWR revalidation of cached data, using the new isInitialCloudLinkStatePending helper.
  • Behavioral Change: ConnectionsSettings now also starts a periodic retry loop on mount to refresh link state while a linked tunnel appears inactive, stopping when the tunnel becomes active or a time budget elapses.
Macroscope summarized ee96d97.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 053ad919-d848-4fc0-87a2-6aa33c81a8c6

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This bug fix introduces new timer-based refresh logic, retry mechanisms, and state synchronization behavior that gates whether managed tunnels are preserved or torn down. The complexity of the timing-sensitive changes and new business logic around reconciliation warrants human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. One finding: the new Connections poll makes both cloud switches flicker into their disabled state every 2s. Details inline.

      Posted via Macroscope — UI Consistency
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4253c5a0f43d379e0a2b5a85d674b33268f82f90. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

      The fixed 2, 5, and 10 second retries can still leave the switch stale when T3 Connect starts more slowly. We do not want to ship a timing-based repair that still has the same failure mode.

      If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

Sign in to join this conversation.