fix(profiles): a Codex switch reaches running and new sessions
Codex >= 0.164 sends every request through a shared app-server daemon that outlives its TUIs and keeps the login it started with, so writing a new auth.json changed nothing: open sessions and even new ones stayed on the old (out-of-quota) account. After a switch, restart that CODEX_HOME's daemon when one runs; open TUIs reconnect to it on their own (verified on 0.164.0 with two keys). The response says so (following), and the toast tells the user running sessions follow.
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
* swap it back in later, touching nothing but that login.
|
||||
*
|
||||
* - `codex`: the whole `$CODEX_HOME/auth.json` (a ChatGPT login or an API
|
||||
* key). Config, sessions, skills and history stay where they are.
|
||||
* key). Config, sessions, skills and history stay where they are. A
|
||||
* switch then restarts Codex's shared app-server daemon when one runs,
|
||||
* so running and new sessions follow the new login (`follow`).
|
||||
* - `omp`: every credential Oh My Pi stores, read with `omp auth export`
|
||||
* and put back with `omp auth import -` (secrets on stdin, never argv).
|
||||
* Import MERGES, so a switch first empties omp's own credential tables in
|
||||
@@ -85,6 +87,15 @@ const codex = {
|
||||
writeJson(codexAuthFile(), secret);
|
||||
return [codexAuthFile()];
|
||||
},
|
||||
// Codex ≥ 0.164 talks to the API through a shared app-server daemon that
|
||||
// outlives every TUI and holds the login it started with: a new auth.json
|
||||
// reached neither a running session nor a NEW one, which kept the old
|
||||
// (often out-of-quota) account. Restarting the daemon makes it read the new
|
||||
// login, and every open TUI reconnects to it on its own (verified on
|
||||
// 0.164.0). No daemon running: nothing to restart — the next one reads the file.
|
||||
follow() {
|
||||
return restartCodexDaemon();
|
||||
},
|
||||
identify(auth) {
|
||||
if (auth.tokens && auth.tokens.id_token) {
|
||||
const c = jwtClaims(auth.tokens.id_token) || {};
|
||||
@@ -107,6 +118,26 @@ const codex = {
|
||||
},
|
||||
};
|
||||
|
||||
/** The control socket's link points into a per-user runtime dir that exists only while a daemon runs. */
|
||||
const codexDaemonSocket = () =>
|
||||
path.join(getCodexHome(), "app-server-control", "app-server-control.sock");
|
||||
|
||||
/** Restart the CODEX_HOME's app-server daemon when one is running; true when a restart was started. */
|
||||
function restartCodexDaemon() {
|
||||
if (!fs.existsSync(codexDaemonSocket())) return false;
|
||||
const bin = process.env.AGENTHUB_CODEX_BIN || require("./ai-tools").detect("codex").path;
|
||||
if (!bin) return false;
|
||||
cp.execFile(
|
||||
bin,
|
||||
["app-server", "daemon", "restart"],
|
||||
{ env: { ...process.env, CODEX_HOME: getCodexHome() }, timeout: 60000, windowsHide: true },
|
||||
(e) => {
|
||||
if (e) console.warn(`[tool-profiles] codex daemon restart failed: ${e.message}`);
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Oh My Pi ───────────────────────────────────────────────────────────
|
||||
|
||||
const ompDir = () => process.env.AGENTHUB_OMP_DIR || path.join(os.homedir(), ".omp");
|
||||
@@ -405,7 +436,9 @@ function activateProfile(tool, name) {
|
||||
}
|
||||
const target = readProfile(tool, name);
|
||||
const written = a.write(target.secret, live);
|
||||
return { ok: true, name, savedOutgoing, written };
|
||||
// `following`: running sessions take the new login without a restart of their own.
|
||||
const following = typeof a.follow === "function" ? a.follow() : false;
|
||||
return { ok: true, name, savedOutgoing, written, following };
|
||||
}
|
||||
|
||||
function deleteProfile(tool, name) {
|
||||
|
||||
Reference in New Issue
Block a user