Skip to content

Commit c79ef8c

Browse files
t3dotggclaude
andauthored
fix(server): use Codex native collaboration modes (#24737)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent c83342d commit c79ef8c

33 files changed

Lines changed: 100 additions & 229 deletions

File tree

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,40 @@ describe("CodexAdapterV2 assistant message streaming", () => {
134134
});
135135

136136
describe("CodexAdapterV2 runtime policy", () => {
137+
it.effect.each([undefined, false, true])(
138+
"selects native collaboration modes without prompt overrides with hasT3Mcp=%s",
139+
(hasT3Mcp) =>
140+
Effect.gen(function* () {
141+
for (const interactionMode of ["plan", "default"] as const) {
142+
for (const reasoningEffort of [undefined, "high"] as const) {
143+
const params = yield* CodexAdapterV2.buildCodexTurnStartParams({
144+
nativeThreadId: "native-mode-switch",
145+
codexInput: [{ type: "text", text: "test" }],
146+
runtimePolicy: { runtimeMode: "full-access", interactionMode, cwd: null },
147+
modelSelection: {
148+
instanceId: ProviderInstanceId.make("codex"),
149+
model: "gpt-5.4",
150+
...(reasoningEffort === undefined
151+
? {}
152+
: { options: [{ id: "reasoningEffort", value: reasoningEffort }] }),
153+
},
154+
...(hasT3Mcp === undefined ? {} : { hasT3Mcp }),
155+
});
156+
157+
assert.deepEqual(params.collaborationMode, {
158+
mode: interactionMode,
159+
settings: {
160+
model: "gpt-5.4",
161+
...(reasoningEffort === undefined ? {} : { reasoning_effort: reasoningEffort }),
162+
},
163+
});
164+
assert.equal(params.effort, reasoningEffort);
165+
assert.equal(params.additionalContext !== undefined, hasT3Mcp === true);
166+
}
167+
}
168+
}),
169+
);
170+
137171
it.effect("derives concrete Codex turn policies from every T3 runtime mode", () =>
138172
Effect.gen(function* () {
139173
const build = (
@@ -620,6 +654,7 @@ function codexReplayPreamble(input: {
620654
approvalsReviewer: "user",
621655
sandboxPolicy: { type: "dangerFullAccess" },
622656
summary: "detailed",
657+
collaborationMode: { mode: "default", settings: { model: "gpt-5.4" } },
623658
},
624659
},
625660
},
@@ -1514,6 +1549,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
15141549
model: "gpt-5.4",
15151550
...turnPolicies[turnModes[index]!],
15161551
summary: "detailed",
1552+
collaborationMode: { mode: "default", settings: { model: "gpt-5.4" } },
15171553
},
15181554
},
15191555
},

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ import { resolveAttachmentPath, resolveAttachmentPathById } from "../../attachme
9898
import { getCodexServiceTierOptionValue } from "../../codexModelOptions.ts";
9999
import { ServerConfig } from "../../config.ts";
100100
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
101-
import {
102-
buildCodexAdditionalContext,
103-
buildCodexDeveloperInstructions,
104-
} from "../../provider/CodexDeveloperInstructions.ts";
101+
import { buildCodexAdditionalContext } from "../../provider/CodexDeveloperInstructions.ts";
105102
import {
106103
describeMcpElicitation,
107104
toMcpElicitationResponse,
@@ -756,10 +753,6 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
756753
input.omitServiceTier === true
757754
? undefined
758755
: getCodexServiceTierOptionValue(input.modelSelection);
759-
const developerInstructions =
760-
input.hasT3Mcp !== true
761-
? undefined
762-
: buildCodexDeveloperInstructions(input.runtimePolicy.interactionMode);
763756
// MCP-written app context must be quoted user input, not developer instructions.
764757
const appContext = Object.fromEntries(
765758
(input.appContext ?? []).map((entry) => [
@@ -781,21 +774,6 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
781774
t3Context === undefined && Object.keys(appContext).length === 0
782775
? undefined
783776
: { ...t3Context, ...appContext };
784-
const collaborationMode: CodexSchema.ClientRequest__CollaborationMode | undefined =
785-
input.runtimePolicy.interactionMode !== "plan" && developerInstructions === undefined
786-
? undefined
787-
: {
788-
mode: input.runtimePolicy.interactionMode === "plan" ? "plan" : "default",
789-
settings: {
790-
model: input.modelSelection.model,
791-
// Codex falls back to the model's default effort when this is left out.
792-
...(effort === undefined ? {} : { reasoning_effort: effort }),
793-
...(developerInstructions === undefined
794-
? {}
795-
: { developer_instructions: developerInstructions }),
796-
},
797-
};
798-
799777
return yield* decodeCodexTurnStartParamsWithCollaborationMode({
800778
threadId: input.nativeThreadId,
801779
input: input.codexInput,
@@ -810,7 +788,14 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
810788
...(sandboxPolicy === undefined ? {} : { sandboxPolicy }),
811789
...(effort === undefined ? {} : { effort }),
812790
...(serviceTier === undefined ? {} : { serviceTier }),
813-
...(collaborationMode === undefined ? {} : { collaborationMode }),
791+
// Codex supplies its own mode instructions; send both modes to clear Plan on exit.
792+
collaborationMode: {
793+
mode: input.runtimePolicy.interactionMode,
794+
settings: {
795+
model: input.modelSelection.model,
796+
...(effort === undefined ? {} : { reasoning_effort: effort }),
797+
},
798+
},
814799
});
815800
},
816801
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{"type":"expect_outbound","label":"thread/start","frame":{"id":2,"method":"thread/start","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000},"cwd":"<workspace>","model":"gpt-6-luna"}}}
66
{"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":1791001627148}}
77
{"type":"emit_inbound","label":"thread/start","frame":{"id":2,"result":{"thread":{"id":"01a10004-0a27-7421-852d-0f7f99ace2d6","environments":[{"environmentId":"local","cwd":"/home/replay-user/t3code/apps/server","runtimeWorkspaceRoots":["/home/replay-user/t3code/apps/server"]}],"extra":null,"sessionId":"01a10004-0a27-7421-852d-0f7f99ace2d6","forkedFromId":null,"parentThreadId":null,"preview":"","ephemeral":false,"section":null,"sectionEnteredAt":null,"projectId":null,"historyMode":"paginated","modelProvider":"cpa","model":"gpt-6-luna","reasoningEffort":null,"createdAt":1791001627,"updatedAt":1791001627,"recencyAt":1791001627,"status":{"type":"idle"},"path":"/home/replay-user/.codex/sessions/2026/10/03/rollout-2026-10-03T00-27-07-01a10004-0a27-7421-852d-0f7f99ace2d6.jsonl","cwd":"/home/replay-user/t3code/apps/server","cliVersion":"0.157.0","originator":"T3 Code","source":"vscode","canAcceptDirectInput":true,"threadSource":null,"agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"daybreakEnabled":null,"turns":[]},"model":"gpt-6-luna","modelProvider":"cpa","serviceTier":"default","disabledPluginIds":[],"cwd":"/home/replay-user/t3code/apps/server","runtimeWorkspaceRoots":["/home/replay-user/t3code/apps/server"],"instructionSources":["/home/replay-user/.codex/AGENTS.md","/home/replay-user/t3code/AGENTS.md"],"approvalPolicy":"on-request","approvalsReviewer":"user","sandbox":{"type":"readOnly","networkAccess":false},"activePermissionProfile":{"id":":read-only","extends":null},"reasoningEffort":null,"multiAgentMode":"explicitRequestOnly"}}}
8-
{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","approvalsReviewer":"user","cwd":"<workspace>","input":[{"text":"Run this exact shell command in the foreground and wait for it to finish: `for i in 1 2 3 4; do printf '\\033[32mstream line %s\\033[0m\\n' $i; sleep 1; done; printf 'progress 50%%\\rprogress 100%%\\n'`. Then respond exactly: command output fixture complete","type":"text"}],"model":"gpt-6-luna","sandboxPolicy":{"networkAccess":false,"type":"workspaceWrite","writableRoots":[]},"summary":"detailed","threadId":"01a10004-0a27-7421-852d-0f7f99ace2d6"}}}
8+
{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","approvalsReviewer":"user","cwd":"<workspace>","input":[{"text":"Run this exact shell command in the foreground and wait for it to finish: `for i in 1 2 3 4; do printf '\\033[32mstream line %s\\033[0m\\n' $i; sleep 1; done; printf 'progress 50%%\\rprogress 100%%\\n'`. Then respond exactly: command output fixture complete","type":"text"}],"model":"gpt-6-luna","sandboxPolicy":{"networkAccess":false,"type":"workspaceWrite","writableRoots":[]},"summary":"detailed","threadId":"01a10004-0a27-7421-852d-0f7f99ace2d6","collaborationMode":{"mode":"default","settings":{"model":"gpt-6-luna"}}}}}
99
{"type":"emit_inbound","label":"thread/started","frame":{"method":"thread/started","params":{"thread":{"id":"01a10004-0a27-7421-852d-0f7f99ace2d6","environments":[{"environmentId":"local","cwd":"/home/replay-user/t3code/apps/server","runtimeWorkspaceRoots":["/home/replay-user/t3code/apps/server"]}],"extra":null,"sessionId":"01a10004-0a27-7421-852d-0f7f99ace2d6","forkedFromId":null,"parentThreadId":null,"preview":"","ephemeral":false,"section":null,"sectionEnteredAt":null,"projectId":null,"historyMode":"paginated","modelProvider":"cpa","model":"gpt-6-luna","reasoningEffort":null,"createdAt":1791001627,"updatedAt":1791001627,"recencyAt":1791001627,"status":{"type":"idle"},"path":"/home/replay-user/.codex/sessions/2026/10/03/rollout-2026-10-03T00-27-07-01a10004-0a27-7421-852d-0f7f99ace2d6.jsonl","cwd":"/home/replay-user/t3code/apps/server","cliVersion":"0.157.0","originator":"T3 Code","source":"vscode","canAcceptDirectInput":true,"threadSource":null,"agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"daybreakEnabled":null,"turns":[]}},"emittedAtMs":1791001627410}}
1010
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a10004-0a27-7421-852d-0f7f99ace2d6","name":"cua_repl","status":"starting","error":null,"failureReason":null},"emittedAtMs":1791001627411}}
1111
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a10004-0a27-7421-852d-0f7f99ace2d6","name":"codex_apps","status":"starting","error":null,"failureReason":null},"emittedAtMs":1791001627411}}

0 commit comments

Comments
 (0)