Skip to content

Commit 7cd0e57

Browse files
Mezzleclaude
andcommitted
fix(codex): default cyber access to Standard, matching Codex
Omitting cyberAccessProgram leaves the choice to OpenAI's server, while Codex's own clients send Standard unless Daybreak is on. Models in the catalog now default to Standard, or to Daybreak when Codex's daybreak setting is on, and T3 sends the program on every turn. Turns with no selection use the model's default from the provider snapshot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3234481 commit 7cd0e57

8 files changed

Lines changed: 200 additions & 60 deletions

File tree

‎apps/server/src/codexModelOptions.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ export function getCodexServiceTierOptionValue(
1313
);
1414
}
1515

16-
export const CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID = "automatic";
17-
18-
/** Undefined leaves Codex's automatic cyber treatment in place. */
1916
export function getCodexCyberAccessProgramOptionValue(
2017
modelSelection: ModelSelection | null | undefined,
2118
): string | undefined {
22-
const value = getModelSelectionStringOptionValue(modelSelection, "cyberAccessProgram");
23-
return value === CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID ? undefined : value;
19+
return getModelSelectionStringOptionValue(modelSelection, "cyberAccessProgram");
2420
}

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ describe("CodexAdapterV2 runtime policy", () => {
222222
}),
223223
);
224224

