Skip to content

perf(desktop): unblock Windows startup and shrink the installer - #5122

Closed
simon-curtis wants to merge 18 commits into
pingdotgg:mainfrom
simon-curtis:main
Closed

simon-curtis wants to merge 18 commits into
pingdotgg:mainfrom
simon-curtis:main

Conversation

@simon-curtis

@simon-curtis simon-curtis commented Jul 31, 2026 •

Copy link
Copy Markdown

Problem

On Windows, the installed desktop app could spend nearly a minute with no window while synchronous command discovery and provider initialization blocked backend readiness. Upgrade installation was similarly opaque and slow because oversized packages contained thousands of unpacked files that the previous uninstaller and antivirus scanned individually.

Windows users also could not choose the executable used for new T3 terminal sessions.

How this fixes it

  • Resolves Windows shell commands with a cached, bounded native lookup instead of thousands of sequential filesystem probes.
  • Preserves PATH/PATHEXT precedence, handles directories that permit direct probing but deny listing, and invalidates stale cached hits safely.
  • Installs a cheap Windows PATH baseline synchronously, then hydrates PowerShell profile PATH/FNM state asynchronously without delaying backend readiness.
  • Refreshes live provider environment objects and environment-sensitive caches after hydration without rebuilding adapters or interrupting active turns.
  • Serializes provider reconciliation and makes cancellation cleanup transactional so scopes cannot leak or remain publicly visible after closure.
  • Defers provider maintenance path discovery, shares concurrent work, retries interrupted discovery, and invalidates successful results only when environment hydration requires it.
  • Omits the optional Linux/WSL runtime and Linux-only staged dependencies from Windows packages unless a Linux node-pty prebuild is supplied.
  • Shows explicit removing, installing, and finishing phases in the Windows installer.
  • Adds an environment-owned default terminal executable setting for new T3 terminal sessions, including remote clients. This does not change shells chosen internally by provider CLIs.

Windows performance results

The original comparison used installed production builds on the same Windows host. Startup was measured from process spawn to the first completed HTTP 200 and to the first visible Electron window.

Build Backend ready Window
Previous Nightly 46.0 s 46.6 s to window creation
New release, cold 4.352 s 5.866 s visible
New release, warm 1 4.492 s 5.994 s visible
New release, warm 2 4.234 s 5.724 s visible
New release median 4.352 s 5.866 s visible

Performance test head (e4a322213) was rebuilt as a production Windows package and rerun from its staged executable with isolated APPDATA, isolated T3CODE_HOME, and a dedicated port. The staged package was used to avoid overwriting the developer's installed app.

Latest-head rerun Backend ready Window visible
Run 1 4.160 s 5.600 s
Run 2 11.290 s 18.250 s
Run 3 4.282 s 5.814 s
Median 4.282 s 5.814 s

The latest-head median is 1.6% faster to HTTP readiness and 0.9% faster to a visible window than the original new-release median. Run 2 is retained as a host-level outlier rather than discarded; temporary unpacked builds showed intermittent Windows scanning/contention, while the other two runs and the median remained in the original range. Individual Windows command-resolution spans remained bounded rather than reproducing the previous synchronous startup stall.

All measurements require HTTP 200 rather than treating an open TCP socket as ready. Each run was fully stopped before the next launch and used isolated state rather than the live user database.

Packaging and installation results

Metric Before After Change
NSIS installer 324.19 MB 134.55 MB 58.5% smaller
Unpacked runtime payload 890 MB 29.07 MB 96.7% smaller
Unpacked files 3,532 200 94.3% fewer
Observed upgrade ~100 s removing the previous build alone ~21 s complete upgrade substantially faster

Upgrade timings are observational rather than a controlled benchmark: the old measurement removed the original 2,494-file Nightly, while the final measurement replaced an already-compacted build.

User-visible behavior

  • General Settings exposes the default terminal executable, searchable and resettable.
  • The setting belongs to the connected environment, so web, desktop, and mobile-created terminals use the same value. Mobile does not currently expose the editing control.
  • Windows installer banners show removal, installation, and completion phases.
  • User documentation describes scope, quoting, fallback behavior, and remote environments.

Verification

  • Rebased onto upstream main at 2a04db134c2d88f06e5b8d61a8410cb51ea07430.
  • 211 focused tests passed across 12 files under Node 24.13.1; the final Claude environment fix then passed 90/90 core tests plus its portable text-generation regression.
  • Post-review provider registry regressions passed 10/10 focused tests across 2 files, including secret-materialization failure and interrupted reconciliation coverage.
  • Affected server, web, desktop, contracts, shared, and scripts typechecks passed.
  • Targeted lint, formatting, and git diff --check passed.
  • The custom NSIS include compiled with warnings-as-errors using Electron Builder's pinned NSIS 3.12; the latest head also completed a fresh production Windows package build and startup rerun.
  • Focused coverage includes command cache/PATH/PATHEXT behavior, inaccessible directory fallback, runtime PATH shell resolution, settings subscription ordering, asynchronous environment hydration, provider environment override precedence, maintenance cancellation/invalidation, concurrent and interrupted provider reconciliation, settings UI/search/reset behavior, WSL package inclusion/omission, and installer phase/error ordering.

