Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(client-runtime): retry queries after connection interruption #8117

Mergedtris203(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/8117/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

What Changed

  • Make environment queries observe the full connection lifecycle instead of connected generations only.
  • Keep queries pending or revalidating while a connection is recovering, and settle them as unavailable for manual disconnect, offline, or blocked states.
  • Add focused regression coverage for session replacement, terminal connection states, retained failures, and stale-while-revalidate values.

Why

A hard refresh of Usage through T3 Connect could briefly surface “This environment could not report usage.” Relay credential reconciliation interrupted the in-flight query before the replacement session retried it, allowing an interrupt-only failure to reach consumers. Handling recovery at the shared environment-query seam fixes every caller without teaching Usage about Effect interruption causes or supervisor phases.

UI Changes

None. This changes shared client-runtime lifecycle behavior; no rendered UI, layout, or motion code changed.

Verification

  • vp test run packages/client-runtime/src/state/runtime.test.ts (25 tests)
  • vp run --filter @t3tools/client-runtime typecheck
  • targeted lint and formatting for the changed files
  • git diff --check

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots are not applicable because no UI code changed
  • Video is not applicable because no animation or interaction code changed

Generated with GPT-5.6 in T3 Code via the Codex harness.


Note

Medium Risk Shared client-runtime query lifecycle affects all environment-query callers; error unions now include connection attempt and unavailable errors, so consumers that narrow failures may need updates.

Overview Environment query atoms in createEnvironmentQueryAtomFamily no longer gate execution on connected generation only. They subscribe to paired supervisor state and session and branch on connectionState.phase.

During connecting and backoff, queries stay pending (Effect.never) so SWR can keep the last value or failure with a waiting flag instead of surfacing interrupt-only failures when the RPC session is replaced. When connected, execution runs only if a session is present; otherwise it stays pending. For available, offline, and blocked, queries fail immediately—using lastFailure when set, otherwise EnvironmentRpcUnavailableError.

Adds regression tests for session replacement retry, terminal disconnect/offline/blocked settling, retaining real query failures across reconnect, and stale-while-revalidate success values during recovery.

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

Note

Fix createEnvironmentQueryAtomFamily to retry queries after connection interruption

Reworks the query trigger signal from a generation-only stream to a combined connection state + session stream using Stream.zipLatest over supervisor.state and supervisor.session changes. Query atoms now execute only when the environment is connected with a concrete session, remain idle during connecting/backoff, and fail immediately in available/offline/blocked phases using lastFailure or EnvironmentRpcUnavailableError.

  • Adds test coverage for interrupted-query retry during session replacement, unavailable settlement on disconnect/offline/blocked, and last-successful-value retention during reconnection in runtime.test.ts
  • Expands the atom's error type to include ConnectionAttemptError and EnvironmentRpcUnavailableError
  • Behavioral Change: queries that previously retried silently during available/offline/blocked phases now fail immediately — consumers must handle the new error types in createEnvironmentQueryAtomFamily's error union
Macroscope summarized 2b76e36.
    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: 8f918472-36b2-4664-9c71-a497378406f3

      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:trusted

    3. One finding on the new unavailable-query failure path in packages/client-runtime/src/state/runtime.ts. Everything else (namespace imports, Foo["Service"] usage, test-only Layer.succeed/service instances) looks consistent with the Effect service conventions.

      Posted via Macroscope — Effect Service Conventions
    4. 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 e11b644dc1fbb153fa41876b75da660c8c581974. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR changes shared client-runtime behavior for all environment queries, including execution gating, reconnect retries, stale values, and terminal connection errors. Although the intent is focused and well-tested, the cross-cutting runtime semantics warrant human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.