Skip to content

Commit 9e136ad

Browse files
fix(server): standalone Codex is checked against the native release channel
`codex update` installs the release on releases.openai.com's latest channel, but the advisory compared standalone installs against npm's latest tag. When npm was ahead, a successful update left the provider reported as outdated. Look up the native channel for codex-native installs instead, leaving the version unknown when it is unavailable. Fixes #23937 AI-assisted; verified with the tests and tools listed above.
1 parent 4c12158 commit 9e136ad

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,22 @@ it.layer(layerTest)("CodexDriver", (it) => {
522522
enabled: false,
523523
environment: [],
524524
config: { ...CodexDriver.defaultConfig(), binaryPath, homePath: home },
525-
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, npmView));
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+
);
526541
const capabilities = yield* instance.snapshot.resolveMaintenance();
527542
expect(capabilities.update?.lockKey).toBe("codex-native");
528543

@@ -532,7 +547,7 @@ it.layer(layerTest)("CodexDriver", (it) => {
532547
ProviderLatestVersions.make(),
533548
),
534549
);
535-
expect(latestVersion).not.toBe("0.164.0");
550+
expect(latestVersion).toBe("0.163.0");
536551
expect(
537552
createProviderVersionAdvisory({
538553
driver: CodexDriver.driverKind,

‎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)