Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- On Windows, install T3 Code (Beta) desktop. It lands in
%LOCALAPPDATA%\Programs\t3code\T3 Code (Beta).exe, a path with spaces and parentheses. - Install Codex globally with pnpm:
pnpm add -g @openai/codex(0.171.0 here).codexon PATH is now pnpm's batch shim,%LOCALAPPDATA%\pnpm\codex.cmd. - Set the Codex provider instance to managed setup. T3's managed Codex 0.166.0 is installed under
~/.t3/tools/codex/0.166.0. - Open Settings → Providers.
You can reproduce the cmd.exe part without T3 or Codex using the script below.
Expected behavior
The managed Codex provider starts and passes its probe.
Actual behavior
The provider status shows:
Codex app-server provider probe failed: Codex App Server protocol operation 'decode-wire-message' failed..
userdata/logs/server.trace.ndjson (span probeCodexAppServerProvider) gives the cause as SchemaError: Expected a valid JSON string. It is raised while awaiting the initialize response, about 50 ms after spawn.
Why it happens (paths checked on main @ d8f480a)
- Managed mode adopts the batch shim.
CodexInstallation.resolve()isresolveLocal() ?? resolveManaged()(apps/server/src/provider/CodexInstallation.ts:568).resolveLocal()finds%LOCALAPPDATA%\pnpm\codex.cmd,localKind()classifies every non-.exeon win32 as a"launcher"(:446), and 0.171.0 is a supported version, so the shim is used instead of T3's nativecodex.exe. (npmCodexVersion()looks for<shimDir>\node_modules\@openai\codex\package.json. pnpm's global layout doesn't have it, so the probe result isn't persisted, but the shim is still adopted.) - Managed launches pass complex
-coverrides.managedCodexLaunchArgs()(apps/server/src/provider/CodexManagedRuntime.ts:23) addsmodel_providers.openai_token_sharing={...,auth={command="<...>\\T3 Code (Beta).exe",args=[...]...}}. That value has embedded"characters and an exe path with spaces and parentheses. - The shim re-parses them. For
.cmd/.bat,resolveSpawnCommand()builds one command line withescapeWindowsShellArgand runs it withshell: true(packages/shared/src/shell.ts:1218-1231). The single caret layer survives thecmd /d /s /cparse. pnpm's shim then expands%*again inside a parenthesized@IF EXIST ... ( ... %* ) ELSE ( ... %* )block. On that second parse each\"toggles cmd's quote state, so the)from(Beta)ends up outside quotes and closes the IF block early. - The shim has no
@ECHO OFF, so cmd echoes the rest of the line to stdout, then fails with...}}" was unexpected at this time.on stderr and exit code 255. decodeWireMessage()(packages/effect-codex-app-server/src/protocol.ts:129) gets the echoed line (C:\Users\<user>> "...\pnpm\\node.exe" "...\codex.js" "app-server" "-c" ...) and fails withdecode-wire-message, which hides the exit code and stderr.
The probe path is checkCodexProviderStatus → probeCodexAppServerProvider → withCodexAppServerClient → resolveSpawnCommand (apps/server/src/provider/CodexProvider.ts:645-654). Managed sessions get the same launch args through makeCodexAppServerSpawnCommand (apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts:1839), so they should break the same way. I didn't verify sessions separately.
What was verified (Windows 11, T3 Code 0.1.13)
- I rebuilt T3's exact probe command line (its escaping, tokenizer and managed launch args, taken from the 0.1.13 bundle) and ran it with the live server environment and cwd against pnpm's
codex.cmd. Result: a non-JSON echo line on stdout,was unexpected at this timeon stderr, exit 255. It fails the same way with or withoutnodeon PATH, because cmd breaks before node starts. - The same managed args spawned directly (no shell) against T3's managed
codex.exe0.166.0, and against pnpm's vendored nativecodex.exe0.171.0, both returned a clean JSONinitializeresponse. Codex called the auth command with its args intact. - The same pnpm shim with plain args (
app-server -c thread_unload_delay_secs=0, the "existing" setup) works.
Minimal repro (Windows; no T3 or Codex needed)
node repro.mjs fails. node repro.mjs "C:\Program Files\Example\App.exe" (no parentheses) passes.
// node repro.mjs ["<auth command path>"]
import { spawn } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
// Copied from packages/shared/src/shell.ts (T3 Code 0.1.13 bundle).
const WINDOWS_SHELL_META_CHARS = /([()\][%!^"`<>&|;, *?])/g;
function escapeWindowsShellArg(arg) {
let escaped = arg.replace(/(\\*)"/g, "$1$1\\\"");
escaped = escaped.replace(/(\\*)$/, "$1$1");
escaped = `"${escaped}"`;
return escaped.replace(WINDOWS_SHELL_META_CHARS, "^$1");
}
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "t3-shim-repro-"));
// Same shape as the shim pnpm writes for global bins (no @ECHO OFF, %* inside IF/ELSE blocks).
fs.writeFileSync(path.join(dir, "fake.cmd"), [
"@SETLOCAL",
"@IF EXIST \"%~dp0\\node.exe\" (",
" \"%~dp0\\node.exe\" \"%~dp0\\fake.js\" %*",
") ELSE (",
" @SET PATHEXT=%PATHEXT:;.JS;=;%",
" node \"%~dp0\\fake.js\" %*",
")",
"",
].join("\r\n"));
fs.writeFileSync(path.join(dir, "fake.js"), "process.stdout.write(JSON.stringify({ok:true,argv:process.argv.slice(2)})+'\\n');\n");
// Shape of the managed-Codex override: TOML with embedded quotes + an exe path containing "(Beta)".
const selfExe = process.argv[2] ?? "C:\\Program Files\\Example\\App (Beta).exe";
const override = `model_providers.x={name="X",auth={command=${JSON.stringify(selfExe)},args=["a","b"]}}`;
const commandLine = [path.join(dir, "fake.cmd"), "app-server", "-c", override].map(escapeWindowsShellArg).join(" ");
const child = spawn(commandLine, [], { shell: true, stdio: ["ignore", "pipe", "pipe"] });
let out = ""; let err = "";
child.stdout.on("data", (d) => (out += d));
child.stderr.on("data", (d) => (err += d));
child.on("exit", (code) => {
console.log(`exit code: ${code}`);
for (const line of out.split(/\r?\n/).filter((l) => l.trim())) {
let json = true; try { JSON.parse(line); } catch { json = false; }
console.log(`stdout ${json ? "JSON " : "NOT-JSON"}: ${line.slice(0, 160)}`);
}
console.log(`stderr: ${err.trim().slice(-200)}`);
fs.rmSync(dir, { recursive: true, force: true });
});Observed:
- Default path (
...\App (Beta).exe):exit code: 255. stdout has aNOT-JSONline echoing the shim'snode ... fake.js ...command. stderr ends with...]}}" was unexpected at this time. C:\Program Files\Example\App.exe:exit code: 0. stdout has oneJSONline whose argv matches what was passed.
Proposed fix
On win32, don't let managed mode adopt a .cmd/.bat launcher. Have localKind() return null for them, so resolve() falls back to T3's managed native build. A batch file's %* can't reliably carry the quoted -c overrides that managed launches pass, and this is the same condition resolveSpawnCommand uses to pick shell: true. This also stops managed mode from adopting npm's codex.cmd on Windows. I haven't checked whether npm's shim (which expands %* outside a parenthesized block) survives these args. Other modes don't use CodexInstallation, so "existing" setup still runs whatever codex is on PATH.
Possible follow-ups, not part of the fix:
- Surface the exit code and stderr (or a truncated preview of the rejected line) instead of a bare
decode-wire-message. [Bug]: A non-Codex binary in Codex "Binary path" reports an opaque decode-wire-message probe failure and adopts its --version #40696 already covers the opaque message for a non-Codex binary. - Let
resolveLocalmap npm/pnpm shims to the package's vendored nativecodex.exe, so managed mode can still use a newer local Codex.
Related: #40696 (same opaque error, different cause), #24699 (closed, extra caret layer for quoted args to npm shims), #24533 (pnpm launcher resolution for Claude).
Impact
Blocks work completely
Version or commit
0.1.13 (desktop and server). Code path unchanged on main @ d8f480a.
Environment
Windows 11, T3 Code (Beta) desktop 0.1.13, managed Codex 0.166.0, pnpm-global Codex CLI 0.171.0
Workaround
- Switch the Codex instance to "existing" setup, or
- Make sure
codexon PATH isn't a.cmdshim (for example, remove pnpm'scodex.cmd).
Unverified side note: after switching to "existing", the probe failed with cmd's localized 'node' is not recognized (shown as mojibake, because cmd's codepage output is decoded as UTF-8). Node came only from fnm, set up in the PowerShell 7 profile. resolveWindowsEnvironment in packages/shared/src/shell.ts has a profile-loading fallback for this, but it didn't take effect for that probe. Adding fnm's default alias directory to the user PATH fixed it. Root cause not confirmed, so I'm not filing it separately yet.
Investigated and written with Claude Opus 5.5 (Claude Code).
Activity