fix: gracefully handle unsupported thread/name/set on older Codex CLI (#126)

* fix: gracefully handle unsupported thread/name/set on older Codex CLI

Codex CLI v0.118.0 does not recognize the thread/name/set JSON-RPC method,
causing startThread() to throw. Thread naming is cosmetic (for job log
labels) and should not block thread creation. Wraps the call in try/catch
so it fails silently on older CLI versions.

Fixes #119

* refactor: only suppress unsupported-method errors for thread/name/set

Address Codex review feedback: the bare catch swallowed all errors
including auth, network, and server failures. Now only suppresses
errors containing 'unknown variant' or 'unknown method' (the specific
error older CLI versions return) and rethrows everything else.
This commit is contained in:
Trevin Chow 2026-04-07 20:08:25 -07:00 committed by GitHub
parent dd335cbc76
commit 4bd783b7ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -639,7 +639,16 @@ async function startThread(client, cwd, options = {}) {
const response = await client.request("thread/start", buildThreadParams(cwd, options)); const response = await client.request("thread/start", buildThreadParams(cwd, options));
const threadId = response.thread.id; const threadId = response.thread.id;
if (options.threadName) { if (options.threadName) {
await client.request("thread/name/set", { threadId, name: options.threadName }); try {
await client.request("thread/name/set", { threadId, name: options.threadName });
} catch (err) {
// Only suppress "unknown variant/method" errors from older CLI versions
// that don't support thread/name/set. Rethrow auth, network, or server errors.
const msg = String(err?.message ?? err ?? "");
if (!msg.includes("unknown variant") && !msg.includes("unknown method")) {
throw err;
}
}
} }
return response; return response;
} }