TypeScript
fix(server): native Codex subagents no longer show the parent's reasoning effort (#24467)
Koushik_xdef515949d0c1
diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsindex 69fca8c0825..19eb2a1e239 100644--- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts+++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts@@ -16,6 +16,7 @@ import {type OrchestrationV2ProviderThread,type OrchestrationV2ProviderTurn,type OrchestrationV2RuntimeRequest,+ type OrchestrationV2Subagent,type OrchestrationV2TurnItem,ProjectId,type ProviderApprovalDecision,@@ -566,6 +567,7 @@ function codexReplayPreamble(input: {readonly nativeTurnId: string;readonly prompt: string;readonly sentPrompt?: string;+ readonly effort?: string;}): Array<CodexReplay.CodexAppServerReplayEntry> {return [{@@ -664,7 +666,14 @@ function codexReplayPreamble(input: {approvalsReviewer: "user",sandboxPolicy: { type: "dangerFullAccess" },summary: "detailed",- collaborationMode: { mode: "default", settings: { model: "gpt-5.4" } },+ ...(input.effort === undefined ? {} : { effort: input.effort }),+ collaborationMode: {+ mode: "default",+ settings: {+ model: "gpt-5.4",+ ...(input.effort === undefined ? {} : { reasoning_effort: input.effort }),+ },+ },},},},@@ -6211,6 +6220,101 @@ describe("CodexAdapterV2 post-settle continuation", () => {),);+ it.effect.each(["activity", "spawn", "activity then spawn"] as const)(+ "creates a child from %s without the parent's effort",+ (source) =>+ Effect.scoped(+ Effect.gen(function* () {+ const created = yield* Deferred.make<OrchestrationV2AppThread>();+ const completed = yield* Deferred.make<OrchestrationV2Subagent>();+ const activity = {+ type: "subAgentActivity",+ id: "call-codex-resume-spawn",+ kind: "started",+ agentThreadId: RESUME_CHILD_THREAD,+ agentPath: "/root/resume_agent",+ };+ const spawn = {+ type: "collabAgentToolCall",+ id: "call-codex-resume-spawn",+ tool: "spawnAgent",+ status: "completed",+ senderThreadId: RESUME_NATIVE_THREAD,+ receiverThreadIds: [RESUME_CHILD_THREAD],+ model: "gpt-5.4",+ reasoningEffort: "high",+ agentsStates: { [RESUME_CHILD_THREAD]: { status: "completed", message: "finished" } },+ };+ const items =+ source === "activity" ? [activity] : source === "spawn" ? [spawn] : [activity, spawn];+ const harness = yield* makeCodexReplayHarness(+ makeCodexReplayTranscript({+ scenario: RESUME_SCENARIO,+ entries: [+ ...codexReplayPreamble({+ nativeThreadId: RESUME_NATIVE_THREAD,+ nativeTurnId: RESUME_NATIVE_TURN,+ prompt: RESUME_PROMPT,+ effort: "low",+ }),+ ...items.map((item) => ({+ type: "emit_inbound" as const,+ frame: {+ method: "item/completed",+ params: {+ item,+ threadId: RESUME_NATIVE_THREAD,+ turnId: RESUME_NATIVE_TURN,+ completedAtMs: 1782622441000,+ },+ },+ })),+ ],+ }),+ (event) =>+ event.type === "app_thread.created"+ ? Deferred.succeed(created, event.appThread)+ : event.type === "subagent.updated" && event.subagent.status === "completed"+ ? Deferred.succeed(completed, event.subagent)+ : Effect.void,+ );+ yield* harness.runtime.startTurn({+ ...makeCodexTestTurnInput({+ threadId: harness.threadId,+ providerThread: harness.providerThread,+ now: yield* DateTime.now,+ attemptId: RunAttemptId.make("attempt-child-effort"),+ text: RESUME_PROMPT,+ }),+ modelSelection: {+ ...CODEX_TEST_MODEL_SELECTION,+ options: [{ id: "reasoningEffort", value: "low" }],+ },+ });+ const child = yield* Deferred.await(created);+ assert.equal(+ child.modelSelection.options?.find(({ id }) => id === "reasoningEffort")?.value,+ source === "spawn" ? "high" : undefined,+ );+ if (source !== "activity") {+ const task = yield* Deferred.await(completed);+ assert.equal(+ task.modelSelection?.options?.find(({ id }) => id === "reasoningEffort")?.value,+ "high",+ );+ assert.lengthOf(+ harness.events.filter((event) => event.type === "app_thread.created"),+ 1,+ );+ }+ }).pipe(+ Effect.provide(+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),+ ),+ ),+ ),+ );+it.effect("preserves a subagent result across a trailing empty final and resume", () =>Effect.scoped(Effect.gen(function* () {diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsindex 58cd4a0c0c1..51796da166e 100644--- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts+++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts@@ -2717,9 +2717,6 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (readonly emitInitialPrompt: boolean;}) {const registeredSubagents = yield* Ref.get(subagentThreads);- if (registeredSubagents.has(input.nativeThreadId)) {- return;- }if (input.model && !subagentSelections.has(input.nativeThreadId)) {yield* updateSubagentSelection(input.nativeThreadId,@@ -2727,6 +2724,9 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (input.reasoningEffort,);}+ if (registeredSubagents.has(input.nativeThreadId)) {+ return;+ }const now = yield* DateTime.now;const subagentNodeId = idAllocator.derive.nodeFromProviderItem({@@ -2803,9 +2803,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (parentNodeId: subagentNodeId,activeProviderThreadId: providerThread.id,providerInstanceId: input.context.input.modelSelection.instanceId,- modelSelection: {+ // A child's effort can differ from the parent's. Until Codex reports it, show none.+ modelSelection: task.modelSelection ?? {...input.context.input.modelSelection,model: task.model ?? input.context.input.modelSelection.model,+ options: (input.context.input.modelSelection.options ?? []).filter(+ ({ id }) => id !== "reasoningEffort",+ ),},title: subagentThreadTitle({parentTitle: input.context.projectionAppThread.title,