@devries-cameron20 / t3code Mirror · read-only / commits / ea6d3fc30f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 08:30 UTC

fix(server): a Codex speed change sent during a running turn reaches Codex (#38130)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Martin committed Nov 17, 2026 at 15:14 UTC ea6d3fc30fb066635f31326f49b85cdee8fbf8d7
5 files changed +145 -1
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+90
@@ -1820,6 +1820,96 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1820 ),
1821 );
1822
1823 + it.effect("a steer that changes the service tier updates Codex's next-turn settings", () =>
1824 + Effect.gen(function* () {
1825 + const nativeThreadId = "steer-tier-thread";
1826 + const nativeTurnId = "steer-tier-turn";
1827 + const harness = yield* makeCodexReplayHarness(
1828 + makeCodexReplayTranscript({
1829 + scenario: "steer-service-tier",
1830 + entries: [
1831 + ...codexReplayPreamble({ nativeThreadId, nativeTurnId, prompt: "Work." }),
1832 + {
1833 + type: "expect_outbound",
1834 + label: "thread/settings/update",
1835 + frame: {
1836 + id: 4,
1837 + method: "thread/settings/update",
1838 + params: { threadId: nativeThreadId, serviceTier: "fast" },
1839 + },
1840 + },
1841 + { type: "emit_inbound", frame: { id: 4, result: {} } },
1842 + {
1843 + type: "expect_outbound",
1844 + label: "turn/steer",
1845 + frame: {
1846 + id: 5,
1847 + method: "turn/steer",
1848 + params: {
1849 + threadId: nativeThreadId,
1850 + expectedTurnId: nativeTurnId,
1851 + input: [{ type: "text", text: "Hurry up." }],
1852 + },
1853 + },
1854 + },
1855 + { type: "emit_inbound", frame: { id: 5, result: { turnId: nativeTurnId } } },
1856 + {
1857 + type: "emit_inbound",
1858 + frame: {
1859 + method: "turn/completed",
1860 + params: {
1861 + threadId: nativeThreadId,
1862 + turn: makeCodexReplayTurn({ id: nativeTurnId, status: "completed" }),
1863 + },
1864 + },
1865 + },
1866 + ],
1867 + }),
1868 + );
1869 + const turnInput = makeCodexTestTurnInput({
1870 + threadId: harness.threadId,
1871 + providerThread: harness.providerThread,
1872 + now: yield* DateTime.now,
1873 + attemptId: RunAttemptId.make("steer-tier-attempt"),
1874 + text: "Work.",
1875 + });
1876 + yield* harness.runtime.startTurn(turnInput);
1877 + yield* harness.until(() =>
1878 + harness.events.some(
1879 + (event) =>
1880 + event.type === "provider_turn.updated" &&
1881 + event.providerTurn.nativeTurnRef?.nativeId === nativeTurnId,
1882 + ),
1883 + );
1884 + const providerTurnId = harness.events.flatMap((event) =>
1885 + event.type === "provider_turn.updated" ? [event.providerTurn.id] : [],
1886 + )[0];
1887 + assert.isDefined(providerTurnId);
1888 + if (providerTurnId === undefined) return;
1889 + yield* harness.runtime.steerTurn({
1890 + ...turnInput,
1891 + providerTurnId,
1892 + modelSelection: {
1893 + ...CODEX_TEST_MODEL_SELECTION,
1894 + options: [{ id: "serviceTier", value: "fast" }],
1895 + },
1896 + message: { ...turnInput.message, text: "Hurry up." },
1897 + });
1898 + yield* harness.firstTerminal;
1899 + assert.equal(harness.terminalEvents()[0]?.status, "completed");
1900 + }).pipe(
1901 + Effect.scoped,
1902 + Effect.provide(
1903 + Layer.mergeAll(
1904 + IdAllocator.layer,
1905 + McpProviderSessions.layer,
1906 + NodeServices.layer,
1907 + NodeCrypto.layer,
1908 + ),
1909 + ),
1910 + ),
1911 + );
1912 +
1913 it.effect("keeps native image views available to the clients", () =>
1914 Effect.gen(function* () {
1915 const nativeThreadId = "image-view-thread";
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+14
@@ -8104,6 +8104,20 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
8104 );
8105 }
8106
8107 + const serviceTier =
8108 + adapterOptions.resolveRuntime === undefined
8109 + ? getCodexServiceTierOptionValue(turnInput.modelSelection)
8110 + : undefined;
8111 + if (serviceTier !== undefined) {
8112 + // turn/steer carries no settings, and the turns Codex starts on its own reuse the thread's.
8113 + yield* client.request("thread/settings/update", { threadId, serviceTier }).pipe(
8114 + Effect.catch((cause) =>
8115 + Effect.logWarning("orchestration-v2.codex-steer-service-tier-failed", {
8116 + cause,
8117 + }),
8118 + ),
8119 + );
8120 + }
8121 const codexInput = yield* toCodexInput(turnInput);
8122 yield* client.request("turn/steer", {
8123 expectedTurnId: activeTurn.nativeTurnId,
packages/effect-codex-app-server/scripts/generate.ts
+21 -1
@@ -66,7 +66,27 @@ class GeneratorError extends Schema.TaggedError<GeneratorError>()("GeneratorErro
66 }
67 }
68
69 +// Codex leaves experimental requests out of its published schema.
70 +const ManualClientRequests: ReadonlyArray<MethodEntry> = [
71 + { method: "thread/settings/update", paramsType: "ThreadSettingsUpdateParams" },
72 +];
73 +
74 const ManualSchemas: Record<string, Schema.Json> = {
75 + ThreadSettingsUpdateParams: {
76 + type: "object",
77 + title: "ThreadSettingsUpdateParams",
78 + properties: {
79 + threadId: { type: "string" },
80 + serviceTier: {
81 + anyOf: [{ type: "string" }, { type: "null" }],
82 + },
83 + },
84 + required: ["threadId"],
85 + },
86 + ThreadSettingsUpdateResponse: {
87 + type: "object",
88 + title: "ThreadSettingsUpdateResponse",
89 + },
90 GetAuthStatusParams: {
91 type: "object",
92 title: "GetAuthStatusParams",
@@ -779,7 +799,7 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
799 `https://raw.githubusercontent.com/openai/codex/${UPSTREAM_REF}/codex-rs/app-server-protocol/schema/typescript/ServerNotification.ts`,
800 );
801
782 - const clientRequestEntries = parseRequestEntries(clientRequestRaw);
802 + const clientRequestEntries = [...parseRequestEntries(clientRequestRaw), ...ManualClientRequests];
803 const clientNotificationEntries = parseNotificationEntries(clientNotificationRaw);
804 const serverRequestEntries = parseRequestEntries(serverRequestRaw);
805 const serverNotificationEntries = parseNotificationEntries(serverNotificationRaw);
packages/effect-codex-app-server/src/_generated/meta.gen.ts
+5
@@ -108,6 +108,7 @@ export const CLIENT_REQUEST_METHODS = {
108 gitDiffToRemote: "gitDiffToRemote",
109 getAuthStatus: "getAuthStatus",
110 fuzzyFileSearch: "fuzzyFileSearch",
111 + "thread/settings/update": "thread/settings/update",
112 } as const;
113
114 export const CLIENT_NOTIFICATION_METHODS = {
@@ -328,6 +329,7 @@ export interface ClientRequestParamsByMethod {
329 readonly gitDiffToRemote: CodexSchema.GitDiffToRemoteParams;
330 readonly getAuthStatus: CodexSchema.GetAuthStatusParams;
331 readonly fuzzyFileSearch: CodexSchema.FuzzyFileSearchParams;
332 + readonly "thread/settings/update": CodexSchema.ThreadSettingsUpdateParams;
333 }
334
335 export interface ClientRequestResponsesByMethod {
@@ -438,6 +440,7 @@ export interface ClientRequestResponsesByMethod {
440 readonly gitDiffToRemote: CodexSchema.GitDiffToRemoteResponse;
441 readonly getAuthStatus: CodexSchema.GetAuthStatusResponse;
442 readonly fuzzyFileSearch: CodexSchema.FuzzyFileSearchResponse;
443 + readonly "thread/settings/update": CodexSchema.ThreadSettingsUpdateResponse;
444 }
445
446 export interface ClientNotificationParamsByMethod {
@@ -667,6 +670,7 @@ export const CLIENT_REQUEST_PARAMS = {
670 gitDiffToRemote: CodexSchema.GitDiffToRemoteParams,
671 getAuthStatus: CodexSchema.GetAuthStatusParams,
672 fuzzyFileSearch: CodexSchema.FuzzyFileSearchParams,
673 + "thread/settings/update": CodexSchema.ThreadSettingsUpdateParams,
674 } as const;
675
676 export const CLIENT_REQUEST_RESPONSES = {
@@ -779,6 +783,7 @@ export const CLIENT_REQUEST_RESPONSES = {
783 gitDiffToRemote: CodexSchema.GitDiffToRemoteResponse,
784 getAuthStatus: CodexSchema.GetAuthStatusResponse,
785 fuzzyFileSearch: CodexSchema.FuzzyFileSearchResponse,
786 + "thread/settings/update": CodexSchema.ThreadSettingsUpdateResponse,
787 } as const;
788
789 export const CLIENT_NOTIFICATION_PARAMS = {
packages/effect-codex-app-server/src/_generated/schema.gen.ts
+15
@@ -50866,6 +50866,21 @@ export const ServerRequest__CommandExecutionApprovalDecision = Schema.Union(
50866 { mode: "oneOf" },
50867 );
50868
50869 +export type ThreadSettingsUpdateParams = {
50870 + readonly threadId: string;
50871 + readonly serviceTier?: string | null;
50872 +};
50873 +export const ThreadSettingsUpdateParams = Schema.Struct({
50874 + threadId: Schema.String,
50875 + serviceTier: Schema.optionalKey(Schema.Union([Schema.String, Schema.Null])),
50876 +}).annotate({ title: "ThreadSettingsUpdateParams" });
50877 +
50878 +export type ThreadSettingsUpdateResponse = { readonly [x: string]: Schema.Json };
50879 +export const ThreadSettingsUpdateResponse = Schema.Record(
50880 + Schema.String,
50881 + Schema.Json.annotate({ expected: "JSON value" }),
50882 +).annotate({ title: "ThreadSettingsUpdateResponse" });
50883 +
50884 export type ToolRequestUserInputParams = {
50885 readonly autoResolutionMs?: number | null;
50886 readonly isBlocking: boolean;