Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(agent-providers): a Codex session on its default model runs one its sign-in can use
raullopez-sandboxfcd483213ca8
diff --git a/console/packages/agent-providers/src/codex/codex-adapter.test.ts b/console/packages/agent-providers/src/codex/codex-adapter.test.tsindex 98f9fe820..255032f2b 100644--- a/console/packages/agent-providers/src/codex/codex-adapter.test.ts+++ b/console/packages/agent-providers/src/codex/codex-adapter.test.ts@@ -179,6 +179,73 @@ describe('CodexAdapter', () => {}});+ it('runs the account’s default when the configuration names a model this sign-in cannot use', async () => {+ const home = await mkdtemp(join(tmpdir(), 'codex-home-'));+ try {+ await writeFile(join(home, 'config.toml'), 'model = "gpt-6.1-sol"\n');+ const adapter = createCodexAdapter();+ const events: ProviderRuntimeEvent[] = [];+ adapter.subscribe((event) => events.push(event));+ const pending = adapter.startSession({+ sessionId: 'inherits',+ cwd: '/work',+ runtimeMode: 'full-access',+ env: { PATH: '/usr/bin', CODEX_HOME: home },+ mcpServers: {},+ connectorMcpServers: [],+ });+ const server = servers.at(-1)!;+ server.replyAlways('model/list', () => ({+ data: [+ { model: 'gpt-6-astra', isDefault: true },+ { model: 'gpt-6-sol', isDefault: false },+ ],+ nextCursor: null,+ }));+ await pending;+ const opened = server.received.find((message) => message.method === 'thread/start');+ expect(opened?.params).toMatchObject({ model: 'gpt-6-astra' });+ expect(eventsOf(events, 'runtime.warning').map((event) => event.message)).toEqual([+ expect.stringContaining('cannot use gpt-6.1-sol'),+ ]);+ await adapter.stopAll();+ } finally {+ await rm(home, { recursive: true, force: true });+ }+ });++ it('leaves a configured model this sign-in can use, and a chosen model, alone', async () => {+ const home = await mkdtemp(join(tmpdir(), 'codex-home-'));+ try {+ await writeFile(join(home, 'config.toml'), 'model = "gpt-6-sol"\n');+ for (const model of [undefined, { id: 'gpt-6-luna', options: {} }]) {+ const adapter = createCodexAdapter();+ const pending = adapter.startSession({+ sessionId: 'configured',+ cwd: '/work',+ runtimeMode: 'full-access',+ env: { PATH: '/usr/bin', CODEX_HOME: home },+ mcpServers: {},+ connectorMcpServers: [],+ ...(model ? { model } : {}),+ });+ const server = servers.at(-1)!;+ server.replyAlways('model/list', () => ({+ data: [{ model: 'gpt-6-sol', isDefault: false }],+ nextCursor: null,+ }));+ await pending;+ const opened = server.received.find((message) => message.method === 'thread/start');+ if (model) expect(opened?.params).toMatchObject({ model: 'gpt-6-luna' });+ else expect(opened?.params).not.toHaveProperty('model');+ if (model) expect(server.received.some((m) => m.method === 'model/list')).toBe(false);+ await adapter.stopAll();+ }+ } finally {+ await rm(home, { recursive: true, force: true });+ }+ });+it('fails resume without silently opening a fresh thread', async () => {const adapter = createCodexAdapter();const pending = adapter.startSession({diff --git a/console/packages/agent-providers/src/codex/codex-adapter.ts b/console/packages/agent-providers/src/codex/codex-adapter.tsindex a7ac1b24a..dba269ac6 100644--- a/console/packages/agent-providers/src/codex/codex-adapter.ts+++ b/console/packages/agent-providers/src/codex/codex-adapter.ts@@ -230,6 +230,47 @@ async function configuredSandbox(codexHome: string | undefined): Promise<CodexSa: null;}+/** The model the configuration in `codexHome` names, which a thread left on its default inherits. */+async function configuredModel(codexHome: string | undefined): Promise<string | null> {+ if (!codexHome) return null;+ let text: string;+ try {+ text = await readFile(join(codexHome, 'config.toml'), 'utf8');+ } catch (error) {+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null;+ throw error;+ }+ const model = parse(text).model;+ return typeof model === 'string' && model.trim() ? model.trim() : null;+}++/**+ * The model a thread left on its default should run: the configuration's when+ * the signed-in account can use it, otherwise the account's own default, with+ * why. A configuration written for another account (or an API key) names a+ * model this sign-in is refused, and every turn would fail on it.+ */+async function defaultModelFor(+ client: StdioJsonRpcClient,+ configured: string | null+): Promise<{ model: string; warning: string } | null> {+ if (configured === null) return null;+ const offered: { model: string; isDefault?: boolean }[] = [];+ let cursor: string | null = null;+ do {+ const page: { data: { model: string; isDefault?: boolean }[]; nextCursor: string | null } =+ await client.request('model/list', { cursor, limit: 100 });+ offered.push(...page.data);+ cursor = page.nextCursor;+ } while (cursor);+ if (offered.length === 0 || offered.some((each) => each.model === configured)) return null;+ const fallback = offered.find((each) => each.isDefault) ?? offered[0]!;+ return {+ model: fallback.model,+ warning: `This Codex sign-in cannot use ${configured}, the model its configuration names, so this session runs ${fallback.model}. Pick a model in the agent's settings to choose another.`,+ };+}+/*** The sandbox a thread runs in. Auto mode never runs unsandboxed: in* `danger-full-access` nothing asks for approval, so Codex's automatic review@@ -429,6 +470,7 @@ export class CodexAdapter implements ProviderAdapter {this.emit(state, { type: 'session.state.changed', status: 'starting' });let sandboxWarning: string | undefined;+ let modelWarning: string | undefined;try {const initializeParams: CodexInitializeParams = {clientInfo: { name: CLIENT_NAME, title: 'Switch Console', version: CLIENT_VERSION },@@ -446,6 +488,22 @@ export class CodexAdapter implements ProviderAdapter {const configured = await configuredSandbox(input.env.CODEX_HOME);const sandbox = sandboxFor(input.runtimeMode, configured);+ const fallback = input.model?.id+ ? null+ : await defaultModelFor(client, await configuredModel(input.env.CODEX_HOME)).catch(+ (error: unknown) => {+ // The session still starts on whatever the configuration names, as it always did.+ this.logger.warn('Could not check the configured model against this sign-in', {+ sessionId: input.sessionId,+ error: String(error),+ });+ return null;+ }+ );+ if (fallback) {+ state.model = fallback.model;+ modelWarning = fallback.warning;+ }if (sandbox !== configured)sandboxWarning = `Auto mode runs Codex in the ${sandbox} sandbox instead of the configured ${configured}: unsandboxed, nothing would reach its automatic review.`;const config = {@@ -453,7 +511,11 @@ export class CodexAdapter implements ProviderAdapter {...(mode.approvalPolicy ? { approvalPolicy: mode.approvalPolicy } : {}),...(sandbox ? { sandbox } : {}),approvalsReviewer: mode.approvalsReviewer,- ...(input.model?.id ? { model: input.model.id } : {}),+ ...(input.model?.id+ ? { model: input.model.id }+ : fallback+ ? { model: fallback.model }+ : {}),...(input.systemContext ? { developerInstructions: input.systemContext } : {}),};const opened = await this.openThread(client, config, input.resume?.nativeSessionId);@@ -486,9 +548,10 @@ export class CodexAdapter implements ProviderAdapter {}this.emit(state, { type: 'session.started', nativeSessionId: state.threadId });- if (sandboxWarning) {- this.logger.warn(sandboxWarning, { sessionId: input.sessionId });- this.emit(state, { type: 'runtime.warning', message: sandboxWarning });+ for (const warning of [sandboxWarning, modelWarning]) {+ if (!warning) continue;+ this.logger.warn(warning, { sessionId: input.sessionId });+ this.emit(state, { type: 'runtime.warning', message: warning });}this.emit(state, { type: 'session.state.changed', status: 'ready' });return { sessionId: input.sessionId, nativeSessionId: state.threadId, provider: PROVIDER };