@devries-cameron20 / t3code Mirror · read-only / commits / f4147ddf79
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 13:15 UTC

fix(server): update shared Codex installs from their owning home (#25235)

Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>

maria committed Oct 29, 2026 at 18:05 UTC f4147ddf7948c30163714975dc8b9de671434f3c
3 files changed +129 -8
apps/server/src/provider/Drivers/CodexDriver.test.ts
+101
@@ -377,6 +377,107 @@ it.layer(layerTest)("CodexDriver", (it) => {
377 ),
378 );
379
380 + it.effect.skipIf(windowsHost)(
381 + "runs the standalone updater against the home that holds a shared install",
382 + () =>
383 + Effect.gen(function* () {
384 + const fs = yield* FileSystem.FileSystem;
385 + const tempDir = yield* fs
386 + .makeTempDirectoryScoped({ prefix: "t3-codex-driver-" })
387 + .pipe(Effect.flatMap((directory) => fs.realPath(directory)));
388 + // One standalone install, linked onto PATH and used by two account homes.
389 + // `İ` gets longer when lowercased, so the home must not be sliced from a
390 + // lowercased copy of the path.
391 + const installHome = NodePath.join(tempDir, "codex-İnstall");
392 + const realBinaryPath = NodePath.join(
393 + installHome,
394 + "packages",
395 + "standalone",
396 + "releases",
397 + "0.162.1-x86_64-unknown-linux-musl",
398 + "bin",
399 + "codex",
400 + );
401 + const binaryPath = NodePath.join(tempDir, "bin", "codex");
402 + yield* fs.makeDirectory(NodePath.dirname(realBinaryPath), { recursive: true });
403 + yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true });
404 + yield* fs.writeFileString(realBinaryPath, "#!/bin/sh\n");
405 + yield* fs.chmod(realBinaryPath, 0o755);
406 + yield* fs.symlink(realBinaryPath, binaryPath);
407 +
408 + const updates = yield* Effect.forEach(["codex-p", "codex-vm"], (account) =>
409 + Effect.gen(function* () {
410 + const homePath = NodePath.join(tempDir, `home-${account}`);
411 + yield* fs.makeDirectory(homePath, { recursive: true });
412 + const instance = yield* CodexDriver.create({
413 + instanceId: ProviderInstanceId.make(account),
414 + displayName: account,
415 + enabled: false,
416 + environment: [],
417 + config: { ...CodexDriver.defaultConfig(), binaryPath, homePath },
418 + });
419 + return (yield* instance.snapshot.resolveMaintenance()).update;
420 + }),
421 + );
422 +
423 + for (const update of updates) {
424 + expect(update).toMatchObject({
425 + command: `${binaryPath} update`,
426 + args: ["update"],
427 + lockKey: "codex-native",
428 + env: { CODEX_HOME: installHome },
429 + });
430 + }
431 + }).pipe(
432 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
433 + Effect.scoped,
434 + ),
435 + );
436 +
437 + it.effect.skipIf(windowsHost)("derives the standalone update home from either command path", () =>
438 + Effect.gen(function* () {
439 + const fs = yield* FileSystem.FileSystem;
440 + const tempDir = yield* fs
441 + .makeTempDirectoryScoped({ prefix: "t3-codex-update-home-" })
442 + .pipe(Effect.flatMap((directory) => fs.realPath(directory)));
443 + const linkedInstallHome = NodePath.join(tempDir, "install");
444 + const fixtures = [
445 + { binary: "codex", realPath: "/packages/standalone/bin/codex", home: "/" },
446 + { binary: "codex", realPath: "C:\\Packages\\Standalone\\bin\\codex.exe", home: "C:\\" },
447 + // The standalone tree itself is a symlink, so only the resolved path names its home.
448 + {
449 + binary: NodePath.join("install", "packages", "standalone", "bin", "codex"),
450 + realPath: "/disk/codex/releases/0.163.0/bin/codex",
451 + home: linkedInstallHome,
452 + },
453 + ];
454 +
455 + for (const fixture of fixtures) {
456 + const binaryPath = NodePath.join(tempDir, fixture.binary);
457 + yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true });
458 + yield* fs.writeFileString(binaryPath, "#!/bin/sh\n");
459 + yield* fs.chmod(binaryPath, 0o755);
460 + const instance = yield* CodexDriver.create({
461 + instanceId: ProviderInstanceId.make("codex-update-home"),
462 + displayName: "Codex update home",
463 + enabled: false,
464 + environment: [],
465 + config: { ...CodexDriver.defaultConfig(), binaryPath, homePath: tempDir },
466 + }).pipe(
467 + // Virtualize only the executable target: these trees do not belong to this test.
468 + Effect.provideService(FileSystem.FileSystem, {
469 + ...fs,
470 + realPath: (path) =>
471 + path === binaryPath ? Effect.succeed(fixture.realPath) : fs.realPath(path),
472 + }),
473 + );
474 + expect((yield* instance.snapshot.resolveMaintenance()).update?.env).toEqual({
475 + CODEX_HOME: fixture.home,
476 + });
477 + }
478 + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), Effect.scoped),
479 + );
480 +
481 for (const fixture of [
482 {
483 name: "leaves mise npm-backend installations manual-only",
apps/server/src/provider/Drivers/CodexDriver.ts
+21 -6
@@ -37,7 +37,6 @@ import {
37 enrichProviderSnapshotWithVersionAdvisory,
38 makeCachedProviderMaintenanceResolution,
39 makePackageManagedProviderMaintenanceResolver,
40 - normalizeCommandPath,
40 resolveProviderMaintenanceCapabilitiesEffect,
41 } from "@t3tools/provider-core/server/maintenanceResolver";
42 import {
@@ -60,20 +59,36 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
59 const decodeCodexSettings = Schema.decodeSync(CodexSettings);
60
61 const DRIVER_KIND = ProviderDriverKind.make("codex");
63 -function isCodexStandaloneCommandPath(commandPath: string): boolean {
64 - return normalizeCommandPath(commandPath).includes("/packages/standalone/");
62 +const CODEX_STANDALONE_HOME_PATTERN = /^(.*)\/packages\/standalone\//is;
63 +
64 +function codexStandaloneHome(commandPath: string): string | null {
65 + // Slash replacement preserves indices; Unicode lowercasing can change the path length.
66 + const match = CODEX_STANDALONE_HOME_PATTERN.exec(commandPath.replaceAll("\\", "/"));
67 + if (!match) {
68 + return null;
69 + }
70 + const home = match[1]!;
71 + // Keep root separators: `C:` is drive-relative, and an empty home is not `/`.
72 + const isRoot = home === "" || /^[a-z]:$/i.test(home);
73 + return commandPath.slice(0, home.length + (isRoot ? 1 : 0));
74 }
75
67 -/** `codex update` owns the shared home's standalone tree; auth-overlay homes do not carry it. */
76 +// Standalone updates locate their install through CODEX_HOME. Account and auth-overlay
77 +// homes can share an executable, so only the updater uses the executable's owning home.
78 function makeCodexMaintenanceResolver(sharedHomePath: string) {
79 return makePackageManagedProviderMaintenanceResolver({
80 provider: DRIVER_KIND,
81 npmPackageName: "@openai/codex",
82 nativeUpdate: {
83 args: ["update"],
74 - isCommandPath: isCodexStandaloneCommandPath,
84 + isCommandPath: (commandPath) => codexStandaloneHome(commandPath) !== null,
85 requiresCommandPath: true,
76 - env: { CODEX_HOME: sharedHomePath },
86 + env: (context) => ({
87 + CODEX_HOME:
88 + codexStandaloneHome(context.realCommandPath) ??
89 + codexStandaloneHome(context.resolvedCommandPath) ??
90 + sharedHomePath,
91 + }),
92 },
93 });
94 }
packages/provider-core/src/server/maintenanceResolver.ts
+7 -2
@@ -87,7 +87,9 @@ export interface PackageManagedProviderMaintenanceDefinition {
87 readonly isCommandPath?: (commandPath: string) => boolean;
88 /** The updater cannot detect installs outside `isCommandPath`, so leave those manual-only. */
89 readonly requiresCommandPath?: boolean;
90 - readonly env?: NodeJS.ProcessEnv;
90 + readonly env?:
91 + | NodeJS.ProcessEnv
92 + | ((context: ProviderMaintenanceResolutionContext) => NodeJS.ProcessEnv);
93 } | null;
94 }
95
@@ -446,6 +448,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
448 }
449
450 const nativeUpdate = definition.nativeUpdate;
451 + const nativeEnv = nativeUpdate?.env;
452 const native = nativeUpdate
453 ? makeProviderMaintenanceCapabilities({
454 provider: definition.provider,
@@ -454,7 +457,9 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
457 updateArgs: nativeUpdate.args,
458 updateLockKey: `${definition.provider}-native`,
459 platform: context.platform,
457 - ...(nativeUpdate.env ? { env: nativeUpdate.env } : {}),
460 + ...(nativeEnv
461 + ? { env: typeof nativeEnv === "function" ? nativeEnv(context) : nativeEnv }
462 + : {}),
463 })
464 : manual;
465 // A native-looking launcher can still delegate to a mise-owned install.