Skip to content

Commit ff9f41b

Browse files
fix(server): Codex turns without a saved effort run at the model's default (#20991)
Co-authored-by: Julius Marminge <[email protected]>
1 parent e3e89f4 commit ff9f41b

6 files changed

Lines changed: 140 additions & 51 deletions

File tree

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

Lines changed: 125 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import * as ProviderReplayHarness from "../testkit/ProviderReplayHarness.ts";
6767
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
6868
import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
6969
import * as CodexAdapterV2 from "./CodexAdapterV2.ts";
70+
import { mapCodexModelCapabilities } from "../../provider/CodexProvider.ts";
7071
import { makeReplayServerConfig, withCodexReplayChildMetadata } from "./CodexAdapterV2.testkit.ts";
7172
import * as CodexAdapterV2Testkit from "./CodexAdapterV2.testkit.ts";
7273

@@ -587,55 +588,138 @@ describe("CodexAdapterV2 runtime policy", () => {
587588

588589
assert.equal(params.collaborationMode?.mode, "plan");
589590
assert.notProperty(params.collaborationMode?.settings, "developer_instructions");
591+
assert.notProperty(params.collaborationMode?.settings, "reasoning_effort");
592+
assert.isUndefined(params.effort);
590593
}),
591594
);
592595

593-
it.effect("compiles per-turn Codex model options and cwd from their owning inputs", () =>
594-
Effect.gen(function* () {
595-
const params = yield* CodexAdapterV2.buildCodexTurnStartParams({
596-
nativeThreadId: "native-model-options",
597-
codexInput: [{ type: "text", text: "test" }],
598-
runtimePolicy: {
599-
runtimeMode: "full-access",
600-
interactionMode: "plan",
601-
cwd: "/workspace/model-options",
602-
reasoningEffort: "low",
603-
},
604-
modelSelection: {
605-
instanceId: ProviderInstanceId.make("codex"),
606-
model: "gpt-5.4",
607-
options: [
608-
{ id: "reasoningEffort", value: "xhigh" },
609-
{ id: "serviceTier", value: "priority" },
610-
],
611-
},
612-
});
596+
it.effect.each(["default", "plan"] as const)(
597+
"compiles per-turn Codex model options and cwd from their owning inputs in %s mode",
598+
(interactionMode) =>
599+
Effect.gen(function* () {
600+
const params = yield* CodexAdapterV2.buildCodexTurnStartParams({
601+
nativeThreadId: "native-model-options",
602+
hasT3Mcp: true,
603+
codexInput: [{ type: "text", text: "test" }],
604+
runtimePolicy: {
605+
runtimeMode: "full-access",
606+
interactionMode,
607+
cwd: "/workspace/model-options",
608+
reasoningEffort: "low",
609+
},
610+
modelSelection: {
611+
instanceId: ProviderInstanceId.make("codex"),
612+
model: "gpt-5.4",
613+
options: [
614+
{ id: "reasoningEffort", value: "xhigh" },
615+
{ id: "serviceTier", value: "priority" },
616+
],
617+
},
618+
});
613619

614-
assert.equal(params.model, "gpt-5.4");
615-
assert.equal(params.effort, "xhigh");
616-
assert.equal(params.serviceTier, "priority");
617-
assert.equal(params.cwd, "/workspace/model-options");
618-
assert.equal(params.collaborationMode?.settings.model, "gpt-5.4");
619-
assert.equal(params.collaborationMode?.settings.reasoning_effort, "xhigh");
620+
assert.equal(params.model, "gpt-5.4");
621+
assert.equal(params.effort, "xhigh");
622+
assert.equal(params.serviceTier, "priority");
623+
assert.equal(params.cwd, "/workspace/model-options");
624+
assert.equal(params.collaborationMode?.settings.model, "gpt-5.4");
625+
assert.equal(params.collaborationMode?.mode, interactionMode);
626+
assert.equal(params.collaborationMode?.settings.reasoning_effort, "xhigh");
627+
assert.include(
628+
params.additionalContext?.t3_code_runtime?.value ?? "",
629+
"as gpt-5.4 with xhigh reasoning effort",
630+
);
620631

621-
const managed = yield* CodexAdapterV2.buildCodexTurnStartParams({
622-
nativeThreadId: "native-model-options",
623-
codexInput: [{ type: "text", text: "test" }],
624-
runtimePolicy: {
625-
runtimeMode: "full-access",
626-
interactionMode: "default",
627-
cwd: "/workspace/model-options",
628-
},
629-
modelSelection: {
630-
instanceId: ProviderInstanceId.make("codex"),
631-
model: "gpt-5.4",
632-
options: [{ id: "serviceTier", value: "priority" }],
633-
},
634-
omitServiceTier: true,
632+
const managed = yield* CodexAdapterV2.buildCodexTurnStartParams({
633+
nativeThreadId: "native-model-options",
634+
codexInput: [{ type: "text", text: "test" }],
635+
runtimePolicy: {
636+
runtimeMode: "full-access",
637+
interactionMode: "default",
638+
cwd: "/workspace/model-options",
639+
},
640+
modelSelection: {
641+
instanceId: ProviderInstanceId.make("codex"),
642+
model: "gpt-5.4",
643+
options: [{ id: "serviceTier", value: "priority" }],
644+
},
645+
omitServiceTier: true,
646+
});
647+
assert.equal(managed.serviceTier, undefined);
648+
}),
649+
);
650+
651+
it.effect("uses Astra's advertised effort default while preserving explicit selections", () =>
652+
Effect.gen(function* () {
653+
const model = "gpt-6-astra";
654+
const capabilities = mapCodexModelCapabilities({
655+
id: model,
656+
model,
657+
displayName: model,
658+
description: "Test model",
659+
hidden: false,
660+
isDefault: true,
661+
defaultReasoningEffort: "low",
662+
supportedReasoningEfforts: ["low", "medium", "high"].map((reasoningEffort) => ({
663+
reasoningEffort,
664+
description: reasoningEffort,
665+
})),
666+
additionalSpeedTiers: [],
635667
});
636-
assert.equal(managed.serviceTier, undefined);
668+
const advertised = capabilities.optionDescriptors?.find(
669+
(option) => option.id === "reasoningEffort",
670+
)?.currentValue;
671+
assert.equal(advertised, "medium");
672+
for (const selected of [undefined, "high"] as const) {
673+
const params = yield* CodexAdapterV2.buildCodexTurnStartParams({
674+
nativeThreadId: "native-astra-effort",
675+
codexInput: [{ type: "text", text: "test" }],
676+
runtimePolicy: { runtimeMode: "full-access", interactionMode: "default", cwd: null },
677+
modelSelection: {
678+
instanceId: ProviderInstanceId.make("codex"),
679+
model,
680+
...(selected ? { options: [{ id: "reasoningEffort", value: selected }] } : {}),
681+
},
682+
hasT3Mcp: true,
683+
});
684+
const expected = selected ?? advertised;
685+
assert.equal(params.effort, expected);
686+
assert.equal(params.collaborationMode?.settings.reasoning_effort, expected);
687+
assert.include(
688+
params.additionalContext?.t3_code_runtime?.value ?? "",
689+
`${expected} reasoning effort`,
690+
);
691+
}
637692
}),
638693
);
694+
695+
it.effect.each(["default", "plan"] as const)(
696+
"omits unset effort from T3 %s collaboration settings and runtime context",
697+
(interactionMode) =>
698+
Effect.gen(function* () {
699+
const params = yield* CodexAdapterV2.buildCodexTurnStartParams({
700+
nativeThreadId: "native-unset-effort",
701+
codexInput: [{ type: "text", text: "test" }],
702+
runtimePolicy: {
703+
runtimeMode: "full-access",
704+
interactionMode,
705+
cwd: null,
706+
},
707+
modelSelection: {
708+
instanceId: ProviderInstanceId.make("codex"),
709+
model: "gpt-5.4",
710+
},
711+
hasT3Mcp: true,
712+
});
713+
714+
assert.isUndefined(params.effort);
715+
assert.equal(params.collaborationMode?.mode, interactionMode);
716+
assert.equal(params.collaborationMode?.settings.model, "gpt-5.4");
717+
assert.notProperty(params.collaborationMode?.settings, "reasoning_effort");
718+
const runtimeContext = params.additionalContext?.t3_code_runtime?.value ?? "";
719+
assert.include(runtimeContext, "as gpt-5.4");
720+
assert.notInclude(runtimeContext, "reasoning effort");
721+
}),
722+
);
639723
});
640724

641725
describe("CodexAdapterV2 process spawning", () => {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { CodexEffectiveRuntime } from "../../provider/CodexManagedRuntime.t
1717
import {
1818
buildCodexInitializeParams,
1919
codexAppServerEnvironment,
20+
codexDefaultReasoningEffortOverride,
2021
} from "../../provider/CodexProvider.ts";
2122
import {
2223
codexRateLimitsToUpdate,
@@ -738,10 +739,9 @@ export function buildCodexTurnStartParams(input: {
738739
input.runtimePolicy.sandboxPolicy === undefined
739740
? runtimeModeDefaults.sandboxPolicy
740741
: yield* decodeTurnSandboxPolicy(input.runtimePolicy.sandboxPolicy);
741-
const selectedEffort = getModelSelectionStringOptionValue(
742-
input.modelSelection,
743-
"reasoningEffort",
744-
);
742+
const selectedEffort =
743+
getModelSelectionStringOptionValue(input.modelSelection, "reasoningEffort") ??
744+
codexDefaultReasoningEffortOverride(input.modelSelection.model);
745745
const effort =
746746
selectedEffort === undefined ? undefined : yield* decodeTurnReasoningEffort(selectedEffort);
747747
const serviceTier =
@@ -764,7 +764,7 @@ export function buildCodexTurnStartParams(input: {
764764
const t3Context =
765765
input.hasT3Mcp === true
766766
? buildCodexAdditionalContext(
767-
{ model: input.modelSelection.model, reasoningEffort: effort ?? "medium" },
767+
{ model: input.modelSelection.model, reasoningEffort: effort ?? undefined },
768768
{
769769
browser: input.browserToolsAvailable ?? true,
770770
device: input.deviceToolsAvailable ?? false,
@@ -782,7 +782,8 @@ export function buildCodexTurnStartParams(input: {
782782
mode: input.runtimePolicy.interactionMode === "plan" ? "plan" : "default",
783783
settings: {
784784
model: input.modelSelection.model,
785-
reasoning_effort: effort ?? "medium",
785+
// Codex falls back to the model's default effort when this is left out.
786+
...(effort === undefined ? {} : { reasoning_effort: effort }),
786787
...(developerInstructions === undefined
787788
? {}
788789
: { developer_instructions: developerInstructions }),

‎apps/server/src/orchestration-v2/testkit/fixtures/plan_questions/codex_transcript.ndjson‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{"type":"emit_inbound","label":"configWarning","frame":{"method":"configWarning","params":{"summary":"Codex could not find bubblewrap on PATH. Install bubblewrap with your OS package manager. See the sandbox prerequisites: https://developers.openai.com/codex/concepts/sandboxing#prerequisites. Codex will use the bundled bubblewrap in the meantime.","details":null},"emittedAtMs":1790295620180}}
77
{"type":"emit_inbound","label":"remoteControl/status/changed","frame":{"method":"remoteControl/status/changed","params":{"status":"disabled","serverName":"replay-host","installationId":"00000000-0000-4000-8000-000000000000","environmentId":null},"emittedAtMs":1790295620180}}
88
{"type":"emit_inbound","label":"thread/start","frame":{"id":2,"result":{"thread":{"id":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","environments":[{"environmentId":"local","cwd":"/home/replay-user/t3code/packages/effect-codex-app-server","runtimeWorkspaceRoots":["/home/replay-user/t3code/packages/effect-codex-app-server"]}],"extra":null,"sessionId":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","forkedFromId":null,"parentThreadId":null,"preview":"","ephemeral":false,"section":null,"sectionEnteredAt":null,"projectId":null,"historyMode":"paginated","modelProvider":"openai","model":"gpt-6-luna","reasoningEffort":null,"createdAt":1790295620,"updatedAt":1790295620,"recencyAt":1790295620,"status":{"type":"idle"},"path":"/home/replay-user/.codex/sessions/2026/09/24/rollout-2026-09-24T17-20-20-01a0d5ef-3a6a-75d0-9942-61b29ab82328.jsonl","cwd":"/home/replay-user/t3code/packages/effect-codex-app-server","cliVersion":"0.156.1","originator":"t3code_desktop","source":"vscode","canAcceptDirectInput":true,"threadSource":null,"agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"daybreakEnabled":null,"turns":[]},"model":"gpt-6-luna","modelProvider":"openai","serviceTier":null,"disabledPluginIds":[],"cwd":"/home/replay-user/t3code/packages/effect-codex-app-server","runtimeWorkspaceRoots":["/home/replay-user/t3code/packages/effect-codex-app-server"],"instructionSources":["/home/replay-user/.codex/AGENTS.md","/home/replay-user/t3code/AGENTS.md"],"approvalPolicy":"on-request","approvalsReviewer":"user","sandbox":{"type":"workspaceWrite","writableRoots":[],"networkAccess":false,"excludeTmpdirEnvVar":false,"excludeSlashTmp":false},"activePermissionProfile":{"id":":workspace","extends":null},"reasoningEffort":null,"multiAgentMode":"explicitRequestOnly"}}}
9-
{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","approvalsReviewer":"user","cwd":"<workspace>","input":[{"text":"Use request_user_input to ask one multiple-choice clarifying question about whether this fixture should prefer strict schemas or UI flexibility. After receiving the answer, respond exactly: plan questions fixture complete","type":"text"}],"model":"gpt-6-luna","sandboxPolicy":{"networkAccess":false,"type":"readOnly"},"summary":"detailed","threadId":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","collaborationMode":{"mode":"plan","settings":{"developer_instructions":"You are in Plan mode. Prefer request_user_input for clarifying questions. When presenting a complete plan, wrap it in <proposed_plan> and </proposed_plan>.","model":"gpt-6-luna","reasoning_effort":"medium"}}}}}
9+
{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","approvalsReviewer":"user","cwd":"<workspace>","input":[{"text":"Use request_user_input to ask one multiple-choice clarifying question about whether this fixture should prefer strict schemas or UI flexibility. After receiving the answer, respond exactly: plan questions fixture complete","type":"text"}],"model":"gpt-6-luna","sandboxPolicy":{"networkAccess":false,"type":"readOnly"},"summary":"detailed","threadId":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","collaborationMode":{"mode":"plan","settings":{"developer_instructions":"You are in Plan mode. Prefer request_user_input for clarifying questions. When presenting a complete plan, wrap it in <proposed_plan> and </proposed_plan>.","model":"gpt-6-luna"}}}}}
1010
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","name":"codex_apps","status":"starting","error":null,"failureReason":null},"emittedAtMs":1790295620428}}
1111
{"type":"emit_inbound","label":"thread/started","frame":{"method":"thread/started","params":{"thread":{"id":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","environments":[{"environmentId":"local","cwd":"/home/replay-user/t3code/packages/effect-codex-app-server","runtimeWorkspaceRoots":["/home/replay-user/t3code/packages/effect-codex-app-server"]}],"extra":null,"sessionId":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","forkedFromId":null,"parentThreadId":null,"preview":"","ephemeral":false,"section":null,"sectionEnteredAt":null,"projectId":null,"historyMode":"paginated","modelProvider":"openai","model":"gpt-6-luna","reasoningEffort":null,"createdAt":1790295620,"updatedAt":1790295620,"recencyAt":1790295620,"status":{"type":"idle"},"path":"/home/replay-user/.codex/sessions/2026/09/24/rollout-2026-09-24T17-20-20-01a0d5ef-3a6a-75d0-9942-61b29ab82328.jsonl","cwd":"/home/replay-user/t3code/packages/effect-codex-app-server","cliVersion":"0.156.1","originator":"t3code_desktop","source":"vscode","canAcceptDirectInput":true,"threadSource":null,"agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"daybreakEnabled":null,"turns":[]}},"emittedAtMs":1790295620428}}
1212
{"type":"emit_inbound","label":"thread/settings/updated","frame":{"method":"thread/settings/updated","params":{"threadId":"01a0d5ef-3a6a-75d0-9942-61b29ab82328","threadSettings":{"disabledPluginIds":[],"cwd":"/home/replay-user/t3code/packages/effect-codex-app-server","approvalPolicy":"never","approvalsReviewer":"user","sandboxPolicy":{"type":"readOnly","networkAccess":false},"activePermissionProfile":null,"model":"gpt-6-luna","modelProvider":"openai","serviceTier":null,"effort":"medium","summary":"detailed","collaborationMode":{"mode":"plan","settings":{"model":"gpt-6-luna","reasoning_effort":"medium","developer_instructions":"You are in Plan mode. Prefer request_user_input for clarifying questions. When presenting a complete plan, wrap it in <proposed_plan> and </proposed_plan>."}},"multiAgentMode":"explicitRequestOnly","personality":null}},"emittedAtMs":1790295620457}}

0 commit comments

Comments
 (0)