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, 23:15 UTC
fix(server): skip local Codex binaries missing codex-code-mode-host (#19154)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
IND_is_Here committed
Oct 20, 2026 at 01:05 UTC
348888a767433464dd47e723ec6509dc5a8282db
2 files changed
+141
-10
apps/server/src/provider/CodexInstallation.test.ts
+99
-10
@@ -18,7 +18,7 @@ import * as Sink from "effect/Sink";
18
import * as Stream from "effect/Stream";
19
import { HttpClient, HttpClientResponse } from "effect/http";
20
import * as TestClock from "effect/testing/TestClock";
21
-import { ChildProcessSpawner } from "effect/process";
21
+import { ChildProcess, ChildProcessSpawner } from "effect/process";
22
import * as CodexInstallation from "./CodexInstallation.ts";
23
24
const archive = Buffer.from(
@@ -47,7 +47,7 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* (
47
const baseDir =
48
input.baseDir ?? (yield* fs.makeTempDirectoryScoped({ prefix: "t3-codex-install-test-" }));
49
const localDirectory = `${baseDir}/local`;
50
- const localBinaryPath = `${localDirectory}/codex`;
50
+ const localBinaryPath = `${localDirectory}/codex${input.platform === "win32" ? ".exe" : ""}`;
51
const probeLog = `${baseDir}/local-probes.txt`;
52
if (input.local) {
53
yield* fs.makeDirectory(localDirectory, { recursive: true });
@@ -202,6 +202,73 @@ it.effect("falls back to a managed download when the reused local executable dis
202
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
203
);
204
205
+const compileNative = Effect.fn("test.compileNative")(function* (
206
+ executablePath: string,
207
+ source: string,
208
+) {
209
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
210
+ const compiler = yield* spawner.spawn(
211
+ ChildProcess.make("cc", ["-x", "c", "-", "-o", executablePath], {
212
+ stdin: Stream.make(new TextEncoder().encode(source)),
213
+ stdout: "inherit",
214
+ stderr: "inherit",
215
+ }),
216
+ );
217
+ expect(yield* compiler.exitCode).toBe(0);
218
+}, Effect.scoped);
219
+
220
+it.effect.each([
221
+ { withHost: false, marker: null },
222
+ { withHost: true, marker: null },
223
+ { withHost: false, marker: ".bunx" },
224
+ { withHost: false, marker: ".shim" },
225
+])("requires the native host or a known package-manager launcher: %j", ({ withHost, marker }) =>
226
+ Effect.gen(function* () {
227
+ const h = yield* makeHarness({
228
+ local: { version: "0.156.1" },
229
+ platform: marker ? "win32" : "darwin",
230
+ });
231
+ yield* compileNative(
232
+ h.localBinaryPath,
233
+ `#include <stdio.h>
234
+#include <string.h>
235
+int main(int argc, char **argv) {
236
+ if (argc == 2 && strcmp(argv[1], "--version") == 0) {
237
+ puts("codex-cli 0.156.1");
238
+ return 0;
239
+ }
240
+ return !(argc == 3 && strcmp(argv[1], "app-server") == 0 && strcmp(argv[2], "--help") == 0);
241
+}
242
+`,
243
+ );
244
+ if (withHost) {
245
+ const packageDirectory = `${h.baseDir}/package`;
246
+ yield* h.fs.makeDirectory(packageDirectory);
247
+ yield* h.fs.rename(h.localBinaryPath, `${packageDirectory}/codex`);
248
+ yield* h.fs.copyFile(`${packageDirectory}/codex`, `${packageDirectory}/codex-code-mode-host`);
249
+ yield* h.fs.symlink(`${packageDirectory}/codex`, h.localBinaryPath);
250
+ }
251
+ if (marker) {
252
+ yield* h.fs.writeFileString(
253
+ h.localBinaryPath.replace(/\.exe$/u, marker),
254
+ "launcher metadata",
255
+ );
256
+ }
257
+ const reusesLocal = withHost || marker !== null;
258
+ const started = yield* h.installation.start;
259
+ if (reusesLocal) {
260
+ expect(started).toMatchObject({
261
+ source: "local",
262
+ phase: "succeeded",
263
+ executablePath: h.localBinaryPath,
264
+ });
265
+ }
266
+ expect((yield* terminalState(h.installation)).phase).toBe("succeeded");
267
+ expect((yield* h.installation.resolve()).source).toBe(reusesLocal ? "local" : "managed");
268
+ expect(h.downloads()).toBe(reusesLocal ? 0 : 1);
269
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
270
+);
271
+
272
it.effect("rechecks compatibility after the local executable is replaced", () =>
273
Effect.gen(function* () {
274
const h = yield* makeHarness({ local: { version: "0.156.1" } });
@@ -263,16 +330,38 @@ it.effect("uses bundled Codex compatibility when the remote manifest omits its p
330
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
331
);
332
266
-it.effect("preserves the invoked name of version-manager launcher symlinks", () =>
333
+it.effect.each([
334
+ { kind: "script", name: "volta-shim" },
335
+ { kind: "native", name: "volta-shim" },
336
+ { kind: "native", name: "mise" },
337
+ { kind: "native", name: "aqua-proxy" },
338
+])("preserves the invoked name of $kind $name launcher symlinks", ({ kind, name }) =>
339
Effect.gen(function* () {
340
const h = yield* makeHarness({ local: { version: "0.156.1" } });
269
- const launcher = `${h.baseDir}/launcher`;
270
- yield* h.fs.writeFileString(
271
- launcher,
272
- '#!/bin/sh\ncase "$0" in */codex) ;; *) exit 1;; esac\ncase "$1" in --version) printf "codex-cli 0.156.1\\n";; app-server) exit 0;; esac\n',
273
- { mode: 0o755 },
274
- );
275
- yield* h.fs.remove(h.localBinaryPath);
341
+ const launcher = `${h.baseDir}/${name}`;
342
+ if (kind === "native") {
343
+ const payload = `${h.baseDir}/codex.js`;
344
+ yield* h.fs.rename(h.localBinaryPath, payload);
345
+ yield* compileNative(
346
+ launcher,
347
+ `#include <string.h>
348
+#include <unistd.h>
349
+int main(int argc, char **argv) {
350
+ const char *name = strrchr(argv[0], '/');
351
+ if (strcmp(name ? name + 1 : argv[0], "codex") != 0) return 1;
352
+ execv(${JSON.stringify(payload)}, argv);
353
+ return 1;
354
+}
355
+`,
356
+ );
357
+ } else {
358
+ yield* h.fs.writeFileString(
359
+ launcher,
360
+ '#!/bin/sh\ncase "$0" in */codex) ;; *) exit 1;; esac\ncase "$1" in --version) printf "codex-cli 0.156.1\\n";; app-server) exit 0;; esac\n',
361
+ { mode: 0o755 },
362
+ );
363
+ yield* h.fs.remove(h.localBinaryPath);
364
+ }
365
yield* h.fs.symlink(launcher, h.localBinaryPath);
366
expect(yield* h.installation.start).toMatchObject({ source: "local", phase: "succeeded" });
367
expect((yield* h.installation.resolve()).executablePath).toBe(h.localBinaryPath);
apps/server/src/provider/CodexInstallation.ts
+42
@@ -329,6 +329,47 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
329
);
330
return output;
331
}, Effect.scoped);
332
+ // Native Codex needs its adjacent host; launchers resolve their own payloads.
333
+ const hasCodeModeHost = Effect.fn("CodexInstallation.hasCodeModeHost")(
334
+ function* (realExecutablePath: string) {
335
+ if (/^(?:volta-shim|mise|aqua-proxy)(?:\.exe)?$/iu.test(path.basename(realExecutablePath)))
336
+ return true;
337
+ if (platform === "win32") {
338
+ if (path.extname(realExecutablePath).toLowerCase() !== ".exe") return true;
339
+ for (const extension of [".bunx", ".shim"]) {
340
+ const marker = yield* fs
341
+ .stat(realExecutablePath.slice(0, -4) + extension)
342
+ .pipe(Effect.option);
343
+ if (
344
+ Option.isSome(marker) &&
345
+ marker.value.type === "File" &&
346
+ Number(marker.value.size) > 0
347
+ )
348
+ return true;
349
+ }
350
+ } else {
351
+ const header = yield* fs.open(realExecutablePath, { flag: "r" }).pipe(
352
+ Effect.flatMap((file) => file.readAlloc(2)),
353
+ Effect.orElseSucceed(() => Option.none()),
354
+ );
355
+ if (Option.isSome(header) && header.value[0] === 0x23 && header.value[1] === 0x21)
356
+ return true;
357
+ }
358
+ const info = yield* fs.stat(
359
+ path.join(
360
+ path.dirname(realExecutablePath),
361
+ `codex-code-mode-host${platform === "win32" ? ".exe" : ""}`,
362
+ ),
363
+ );
364
+ return (
365
+ info.type === "File" &&
366
+ Number(info.size) > 0 &&
367
+ (platform === "win32" || (info.mode & 0o111) !== 0)
368
+ );
369
+ },
370
+ Effect.scoped,
371
+ Effect.orElseSucceed(() => false),
372
+ );
373
const localCache = new Map<string, { fingerprint: string; executable: CodexExecutable | null }>();
374
const resolveLocal = Effect.fn("CodexInstallation.resolveLocal")(
375
function* () {
@@ -347,6 +388,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
388
)
389
)
390
return null;
391
+ if (!(yield* hasCodeModeHost(realExecutablePath))) return null;
392
const info = yield* fs.stat(executablePath);
393
const fingerprint = `${realExecutablePath}:${info.size}:${Option.getOrUndefined(info.mtime)?.getTime()}:${Option.getOrUndefined(info.ino)}`;
394
const cached = localCache.get(executablePath);