Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix: prevent reconnect loops during server stalls #5561

Mergedgfsaaser24(GitHub profile, opens in a new tab)merged 9 commits intomain fromrefs/pull/5561/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Server event-loop stalls could make one delayed pong kill the RPC connection, then immediately reconnect into the same expensive bootstrap work. Users saw repeated disconnects and Syncing... even when the underlying network was healthy.

This tolerates short pong delays, uses a safer reconnect ladder, and avoids repeated bootstrap work by caching command and editor discovery and resuming shell state from an authoritative cursor. Failed HTTP snapshot refreshes still request a complete socket snapshot, trace attributes are bounded to preserve useful diagnostics, and sends attempted while disconnected now explain why they were not sent.

Focused tests cover pinger tolerance, wake recovery, shell synchronization, discovery caching, and trace truncation.

🤖 Final review fixes and PR cleanup by GPT-5.6 Codex using the Codex harness in T3 Code.


Note

Medium Risk Changes core connection supervisor, RPC protocol (patched dependency), and shell subscription resume semantics; mis-tuned wake/backoff or resume cursors could cause extra sync work or delayed reconnects.

Overview Hardens client–server connection behavior against event-loop stalls, aggressive reconnect loops, and expensive session bootstrap.

Transport & supervisor: Patches Effect RPC ping/pong to allow two missed 5s windows before closing (~15s silence). Raises the first reconnect delay from 1s → 3s and, when a foreground wake probe fails, skips the first backoff sleep once (then normal backoff resumes). Supervisor and session tests are updated for the new timing and wake behavior.

Connect cost: Adds a 30s PATH command-resolution cache in shared shell code and 60s memoized editor discovery on the server so repeat connects avoid huge filesystem scans. Trace file sink now clamps oversized span attributes (including db.query.text) without mutating live spans.

Shell sync: On the same live RPC session, foreground resubscribe resumes from the in-memory snapshotSequence instead of always forcing a full HTTP refresh; failed HTTP refresh falls back to a full socket snapshot. New/rewritten shell-sync tests cover these paths.

Web: Sending while the environment is unavailable shows a warning toast (draft preserved) instead of silently attaching an annotation.

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

Note

Harden connection resilience by fixing idle disconnects with backoff, pinger tolerance, and shell cursor reuse

  • Changes the EnvironmentSupervisor retry ladder first rung from 1s to 3s; a failed foreground wake probe now triggers an immediate reconnect instead of waiting for the first backoff sleep
  • Patches the Effect WebSocket pinger to tolerate two missed pong windows before closing, up from zero tolerance
  • Foreground resubscriptions on the same live session resume from the in-memory shell cursor; new sessions fall back to a full socket snapshot when the HTTP load fails
  • Memoizes editor discovery in ExternalLauncher (60s TTL) and command path resolution in shell.resolveCommandPathForPlatform (30s TTL) to reduce redundant filesystem scans
  • Behavioral Change: attempting to send a chat message when the environment is unavailable now shows a warning toast instead of silently attaching to draft
Macroscope summarized c44dad4.
    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: b7ccb510-cc89-4051-8cbe-494d8a5c81c5

      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 PR introduces significant runtime behavior changes to connection resilience including retry timing, wake probe handling, caching, and shell synchronization logic across multiple packages. Additionally, there is an unresolved review comment identifying a potential bug in the shell resume fallback path.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. One finding: the new command-resolution memo lives in a module-global mutable Map in packages/shared/src/shell.ts rather than being owned by a layer/service, which hides the cache's lifetime from the Effect environment. Everything else reviewed (the Effect.cachedWithTTL memo in ExternalLauncher.make, the supervisor Ref state, the shell-state warm-resume path, and the trace-attribute helpers) follows the service conventions: subpath namespace imports, inline Context.Service interfaces, real make/layer exports, and no new ManagedRuntime/runPromise boundaries or service-instance injection.

      Posted via Macroscope — Effect Service Conventions
    5. Update: rather than a separate PR, I pushed the follow-up fixes directly onto this branch as 6eb16ea5d (maintainer edits are enabled). #5564 is closed. The commit addresses the remaining review findings: monotonic retry ladder ([3s, 4s, 8s, 16s]), recursive trace-attribute truncation with a unit test, the resolution cache moved to a Context.Reference per the conventions check, and a documented negative-caching window. @gfsaaser24 feel free to amend or push back on any of it.

    6. @t3dotgg Reviewed 6eb16ea5d line by line — no pushback, taking all three:

      • Monotonic ladder: correct call. The [3s, 2s, …] wart was an artifact of "raise the floor, don't restructure the ladder" on our side — yours is what it should have been from the start.
      • Recursive truncation: this caught a real gap. Nested error.stacks were bypassing the top-level clamp and quietly eating the retention win we claimed in the PR body. The reference-preserving recursion (returning the same object when nothing clamps) + the immutability test is the right shape for a hot serialization path.
      • Context.Reference cache: the better idiom — matches SpawnExecutableResolution one screen up in the same file, and it resolves the global-mutable-state thread without the heavier Cache.makeWith layer plumbing.

      Regression run against this branch tip, on Windows:

      • client-runtime: 579/579 (includes the wake-probe skip, warm-resume, and your updated ladder tests)
      • shared: green vs. baseline — the only failures are the 5 pre-existing Windows-environment ones that reproduce identically on clean main (ENAMETOOLONG semantics + POSIX path/extension assumptions in relayClient); your two new truncation tests pass
      • typecheck clean across shared / client-runtime / web / t3

      For pressure testing: the underlying fixes have been soaking on our fork's hosted deployment since yesterday, on the exact workload that motivated this PR — a relay session against a 24-core laptop drowning in agent threads, operated by an impatient user with a phone. Disconnect-loop symptoms gone; steering works mid-run.

      Happy to pick up the deferred items (steer-button visual pass, mobile parity) here or in a follow-up, and to file the pinger tolerance upstream on effect.

      Sent from my Fable 5

    7. @@ -210,0 +195,21 @@
      195+ const hasAuthoritativeSnapshot = (yield* Ref.get(lastAuthoritativeSession)) === session;
      196+ let current = yield* SubscriptionRef.get(state);
      197+ if (!hasAuthoritativeSnapshot || Option.isNone(current.snapshot)) {
      198+ const prepared = yield* SubscriptionRef.get(supervisor.prepared).pipe(
      199+ Effect.flatMap(
      200+ Option.match({
      201+ onSome: Effect.succeed,
      202+ onNone: () =>
      203+ SubscriptionRef.changes(supervisor.prepared).pipe(
      204+ Stream.filter(Option.isSome),
      205+ Stream.map((value) => value.value),
      206+ Stream.runHead,
      207+ Effect.map(Option.getOrThrow),
      208+ ),
      209+ }),
      210+ ),
      211+ );
      212+ const httpSnapshot = yield* snapshotLoader.load(prepared);
      213+ if (Option.isSome(httpSnapshot)) {
      214+ yield* applyItem({ kind: "snapshot", snapshot: httpSnapshot.value });
      215+ yield* Ref.set(lastAuthoritativeSession, session);
      cursor[bot](GitHub profile, opens in a new tab)commented

      Stale shell resume after HTTP fail

      Medium Severity

      On a new RPC session, makeSubscribeInput tries an authoritative HTTP shell refresh when lastAuthoritativeSession does not match. If that load returns Option.none (the documented “use the socket snapshot instead” path), the code still subscribes with afterSequence from the existing in-memory snapshot left over from cache or the prior session, so resume skips the full socket snapshot the fallback is meant to use.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit fb2b8c52de4399083781290ee61648d71542fc9d. Configure [here](https://www.cursor.com/dashboard/bugbot).
    8. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      There are 2 total unresolved issues (including 1 from previous review).

      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 c7aba013344111c694c8ba8c32399070d7308d0c. Configure [here](https://www.cursor.com/dashboard/bugbot).
    9. t3dotgg(GitHub profile, opens in a new tab) changed the title

Sign in to join this conversation.