Skip to content

Commit 0a333a6

Browse files
fix(server): Codex shadow home shares the instance environment CODEX_HOME (#35912)
1 parent b62e80e commit 0a333a6

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,38 @@ it.layer(layerTest)("CodexDriver", (it) => {
580580
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), Effect.scoped),
581581
);
582582

583+
it.effect.skipIf(windowsHost)(
584+
"shares state from the environment CODEX_HOME in a shadow home",
585+
() =>
586+
Effect.gen(function* () {
587+
const fs = yield* FileSystem.FileSystem;
588+
const tempDir = yield* fs
589+
.makeTempDirectoryScoped({ prefix: "t3-codex-driver-" })
590+
.pipe(Effect.flatMap((directory) => fs.realPath(directory)));
591+
const codexHome = NodePath.join(tempDir, "custom-codex");
592+
const shadowHome = NodePath.join(tempDir, "shadow");
593+
yield* fs.makeDirectory(codexHome, { recursive: true });
594+
yield* fs.writeFileString(NodePath.join(codexHome, "config.toml"), 'model = "custom"\n');
595+
const instance = yield* CodexDriver.create({
596+
instanceId: ProviderInstanceId.make("env-shadow"),
597+
displayName: "env-shadow",
598+
enabled: false,
599+
environment: [{ name: "CODEX_HOME", value: codexHome, sensitive: false }],
600+
config: { ...CodexDriver.defaultConfig(), shadowHomePath: shadowHome },
601+
}).pipe(Effect.provideService(HostProcess.HomeDirectory, NodePath.join(tempDir, "user")));
602+
expect(instance.continuationIdentity.continuationKey).toBe(`codex:home:${codexHome}`);
603+
expect(yield* fs.readLink(NodePath.join(shadowHome, "config.toml"))).toBe(
604+
NodePath.join(codexHome, "config.toml"),
605+
);
606+
expect(yield* fs.readLink(NodePath.join(shadowHome, "sessions"))).toBe(
607+
NodePath.join(codexHome, "sessions"),
608+
);
609+
}).pipe(
610+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
611+
Effect.scoped,
612+
),
613+
);
614+
583615
for (const fixture of [
584616
{
585617
name: "leaves mise npm-backend installations manual-only",

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ export const CodexDriver: ProviderDriver<
190190
yield* HostProcess.Environment,
191191
);
192192
const environmentHome = processEnv.CODEX_HOME;
193-
const homeLayout = yield* resolveCodexHomeLayout(
194-
!config.homePath.trim() && !config.shadowHomePath.trim() && environmentHome?.trim()
193+
const homeConfig =
194+
!config.homePath.trim() && environmentHome?.trim()
195195
? { ...config, homePath: environmentHome }
196-
: config,
197-
);
196+
: config;
197+
const homeLayout = yield* resolveCodexHomeLayout(homeConfig);
198198
const continuationIdentity = codexContinuationIdentity(homeLayout);
199199
const stampIdentity = withInstanceIdentity({
200200
instanceId,
@@ -245,7 +245,7 @@ export const CodexDriver: ProviderDriver<
245245
accentColor,
246246
environment,
247247
enabled,
248-
config,
248+
config: homeConfig,
249249
},
250250
{
251251
onUsageLimits: (update) => snapshot.applyUsageLimits(update),

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,7 @@ export const codexUsageReader: ProviderUsageReader<
516516
const path = yield* Path.Path;
517517
const environmentHome = environment.CODEX_HOME?.trim();
518518
const layout = yield* resolveCodexHomeLayout(
519-
config.setupMode !== "managed" &&
520-
!config.homePath.trim() &&
521-
!config.shadowHomePath.trim() &&
522-
environmentHome
519+
config.setupMode !== "managed" && !config.homePath.trim() && environmentHome
523520
? { ...config, homePath: environmentHome }
524521
: config,
525522
);

‎apps/server/src/usage/UsageService.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,7 @@ describe("UsageService", () => {
23372337
},
23382338
[ProviderInstanceId.make("codex-work")]: {
23392339
driver: ProviderDriverKind.make("codex"),
2340+
config: { shadowHomePath: NodePath.join(home, "work-shadow") },
23402341
environment: [{ name: "CODEX_HOME", value: codexHome, sensitive: false }],
23412342
},
23422343
[ProviderInstanceId.make("codex-alias")]: {

0 commit comments

Comments
 (0)