Skip to content

Commit 12b29eb

Browse files
fix(server): Codex turns use the configured reasoning summary instead of forcing detailed (pingdotgg#35089)
1 parent 6da3ff2 commit 12b29eb

30 files changed

Lines changed: 318 additions & 147 deletions

File tree

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

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ describe("CodexAdapterV2 runtime policy", () => {
183183
},
184184
});
185185
assert.equal(params.effort, reasoningEffort);
186+
// Some Responses providers reject `detailed`; `auto` is the most detailed a model supports.
187+
assert.equal(params.summary, "auto");
186188
assert.equal(params.additionalContext !== undefined, hasT3Mcp === true);
187189
}
188190
}
@@ -683,7 +685,7 @@ function codexReplayPreamble(input: {
683685
approvalPolicy: "never",
684686
approvalsReviewer: "user",
685687
sandboxPolicy: { type: "dangerFullAccess" },
686-
summary: "detailed",
688+
summary: "auto",
687689
...(input.effort === undefined ? {} : { effort: input.effort }),
688690
collaborationMode: {
689691
mode: "default",
@@ -717,6 +719,61 @@ function codexReplayPreamble(input: {
717719
];
718720
}
719721

722+
/** Every turn/start follows a config/read; inserts that exchange and shifts later client ids. */
723+
function withConfigReadBeforeTurnStart(
724+
entries: ReadonlyArray<CodexReplay.CodexAppServerReplayEntry>,
725+
): Array<CodexReplay.CodexAppServerReplayEntry> {
726+
const result: Array<CodexReplay.CodexAppServerReplayEntry> = [];
727+
let offset = 0;
728+
let clientIds = new Map<number, number>();
729+
for (const entry of entries) {
730+
const frame = entry.type === "runtime_exit" ? undefined : entry.frame;
731+
if (!Predicate.isObject(frame) || typeof frame.id !== "number") {
732+
result.push(entry);
733+
continue;
734+
}
735+
if (entry.type === "expect_outbound" && typeof frame.method === "string") {
736+
if (frame.method === "initialize") {
737+
offset = 0;
738+
clientIds = new Map();
739+
}
740+
if (frame.method === "turn/start") {
741+
const id = frame.id + offset;
742+
const params = Predicate.isObject(frame.params) ? frame.params : {};
743+
result.push(
744+
{
745+
type: "expect_outbound",
746+
label: "config/read",
747+
frame: { id, method: "config/read", params: { cwd: params.cwd, includeLayers: false } },
748+
},
749+
{
750+
type: "emit_inbound",
751+
label: "config/read",
752+
frame: { id, result: { config: {}, origins: {} } },
753+
},
754+
);
755+
offset += 1;
756+
}
757+
clientIds.set(frame.id, frame.id + offset);
758+
result.push(withReplayRequestId(entry, frame.id + offset));
759+
continue;
760+
}
761+
const mapped = clientIds.get(frame.id);
762+
result.push(
763+
entry.type === "emit_inbound" && frame.method === undefined && mapped !== undefined
764+
? withReplayRequestId(entry, mapped)
765+
: entry,
766+
);
767+
}
768+
return result;
769+
}
770+
771+
function withConfigReads(
772+
transcript: CodexReplay.CodexAppServerReplayTranscript,
773+
): CodexReplay.CodexAppServerReplayTranscript {
774+
return { ...transcript, entries: withConfigReadBeforeTurnStart(transcript.entries) };
775+
}
776+
720777
function makeCodexReplayTranscript(input: {
721778
readonly scenario: string;
722779
readonly entries: ReadonlyArray<CodexReplay.CodexAppServerReplayEntry>;
@@ -757,7 +814,9 @@ describe("CodexAdapterV2 process exit", () => {
757814
const turnStarted = yield* Deferred.make<void>();
758815
const turnCompleted = yield* Deferred.make<void>();
759816
const events: Array<ProviderAdapter.ProviderAdapterV2Event> = [];
760-
const preamble = codexReplayPreamble({ nativeThreadId, nativeTurnId, prompt: "work" });
817+
const preamble = withConfigReadBeforeTurnStart(
818+
codexReplayPreamble({ nativeThreadId, nativeTurnId, prompt: "work" }),
819+
);
761820
const terminationError =
762821
exit === "numeric"
763822
? new CodexError.CodexAppServerProcessExitedError({ code: 17, pid: 52 })
@@ -962,7 +1021,7 @@ describe("CodexAdapterV2 session initialize", () => {
9621021
) =>
9631022
Effect.gen(function* () {
9641023
const driver = yield* CodexReplay.makeReplayDriver(
965-
transcript,
1024+
withConfigReads(transcript),
9661025
beforeEmitInbound === undefined ? {} : { beforeEmitInbound },
9671026
);
9681027
let initializeRequests = 0;
@@ -1254,7 +1313,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
12541313
const continuationRequests: Array<ProviderContinuationRequests.ProviderContinuationRequest> =
12551314
[];
12561315
const driver = yield* CodexReplay.makeReplayDriver(
1257-
transcript,
1316+
withConfigReads(transcript),
12581317
beforeEmitInbound === undefined ? {} : { beforeEmitInbound },
12591318
);
12601319
const clientFactory: CodexAdapterV2.CodexAppServerClientFactoryShape = {
@@ -2465,7 +2524,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
24652524
cwd: "/workspace",
24662525
model: "gpt-5.4",
24672526
...turnPolicies[turnModes[index]!],
2468-
summary: "detailed",
2527+
summary: "auto",
24692528
collaborationMode: { mode: "default", settings: { model: "gpt-5.4" } },
24702529
},
24712530
},
@@ -3553,7 +3612,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
35533612
approvalPolicy: "never",
35543613
approvalsReviewer: "user",
35553614
sandboxPolicy: { type: "dangerFullAccess" },
3556-
summary: "detailed",
3615+
summary: "auto",
35573616
collaborationMode: { mode: "default", settings: { model: "gpt-5.4" } },
35583617
},
35593618
},
@@ -3807,7 +3866,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
38073866
makeCodexReplayTranscript({ scenario, entries }),
38083867
)).replaceAll(yield* encodeStringJson("/workspace"), yield* encodeStringJson(cwd)),
38093868
);
3810-
const driver = yield* CodexReplay.makeReplayDriver(localTranscript);
3869+
const driver = yield* CodexReplay.makeReplayDriver(withConfigReads(localTranscript));
38113870
yield* Effect.gen(function* () {
38123871
const orchestrator = yield* Orchestrator.OrchestratorV2;
38133872
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
@@ -5443,7 +5502,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
54435502
yield* encodeStringJson(cwd),
54445503
),
54455504
);
5446-
const replayDriver = yield* CodexReplay.makeReplayDriver(localTranscript);
5505+
const replayDriver = yield* CodexReplay.makeReplayDriver(withConfigReads(localTranscript));
54475506
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
54485507
assert.equal(
54495508
Number(yield* spawner.exitCode(ChildProcess.make("git", ["init", "--quiet"], { cwd }))),
@@ -5666,7 +5725,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
56665725
Effect.provide(
56675726
ProviderReplayHarness.layerWithRegistry(
56685727
{ name: "codex-background-stop-untracked", runtimePolicyOverride: { cwd } },
5669-
CodexAdapterV2Testkit.layer({ transcript: localTranscript }),
5728+
CodexAdapterV2Testkit.layer({ transcript: withConfigReads(localTranscript) }),
56705729
{ runEffectWorker: false },
56715730
),
56725731
),
@@ -7932,7 +7991,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
79327991
approvalPolicy: "never",
79337992
approvalsReviewer: "user",
79347993
sandboxPolicy: { type: "dangerFullAccess" },
7935-
summary: "detailed",
7994+
summary: "auto",
79367995
collaborationMode: { mode: "default", settings: { model: "gpt-5.4" } },
79377996
},
79387997
},
@@ -8080,7 +8139,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
80808139
approvalPolicy: "never",
80818140
approvalsReviewer: "user",
80828141
sandboxPolicy: { type: "dangerFullAccess" },
8083-
summary: "detailed",
8142+
summary: "auto",
80848143
collaborationMode: { mode: "default", settings: { model: "gpt-5.4" } },
80858144
},
80868145
},

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
782782
/** ChatGPT token sharing does not accept service tiers. */
783783
readonly omitServiceTier?: boolean;
784784
readonly appContext?: ProviderAdapter.ProviderAdapterV2TurnInput["appContext"];
785+
/** The user's `model_reasoning_summary` from the Codex config, when set. */
786+
readonly configuredReasoningSummary?: CodexSchema.V2TurnStartParams__ReasoningSummary;
785787
}) {
786788
const runtimeModeDefaults = codexRuntimeModeTurnDefaults(input.runtimePolicy.runtimeMode);
787789
const approvalPolicy =
@@ -828,8 +830,9 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
828830
...(additionalContext ? { additionalContext } : {}),
829831
cwd: input.runtimePolicy.cwd,
830832
model: input.modelSelection.model,
831-
// Catalogues can default summaries to "none"; request them explicitly on every turn.
832-
summary: "detailed",
833+
// Catalogues can default summaries to "none", and turn/start overrides the user's config,
834+
// so pass theirs through or `auto`: some providers (Amazon Bedrock) reject `detailed`.
835+
summary: input.configuredReasoningSummary ?? "auto",
833836
// Omitting the reviewer on resume preserves the previous Auto reviewer.
834837
approvalsReviewer: runtimeModeDefaults.approvalsReviewer,
835838
...(approvalPolicy === undefined ? {} : { approvalPolicy }),
@@ -7237,6 +7240,14 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
72377240
) {
72387241
const threadId = yield* getNativeThreadId(turnInput.providerThread);
72397242
const mcpSession = yield* mcpSessions.read(turnInput.threadId);
7243+
const configuredReasoningSummary = yield* client
7244+
.request("config/read", { cwd: turnInput.runtimePolicy.cwd, includeLayers: false })
7245+
.pipe(
7246+
Effect.map((response) => response.config.model_reasoning_summary ?? undefined),
7247+
Effect.catch(() =>
7248+
Effect.logDebug("Codex config read failed.").pipe(Effect.as(undefined)),
7249+
),
7250+
);
72407251
const turnStartParams = yield* buildCodexTurnStartParams({
72417252
nativeThreadId: threadId,
72427253
codexInput,
@@ -7247,6 +7258,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
72477258
deviceToolsAvailable: mcpSession?.capabilities?.has("device") ?? false,
72487259
omitServiceTier: adapterOptions.resolveRuntime !== undefined,
72497260
...(turnInput.appContext === undefined ? {} : { appContext: turnInput.appContext }),
7261+
...(configuredReasoningSummary === undefined ? {} : { configuredReasoningSummary }),
72507262
});
72517263
yield* Ref.update(pendingRootTurns, (current) => {
72527264
const updated = new Map(current);

0 commit comments

Comments
 (0)