Skip to content

Commit 24d817f

Browse files
Alb11747codex
andcommitted
fix(server): keep Codex loaded when reasoning effort changes
Codex applies reasoning effort on turn/start. Exclude that option from the loaded native-thread key so an effort-only change does not resume the thread and reset its pinned reasoning baseline. Preserve reloads for other selection and runtime changes. Co-Authored-By: GPT-6.1 Sol at high effort <[email protected]> Co-Authored-By: GPT-6.1 Sol at high effort, implementation subagent for Codex thread reuse <[email protected]> Co-Authored-By: GPT-6.1 Sol at xhigh effort, review subagent for Codex thread reuse <[email protected]>
1 parent 8e6a732 commit 24d817f

2 files changed

Lines changed: 124 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderSessionManager.test.ts‎

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3725,12 +3725,76 @@ it.effect(
37253725
const resumeSecondThread = secondRuntime.resumeThread({
37263726
providerThread: secondProviderThread,
37273727
threadId: secondThreadId,
3728-
modelSelection,
3728+
modelSelection: {
3729+
...modelSelection,
3730+
options: [{ id: "reasoningEffort", value: "medium" }],
3731+
},
37293732
runtimePolicy,
37303733
});
37313734
yield* resumeSecondThread;
37323735
yield* resumeSecondThread;
37333736
assert.equal((yield* Ref.get(state)).resumeCount, 1);
3737+
const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
3738+
const appThread = (yield* projectionStore.getThreadProjection(secondThreadId)).thread;
3739+
const turnEvents = (yield* Ref.get(state)).eventQueues.get(String(providerSessionId));
3740+
assert.isDefined(turnEvents);
3741+
for (const [index, effort] of ["medium", "high", "medium"].entries()) {
3742+
const selection = {
3743+
...modelSelection,
3744+
options: [{ id: "reasoningEffort", value: effort }],
3745+
} satisfies ModelSelection;
3746+
yield* secondRuntime.resumeThread({
3747+
providerThread: secondProviderThread,
3748+
threadId: secondThreadId,
3749+
modelSelection: selection,
3750+
runtimePolicy,
3751+
});
3752+
const ordinal = index + 1;
3753+
const runId = idAllocator.derive.run({ threadId: secondThreadId, ordinal });
3754+
yield* secondRuntime.startTurn({
3755+
appThread,
3756+
threadId: secondThreadId,
3757+
runId,
3758+
runOrdinal: ordinal,
3759+
providerTurnOrdinal: ordinal,
3760+
attemptId: idAllocator.derive.runAttempt({ runId, attemptOrdinal: 1 }),
3761+
rootNodeId: idAllocator.derive.rootNode({ runId }),
3762+
providerThread: secondProviderThread,
3763+
message: {
3764+
createdBy: "user",
3765+
creationSource: "web",
3766+
messageId: yield* idAllocator.allocate.message({
3767+
threadId: secondThreadId,
3768+
ordinal,
3769+
}),
3770+
text: "turn",
3771+
attachments: [],
3772+
},
3773+
modelSelection: selection,
3774+
runtimePolicy,
3775+
});
3776+
const subscription = yield* secondRuntime.subscribeEvents!;
3777+
const terminal = yield* subscription.events.pipe(
3778+
Stream.filter((event) => event.type === "turn.terminal"),
3779+
Stream.runHead,
3780+
Effect.forkScoped,
3781+
);
3782+
yield* Queue.offer(turnEvents!, {
3783+
type: "turn.terminal",
3784+
driver: CODEX_DRIVER,
3785+
providerThreadId: secondProviderThread.id,
3786+
providerTurnId: idAllocator.derive.providerTurn({
3787+
driver: CODEX_DRIVER,
3788+
nativeTurnId: `native-effort-turn-${ordinal}`,
3789+
}),
3790+
runOrdinal: ordinal,
3791+
status: "completed",
3792+
failure: null,
3793+
threadDisposition: "reusable",
3794+
});
3795+
yield* Fiber.join(terminal);
3796+
assert.equal((yield* Ref.get(state)).resumeCount, 1, `${effort} effort reloaded Codex`);
3797+
}
37343798
yield* secondRuntime.resumeThread({
37353799
providerThread: secondProviderThread,
37363800
threadId: secondThreadId,
@@ -3780,6 +3844,54 @@ it.effect(
37803844

37813845
assert.deepEqual((yield* Ref.get(state)).unloadedNativeThreadIds, ["native-thread"]);
37823846

3847+
const otherDriver = ProviderDriverKind.make("claudeAgent");
3848+
const otherProviderThread = {
3849+
...secondProviderThread,
3850+
driver: otherDriver,
3851+
nativeThreadRef: { driver: otherDriver, nativeId: "native-other", strength: "strong" },
3852+
} satisfies OrchestrationV2ProviderThread;
3853+
const reloadCases = [
3854+
{
3855+
name: "other model options",
3856+
providerThread: secondProviderThread,
3857+
selection: {
3858+
...modelSelection,
3859+
options: [{ id: "serviceTier", value: "priority" }],
3860+
},
3861+
policy: runtimePolicy,
3862+
},
3863+
{
3864+
name: "runtime policy",
3865+
providerThread: secondProviderThread,
3866+
selection: modelSelection,
3867+
policy: { ...runtimePolicy, interactionMode: "plan" },
3868+
},
3869+
...["medium", "high"].map((effort) => ({
3870+
name: `non-Codex ${effort} effort`,
3871+
providerThread: otherProviderThread,
3872+
selection: {
3873+
...modelSelection,
3874+
options: [{ id: "reasoningEffort", value: effort }],
3875+
},
3876+
policy: runtimePolicy,
3877+
})),
3878+
] satisfies ReadonlyArray<{
3879+
name: string;
3880+
providerThread: OrchestrationV2ProviderThread;
3881+
selection: ModelSelection;
3882+
policy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
3883+
}>;
3884+
for (const { name, providerThread, selection, policy } of reloadCases) {
3885+
const before = (yield* Ref.get(state)).resumeCount;
3886+
yield* secondRuntime.resumeThread({
3887+
providerThread,
3888+
threadId: secondThreadId,
3889+
modelSelection: selection,
3890+
runtimePolicy: policy,
3891+
});
3892+
assert.equal((yield* Ref.get(state)).resumeCount, before + 1, `${name} did not reload`);
3893+
}
3894+
37833895
yield* manager.detach({ providerSessionId, threadId: firstThreadId });
37843896
assert.isTrue(Option.isSome(yield* manager.get(providerSessionId)));
37853897
assert.equal((yield* Ref.get(state)).closeCount, 0);

‎apps/server/src/orchestration-v2/ProviderSessionManager.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,19 @@ function providerThreadLoadKey(input: {
311311
readonly modelSelection?: ModelSelection;
312312
readonly runtimePolicy?: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
313313
}): string {
314+
let modelSelection = input.modelSelection;
315+
if (input.providerThread.driver === "codex" && modelSelection !== undefined) {
316+
// Codex applies effort on turn/start. Resuming here discards its pinned request effort.
317+
const { options, ...selection } = modelSelection;
318+
const loadOptions = options?.filter((option) => option.id !== "reasoningEffort");
319+
modelSelection = {
320+
...selection,
321+
...(loadOptions?.length ? { options: loadOptions } : {}),
322+
};
323+
}
314324
return JSON.stringify({
315325
providerThread: providerThreadRuntimeKey(input.providerThread),
316-
modelSelection: input.modelSelection ?? null,
326+
modelSelection: modelSelection ?? null,
317327
runtimePolicy: input.runtimePolicy ?? null,
318328
});
319329
}

0 commit comments

Comments
 (0)