fix(pool): a Codex ChatGPT pool pane runs on the login placed for it

Codex >= 0.164 hands a plain TUI (no -c override) to the CODEX_HOME's
shared app-server daemon, which outlives every TUI and keeps the login it
started with. A ChatGPT pool account written into a member's auth.json
therefore reached no pane while their daemon still ran on the previous
login (reproduced on 0.164.0: the daemon kept sending the old key, a
--no-daemon TUI sent the new one). Such a pane now runs `codex
--no-daemon`, only when that binary's --help lists the flag (probed once
per path/size/mtime), so an older Codex still starts.
This commit is contained in:
2026-10-30 16:06:20 +07:00
parent 6bcef26446
commit 3ab484ddc0
3 changed files with 75 additions and 3 deletions
+44 -2
View File
@@ -19,7 +19,9 @@
* home AgentHub placed that account in, never dated in the future, and
* only when its id_token names the same account (`mayCopyBack`); the 2026-10-08
* spike showed an old refresh token still refreshes, so panes sharing an
* account do not log each other out.
* account do not log each other out. Such a pane runs `--no-daemon`
* (when its Codex has the flag): the home's shared app-server daemon
* would keep serving the login it started with.
*
* Records live in `<CLAUDE_HOME>/agenthub-codex-accounts/<name>.json` (dir
* 0700, file 0600); no route returns a key or a token.
@@ -424,6 +426,46 @@ function liveInHome(name, member) {
});
}
// Codex ≥ 0.164 hands a plain TUI (no `-c` override) to the CODEX_HOME's shared
// app-server daemon, which outlives every TUI and keeps the login it started
// with — so a ChatGPT login placed in the home reached no pane while the
// member's daemon ran on the previous one (reproduced on 0.164.0). A pool pane
// runs its own app server instead. An older Codex has neither the daemon nor
// the flag (it would refuse to start), so the flag goes only to a binary whose
// --help lists it: probed once per binary (path, size, mtime).
const noDaemonCache = new Map();
function noDaemonArgv(member) {
const bin =
process.env.AGENTHUB_CODEX_BIN ||
(member
? require("./shared-tools").sharedPath("codex")
: require("./ai-tools").detect("codex").path);
if (!bin) return [];
let key;
try {
const st = fs.statSync(bin);
key = `${fs.realpathSync(bin)}:${st.size}:${st.mtimeMs}`;
} catch {
return [];
}
if (!noDaemonCache.has(key)) {
let help = "";
try {
help = require("node:child_process").execFileSync(bin, ["--help"], {
encoding: "utf8",
timeout: 5000,
stdio: ["ignore", "pipe", "ignore"],
windowsHide: true,
});
} catch {
/* no answer: leave the flag out, as before */
}
noDaemonCache.set(key, /--no-daemon\b/.test(help));
}
return noDaemonCache.get(key) ? ["--no-daemon"] : [];
}
/** `{name, kind}` of the account a new Codex pane would get, or null. */
function pickAccount(member = null, ownerId = null) {
const a = pick(member, ownerId);
@@ -449,7 +491,7 @@ function forSpawn(member = null, ownerId = null) {
}
return {
name: a.name,
argv: [],
argv: noDaemonArgv(member),
env: {},
place: () => {
syncHome(member.home); // a live pane may hold a newer login than ours