Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(codex): explain keyring login limitations in isolated sessions (#1050)

yuxiaojian847b558aa86c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd821b3d0..e853db87f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2045,6 +2045,18 @@ version of their own to them without also giving them a release of their own.
skill said a request card needed the owner's linked identity and room
membership. Its addressing policy decides, and agents now read theirs with
`get_agent_detail` and name the people who can answer.
+- **A Codex session explains why a keyring login is not available to it.**
+ Each session runs in its own Codex home, which receives the machine's
+ `auth.json` but not a login stored in the OS keyring, so a machine signed in
+ with keyring storage (`cli_auth_credentials_store = "keyring"` or `"auto"`)
+ failed with only "Sign in on the execution machine with codex login" while
+ `codex login status` said it was signed in. The error now says that sessions
+ cannot use a keyring login, and gives the workaround for a machine whose
+ organization does not enforce the keyring: switch Codex to file storage,
+ which keeps the login in plaintext, sign in again and start a new session.
+ Giving this computer's Codex login to a machine says the same instead of
+ "This computer is not signed in to codex". Keyring logins are still not
+ supported in Switch sessions (#1048).
### [0.40.1] - 2026-10-21
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.ts b/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.ts
index b99d5dcaf..78638a4ee 100644
--- a/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.ts
+++ b/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.ts
@@ -311,6 +311,13 @@ async function loginToGive(
);
const credential = await readLocalProviderSignIn(provider, localProviderAuthPath(provider));
if (!credential)
- throw new Error(`This computer is not signed in to ${provider}. Sign in here first.`);
+ throw new Error(
+ provider === 'codex'
+ ? 'This computer is not signed in to codex. Sign in here first. If Codex says you are ' +
+ 'already signed in, its login is likely in the OS keyring, which cannot be given to ' +
+ 'another machine: unless your organization enforces the keyring, set ' +
+ 'cli_auth_credentials_store = "file" in the Codex config.toml and sign in again.'
+ : `This computer is not signed in to ${provider}. Sign in here first.`
+ );
return { kind: 'auth-json', credential };
}
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-agents/give-machine-login.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-agents/give-machine-login.test.ts
index 49c9cb163..688695967 100644
--- a/console/apps/switch-console-desktop/src/main/core/managed-agents/give-machine-login.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/managed-agents/give-machine-login.test.ts
@@ -109,6 +109,27 @@ describe('giving a machine a provider login', () => {
).rejects.toThrow(/cannot be given/);
});
+ it('says a Codex login in the OS keyring cannot be given', async () => {
+ mocks.fetchManagementControllers.mockResolvedValue([
+ machine({ key: keys.publicKey, keyId: sealingKeyId(keys.publicKey) }),
+ ]);
+ mocks.readLocalProviderSignIn.mockResolvedValue(null);
+ const give = (provider: 'codex' | 'opencode') =>
+ managedAgentsController.giveMachineLogin({
+ serverId: 'server-1',
+ machineId: 'controller-1',
+ provider,
+ login: { source: 'this-computer' },
+ });
+ await expect(give('codex')).rejects.toThrow(
+ /OS keyring, which cannot be given.*cli_auth_credentials_store = "file"/
+ );
+ await expect(give('opencode')).rejects.toThrow(
+ 'This computer is not signed in to opencode. Sign in here first.'
+ );
+ expect(mocks.giveMachineLogin).not.toHaveBeenCalled();
+ });
+
describe('through Vertex AI', () => {
let gcloud: string;
const previous = process.env.CLOUDSDK_CONFIG;
diff --git a/console/packages/agent-providers/src/codex/codex-adapter.test.ts b/console/packages/agent-providers/src/codex/codex-adapter.test.ts
index 546a64d98..aac4de5f9 100644
--- a/console/packages/agent-providers/src/codex/codex-adapter.test.ts
+++ b/console/packages/agent-providers/src/codex/codex-adapter.test.ts
@@ -7,7 +7,8 @@ import type { ProviderRuntimeEvent, ProviderRuntimeEventType } from '../events';
import { FakeAppServer, type FakeJsonRpcMessage } from './fake-app-server';
const servers: FakeAppServer[] = [];
-let authenticated = true;
+let account: Record<string, unknown> | null = { type: 'apiKey' };
+let requiresOpenaiAuth = true;
vi.mock('node:child_process', () => ({
spawn: (_command: string, args: string[]) => {
@@ -15,8 +16,8 @@ vi.mock('node:child_process', () => ({
Object.assign(server, { spawnArgs: args });
server.replyAlways('initialize', () => ({ userAgent: 'fake' }));
server.replyAlways('account/read', () => ({
- account: authenticated ? { type: 'apiKey' } : null,
- requiresOpenaiAuth: true,
+ account,
+ requiresOpenaiAuth,
}));
server.replyAlways('thread/start', () => ({ thread: { id: 'thread-1' } }));
servers.push(server);
@@ -24,7 +25,7 @@ vi.mock('node:child_process', () => ({
},
}));
-const { createCodexAdapter } = await import('./codex-adapter');
+const { CODEX_SIGN_IN_REQUIRED, createCodexAdapter } = await import('./codex-adapter');
const THREAD = 'thread-1';
@@ -61,7 +62,8 @@ function turnNotification(id: string, status: string) {
describe('CodexAdapter', () => {
beforeEach(() => {
servers.length = 0;
- authenticated = true;
+ account = { type: 'apiKey' };
+ requiresOpenaiAuth = true;
});
it('checks authentication on the session process before opening a thread', async () => {
@@ -74,11 +76,70 @@ describe('CodexAdapter', () => {
});
it('rejects signed-out startup without opening a thread', async () => {
- authenticated = false;
+ account = null;
await expect(start()).rejects.toThrow('codex login');
expect(servers[0].received.some((m) => m.method === 'thread/start')).toBe(false);
});
+ it('explains that an isolated session cannot use a keyring login, and the file workaround', async () => {
+ account = null;
+ const exited = vi.fn();
+ const failed = start();
+ servers.at(-1)?.on('exit', exited);
+ const error = await failed.catch((cause: unknown) => cause);
+ expect(error).toBeInstanceOf(Error);
+ const message = (error as Error).message;
+ expect(message).toContain(CODEX_SIGN_IN_REQUIRED);
+ expect(message).toContain('OS keyring');
+ expect(message).toContain('cli_auth_credentials_store = "file"');
+ expect(message).toContain('start a new session');
+ expect(message).toContain('plaintext');
+ expect(servers).toHaveLength(1);
+ expect(servers[0].received.map((m) => m.method)).toEqual([
+ 'initialize',
+ 'initialized',
+ 'account/read',
+ ]);
+ expect(exited).toHaveBeenCalled();
+ });
+
+ it('keeps the diagnostic static, with nothing from the session environment in it', async () => {
+ account = null;
+ const marker = 'placeholder-secret-marker';
+ const adapter = createCodexAdapter();
+ const failure = adapter.startSession({
+ sessionId: 'session-1',
+ cwd: `/work/${marker}`,
+ runtimeMode: 'full-access',
+ env: { PATH: '/usr/bin', CODEX_HOME: `/home/${marker}`, OPENAI_API_KEY: marker },
+ mcpServers: {},
+ connectorMcpServers: [],
+ });
+ await expect(failure).rejects.toThrow(CODEX_SIGN_IN_REQUIRED);
+ await expect(failure).rejects.not.toThrow(marker);
+ await expect(adapter.interruptTurn('session-1')).rejects.toThrow(/unknown or stopped session/);
+ });
+
+ it('starts with a recognized login even when the backend requires OpenAI sign-in', async () => {
+ for (const recognized of [
+ { type: 'apiKey' },
+ { type: 'chatgpt', email: null, planType: null },
+ ]) {
+ account = recognized;
+ const { adapter, session } = await start();
+ expect(session.nativeSessionId).toBe(THREAD);
+ await adapter.stopAll();
+ }
+ });
+
+ it('starts without a login when the backend does not require OpenAI sign-in', async () => {
+ account = null;
+ requiresOpenaiAuth = false;
+ const { adapter, session } = await start();
+ expect(session.nativeSessionId).toBe(THREAD);
+ await adapter.stopAll();
+ });
+
it('initializes, opens a thread and reports the thread id as the native session', async () => {
const { server, session, events } = await start();
expect(session.nativeSessionId).toBe(THREAD);
diff --git a/console/packages/agent-providers/src/codex/codex-adapter.ts b/console/packages/agent-providers/src/codex/codex-adapter.ts
index 18c5844d3..8ac6cb0d6 100644
--- a/console/packages/agent-providers/src/codex/codex-adapter.ts
+++ b/console/packages/agent-providers/src/codex/codex-adapter.ts
@@ -68,6 +68,20 @@ const PROVIDER = 'codex';
const CLIENT_NAME = 'switch-console';
const CLIENT_VERSION = '0.1.0';
+/**
+ * Codex keys a keyring login by its CODEX_HOME path, and a session runs in its
+ * own CODEX_HOME that receives only the execution machine's auth.json, so a
+ * keyring login reads as signed out here even though `codex login status`
+ * reports it.
+ */
+export const CODEX_SIGN_IN_REQUIRED =
+ 'Sign in on the execution machine with codex login. If Codex says you are already signed in, ' +
+ 'your login is likely in the OS keyring (cli_auth_credentials_store = "keyring" or "auto"), ' +
+ 'which Switch sessions cannot use: they get the login only from auth.json. Unless your ' +
+ 'organization enforces the keyring, set cli_auth_credentials_store = "file" in the Codex ' +
+ 'config.toml on the execution machine, which keeps the login in plaintext, then run codex ' +
+ 'login again and start a new session.';
+
/**
* `multi_agent_v2` ships stable but off, and it is what puts `spawn_agent` in
* the model's tool set — without it a delegation request is answered inline and
@@ -395,8 +409,7 @@ export class CodexAdapter implements ProviderAdapter {
const account = z
.object({ account: z.unknown().nullable(), requiresOpenaiAuth: z.boolean() })
.parse(await client.request('account/read', { refreshToken: false }));
- if (!account.account && account.requiresOpenaiAuth)
- throw new Error('Sign in on the execution machine with codex login.');
+ if (!account.account && account.requiresOpenaiAuth) throw new Error(CODEX_SIGN_IN_REQUIRED);
const configured = await configuredSandbox(input.env.CODEX_HOME);
const sandbox = sandboxFor(input.runtimeMode, configured);