Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): avoid blocking IPC during topology polling #12698

Closedhnasser22(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12698/headopened View on GitHub

What changed

The desktop preload now refreshes the local environment snapshot with asynchronous IPC. getLocalEnvironmentBootstraps and getLocalEnvironmentEnabled read the last successful snapshot instead of calling ipcRenderer.sendSync. Startup awaits the first refresh before importing the app. Each connection poll refreshes the snapshot without blocking the renderer.

Concurrent refreshes share one request pair. A failed refresh keeps the cached snapshot and goes through the existing connection-retention and credential-expiry handling. A successful empty snapshot still removes stopped backends. Browser builds and older desktop bridges keep their existing startup paths, because refreshLocalEnvironment is optional.

Why

Typing in the Windows desktop app freezes, even in an empty chat, while the browser UI on the same backend stays smooth (#12689). The original profile attached to the issue spent about 1 s in getLocalEnvironmentBootstraps -> ipcRenderer.sendSync. A second capture on 0.0.46-nightly spent 530 ms in getLocalEnvironmentEnabled -> sendSync. The main process handled each of those calls in under 0.4 ms, so the renderer was waiting for a busy main process, not for a slow handler. This follows the direction in the triage comment: async invoke plus a cached snapshot.

This PR does not touch the "Some requests are slow" toast. Nobody has shown it shares this cause.

Fixes #12689

Validation

Machine: Windows 11 Pro 10.0.26300, Intel Core i7-12700H, Electron 44.4.2.

Commits:

  • Fix: b25455c06 (original commit, unchanged).
  • Upstream main merged twice without conflicts: 71e0331fc (main at 781223057) and 077764437 (main at f60367b8c).
  • Two test updates for upstream changes. cbecbb528: the preload now reads legacy localStorage once with sendSync at load, so the preload test resets that mock after import. It still asserts that topology refreshes and reads add no sync IPC. a11730cd1: a new upstream bootstrap-token test called the handler without the void payload.
  • Before build: upstream main f60367b8c. After build: a11730cd1 (f60367b8c plus this fix).

Tests and checks on a11730cd1:

  • vp test run on 9 files (preload snapshot, local environment and window IPC handlers, backend configuration, web bootstrap, platform connection source, desktop-local bootstraps, primary auth/bootstrap): 99 passed, 1 skipped. The skip is an existing non-Windows editor-discovery test in window.test.ts.
  • vp run --filter <pkg> typecheck for contracts, desktop and web: pass.
  • vp lint and vp fmt --check on the 13 changed files: pass.
  • vp run build:desktop, then apps/desktop/scripts/verify-preload-bundle.mjs: pass. The built after preload has no sendSync for either topology channel. The before preload has both.

How I measured: I ran both builds unpackaged (electron dist-electron/main.cjs), each with its own Electron profile, its own T3CODE_HOME and its own backend port. Both homes started from the same vp run migrate-dev-db snapshot (identical SHA-256): 5 projects, 6 threads. For each capture I took a renderer CPU profile over CDP (0.5 ms sampling interval), Long Tasks, and Event Timing for keyboard events of 16 ms or more. I also counted main-process desktop.ipc.invokeSync and desktop.ipc.invoke spans for the two topology channels from that profile's desktop.trace.ndjson. The issue reporter did the typing, on the real keyboard, into the empty new-thread composer, and never sent anything.

  1. Launch, no typing, 45 s, three runs per build, alternating:
BuildTopology sendSync time in rendererLongest single blockMain-process sync / async topology calls
before, run 123.7 ms2.3 ms53 sync / 0 async
before, run 230.0 ms2.3 ms53 sync / 0 async
before, run 3119.9 ms83.3 ms44 sync / 0 async
after, runs 1 to 30 msnone0 sync / 32, 32, 26 async

The block size varies a lot between runs. An earlier round on 781223057 measured 365 ms and 190 ms totals, with blocks up to 336 ms. Both builds have launch long tasks from module evaluation and first render. None of the after-build long tasks contain topology sendSync.

  1. Manual typing, 20 s each, well after launch:
BuildInputsTopology sendSync in rendererLong tasksSlowest key eventp95 key eventMax input delayMain-process sync / async topology calls
before11916.0 ms (longest 2.2 ms)040 ms32 ms3.2 ms21 sync / 0 async
after1260 ms032 ms32 ms6.1 ms0 sync / 14 async

In this clean profile the before build did not stall during steady typing. Its sync calls returned in about 2 ms, and the reporter felt no lag in either build. So this table shows the sync calls are gone. It does not show a felt difference. Both rows leave out key events that started while Profiler.start itself blocked the renderer: 8 events in the before run (199 ms startup, max 152 ms) and 4 in the after run (175 ms startup, max 136 ms).

  1. Real install, before the fix (0.0.46-nightly.20261005.2667, reporter's own profile, 2026-10-05). 59 inputs over 14.6 s. 534.9 ms in sendSync, with one 528.6 ms block in getLocalEnvironmentEnabled. Two long tasks (51 ms, 530 ms). Six keyboard events over 100 ms, max 488 ms. The main-process trace logged 26 sync topology calls in that window, each handled in 0.1 to 0.35 ms. The capture started about 17 s after launch.

What I could not check:

  • I did not run the patched build against the reporter's real profile, to keep the live database untouched. The isolated profile reproduces stalls at launch (up to 336 ms across rounds) but not the 530 ms to 1 s stalls from the real install during typing.
  • I don't know why the main process is busy when the stall happens. In the real trace it lined up with the startup update check and remote-editor probing, but those use async I/O and the trace doesn't prove they block the thread. This PR stops the renderer from waiting on the main process. It doesn't make the main process less busy.
  • Sampling can miss very short sync calls, so I treat the main-process span counts as the exact numbers. Event Timing only reports events of 16 ms or more, rounded to 8 ms.
  • WSL secondary backends were off in the manual runs. Unit tests cover them.
  • Unpackaged builds, not the NSIS installer. Same Electron version.

Evidence

Before: upstream main f60367b8c, reporter typing in the empty composer (the profiled 20 s window).

https://github.com/user-attachments/assets/ddfcdabc-b0f5-48b9-980b-fc210d0b3d5f

After: a11730cd1, same setup.

https://github.com/user-attachments/assets/9276a90b-1c5f-47c7-855f-4e98da0bdd20

  • comparison.json: every launch and typing capture above, analyzed.
  • pr12698-profiles.zip: the launch and typing CPU profiles with their JSON summaries (build identity, Long Tasks, Event Timing, main-process span counts), plus the original nightly capture.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No visual layout changes requiring before/after screenshots
  • I included a video for animation/interaction changes

Original fix: GPT-6 in Codex. Merges, test updates and Windows validation: Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at b25455c

      Macroscope's review found this PR approvable — This is a focused desktop responsiveness fix that replaces blocking topology IPC with asynchronous refreshes and an in-memory snapshot, while preserving existing connection retention behavior and adding targeted coverage. It does not introduce a new user-facing capability, product-default change, deployment change, or broadened static-analysis suppression.

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

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 11530ecd-0d0a-4490-881d-88802e1e87fc

      📥 Commits

      Reviewing files that changed from the base of the PR and between 7445aa733ada33e45289e5aa5055f79142556513 and b25455c06e8b2ff924484a1943a68f119e8250be.

      📒 Files selected for processing (13)
      • apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
      • apps/desktop/src/ipc/DesktopIpcHandlers.ts
      • apps/desktop/src/ipc/methods/localEnvironment.test.ts
      • apps/desktop/src/ipc/methods/localEnvironment.ts
      • apps/desktop/src/ipc/methods/window.test.ts
      • apps/desktop/src/ipc/methods/window.ts
      • apps/desktop/src/preload.test.ts
      • apps/desktop/src/preload.ts
      • apps/desktop/src/wsl/DesktopWslEnvironment.ts
      • apps/web/src/bootstrap.test.ts
      • apps/web/src/bootstrap.ts
      • apps/web/src/connection/platform.ts
      • packages/contracts/src/ipc.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      The desktop local environment IPC changed from synchronous to asynchronous. The preload bridge now caches refreshed topology and enabled state. Web startup and platform registration refresh the snapshot before reading it, with tests covering initialization, concurrency, failures, and compatibility.

      Changes

      Local environment snapshot

      Layer / File(s)Summary
      Asynchronous IPC contract and handlers
      packages/contracts/src/ipc.ts, apps/desktop/src/ipc/*, apps/desktop/src/backend/DesktopBackendConfiguration.test.ts, apps/desktop/src/wsl/DesktopWslEnvironment.ts
      Local environment IPC methods now use asynchronous handlers with void payloads. Existing handler tests pass undefined. Related comments were updated.
      Preload snapshot and refresh
      apps/desktop/src/preload.ts, apps/desktop/src/preload.test.ts
      The preload bridge refreshes bootstraps and enabled state in parallel, caches successful results, coalesces concurrent refreshes, and rejects reads before initialization.
      Startup and platform refresh integration
      apps/web/src/bootstrap.ts, apps/web/src/bootstrap.test.ts, apps/web/src/connection/platform.ts
      Web startup waits for the optional refresh before importing the application. Platform registration uses refresh failures as topology failures and retains cached registrations through the existing failure path.

      Priority: ⬆️ High

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant WebBootstrap
        participant DesktopBridge
        participant DesktopIPC
        participant LocalEnvironmentSnapshot
        WebBootstrap->>DesktopBridge: refreshLocalEnvironment()
        DesktopBridge->>DesktopIPC: request bootstraps and enabled state
        DesktopIPC-->>LocalEnvironmentSnapshot: return refreshed values
        LocalEnvironmentSnapshot-->>DesktopBridge: cache snapshot
        DesktopBridge-->>WebBootstrap: resolve refresh
        WebBootstrap->>WebBootstrap: import ./main

      Suggested reviewers: juliusmarminge, t3dotgg

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 13 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly summarizes the main change: replacing blocking synchronous IPC during desktop topology polling with a non-blocking approach.
      Description check✅ PassedThe description includes clear What Changed and Why sections, validation details, issue context, and a completed checklist. It also explains that no UI changes require screenshots and accurately leave…
      Linked Issues check✅ PassedIssue #12689 requires immediate desktop composer responsiveness by removing the synchronous IPC stall during local-environment polling. The PR changes getLocalEnvironmentBootstraps and `getLocalEnvi…
      Out of Scope Changes check✅ PassedThe changed files support Issue #12689. They update local-environment IPC, preload snapshot handling, desktop bootstrap timing, topology polling, contracts, and related tests. The WSL comment and test…
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      Comment `@coderabbitai help` to get the list of available commands.
    4. Note

      This comment is posted by Julius' dot

      The async IPC snapshot follows Julius’s direction in #12689. The supplied CPU-profile ZIP timed out while downloading here, so that artifact remains unassessed. Please provide an accessible copy and the requested post-fix Windows typing profile or short before/after typing recording; the PR currently says neither post-fix artifact was captured. That will let us assess the timing verification. Leaving this open; download failure is not a policy violation.

    5. Note

      This comment is posted by Julius' dot

      The original profile is now retrieved and inspected: its 18.30-second capture includes 1,002 ms in getLocalEnvironmentBootstraps → sendSync, confirming the reported stall. The remaining gap is post-fix timing evidence. The PR explicitly says no post-fix profile or interaction video was captured, although Julius requested Windows re-profiling. The 78 focused tests and reported typing improvement are useful, but do not show that real interaction after the change. Under verification, please attach the post-fix profile or a short before/after Windows typing recording with the build and observed result, then request reconsideration. Closing for that evidence gap.

    6. juliusmarminge closed this

    7. Requesting reconsideration. This adds the post-fix Windows timing evidence that the closing comment asked for.

      The branch now merges upstream main at f60367b8c with no conflicts, plus two small test updates for upstream changes (cbecbb528, a11730cd1). The fix commit b25455c06 is unchanged.

      I built f60367b8c (before) and a11730cd1 (after) on Windows 11 (i7-12700H, Electron 44.4.2). I ran them unpackaged with isolated profiles seeded from the same migrate-dev-db snapshot, and profiled the renderer over CDP.

      • At launch, with no typing (3 runs each), the before build blocked the renderer in topology sendSync for 24, 30 and 120 ms, with the longest single block at 83 ms. An earlier round on 781223057 hit blocks of up to 336 ms. The after build blocked for 0 ms in every run. The main-process trace shows 44 to 53 invokeSync topology calls per run before, and 0 after (26 to 32 async invoke).
      • During manual typing in the empty composer (20 s, 119 and 126 inputs), neither build had long tasks. The slowest key event was 40 ms before and 32 ms after. The before build still made 21 sync topology calls. The after build made none.
      • My real install (0.0.46-nightly, my own profile) blocked for 530 ms in getLocalEnvironmentEnabled -> sendSync while typing, with key events up to 488 ms.

      To be clear about the limits: the clean isolated profile reproduces the stall at launch but not during steady typing, and I did not run the patched build against my real profile. I also haven't established why the main process is busy. This change removes the renderer's synchronous wait on it, and the measurements show that wait is gone.

      The PR description now has the full tables, reproduction steps and limits, with the labeled before/after typing clips, the CPU profiles with JSON summaries, and the comparison JSON. I can't reopen the PR from my side, so please reopen it if this closes the evidence gap.

Sign in to join this conversation.