fix(codex): pick up a new login without restarting T3 #11147
ClosedGigioxx(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/11147/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/provider/Layers/CodexProvider.ts line 560Resolvedby Gigioxx(GitHub profile, opens in a new tab)@@ -524,3 +524,18 @@524524 });525525 });526526527+/**528+ * A live app-server keeps the credentials it loaded at spawn, so after529+ * `codex login` to another account, threads with a live process keep using530+ * the old one. Only a change between two signed-in accounts counts; a531+ * signed-out or failed probe is not a switch, and neither is a plan change532+ * (`label`) on the same account.533+ */534+export function hasCodexAccountChanged(535+ previous: ServerProvider["auth"] | null,536+ next: ServerProvider["auth"],537+): boolean {538+ if (!previous || previous.status !== "authenticated" || next.status !== "authenticated") {539+ return false;540+ }541+ return previous.type !== next.type || previous.email !== next.email;
- apps/server/src/provider/Drivers/CodexDriver.ts lines 219 to 232OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -205,3 +213,20 @@205213 { concurrent: true },206214 ),207215 ),216+ Effect.tap((probed) =>217+ probed.auth.status !== "authenticated"218+ ? Effect.void219+ : Ref.getAndSet(lastProbedAuth, probed.auth).pipe(220+ Effect.flatMap((previous) =>221+ hasCodexAccountChanged(previous, probed.auth)222+ ? Effect.logInfo("Codex account changed; stopping live sessions.", {223+ instanceId,224+ email: probed.auth.email,225+ }).pipe(226+ Effect.andThen(adapter.stopAll()),227+ Effect.catchCause((cause) =>228+ Effect.logWarning("Failed to stop Codex sessions after account change.", {229+ instanceId,230+ cause,231+ }),232+ ),apps/server/src/provider/Drivers/CodexDriver.ts line 224OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -205,3 +213,12 @@205213 { concurrent: true },206214 ),207215 ),216+ Effect.tap((probed) =>217+ probed.auth.status !== "authenticated"218+ ? Effect.void219+ : Ref.getAndSet(lastProbedAuth, probed.auth).pipe(220+ Effect.flatMap((previous) =>221+ hasCodexAccountChanged(previous, probed.auth)222+ ? Effect.logInfo("Codex account changed; stopping live sessions.", {223+ instanceId,224+ email: probed.auth.email,
juliusmarminge added labelsmacroscope-review
- apps/server/src/provider/Drivers/CodexDriver.ts line 222Resolvedby Gigioxx(GitHub profile, opens in a new tab)@@ -205,3 +214,4 @@205214 { concurrent: true },206215 ),207216 ),217+ Effect.tap((probed) =>
- @@ -188,3 +189,10 @@188189 ),189190 );190191192+ // Live sessions keep the account they spawned with. When a probe shows a193+ // different login, stop them so the next send respawns app-server with194+ // the current credentials (the same path as Stop or the idle reaper).195+ const trackAccountSwitch = yield* makeCodexAccountSwitchTracker(196+ Effect.logInfo("Codex account changed; stopping live sessions.", { instanceId }).pipe(197+ // `adapter` is created below; suspend so the stop resolves it lazily.198+ Effect.andThen(Effect.suspend(() => adapter.stopAll())),@@ -205,3 +216,5 @@205216 { concurrent: true },206217 ),207218 ),219+ Effect.tap((probed) =>220+ trackAccountSwitch(probed.auth).pipe(
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed