Skip to content

Commit 30317f6

Browse files
fix(codex): update the standalone tree in the shared home, not the shadow home
An auth-overlay shadow home only carries auth and a few local entries; the standalone install stays under the shared CODEX_HOME. The updater now targets `sharedHomePath` so a shadow-home instance updates the binary it actually runs. Adds CodexDriver.test.ts covering the shadow-home case and a missing explicit path staying manual-only. Co-Authored-By: Claude Code <[email protected]>
1 parent fb015da commit 30317f6

2 files changed

Lines changed: 112 additions & 8 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// @effect-diagnostics nodeBuiltinImport:off
2+
import * as NodeServices from "@effect/platform-node/NodeServices";
3+
import * as NodeOS from "node:os";
4+
import * as NodePath from "node:path";
5+
import { expect, it } from "@effect/vitest";
6+
import { ProviderInstanceId } from "@t3tools/contracts";
7+
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
8+
import * as Effect from "effect/Effect";
9+
import * as FileSystem from "effect/FileSystem";
10+
import * as Layer from "effect/Layer";
11+
import { HttpClient } from "effect/unstable/http";
12+
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
13+
14+
import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts";
15+
import { ServerConfig } from "../../config.ts";
16+
import { ServerSettingsService } from "../../serverSettings.ts";
17+
import { layerTest as codexResetCreditLayerTest } from "../Layers/codexResetCredit.ts";
18+
import { NoOpProviderEventLoggers, ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
19+
import * as ModelManifest from "../ModelManifest.ts";
20+
import { CodexDriver } from "./CodexDriver.ts";
21+
22+
const testLayer = ServerConfig.layerTest(process.cwd(), {
23+
prefix: "t3-codex-driver-maintenance-",
24+
}).pipe(
25+
Layer.provideMerge(NodeServices.layer),
26+
Layer.provideMerge(ServerSettingsService.layerTest()),
27+
Layer.provideMerge(ModelManifest.layerTest),
28+
Layer.provideMerge(codexResetCreditLayerTest),
29+
Layer.provideMerge(
30+
Layer.mock(BackgroundPolicy.BackgroundPolicy)({
31+
shouldRunScopeWork: () => Effect.succeed(false),
32+
}),
33+
),
34+
Layer.provideMerge(Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers)),
35+
Layer.provideMerge(
36+
Layer.succeed(
37+
HttpClient.HttpClient,
38+
HttpClient.make(() => Effect.die("Disabled Codex must not make an HTTP request")),
39+
),
40+
),
41+
);
42+
43+
// The `#!/bin/sh` stub below cannot be resolved as an executable on Windows.
44+
const windowsHost = HostProcessPlatform.defaultValue() === "win32";
45+
46+
const noSpawn = ChildProcessSpawner.make(() =>
47+
Effect.die("Disabled Codex must not spawn a process"),
48+
);
49+
50+
it.layer(testLayer)("CodexDriver", (it) => {
51+
it.effect.skipIf(windowsHost)(
52+
"runs the standalone updater against the shared home, not the shadow home",
53+
() =>
54+
Effect.gen(function* () {
55+
const fs = yield* FileSystem.FileSystem;
56+
const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-codex-driver-" });
57+
const sharedHome = NodePath.join(tempDir, "codex-home");
58+
const shadowHome = NodePath.join(tempDir, "codex-shadow");
59+
const binaryPath = NodePath.join(sharedHome, "packages", "standalone", "bin", "codex");
60+
yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true });
61+
yield* fs.writeFileString(binaryPath, "#!/bin/sh\n");
62+
yield* fs.chmod(binaryPath, 0o755);
63+
64+
const instance = yield* CodexDriver.create({
65+
instanceId: ProviderInstanceId.make("codex-shadow"),
66+
displayName: "Codex test",
67+
enabled: false,
68+
environment: [],
69+
config: {
70+
...CodexDriver.defaultConfig(),
71+
binaryPath,
72+
homePath: sharedHome,
73+
shadowHomePath: shadowHome,
74+
},
75+
});
76+
77+
const capabilities = yield* instance.snapshot.resolveMaintenance();
78+
expect(capabilities.update).toMatchObject({
79+
executable: binaryPath,
80+
args: ["update"],
81+
lockKey: "codex-native",
82+
env: { CODEX_HOME: sharedHome },
83+
});
84+
}).pipe(
85+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
86+
Effect.scoped,
87+
),
88+
);
89+
90+
it.effect("stays manual-only when the configured executable does not exist", () =>
91+
Effect.gen(function* () {
92+
const instance = yield* CodexDriver.create({
93+
instanceId: ProviderInstanceId.make("codex-missing"),
94+
displayName: "Codex test",
95+
enabled: false,
96+
environment: [],
97+
config: {
98+
...CodexDriver.defaultConfig(),
99+
binaryPath: NodePath.join(NodeOS.tmpdir(), "t3-codex-missing", "codex"),
100+
},
101+
});
102+
expect((yield* instance.snapshot.resolveMaintenance()).update).toBeNull();
103+
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), Effect.scoped),
104+
);
105+
});

‎apps/server/src/provider/Drivers/CodexDriver.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
5252
import * as ModelManifest from "../ModelManifest.ts";
5353
import type { ProviderDriver, ProviderInstance } from "../ProviderDriver.ts";
5454
import { withInstanceIdentity } from "./instanceIdentity.ts";
55-
import { expandHomePath } from "../../pathExpansion.ts";
5655
import { mergeProviderInstanceEnvironment } from "../ProviderInstanceEnvironment.ts";
5756
import {
5857
enrichProviderSnapshotWithVersionAdvisory,
@@ -81,19 +80,19 @@ function isCodexStandaloneCommandPath(commandPath: string): boolean {
8180
}
8281

8382
/**
84-
* `codex update` replaces the standalone tree under `CODEX_HOME`, so the
85-
* updater must run with this instance's home or it would update `~/.codex`
86-
* and leave the instance's binary behind.
83+
* `codex update` replaces the standalone tree under `CODEX_HOME`. That tree
84+
* lives in the shared home even when an auth-overlay shadow home is in use
85+
* (the overlay only carries auth and a few local entries), so the updater
86+
* runs against `sharedHomePath` rather than the instance's effective home.
8787
*/
88-
function makeCodexMaintenanceResolver(homePath: string) {
89-
const resolvedHomePath = homePath ? expandHomePath(homePath) : undefined;
88+
function makeCodexMaintenanceResolver(sharedHomePath: string) {
9089
return makePackageManagedProviderMaintenanceResolver({
9190
provider: DRIVER_KIND,
9291
npmPackageName: "@openai/codex",
9392
nativeUpdate: {
9493
args: ["update"],
9594
isCommandPath: isCodexStandaloneCommandPath,
96-
...(resolvedHomePath ? { env: { CODEX_HOME: resolvedHomePath } } : {}),
95+
env: { CODEX_HOME: sharedHomePath },
9796
},
9897
});
9998
}
@@ -162,7 +161,7 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
162161
} satisfies CodexSettings;
163162
const resolveMaintenance = yield* makeCachedProviderMaintenanceResolution(
164163
resolveProviderMaintenanceCapabilitiesEffect(
165-
makeCodexMaintenanceResolver(effectiveConfig.homePath),
164+
makeCodexMaintenanceResolver(homeLayout.sharedHomePath),
166165
{
167166
binaryPath: effectiveConfig.binaryPath,
168167
env: processEnv,

0 commit comments

Comments
 (0)