Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(shared): skip duplicate PATH entries and per-probe tracing #9618

Mergedjadeva(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/9618/headmerged by juliusmarminge View on GitHub

Repeated PATH directories make command discovery probe the same files again. Each probe also creates a trace span. On slow Windows installations, this work contributes to editor discovery timing out and showing no editors in #4697.

Skip exact duplicate PATH entries within a lookup and trace the enclosing command lookup instead of every candidate file. Keep case-distinct directories and all existing upper/lowercase PATHEXT candidates. The original version removed lowercase candidates, but two real-file regressions showed that this misses lowercase executable files in case-sensitive directories; that change has been removed.

Verification on main 2d5464af:

  • The production resolver performs 16 probes for two repeated directories and two PATHEXT extensions on main, versus 8 with this change. Case-distinct directory spellings are still visited separately.
  • Real-file controls preserve lowercase .cmd resolution, explicit-path lookup, and the existing 30-second negative-cache expiry. The original uppercase-only patch fails both lowercase-file controls; the revised patch passes.
  • vp test run packages/shared/src/shell.test.ts apps/server/src/process/externalLauncher.test.ts --maxWorkers=2: 57 tests pass, 1 skips. The server integration resolves this worktree's edited shared package. Targeted lint/format plus shared and server typechecks pass.

This is a bounded reduction in redundant work, not a guarantee that every Windows machine finishes discovery within five seconds. The timeout and its empty-editor fallback remain unchanged. The author's original Windows timings included the removed uppercase-only optimization and are not measurements of this revised head. A current native Windows end-to-end timing is still missing; do not close the full editor-discovery report based on these Linux fixtures.

Screenshots do not establish filesystem probe counts; the before/after evidence is the focused production-resolver tests. All executed current-head CI and configured review checks pass; preview jobs skip. The root reviewer read both changed files and the resolver/cache call paths, checked the case-sensitive and cache-expiry controls, and found no unresolved review threads. This is a bounded reduction of duplicate work, with no timeout, cache policy or supported executable changes. The broader Windows report remains open.

Original implementation and Windows investigation by Niklas Westman. Compatibility fixes and updated verification by GPT 6 Astra via Codex in T3 Code.


Note

Medium Risk Touches core Windows command discovery used for spawn and editor detection; behavior changes are narrow (dedupe + tracing) but incorrect PATH/case handling could miss binaries or regress discovery timeouts.

Overview Windows command resolution (resolveCommandPath) now skips exact duplicate PATH segments within a single lookup so repeated directories are not re-scanned, while case-distinct PATH spellings (e.g. C:\bin vs C:\BIN) are still visited separately for case-sensitive directories.

Tracing moves from per-file isExecutableFile spans to untraced probes, cutting span noise during large PATH walks. PATHEXT behavior is unchanged: upper- and lowercase extension candidates are still tried.

New shell.test.ts coverage records probe counts via a noop filesystem, asserts dedupe vs case-split PATH, lowercase .cmd resolution in case-sensitive dirs, 30s negative-cache expiry with TestClock, and mixed-case PATHEXT probes.

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

Note

Skip duplicate PATH entries in resolveCommandPathForPlatform and untrace isExecutableFile probes

  • Windows command resolution now tracks exact PATH-entry strings and skips empty or repeated entries with the same spelling, while retaining entries that differ only by case.
  • isExecutableFile file probes use the untraced effect wrapper so individual candidate stats no longer generate tracing spans; the surrounding lookup stays traced.
  • Adds test coverage for duplicate PATH deduplication, case-distinct PATH entries, lowercase executable resolution, negative-cache expiry, and upper/lowercase PATHEXT probing in shell.test.ts.
  • Risk: resolveCommandPathForPlatform deduplication is string-exact only; PATH entries that differ only by case on a case-insensitive filesystem will still be scanned twice, which is intended but may surprise reviewers expecting case-insensitive deduplication.
Macroscope summarized faa22fc.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at faa22fc

      Macroscope's review found this PR approvable — This is a narrowly scoped performance and tracing optimization in shared command lookup: exact duplicate PATH segments are skipped while ordering and case-distinct entries remain intact. Focused tests cover the changed Windows path, cache, and PATHEXT behavior, with no product-default or static-analysis configuration changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Thanks for the review. Taking the two findings separately, because I agree with one and disagree with the other.

      Case-folded de-duplication (High) — fixed in bde6b7ba4

      Agreed, and this was the better catch of the two. I had a defence available and it does not hold up: mergePathValues already folds case through normalizePathEntryForComparison, so I was being consistent with the file. But that helper is choosing which spelling of an entry to keep, whereas skipping a probe is a stronger claim. Windows 10+ can mark a directory case-sensitive with fsutil file setCaseSensitiveInfo, so C:\Tools and C:\tools are not provably one directory, and folding them could hide a command that is really there and then cache that miss for 30s. A silent miss is a bad trade for a few saved syscalls.

      Entries are now compared verbatim. What it costs on my PATH:

      entries dropped (of 75)probes per discovery pass
      case-folded2013,992
      verbatim1515,312

      The five it gives up are all C:\Windows vs C:\WINDOWS spellings of system directories. The reduction against main's 35,904 goes from 61% to 57.4%, and in the built app buildAvailableEditors still completes in 1,418 ms where main is interrupted at the 5s timeout. So the fix costs very little.

      There is now a test asserting that a PATH entry differing only in case is still visited, so this is pinned by a test rather than only by a comment.

      Commands appearing mid-scan (Medium) — I do not think this is a regression

      This one I would push back on. The concern is that a command created between the first and the skipped occurrence of a directory is reported as not-found and cached for 30s. That is already true on main, and it is deliberate. From packages/shared/src/shell.ts:504:

      A "not-found" outcome is also cached for the TTL, so a just-installed binary can stay invisible for up to 30s unless resolved by explicit path.

      The scan has never been atomic. A binary created after the walk passes a directory is missed and cached whether or not repeats are skipped; de-duplication changes that window by the microseconds between two probes of the same directory inside a single pass. Callers that have just written a binary resolve it by explicit path, which is never cached, and the comment above says so.

      The suggested diff also reverts the change rather than narrowing it, so I have left this one as is. Happy to be shown a case where the timing actually matters.

      Note on the description

      The tables in the PR body still quote the case-folded numbers (13,992 probes, 61%, 1,705 ms). The correct figures after bde6b7ba4 are the ones above: 15,312 probes, 57.4%, 1,418 ms. The conclusion is unchanged, main hits the 5s timeout and this branch does not.

      🤖 Generated with Claude Code

    4. Confirmed the fallback behind #4697. With the production resolveAvailableEditorsForConfig, a successful editor result delayed by 5.1 seconds becomes [] after the 5-second discovery timeout under TestClock. Tested at dd7bc147; that timeout path is unchanged through September 4 main 0dd5c64b.

      This optimization can prevent the timeout for the author's measured PATH, but it does not distinguish an incomplete lookup from a confirmed empty editor list. Keep those scopes separate. I have not reproduced the Windows built-app timings or completed a current-head audit of this PR's probe de-duplication and cache behavior, so it is not marked merge-ready by this audit. The existing rejected alternatives are not being revived.

      GPT 6 Astra via Codex in T3 Code.

    5. juliusmarminge changed the title

    6. juliusmarminge approved these changes

      Independent full-PR review completed. Exact PATH-entry deduplication preserves order, case-distinct entries and every existing PATHEXT candidate. Per-probe trace removal retains the enclosing lookup trace. The 16-to-8 probe fixture, two lowercase-file controls and unchanged cache-expiry/explicit-path behavior support the bounded fix; 57 focused tests pass with one skip, and current CI/reviews pass. No claim that all Windows discovery timeouts are fixed. GPT 6 Astra via Codex in T3 Code.

    7. juliusmarminge merged thisc3cacea

    8. juliusmarminge closed this

Sign in to join this conversation.