Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): only run provider updates through the installer that owns the binary #9325

Mergedjuliusmarmingemerged 13 commits intomain fromrefs/pull/9325/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Problem

T3 Code could pick an update command from one installation while the active executable belonged to another:

  • a standalone Codex install (~/.codex/packages/standalone/) got npm install -g @openai/codex@latest, which never touches it, so the advisory looped forever (#5629)
  • a brew install claude-code@latest keg got brew upgrade claude-code, which fails (#6245)
  • Homebrew casks were compared against npm's latest, which lands hours before the cask bump, so brew upgrade could never clear the advisory (#7730)

Fix

Ownership is derived from the resolved executable's real path, and a package manager is only invoked against an install it has evidence of owning:

EvidenceCommandLatest
Native installer path<resolved binary> updatenpm registry
<brew --prefix>/Cellar/<name>/<version>/ or …/Caskroom/<name>/<version>/brew upgrade [--cask] <name>brew info --json=v2
<prefix>/lib/node_modules/<pkg>/ (Windows: shim beside node_modules/<pkg>/package.json)npm install -g --prefix <prefix> <pkg>@latestnpm registry
pnpm / bun / vp global binas beforenpm registry
anything elsemanual-only, version gap still shownnpm registry

The npm prefix is pinned because the npm on PATH can belong to a different Node than the one that owns the provider. Native installs share npm's version train, so the registry stays authoritative for them and native users keep their launch toast. A Homebrew-shaped path is only trusted when its prefix matches brew --prefix of the brew that would run the upgrade.

Resolution is cached per instance for an hour. The maintenance runner re-reads it fresh immediately before executing, refuses with "Provider installation changed" if the lock key moved since the advisory, reads fresh again afterwards so a Homebrew upgrade's new latest is reflected, and reports succeeded only when the refreshed provider is still installed with a readable version (an updater that exits 0 and leaves the binary gone reports unchanged). Settings tracks in-flight updates per instance instead of per driver.

Docs: docs/internals/providers.md gains a "Provider updates run only through the owning installer" section; docs/user/install.md gains a paragraph on when Update now appears.

Evidence

Three Codex instances on one machine, all at 0.153.3 with 0.153.4 on npm. codex on PATH resolves to a wrapper script outside any package manager; the other two point at a symlinked <prefix>/lib/node_modules/@openai/codex layout and a packages/standalone layout. Same seeded state, same viewport, base = merge-base with main.

InstallBefore (main)After (this PR)
PATH wrapper, no ownerOffers npm install -g @openai/codex@latest against an install npm does not ownVersion gap shown, no one-click command
before: unowned PATH codex offers a global npm installafter: unowned PATH codex is manual-only
npm global prefixSame unpinned npm install -g; the npm on PATH could target a different Nodenpm install -g --prefix <that prefix> …
before: npm-prefix instance shows an unpinned npm commandafter: npm-prefix instance pins --prefix to the owning tree
Standalone installer (#5629)No command at all; other instances' commands conflicted, so one-click was withheldcodex update with Update now
before: standalone codex has no update commandafter: standalone codex offers codex update

Homebrew is covered by unit tests (keg/cask parsing, brew --prefix gate, brew info version, foreign-prefix rejection) since this machine has no Homebrew.

Relationship to #6436

Supersedes #6436 by @ettoc00, which identified the same root cause and whose npm --prefix pinning, Homebrew formula/cask detection, and per-instance settings state are carried over here. Scoop/WinGet support is worth its own PR with a Windows validator; @ettoc00 has confirmed those work through this runner.

Closes #5629 Closes #6245 Closes #7730

Verification

  • apps/server, apps/web typecheck; vp lint and vp fmt --check on touched files
  • Server: 118 tests across the touched files (providerMaintenance, providerMaintenanceRunner, makeManagedServerProvider, CursorDriver, ProviderRegistry, ProviderAdapterRegistry, AntigravityProvider); web: 55 tests in the two touched files
  • New coverage: npm prefix from real symlinks in a temp dir; POSIX/Windows/nested/project-local/root-prefix parsing; npm ownership outranks a Cellar/node/<ver> keg; Homebrew cask via fake spawner asserting brew --prefix then brew info; keg outside brew's prefix stays manual; missing explicit binary stays manual; explicit native path with spaces outside PATH is what gets spawned (#9850); copyable command quotes a spaced path (#9856); cache-until-fresh; runner re-resolve ordering; lock-key-changed abort with no spawn; updater exits 0 but provider disappears → unchanged; provider present but version unreadable → still succeeded
  • POSIX-only fixtures use the shared windowsHost / symlinksSupported guards from #9565/#9566
  • Independent audit (Claude, read-only worktree) found two real issues, both fixed in 3e98200b5: Homebrew-Node kegs were offered brew upgrade node, and Cursor's transient null version after a successful update reported "unchanged". A third note, that a successful update only refreshes the clicked instance, is pre-existing on main and left as is.

Written by Claude Fable 5 in Claude Code.

🤖 Generated with Claude Code


Note

Medium Risk Changes how update commands are chosen and executed across all provider drivers; incorrect ownership heuristics could remove one-click updates or run the wrong installer, but stale-command and lock-key guards reduce execution risk.

Overview Provider one-click updates now prove ownership from the resolved executable (real path, symlinks) instead of assuming a default global npm install. Unowned or missing binaries stay manual-only while still showing a version gap; npm updates pin --prefix, Homebrew uses brew upgrade with brew --prefix / brew info for latest, and native/standalone installs run the resolved binary (Codex passes CODEX_HOME to the shared home, not the shadow overlay).

Maintenance capabilities are resolved lazily via resolveMaintenance() with a one-hour cache and { fresh: true } before running an update. The runner re-resolves, aborts if the lock key changed, forwards updater env, and treats success as still installed (null version alone no longer fails Cursor). Settings UI tracks in-flight updates per instance, not per driver.

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

Note

Gate provider updates on proven installer ownership of the binary

  • Provider maintenance now resolves ownership from the real executable path before offering one-click updates. Native, Bun, pnpm, npm (by package name and global prefix), and Homebrew (by versioned keg path and brew-prefix verification) are checked in order; unproven installations get manual-only capabilities.
  • The update runner re-derives capabilities with fresh ownership data before spawning the updater, aborts if the action disappeared or its lock key changed, and verifies post-update that at least one provider remains installed and none are outdated. A missing version alone is no longer a verification failure.
  • Homebrew ownership is derived structurally from Cellar/Caskroom paths instead of a fixed prefix list, with bounded probes (10-second timeout, 256 KiB stdout cap). Installer-reported latest versions from Homebrew or native updaters short-circuit npm registry lookups.
  • npm global ownership requires a package-specific real-path layout (POSIX) or a neighboring package manifest (Windows); project-local or unrelated node_modules paths no longer qualify.
  • Capability resolution is cached for one hour; explicit fresh reads invalidate and re-resolve. Shell quoting now covers update arguments as well as executable paths.
  • Risk: resolveProviderMaintenanceCapabilitiesEffect in providerMaintenance.ts no longer falls back to npm-global updates when the binary is missing or unresolvable — those cases return manual-only capabilities. ClaudeDriver in ClaudeDriver.ts removed its hard-coded Homebrew formula and native lock key, so Claude installs previously matched by fixed prefixes will now require structural Homebrew ownership.
Macroscope summarized 30317f6.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      🟡 Medium Drivers/CodexDriver.ts:67

      Custom CODEX_HOME installations are treated as manual-only, so their Codex binaries do not receive the one-click update action. isCodexStandaloneCommandPath only matches paths containing /.codex/packages/standalone/, but the installer places a custom-home binary under /work/codex-home/packages/standalone/...; match the standalone path suffix independently of the default .codex home.

        return normalizeCommandPath(commandPath).includes("/packages/standalone/");
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/provider/Drivers/CodexDriver.ts around line 67:
      
      Custom `CODEX_HOME` installations are treated as manual-only, so their Codex binaries do not receive the one-click update action. `isCodexStandaloneCommandPath` only matches paths containing `/.codex/packages/standalone/`, but the installer places a custom-home binary under `/work/codex-home/packages/standalone/...`; match the standalone path suffix independently of the default `.codex` home.
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Drivers/CursorDriver.ts:66

      The manual update command always renders cursor-agent update, even when context.resolvedCommandPath points to a configured executable such as /opt/cursor-preview/bin/cursor-agent. As a result, the settings card targets the first unrelated cursor-agent on PATH, while one-click updates use the configured binary; build updateCommand from the resolved executable instead.

              updateCommand: `${context?.resolvedCommandPath ?? "cursor-agent"} update`,
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/provider/Drivers/CursorDriver.ts around line 66:
      
      The manual update command always renders `cursor-agent update`, even when `context.resolvedCommandPath` points to a configured executable such as `/opt/cursor-preview/bin/cursor-agent`. As a result, the settings card targets the first unrelated `cursor-agent` on `PATH`, while one-click updates use the configured binary; build `updateCommand` from the resolved executable instead.
    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.5 KiB13.5 KiB+9 B (+0.1%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB−1 B (−0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.5 KiB+10 B (+0.2%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.0 KiB57.0 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages880 (0.0%)21✅
      ClaudeTotal thread wire13.5 KiB13.5 KiB−7 B (−0.1%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB−4 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.5 KiB−3 B (−0.0%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.8 KiB−44 B (−0.1%)66.4 KiB✅
      ClaudeLive turn messages98−1 (−11.1%)21✅

      Baseline: ac90950 · PR result: 30317f6 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

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

      🟡 Medium settings/ProviderSettingsPanel.tsx:479

      Up-to-date providers with versionAdvisory.status === "current" are shown as having an available update and can run their package-manager update unnecessarily. The new filter checks only canUpdate and updateCommand, but the server preserves both for current advisories; require status === "behind_latest" as the previous isProviderUpdateCandidate path did.

                .filter(
                  (candidate) =>
                    isProviderSettingsUpdateCandidate(candidate) &&
                    candidate.versionAdvisory.status === "behind_latest",
                )
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/settings/ProviderSettingsPanel.tsx around line 479:
      
      Up-to-date providers with `versionAdvisory.status === "current"` are shown as having an available update and can run their package-manager update unnecessarily. The new filter checks only `canUpdate` and `updateCommand`, but the server preserves both for current advisories; require `status === "behind_latest"` as the previous `isProviderUpdateCandidate` path did.
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/7009338fc4ba23c448bbda7dfcba824d2fe9f384/apps/server/src/provider/providerMaintenance.ts#L478-L489

      A nonexistent explicit binaryPath such as /tmp/.local/bin/claude produces a native one-click update action instead of the resolver's no-context fallback, so running the advertised update fails. The fallback at line 481 and the ignored realPath failure both pass an unverified path to the resolver; treat either resolution failure as no context.

      -  const resolvedCommandPath =
      -    (yield* resolveCommandPath(binaryPath, { env }).pipe(
      -      Effect.catchTag("CommandResolutionError", () => Effect.succeed(null)),
      -    )) ?? (hasPathSeparator(binaryPath) ? binaryPath : null);
      +  const resolvedCommandPath = yield* resolveCommandPath(binaryPath, { env }).pipe(
      +    Effect.catchTag("CommandResolutionError", () => Effect.succeed(null)),
      +  );
         if (!resolvedCommandPath) {
           return yield* resolver.resolve(null);
         }
       
         const fileSystem = yield* FileSystem.FileSystem;
      -  const realCommandPath = yield* fileSystem
      +  const realCommandPath = yield* fileSystem
           .realPath(resolvedCommandPath)
      -    .pipe(Effect.orElseSucceed(() => resolvedCommandPath));
      +    .pipe(Effect.orElseSucceed(() => null));
      +  if (!realCommandPath) {
      +    return yield* resolver.resolve(null);
      +  }
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/provider/providerMaintenance.ts around lines 478-489:
      
      A nonexistent explicit `binaryPath` such as `/tmp/.local/bin/claude` produces a native one-click update action instead of the resolver's no-context fallback, so running the advertised update fails. The fallback at line 481 and the ignored `realPath` failure both pass an unverified path to the resolver; treat either resolution failure as no context.
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The PR substantially changes how provider updates are detected, selected, executed, and verified across the server and settings UI, including new installer-ownership heuristics and environment propagation. It also adds static-analysis diagnostic overrides in test files, making the change unsuitable for automatic approval.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. Good catch. Now matches /packages/standalone/ for any CODEX_HOME (7ba6f01ba).

    7. Not applied: updateCommand is the human-readable command shown in Settings for manual use. Rendering an absolute path there would show something like /opt/cursor-preview/bin/cursor-agent update while every other provider shows the bare tool name. The executed command already uses resolvedCommandPath. Same convention as native Claude/Codex/OpenCode.

    8. juliusmarmingecommented

      Applied to isProviderSettingsUpdateCandidate itself rather than at the call site so the type guard stays honest (7ba6f01ba).

    9. Fixed: dropped the path-separator fallback (resolveCommandPath already validates explicit paths) and a failed realPath now resolves to no context. Test added for a missing explicit binary (7ba6f01ba).

    10. Stale Bugbot comment from a previous run.

    11. ettoc00(GitHub profile, opens in a new tab)commented

      Quick Windows validation update: Scoop and WinGet both completed real provider updates successfully across Claude and OpenCode through the actual resolver + maintenance runner, including a same-provider Scoop/WinGet coexistence case where only the explicitly selected installation was updated.

      I also found one generic post-update edge case on Windows: if the updater exits successfully but the provider disappears or its installation can no longer be ownership-verified afterward, the runner can still report succeeded simply because it is no longer behind_latest.

      Separately, I found a few test-only Windows portability issues in the existing fixtures, e.g. POSIX/macOS symlink fixtures hitting EPERM, a Darwin fixture being evaluated with Windows path semantics, and a /tmp expectation that isn’t host-normalized.

    12. @ettoc00 thanks for running that on Windows.

      • Post-update edge case: fixed in 8e10864c5. "Succeeded" now requires the refreshed provider to still be installed with a readable version; an updater that exits 0 and leaves the binary gone or unreadable reports "unchanged" with the could-not-verify message. Test added.
      • Test portability: the symlink fixtures now use skipIf(!symlinksSupported) and the #!/bin/sh + darwin/linux fixtures use skipIf(windowsHost), matching the helpers that landed on main in #9565/#9566. The /tmp expectation went away with the manifest-beside-shim rewrite (it compares against the temp dir the test created).

      Good to hear Scoop/WinGet coexistence worked through the runner. Those still want their own PR with your validation attached; the ownership proofs here should make it a small addition.

    13. docs/internals/providers.md lines 60 to 64OutdatedResolvedby juliusmarminge
    14. docs/internals/providers.md lines 60 to 61OutdatedResolvedby juliusmarminge
    15. Stale Bugbot comment from a previous run.

    16. Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

      Fix All in Cursor Bugbot Autofix is [ON](https://www.cursor.com/dashboard/bugbot), but a cloud agent failed to start. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit fb015da551f291aeeb2bec0d35252db32c1f0c31. Configure [here](https://www.cursor.com/dashboard/bugbot).
    17. juliusmarminge merged this2fb99a7

    18. juliusmarminge closed this

Sign in to join this conversation.