Skip to content

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

Closed
maslinedwin wants to merge 4 commits into
pingdotgg:mainfrom
maslinedwin:fix/connect-switch-stale
Closed

maslinedwin wants to merge 4 commits into
pingdotgg:mainfrom
maslinedwin:fix/connect-switch-stale

Conversation

@maslinedwin

@maslinedwin maslinedwin commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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 for commit ee96d97. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

Startup reconcile applies relay config after routes are live. The first
link-state read can cache managedTunnelActive: false, and the Settings
switch stayed off because nothing invalidated that SWR atom. Refresh
once after the first settled read, and again when Connections opens.

Fixes pingdotgg#6628
@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Aug 16, 2026
Comment thread apps/web/src/cloud/primaryCloudLinkState.ts Outdated
Comment thread apps/web/src/cloud/primaryCloudLinkState.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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.

A single 2s refresh could still miss a slow startup reconcile, and the
one-shot key then blocked later retries. Refresh at 2s/5s/10s and again
while Connections is open, then stop.

Onboarding now resyncs untouched toggles from later link-state reads and
never submits managedTunnel:false against an already-active tunnel.
@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Aug 16, 2026
Comment thread apps/web/src/components/cloud/ConnectOnboardingDialog.tsx Outdated

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One finding: the new Connections poll makes both cloud switches flicker into their disabled state every 2s. Details inline.

Posted via Macroscope — UI Consistency

Comment thread apps/web/src/components/settings/ConnectionsSettings.tsx Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Reviewed by Cursor Bugbot for commit 4253c5a. Configure here.

Comment thread apps/web/src/cloud/connectOnboarding.ts
Both-off still means skip, even if a later refresh showed the tunnel
active, so onboarding does not rewrite publish. Connections retries
only while a linked tunnel still looks inactive.
After an account switch, do not treat the previous user's cached
managedTunnelActive as this wizard's tunnel. Disable the Connections
switches only on the first link-state load so SWR revalidation no
longer eats clicks.
@t3dotgg

t3dotgg commented Aug 28, 2026

Copy link
Copy Markdown
Member

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: T3 Connect switch stays off after startup restores the tunnel

2 participants