225-
it.effect("leaves Codex's automatic cyber access in place unless a program is chosen", () =>
225+
it.effect("sends the chosen cyber access program, else the model's default", () =>
226226
Effect.gen(function* () {
227-
const build = (value?: string) =>
227+
const build = (value?: string, defaultCyberAccessProgram?: string) =>
228228
CodexAdapterV2.buildCodexTurnStartParams({
229229
nativeThreadId: "native-cyber",
230230
codexInput: [{ type: "text", text: "test" }],
@@ -234,12 +234,15 @@ describe("CodexAdapterV2 runtime policy", () => {
234234
model: "gpt-5.4",
235235
...(value === undefined ? {} : { options: [{ id: "cyberAccessProgram", value }] }),
236236
},
237+
defaultCyberAccessProgram,
237238
});
238239

240+
// Custom models have no catalog entry, so Codex keeps its own treatment.
239241
assert.notProperty(yield* build(), "cyberAccessProgram");
240-
assert.notProperty(yield* build("automatic"), "cyberAccessProgram");
241-
assert.equal((yield* build("standard")).cyberAccessProgram, "standard");
242-
assert.equal((yield* build("daybreakBlue")).cyberAccessProgram, "daybreakBlue");
242+
assert.equal((yield* build(undefined, "standard")).cyberAccessProgram, "standard");
243+
assert.equal((yield* build("automatic", "standard")).cyberAccessProgram, "standard");
244+
assert.equal((yield* build("daybreakBlue", "standard")).cyberAccessProgram, "daybreakBlue");
245+
assert.equal((yield* build("standard", "daybreakBlue")).cyberAccessProgram, "standard");
243246
}),
244247
);
245248

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ function codexRuntimeModeTurnDefaults(runtimeMode: RuntimeMode): {
741741
}
742742
}
743743

744+
const isCodexCyberAccessProgram = Schema.is(CodexSchema.V2TurnStartParams__CyberAccessProgram);
745+
744746
export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTurnStartParams")(
745747
function* (input: {
746748
readonly nativeThreadId: string;
@@ -753,6 +755,7 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
753755
/** ChatGPT token sharing does not accept service tiers. */
754756
readonly omitServiceTier?: boolean;
755757
readonly appContext?: ProviderAdapter.ProviderAdapterV2TurnInput["appContext"];
758+
readonly defaultCyberAccessProgram?: string | undefined;
756759
}) {
757760
const runtimeModeDefaults = codexRuntimeModeTurnDefaults(input.runtimePolicy.runtimeMode);
758761
const approvalPolicy =
@@ -772,7 +775,10 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
772775
input.omitServiceTier === true
773776
? undefined
774777
: getCodexServiceTierOptionValue(input.modelSelection);
775-
const cyberAccessProgram = getCodexCyberAccessProgramOptionValue(input.modelSelection);
778+
const selectedCyberAccessProgram = getCodexCyberAccessProgramOptionValue(input.modelSelection);
779+
const cyberAccessProgram = [selectedCyberAccessProgram, input.defaultCyberAccessProgram].find(
780+
isCodexCyberAccessProgram,
781+
);
776782
// MCP-written app context must be quoted user input, not developer instructions.
777783
const appContext = Object.fromEntries(
778784
(input.appContext ?? []).map((entry) => [
@@ -1590,7 +1596,10 @@ export type CodexAdapterV2DriverEnv =
15901596

15911597
export const createCodexAdapterV2 = Effect.fn("CodexAdapterV2.createCodexAdapterV2")(function* (
15921598
{ instanceId, environment, enabled, config }: ProviderAdapterDriverCreateInput<CodexSettings>,
1593-
hooks: Pick<CodexAdapterV2Options, "onUsageLimits" | "resolveRuntime" | "compatibility"> = {},
1599+
hooks: Pick<
1600+
CodexAdapterV2Options,
1601+
"onUsageLimits" | "resolveRuntime" | "compatibility" | "defaultCyberAccessProgram"
1602+
> = {},
15941603
) {
15951604
const clientFactory = yield* CodexAppServerClientFactory;
15961605
const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
@@ -1640,6 +1649,7 @@ export interface CodexAdapterV2Options {
16401649
readonly environment: NodeJS.ProcessEnv;
16411650
readonly clientFactory: CodexAppServerClientFactoryShape;
16421651
readonly onUsageLimits?: ManagedServerProvider["applyUsageLimits"];
1652+
readonly defaultCyberAccessProgram?: (model: string) => Effect.Effect<string | undefined>;
16431653
readonly resolveRuntime?: Effect.Effect<CodexEffectiveRuntime, ProviderSetupError, Scope.Scope>;
16441654
readonly compatibility?: (
16451655
version: string,
@@ -6710,7 +6720,12 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
67106720
) {
67116721
const threadId = yield* getNativeThreadId(turnInput.providerThread);
67126722
const mcpSession = yield* mcpSessions.read(turnInput.threadId);
6723+
const defaultCyberAccessProgram =
6724+
adapterOptions.defaultCyberAccessProgram === undefined
6725+
? undefined
6726+
: yield* adapterOptions.defaultCyberAccessProgram(turnInput.modelSelection.model);
67136727
const turnStartParams = yield* buildCodexTurnStartParams({
6728+
defaultCyberAccessProgram,
67146729
nativeThreadId: threadId,
67156730
codexInput,
67166731
runtimePolicy: turnInput.runtimePolicy,

‎apps/server/src/provider/CodexProvider.test.ts‎

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { assert, it } from "@effect/vitest";
33
import {
44
appendCustomCodexModels,
55
applyPreferredCodexDefaultModel,
6+
applyConfiguredCodexCyberAccess,
7+
codexDefaultCyberAccessProgram,
68
mapCodexModelCapabilities,
79
} from "./CodexProvider.ts";
810

@@ -158,7 +160,7 @@ it("ignores custom models that shadow a preferred slug", () => {
158160
assert.deepStrictEqual(models.find((model) => model.isDefault)?.slug, "gpt-5.4");
159161
});
160162

161-
it("offers cyber access programs only when the catalog has a Daybreak program", () => {
163+
it("defaults cyber access to Standard when the catalog offers it", () => {
162164
const model = {
163165
additionalSpeedTiers: [],
164166
defaultReasoningEffort: "medium",
@@ -170,33 +172,86 @@ it("offers cyber access programs only when the catalog has a Daybreak program",
170172
model: "gpt-test",
171173
supportedReasoningEfforts: [],
172174
};
173-
174-
assert.deepStrictEqual(
175-
mapCodexModelCapabilities({
176-
...model,
177-
availableAccessPrograms: { cyber: ["standard"] },
178-
}).optionDescriptors,
179-
[],
180-
);
181-
assert.deepStrictEqual(
175+
const cyber = (programs?: ReadonlyArray<"standard" | "daybreakBlue">) =>
182176
mapCodexModelCapabilities({
183177
...model,
184-
availableAccessPrograms: { cyber: ["standard", "daybreakBlue"] },
185-
}).optionDescriptors,
186-
[
187-
{
188-
id: "cyberAccessProgram",
189-
label: "Cyber Access",
190-
type: "select",
191-
options: [
192-
{ id: "automatic", label: "Automatic", isDefault: true },
193-
{ id: "standard", label: "Standard" },
194-
{ id: "daybreakBlue", label: "Daybreak Blue" },
195-
],
196-
currentValue: "automatic",
197-
},
178+
...(programs ? { availableAccessPrograms: { cyber: [...programs] } } : {}),
179+
}).optionDescriptors?.[0];
180+
181+
assert.strictEqual(cyber(), undefined);
182+
assert.deepStrictEqual(cyber(["standard", "daybreakBlue"]), {
183+
id: "cyberAccessProgram",
184+
label: "Cyber Access",
185+
type: "select",
186+
options: [
187+
{ id: "standard", label: "Standard", isDefault: true },
188+
{ id: "daybreakBlue", label: "Daybreak Blue" },
198189
],
199-
);
190+
currentValue: "standard",
191+
});
192+
assert.deepInclude(cyber(["standard"]), { currentValue: "standard" });
193+
assert.deepInclude(cyber(["daybreakBlue"]), { currentValue: "daybreakBlue" });
194+
});
195+
196+
it("finds the default cyber access program for a model", () => {
197+
const capabilities = mapCodexModelCapabilities({
198+
additionalSpeedTiers: [],
199+
availableAccessPrograms: { cyber: ["standard", "daybreakBlue"] },
200+
defaultReasoningEffort: "medium",
201+
description: "Test model",
202+
displayName: "GPT Test",
203+
hidden: false,
204+
id: "gpt-test",
205+
isDefault: true,
206+
model: "gpt-test",
207+
supportedReasoningEfforts: [],
208+
});
209+
const models = [{ slug: "gpt-test", name: "GPT Test", isCustom: false, capabilities }];
210+
assert.strictEqual(codexDefaultCyberAccessProgram(models, "gpt-test"), "standard");
211+
assert.strictEqual(codexDefaultCyberAccessProgram(models, "my-model"), undefined);
212+
});
213+
214+
it("follows Codex's daybreak setting for the default program", () => {
215+
const capabilities = (cyber: ReadonlyArray<"standard" | "daybreakBlue">) =>
216+
mapCodexModelCapabilities({
217+
additionalSpeedTiers: [],
218+
availableAccessPrograms: { cyber: [...cyber] },
219+
defaultReasoningEffort: "medium",
220+
description: "Test model",
221+
displayName: "GPT Test",
222+
hidden: false,
223+
id: "gpt-test",
224+
isDefault: true,
225+
model: "gpt-test",
226+
supportedReasoningEfforts: [],
227+
});
228+
const models = [
229+
{
230+
slug: "both",
231+
name: "Both",
232+
isCustom: false,
233+
capabilities: capabilities(["standard", "daybreakBlue"]),
234+
},
235+
{
236+
slug: "standard",
237+
name: "Standard",
238+
isCustom: false,
239+
capabilities: capabilities(["standard"]),
240+
},
241+
];
242+
243+
const on = applyConfiguredCodexCyberAccess(models, {
244+
daybreakEnabled: true,
245+
apiKeyProgramsDisabled: false,
246+
});
247+
assert.strictEqual(codexDefaultCyberAccessProgram(on, "both"), "daybreakBlue");
248+
assert.strictEqual(codexDefaultCyberAccessProgram(on, "standard"), "standard");
249+
250+
const disabled = applyConfiguredCodexCyberAccess(models, {
251+
daybreakEnabled: false,
252+
apiKeyProgramsDisabled: true,
253+
});
254+
assert.strictEqual(codexDefaultCyberAccessProgram(disabled, "both"), undefined);
200255
});
201256

202257
it("keeps Daybreak access off custom models that borrow built-in options", () => {

‎apps/server/src/provider/CodexProvider.ts‎

Lines changed: 78 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {
5252
type CodexRateLimitSnapshot,
5353
type CodexResetCreditsSummary,
5454
} from "./codexUsageLimits.ts";
55-
import { CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID } from "../codexModelOptions.ts";
5655
import * as HostProcess from "@t3tools/shared/HostProcess";
5756
import packageJson from "../../package.json" with { type: "json" };
5857
const isCodexAppServerSpawnError = Schema.is(CodexErrors.CodexAppServerSpawnError);
@@ -94,6 +93,8 @@ export interface CodexAppServerProviderSnapshot {
9493
readonly version: string | undefined;
9594
readonly models: ReadonlyArray<ServerProviderModel> | undefined;
9695
readonly serviceTier?: string | undefined;
96+
readonly daybreakEnabled?: boolean | undefined;
97+
readonly apiKeyCyberAccessProgramsDisabled?: boolean | undefined;
9798
readonly skills: ReadonlyArray<ServerProviderSkill>;
9899
}
99100

@@ -249,24 +250,21 @@ export function mapCodexModelCapabilities(
249250
});
250251
}
251252
const cyberAccessPrograms = model.availableAccessPrograms?.cyber ?? [];
252-
// Only Daybreak programmes need a choice; standard-only models keep their usual controls.
253-
if (cyberAccessPrograms.some((program) => program !== "standard")) {
253+
if (cyberAccessPrograms.length > 0) {
254+
// Codex's own clients request Standard unless Daybreak is on; omitting the field does not.
255+
const defaultProgram = cyberAccessPrograms.includes("standard")
256+
? "standard"
257+
: cyberAccessPrograms[0];
254258
optionDescriptors.push({
255259
id: "cyberAccessProgram",
256260
label: "Cyber Access",
257261
type: "select",
258-
options: [
259-
{
260-
id: CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID,
261-
label: "Automatic",
262-
isDefault: true,
263-
},
264-
...cyberAccessPrograms.map((program) => ({
265-
id: program,
266-
label: CYBER_ACCESS_PROGRAM_LABELS[program] ?? program,
267-
})),
268-
],
269-
currentValue: CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID,
262+
options: cyberAccessPrograms.map((program) => ({
263+
id: program,
264+
label: CYBER_ACCESS_PROGRAM_LABELS[program] ?? program,
265+
...(program === defaultProgram ? { isDefault: true } : {}),
266+
})),
267+
...(defaultProgram === undefined ? {} : { currentValue: defaultProgram }),
270268
});
271269
}
272270

@@ -308,6 +306,58 @@ export function applyPreferredCodexDefaultModel(
308306
});
309307
}
310308

309+
/** Mirrors Codex: `daybreak = true` prefers a Daybreak program, Blue before Red. */
310+
export function applyConfiguredCodexCyberAccess(
311+
models: ReadonlyArray<ServerProviderModel>,
312+
input: {
313+
readonly daybreakEnabled: boolean;
314+
readonly apiKeyProgramsDisabled: boolean;
315+
},
316+
): ReadonlyArray<ServerProviderModel> {
317+
if (!input.daybreakEnabled && !input.apiKeyProgramsDisabled) return models;
318+
return models.map((model) => {
319+
const descriptors = model.capabilities?.optionDescriptors;
320+
if (!model.capabilities || !descriptors) return model;
321+
return {
322+
...model,
323+
capabilities: {
324+
...model.capabilities,
325+
// Codex rejects explicit programs in this session, so none can be offered or sent.
326+
optionDescriptors: (input.apiKeyProgramsDisabled
327+
? descriptors.filter((descriptor) => descriptor.id !== "cyberAccessProgram")
328+
: descriptors
329+
).map((descriptor) => {
330+
if (descriptor.id !== "cyberAccessProgram" || descriptor.type !== "select") {
331+
return descriptor;
332+
}
333+
const value = ["daybreakBlue", "daybreakRed"].find((program) =>
334+
descriptor.options.some((option) => option.id === program),
335+
);
336+
if (!value) return descriptor;
337+
return {
338+
...descriptor,
339+
currentValue: value,
340+
options: descriptor.options.map(({ isDefault: _isDefault, ...option }) =>
341+
option.id === value ? { ...option, isDefault: true } : option,
342+
),
343+
};
344+
}),
345+
},
346+
};
347+
});
348+
}
349+
350+
/** Applies when a selection names no program, such as older threads and agent-started turns. */
351+
export function codexDefaultCyberAccessProgram(
352+
models: ReadonlyArray<ServerProviderModel>,
353+
slug: string,
354+
): string | undefined {
355+
const descriptor = models
356+
.find((model) => model.slug === slug)
357+
?.capabilities?.optionDescriptors?.find(({ id }) => id === "cyberAccessProgram");
358+
return descriptor?.type === "select" ? descriptor.currentValue : undefined;
359+
}
360+
311361
function applyConfiguredCodexServiceTier(
312362
models: ReadonlyArray<ServerProviderModel>,
313363
serviceTier: string | undefined,
@@ -585,7 +635,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
585635

586636
// Optional discovery must finish before the outer timeout can discard the account result.
587637
const deadlineMs = spawnedAtMs + CODEX_AUTH_PROBE_TIMEOUT_MS - CODEX_DISCOVERY_MARGIN_MS;
588-
const [skillsResponse, models, serviceTier, rateLimits] = yield* Effect.all(
638+
const [skillsResponse, models, config, rateLimits] = yield* Effect.all(
589639
[
590640
withCodexDiscoveryDeadline(client.request("skills/list", { cwds: [input.cwd] }), deadlineMs),
591641
accountResponse.account?.type === "chatgpt"
@@ -602,7 +652,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
602652
deadlineMs,
603653
CODEX_CONFIG_PROBE_TIMEOUT_MS,
604654
).pipe(
605-
Effect.map((response) => response?.config.service_tier ?? undefined),
655+
Effect.map((response) => response?.config),
606656
Effect.catch(() => Effect.logDebug("Codex config read failed.").pipe(Effect.as(undefined))),
607657
),
608658
// Usage is an enrichment: a failure or a slow answer degrades to "no
@@ -640,7 +690,12 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
640690
...(rateLimits ? { rateLimits } : {}),
641691
version,
642692
models,
643-
serviceTier,
693+
serviceTier: config?.service_tier ?? undefined,
694+
daybreakEnabled: config?.["daybreak"] === true,
695+
apiKeyCyberAccessProgramsDisabled:
696+
accountResponse.account?.type === "apiKey" &&
697+
(config?.["features"] as { readonly api_key_cyber_access_programs?: unknown } | undefined)
698+
?.api_key_cyber_access_programs === false,
644699
skills: skillsResponse ? parseCodexSkillsListResponse(skillsResponse, input.cwd) : [],
645700
} satisfies CodexAppServerProviderSnapshot;
646701
});
@@ -901,6 +956,11 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
901956
appendCustomCodexModels(snapshot.models ?? [], codexSettings.customModels),
902957
applyPreferredCodexDefaultModel,
903958
(models) => applyConfiguredCodexServiceTier(models, snapshot.serviceTier),
959+
(models) =>
960+
applyConfiguredCodexCyberAccess(models, {
961+
daybreakEnabled: snapshot.daybreakEnabled === true,
962+
apiKeyProgramsDisabled: snapshot.apiKeyCyberAccessProgramsDisabled === true,
963+
}),
904964
),
905965
skills: snapshot.skills,
906966
slashCommands: [

0 commit comments

Comments
 (0)