Skip to content

Commit 5fb9ee5

Browse files
fix(server): standalone Codex is checked against the native release channel (pingdotgg#34910)
1 parent 0b1b9d4 commit 5fb9ee5

2 files changed

Lines changed: 114 additions & 2 deletions

File tree

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,87 @@ it.layer(layerTest)("CodexDriver", (it) => {
481481
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), Effect.scoped),
482482
);
483483

484+
// regression: #23937 `codex update` installs the native channel's release, which can lag npm.
485+
it.effect.skipIf(windowsHost)(
486+
"does not advertise npm's latest Codex to a standalone install",
487+
() =>
488+
Effect.gen(function* () {
489+
const fs = yield* FileSystem.FileSystem;
490+
const tempDir = yield* fs
491+
.makeTempDirectoryScoped({ prefix: "t3-codex-driver-" })
492+
.pipe(Effect.flatMap((directory) => fs.realPath(directory)));
493+
const home = NodePath.join(tempDir, "codex-home");
494+
const binaryPath = NodePath.join(home, "packages", "standalone", "current", "bin", "codex");
495+
yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true });
496+
yield* fs.writeFileString(binaryPath, "#!/bin/sh\n");
497+
yield* fs.chmod(binaryPath, 0o755);
498+
// npm's latest tag is ahead of the native channel, as during a staggered release.
499+
const npmView = ChildProcessSpawner.make((command) => {
500+
if (!ChildProcess.isStandardCommand(command) || command.args[0] !== "view") {
501+
return Effect.die("Version lookup must not run a provider or updater");
502+
}
503+
return Effect.succeed(
504+
ChildProcessSpawner.makeHandle({
505+
pid: ChildProcessSpawner.ProcessId(1),
506+
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
507+
isRunning: Effect.succeed(false),
508+
kill: () => Effect.void,
509+
unref: Effect.succeed(Effect.void),
510+
stdin: Sink.drain,
511+
stdout: Stream.encodeText(Stream.make('"0.164.0"')),
512+
stderr: Stream.empty,
513+
all: Stream.empty,
514+
getInputFd: () => Sink.drain,
515+
getOutputFd: () => Stream.empty,
516+
}),
517+
);
518+
});
519+
const instance = yield* CodexDriver.create({
520+
instanceId: ProviderInstanceId.make("codex-standalone-latest"),
521+
displayName: "Codex standalone",
522+
enabled: false,
523+
environment: [],
524+
config: { ...CodexDriver.defaultConfig(), binaryPath, homePath: home },
525+
}).pipe(
526+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, npmView),
527+
Effect.provideService(
528+
HttpClient.HttpClient,
529+
HttpClient.make((request) =>
530+
Effect.succeed(
531+
HttpClientResponse.fromWeb(
532+
request,
533+
request.url === "https://releases.openai.com/codex/channels/latest"
534+
? Response.json({ tag_name: "rust-v0.163.0", assets: [] })
535+
: new Response(null, { status: 404 }),
536+
),
537+
),
538+
),
539+
),
540+
);
541+
const capabilities = yield* instance.snapshot.resolveMaintenance();
542+
expect(capabilities.update?.lockKey).toBe("codex-native");
543+
544+
const latestVersion = yield* resolveLatestProviderVersion(capabilities).pipe(
545+
Effect.provideServiceEffect(
546+
ProviderLatestVersions.ProviderLatestVersions,
547+
ProviderLatestVersions.make(),
548+
),
549+
);
550+
expect(latestVersion).toBe("0.163.0");
551+
expect(
552+
createProviderVersionAdvisory({
553+
driver: CodexDriver.driverKind,
554+
currentVersion: "0.163.0",
555+
latestVersion,
556+
maintenanceCapabilities: capabilities,
557+
}).status,
558+
).not.toBe("behind_latest");
559+
}).pipe(
560+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn),
561+
Effect.scoped,
562+
),
563+
);
564+
484565
it.effect("uses each instance's environment CODEX_HOME for continuation", () =>
485566
Effect.gen(function* () {
486567
const fs = yield* FileSystem.FileSystem;

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import type * as Signature from "effect/crypto/Signature";
55
import * as Duration from "effect/Duration";
66
import * as Effect from "effect/Effect";
77
import * as FileSystem from "effect/FileSystem";
8+
import * as Option from "effect/Option";
89
import * as Path from "effect/Path";
910
import * as Schema from "effect/Schema";
1011
import * as Stream from "effect/Stream";
11-
import { HttpClient } from "effect/http";
12+
import { HttpClient, HttpClientResponse } from "effect/http";
1213
import { ChildProcessSpawner } from "effect/process";
1314

1415
import type * as CodexUsageHistory from "../../usage/CodexUsageHistory.ts";
@@ -42,6 +43,7 @@ import {
4243
makeCachedProviderMaintenanceResolution,
4344
makePackageManagedProviderMaintenanceResolver,
4445
resolveProviderMaintenanceCapabilitiesEffect,
46+
type ProviderMaintenanceCapabilities,
4547
} from "@t3tools/provider-core/server/maintenanceResolver";
4648
import {
4749
haveProviderSnapshotSettingsChanged,
@@ -98,6 +100,31 @@ function makeCodexMaintenanceResolver(sharedHomePath: string) {
98100
});
99101
}
100102

103+
// `codex update` installs this channel's release, which can lag npm's latest tag.
104+
const CODEX_NATIVE_CHANNEL = "https://releases.openai.com/codex/channels/latest";
105+
const CodexNativeRelease = Schema.Struct({ tag_name: Schema.String });
106+
107+
function withCodexNativeLatestVersion(
108+
capabilities: ProviderMaintenanceCapabilities,
109+
http: HttpClient.HttpClient,
110+
): ProviderMaintenanceCapabilities {
111+
if (capabilities.update?.lockKey !== `${DRIVER_KIND}-native`) return capabilities;
112+
return {
113+
...capabilities,
114+
latestVersion: null,
115+
latestVersionCacheKey: CODEX_NATIVE_CHANNEL,
116+
lookupLatestVersion: http.get(CODEX_NATIVE_CHANNEL).pipe(
117+
Effect.flatMap(HttpClientResponse.filterStatusOk),
118+
Effect.flatMap((response) => response.json),
119+
Effect.flatMap(Schema.decodeUnknownEffect(CodexNativeRelease)),
120+
Effect.map((release) => /^rust-v(\d+\.\d+\.\d+)$/.exec(release.tag_name)?.[1] ?? null),
121+
Effect.timeoutOption("4 seconds"),
122+
Effect.map(Option.getOrNull),
123+
Effect.orElseSucceed(() => null),
124+
),
125+
};
126+
}
127+
101128
export type CodexDriverEnv =
102129
| CodexAdapterV2DriverEnv
103130
| ProviderHost.ProviderHost
@@ -192,7 +219,7 @@ export const CodexDriver: ProviderDriver<
192219
binaryPath: expandHomePath(config.binaryPath, yield* HostProcess.HomeDirectory),
193220
homePath: homeLayout.effectiveHomePath ?? "",
194221
} satisfies CodexSettings;
195-
const resolveMaintenance = yield* makeCachedProviderMaintenanceResolution(
222+
const resolveInstallation = yield* makeCachedProviderMaintenanceResolution(
196223
resolveProviderMaintenanceCapabilitiesEffect(
197224
makeCodexMaintenanceResolver(homeLayout.sharedHomePath),
198225
{
@@ -205,6 +232,10 @@ export const CodexDriver: ProviderDriver<
205232
Effect.provideService(Path.Path, pathService),
206233
),
207234
);
235+
const resolveMaintenance: typeof resolveInstallation = (options) =>
236+
resolveInstallation(options).pipe(
237+
Effect.map((capabilities) => withCodexNativeLatestVersion(capabilities, httpClient)),
238+
);
208239

209240
const orchestrationAdapter = yield* createCodexAdapterV2(
210241
{

0 commit comments

Comments
 (0)