Skip to content

Commit d5d4874

Browse files
feat(codex): require Codex 0.156 and regenerate its protocol (#13481)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 567783e commit d5d4874

14 files changed

Lines changed: 14830 additions & 3042 deletions

File tree

‎apps/server/src/provider/Layers/CodexAdapter.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,7 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
23832383
method: "item/tool/requestUserInput",
23842384
requestId: ApprovalRequestId.make("req-user-input-1"),
23852385
payload: {
2386+
isBlocking: true,
23862387
itemId: "item-user-input-1",
23872388
threadId: "thread-1",
23882389
turnId: "turn-1",

‎apps/server/src/provider/Layers/CodexProvider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
441441
requestAllCodexModels(client),
442442
// Usage is an enrichment: a failure or a slow answer degrades to "no
443443
// usage this probe" rather than costing the account and models.
444-
client.request("account/rateLimits/read", undefined).pipe(
444+
client.request("account/rateLimits/read", null).pipe(
445445
Effect.map((response): CodexRateLimitsProbe => ({
446446
snapshot: response.rateLimits,
447447
rateLimitsByLimitId: response.rateLimitsByLimitId,

‎apps/server/src/provider/Layers/CodexSessionRuntime.test.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,28 @@ describe("Codex thread history", () => {
9090
);
9191
}
9292

93-
it.effect("keeps the count-based rollback API for older threads", () =>
93+
it.effect("surfaces Codex rejecting a revert of a legacy thread", () =>
9494
Effect.gen(function* () {
95+
const rejection = CodexErrors.CodexAppServerRequestError.invalidRequest(
96+
"thread/revert only supports paginated threads",
97+
);
9598
const client: Parameters<typeof rollbackCodexThread>[0] = {
96-
raw: { request: () => Effect.succeed({ thread: {} }) },
97-
request: <M extends CodexRpc.ClientRequestMethod>(
98-
method: M,
99-
params: CodexRpc.ClientRequestParamsByMethod[M],
100-
) => {
101-
NodeAssert.equal(method, "thread/rollback");
102-
NodeAssert.deepEqual(params, { threadId: "legacy-thread", numTurns: 2 });
99+
raw: {
100+
request: (method) => {
101+
if (method === "thread/read") return Effect.succeed({ thread: {} });
102+
if (method === "thread/revert") return Effect.fail(rejection);
103+
return Effect.die(`Unexpected raw request: ${method}`);
104+
},
105+
},
106+
request: <M extends CodexRpc.ClientRequestMethod>(method: M) => {
107+
NodeAssert.equal(method, "thread/read");
103108
return Effect.succeed({
104-
thread: { id: "legacy-thread", turns: [] },
109+
thread: { id: "legacy-thread", turns: [{ id: "turn-1", items: [] }] },
105110
} as unknown as CodexRpc.ClientRequestResponsesByMethod[M]);
106111
},
107112
};
108-
NodeAssert.deepEqual(yield* rollbackCodexThread(client, "legacy-thread", 2), {
109-
threadId: "legacy-thread",
110-
turns: [],
111-
});
113+
const error = yield* Effect.flip(rollbackCodexThread(client, "legacy-thread", 1));
114+
NodeAssert.strictEqual(error, rejection);
112115
}),
113116
);
114117
});
@@ -680,6 +683,7 @@ function makeThreadStartedNotification(
680683
id: threadId,
681684
modelProvider: "openai",
682685
preview: "",
686+
projectId: null,
683687
sessionId: threadId,
684688
source,
685689
status: { type: "idle" as const },

‎apps/server/src/provider/Layers/CodexSessionRuntime.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ export type CodexTurnStartParamsWithCollaborationMode =
163163
export type CodexResumeCursor = typeof CodexResumeCursorSchema.Type;
164164
type CodexServiceTier = NonNullable<EffectCodexSchema.V2ThreadStartParams["serviceTier"]>;
165165
type CodexThreadItem =
166-
| EffectCodexSchema.V2ThreadReadResponse["thread"]["turns"][number]["items"][number]
167-
| EffectCodexSchema.V2ThreadRollbackResponse["thread"]["turns"][number]["items"][number];
166+
EffectCodexSchema.V2ThreadReadResponse["thread"]["turns"][number]["items"][number];
168167

169168
export interface CodexSessionRuntimeOptions {
170169
readonly threadId: ThreadId;
@@ -1185,7 +1184,7 @@ function updateSession(
11851184
}
11861185

11871186
function parseThreadSnapshot(
1188-
response: EffectCodexSchema.V2ThreadReadResponse | EffectCodexSchema.V2ThreadRollbackResponse,
1187+
response: EffectCodexSchema.V2ThreadReadResponse,
11891188
): CodexThreadSnapshot {
11901189
return {
11911190
threadId: response.thread.id,
@@ -1273,11 +1272,8 @@ export const rollbackCodexThread = Effect.fn("rollbackCodexThread")(function* (
12731272
threadId: string,
12741273
numTurns: number,
12751274
): Effect.fn.Return<CodexThreadSnapshot, CodexErrors.CodexAppServerError> {
1276-
if ((yield* readCodexHistoryMode(client, threadId)) !== "paginated") {
1277-
return parseThreadSnapshot(yield* client.request("thread/rollback", { threadId, numTurns }));
1278-
}
1279-
// Paginated threads replace history at a turn boundary instead of supporting
1280-
// the legacy count-based rollback endpoint.
1275+
// Codex replaces history at a turn boundary. It rejects threads that still
1276+
// use legacy history, which have no rollback API since Codex 0.156.
12811277
const snapshot = yield* readCodexThread(client, threadId);
12821278
const retainedCount = Math.max(0, snapshot.turns.length - numTurns);
12831279
const firstRemoved = snapshot.turns[retainedCount];

‎apps/server/src/provider/model-manifest.json‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"version": 1,
3-
"updatedAt": "2026-09-24T00:11:29Z",
3+
"updatedAt": "2026-09-24T18:40:00Z",
44
"compatibility": [
55
{
66
"driver": "codex",
77
"t3CodeRange": ">=0.0.42",
8-
"recommendedRange": ">=0.129.0",
8+
"recommendedRange": ">=0.156.0",
99
"ranges": [
10-
{ "range": ">=0.129.0", "status": "supported" },
11-
{ "range": "<0.129.0", "status": "broken" }
10+
{ "range": ">=0.156.0", "status": "supported" },
11+
{ "range": ">=0.149.0 <0.156.0", "status": "unsupported" },
12+
{ "range": "<0.149.0", "status": "broken" }
1213
]
1314
},
1415
{

‎apps/server/src/provider/providerCompatibility.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ describe("provider compatibility", () => {
6565
}
6666
});
6767

68+
it("supports Codex 0.156 and marks Codex without Thread.projectId broken", () => {
69+
const bundled = ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility;
70+
for (const [t3CodeVersion, codexVersion, expected] of [
71+
["0.0.42", "0.148.0", "broken"],
72+
["0.0.42", "0.149.0", "unsupported"],
73+
["0.0.42", "0.155.0", "unsupported"],
74+
["0.0.42", "0.156.0", "supported"],
75+
["0.0.43-nightly.20260924.2200", "0.153.3", "unsupported"],
76+
["0.0.43-nightly.20260924.2200", "0.156.1", "supported"],
77+
] as const) {
78+
assert.strictEqual(
79+
resolveProviderCompatibility(bundled, driver, codexVersion, t3CodeVersion)?.status,
80+
expected,
81+
`T3 Code ${t3CodeVersion} with Codex ${codexVersion}`,
82+
);
83+
}
84+
});
85+
6886
it("compares Cursor build dates without treating semver prereleases as stable", () => {
6987
const cursor = ProviderDriverKind.make("cursor");
7088
const cursorPolicy: ProviderCompatibilityPolicy = {

‎apps/server/src/provider/testFixtures/codexMultiAgentWire.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"forkedFromId": null,
2121
"parentThreadId": null,
2222
"preview": "",
23+
"projectId": null,
2324
"ephemeral": false,
2425
"historyMode": "legacy",
2526
"modelProvider": "openai",
@@ -389,6 +390,7 @@
389390
"forkedFromId": null,
390391
"parentThreadId": null,
391392
"preview": "",
393+
"projectId": null,
392394
"ephemeral": false,
393395
"historyMode": "legacy",
394396
"modelProvider": "openai",

‎packages/effect-codex-app-server/scripts/generate.ts‎

Lines changed: 6 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from "effect/unstable/http";
1818
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
1919

20-
const UPSTREAM_REF = "678157acaa819d5510adfe359abb5d0392cfe461";
20+
const UPSTREAM_REF = "fe74a774532af67b5a4a3dec03ce9469e17f89af";
2121
const USER_AGENT = "effect-codex-app-server-generator";
2222
const GITHUB_API_BASE =
2323
"https://api.github.com/repos/openai/codex/contents/codex-rs/app-server-protocol";
@@ -145,112 +145,6 @@ const ManualSchemas: Record<string, Schema.Json> = {
145145
},
146146
};
147147

148-
// Codex 0.150 added these multi-agent values before our next full protocol
149-
// refresh. Keep every generated response namespace compatible with them.
150-
const Codex0150DefinitionSchemas: Record<string, Schema.Json> = {
151-
CollabAgentTool: {
152-
type: "string",
153-
enum: [
154-
"spawnAgent",
155-
"sendInput",
156-
"resumeAgent",
157-
"wait",
158-
"closeAgent",
159-
"sendMessage",
160-
"followupTask",
161-
"interruptAgent",
162-
"listAgents",
163-
],
164-
},
165-
CollabAgentToolCallStatus: {
166-
type: "string",
167-
enum: ["inProgress", "completed", "failed", "interrupted"],
168-
},
169-
PlanType: {
170-
type: "string",
171-
enum: [
172-
"free",
173-
"go",
174-
"plus",
175-
"pro",
176-
"prolite",
177-
"team",
178-
"self_serve_business_prolite",
179-
"self_serve_business_usage_based",
180-
"business",
181-
"ent26",
182-
"enterprise_cbp_automation",
183-
"enterprise_cbp_usage_based",
184-
"enterprise",
185-
"edu",
186-
"edu_plus",
187-
"edu_pro",
188-
"unknown",
189-
],
190-
},
191-
SubAgentActivityKind: {
192-
type: "string",
193-
enum: ["started", "interacted", "interrupted", "completed"],
194-
},
195-
};
196-
197-
// Pinned protocol JSON omits later CodexErrorInfo variants. Keep historical
198-
// thread payloads decodable; do not fold unknown values into "other".
199-
const CodexErrorInfoCompatibilityValues = [
200-
"rateLimitExceeded",
201-
"misalignmentPolicyViolation",
202-
] as const;
203-
204-
const CodexErrorInfoCompatibilityExports = new Set([
205-
"V2ThreadReadResponse",
206-
"V2ThreadResumeResponse",
207-
"V2ThreadRollbackResponse",
208-
"V2ThreadForkResponse",
209-
"V2TurnCompletedNotification",
210-
]);
211-
212-
function applyCodex0151DefinitionCompatibility(
213-
exportName: string,
214-
definitionName: string,
215-
definitionSchema: Schema.Json,
216-
): Schema.Json {
217-
if (
218-
!CodexErrorInfoCompatibilityExports.has(exportName) ||
219-
definitionName !== "CodexErrorInfo" ||
220-
typeof definitionSchema !== "object"
221-
) {
222-
return definitionSchema;
223-
}
224-
225-
const schema = definitionSchema as {
226-
readonly oneOf?: ReadonlyArray<{ readonly enum?: ReadonlyArray<string> }>;
227-
};
228-
const [firstVariant, ...remainingVariants] = schema.oneOf ?? [];
229-
const currentEnum = firstVariant?.enum;
230-
if (!currentEnum) {
231-
return definitionSchema;
232-
}
233-
234-
const missingValues = CodexErrorInfoCompatibilityValues.filter(
235-
(value) => !currentEnum.includes(value),
236-
);
237-
if (missingValues.length === 0) {
238-
return definitionSchema;
239-
}
240-
241-
const enumValues = [...currentEnum];
242-
const otherIndex = enumValues.indexOf("other");
243-
const nextEnum =
244-
otherIndex === -1
245-
? [...enumValues, ...missingValues]
246-
: [...enumValues.slice(0, otherIndex), ...missingValues, ...enumValues.slice(otherIndex)];
247-
248-
return {
249-
...definitionSchema,
250-
oneOf: [{ ...firstVariant, enum: nextEnum }, ...remainingVariants],
251-
};
252-
}
253-
254148
const getGeneratedPaths = Effect.fn("getGeneratedPaths")(function* () {
255149
const path = yield* Path.Path;
256150
const generatedDir = path.join(import.meta.dirname, "..", "src", "_generated");
@@ -470,61 +364,6 @@ function adaptSchemaForEffect(value: Schema.Json): Schema.Json {
470364
};
471365
}
472366

473-
// Codex 0.153 adds async questions to agent messages. Keep older protocol
474-
// fields until the next full refresh, including every thread history namespace.
475-
function addAsyncQuestionFields(value: Schema.Json): Schema.Json {
476-
if (Array.isArray(value)) {
477-
return value.map(addAsyncQuestionFields);
478-
}
479-
if (value === null || typeof value !== "object") {
480-
return value;
481-
}
482-
const properties = "properties" in value ? value.properties : undefined;
483-
const itemType =
484-
properties && typeof properties === "object" && "type" in properties
485-
? properties.type
486-
: undefined;
487-
if (
488-
properties &&
489-
typeof properties === "object" &&
490-
itemType &&
491-
typeof itemType === "object" &&
492-
"enum" in itemType &&
493-
Array.isArray(itemType.enum) &&
494-
itemType.enum.includes("agentMessage")
495-
) {
496-
return {
497-
...value,
498-
properties: {
499-
...Object.fromEntries(Object.entries(properties).filter(([key]) => key !== "type")),
500-
delivery: { anyOf: [{ type: "string", enum: ["async"] }, { type: "null" }] },
501-
questions: {
502-
anyOf: [
503-
{
504-
type: "array",
505-
items: {
506-
type: "object",
507-
properties: {
508-
title: { type: "string" },
509-
options: {
510-
anyOf: [{ type: "array", items: { type: "string" } }, { type: "null" }],
511-
},
512-
},
513-
required: ["title"],
514-
},
515-
},
516-
{ type: "null" },
517-
],
518-
},
519-
type: itemType,
520-
},
521-
};
522-
}
523-
return Object.fromEntries(
524-
Object.entries(value).map(([key, child]) => [key, addAsyncQuestionFields(child)]),
525-
);
526-
}
527-
528367
function toPascalCaseMethod(method: string) {
529368
return method
530369
.split("/")
@@ -536,13 +375,14 @@ function toPascalCaseMethod(method: string) {
536375
}
537376

538377
function parseRequestEntries(fileContents: string): ReadonlyArray<MethodEntry> {
539-
const entryPattern = /\{\s*"method":\s*"([^"]+)",\s*id:\s*RequestId,\s*params:\s*([^,}]+)/g;
378+
// Optional params render as `params?: Foo | undefined`; their JSON schema is `NullableFoo`.
379+
const entryPattern = /\{\s*"method":\s*"([^"]+)",\s*id:\s*RequestId,\s*params(\??):\s*([^,}|]+)/g;
540380
const entries: Array<MethodEntry> = [];
541381
let match: RegExpExecArray | null;
542382
while ((match = entryPattern.exec(fileContents)) !== null) {
543383
entries.push({
544384
method: match[1]!,
545-
paramsType: match[2]!.trim(),
385+
paramsType: `${match[2] ? "Nullable" : ""}${match[3]!.trim()}`,
546386
});
547387
}
548388
return entries;
@@ -800,13 +640,10 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
800640
);
801641

802642
for (const [definitionName, definitionSchema] of Object.entries(parsed.definitions ?? {})) {
803-
const compatibleDefinitionSchema =
804-
Codex0150DefinitionSchemas[definitionName] ??
805-
applyCodex0151DefinitionCompatibility(file.exportName, definitionName, definitionSchema);
806643
aggregateSchemas[localDefinitionNames.get(definitionName)!] = stripNullDefaults(
807644
normalizeNullableTypes(
808645
rewriteExternalRefs(
809-
compatibleDefinitionSchema,
646+
definitionSchema,
810647
localDefinitionNames,
811648
file.namespace,
812649
exportNameByQualifiedName,
@@ -844,7 +681,7 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
844681
for (const [name, schema] of Object.entries(aggregateSchemas).toSorted(([left], [right]) =>
845682
left.localeCompare(right),
846683
)) {
847-
aggregateSchemas[name] = adaptSchemaForEffect(addAsyncQuestionFields(schema));
684+
aggregateSchemas[name] = adaptSchemaForEffect(schema);
848685
generator.addSchema(name, aggregateSchemas[name] as never);
849686
}
850687

0 commit comments

Comments
 (0)