Checklist

  • This PR is focused on the Windows experience
  • I explained what changed and why
  • The branch is rebased onto current upstream main
  • Focused tests and affected typechecks pass
  • I included before/after screenshots for UI changes
  • I included a short video for timing/interaction changes

Model: GPT-5 / GPT-5.4
Harness: OpenAI Codex desktop app with dev-loop specialist review


Note

Medium Risk
Touches Windows PATH timing at startup, provider registry reconciliation, and live environment refresh for all drivers; incorrect hydration or refresh ordering could leave tools undiscovered until profile load completes or briefly stale maintenance metadata.

Overview
This PR targets Windows startup and upgrades by stopping synchronous PowerShell profile work from blocking server readiness, tightening command/PATH resolution, and refreshing provider state in place after the profile finishes loading.

Startup and environment: The server applies a baseline Windows PATH immediately and forks PowerShell profile hydration (PATH, FNM vars) in the background. The desktop app no longer spawns PowerShell to build PATH at launch. Shared resolveCommandPath gains caching, PATH/PATHEXT precedence, concurrent probing, and safer invalidation when directories are unreadable.

Providers: Instance env is built from makeProviderInstanceEnvironmentSource with refreshEnvironment so host PATH changes merge without recreating adapters. Maintenance capabilities are lazy/cached and refresh after hydration. After Windows profile hydration completes, the registry refreshes snapshots in place (no reconcile/replace). Reconcile is serialized and interrupt-safe with staged entries during rebuilds. Settings watcher re-reads settings and can restore redacted secrets when secret-store reads fail.

Terminals and settings: New defaultTerminalShell setting (General settings, contracts, docs) drives spawn behavior; Windows resolves configured names through PATH, treats the value as an executable only (no embedded args), and subscribes to live settings updates.

Installer / docs: NSIS hooks show explicit “Removing the previous version…” / install phase text. README links terminal shell user docs.

Reviewed by Cursor Bugbot for commit b990f52. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Improve Windows environment hydration, command-path resolution, and terminal shell configuration

  • On Windows, server startup now applies a baseline PATH immediately and hydrates PowerShell profile environment variables (PATH, FNM) asynchronously in the background via hostEnvironmentHydrationLayer in os-jank.ts, unblocking startup.
  • Adds a defaultTerminalShell setting to ServerSettings and the General settings panel; on Windows the configured shell name is resolved against PATH/PATHEXT before spawning.
  • Windows command-path resolution in shell.ts now uses a per-process cache keyed on platform/command/PATH/PATHEXT, probes PATH directories concurrently (batched 32, concurrency 16), and handles directory-listing failures and case-insensitive semantics.
  • Provider drivers (Claude, Codex, Cursor, Grok, OpenCode) gain a refreshEnvironment effect that re-syncs inherited host env values and invalidates maintenance capability caches without replacing the instance.
  • ProviderInstanceRegistry.reconcile is now serialized, interruption-safe, and supports a { force: true } option; previous snapshots remain visible during rebuild.
  • Windows Desktop builds without a WSL runtime no longer unpack the full asar payload; NSIS installer now displays phase text ('Removing the previous version…' / 'Installing the new version…') during one-click install.
  • Risk: FNM_DIR and FNM_MULTISHELL_PATH are no longer populated by installWindowsEnvironment on Desktop; PATH enrichment from the PowerShell profile happens asynchronously and may arrive after the first terminal is opened.

Macroscope summarized b990f52.

@coderabbitai

coderabbitai Bot commented Jul 31, 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: 7ae810ae-5ced-4cc6-b92b-c5bcb622dc49

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 Author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jul 31, 2026

@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 Effect convention issue found in the changed service code (apps/server/src/terminal/Manager.ts). Everything else in the diff (namespace imports, dependency acquisition via yield* ServerSettings.ServerSettingsService, capability-source construction) looks consistent with the conventions.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/terminal/Manager.ts Resolved
@simon-curtis

Copy link
Copy Markdown
Author

Fixes #4533

Comment thread packages/shared/src/shell.ts Resolved
Comment thread apps/server/src/terminal/Manager.ts Resolved

@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 command-resolution cache is process-global mutable state rather than an environment value. See the inline comment.

Posted via Macroscope — Effect Service Conventions

Comment thread packages/shared/src/shell.ts Resolved
Comment thread apps/server/src/terminal/Manager.ts Resolved
Comment thread packages/shared/src/shell.ts Resolved
@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Aug 5, 2026
@simon-curtis
simon-curtis marked this pull request as ready for review August 5, 2026 14:39
@macroscopeapp

macroscopeapp Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new user-facing terminal shell setting, changes Windows startup behavior from blocking to async profile loading, adds provider environment refresh infrastructure across all drivers, and includes Windows installer customizations. These are significant new capabilities and runtime behavior changes warranting human review.

You can customize Macroscope's approvability policy. Learn more.

@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 1f7ea81. Configure here.

@simon-curtis simon-curtis changed the title Windows Experience #1 perf(desktop): unblock Windows startup and shrink the installer Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant