Skip to content

Commit 0f6d5ff

Browse files
committed
fix(server): Codex forks no longer request the full thread history
A fork of a very large Codex conversation returned the whole turn history and exceeded the transport limit, though the adapter only needs thread metadata. The fork request now sets excludeTurns, and the recorded fork frames in the replay fixtures were updated to match. Fixes #24460
1 parent d53873b commit 0f6d5ff

6 files changed

Lines changed: 92 additions & 7 deletions

File tree

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

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5718,7 +5718,11 @@ describe("CodexAdapterV2 post-settle continuation", () => {
57185718
frame: {
57195719
id: 3,
57205720
method: "thread/fork",
5721-
params: { threadId: nativeThreadId, config: CodexAdapterV2.CODEX_THREAD_CONFIG },
5721+
params: {
5722+
threadId: nativeThreadId,
5723+
excludeTurns: true,
5724+
config: CodexAdapterV2.CODEX_THREAD_CONFIG,
5725+
},
57225726
},
57235727
},
57245728
{
@@ -5841,6 +5845,83 @@ describe("CodexAdapterV2 post-settle continuation", () => {
58415845
),
58425846
);
58435847

5848+
it.effect("forks at a native turn without asking Codex for the historical turns", () =>
5849+
Effect.gen(function* () {
5850+
const nativeThreadId = "exclude-turns-source-thread";
5851+
const forkThreadId = "exclude-turns-fork-thread";
5852+
const preamble = codexReplayPreamble({
5853+
nativeThreadId,
5854+
nativeTurnId: "exclude-turns-source-turn",
5855+
prompt: "unused",
5856+
});
5857+
// Replay matches the whole outbound frame, so a fork request that omits
5858+
// `excludeTurns` (the full-history payload that overran the transport
5859+
// limit) fails here instead of reaching a real app-server.
5860+
const transcript = makeCodexReplayTranscript({
5861+
scenario: "codex-fork-exclude-turns",
5862+
entries: [
5863+
...preamble.slice(0, 5),
5864+
{
5865+
type: "expect_outbound",
5866+
label: "thread/fork",
5867+
frame: {
5868+
id: 3,
5869+
method: "thread/fork",
5870+
params: {
5871+
threadId: nativeThreadId,
5872+
lastTurnId: "native-turn-first",
5873+
excludeTurns: true,
5874+
config: CodexAdapterV2.CODEX_THREAD_CONFIG,
5875+
},
5876+
},
5877+
},
5878+
{
5879+
type: "emit_inbound",
5880+
label: "thread/fork",
5881+
frame: {
5882+
id: 3,
5883+
result: codexReplayThreadResult({
5884+
nativeThreadId: forkThreadId,
5885+
forkedFromId: nativeThreadId,
5886+
}),
5887+
},
5888+
},
5889+
],
5890+
});
5891+
const harness = yield* makeCodexReplayHarness(transcript);
5892+
const now = yield* DateTime.now;
5893+
const firstTurn = codexReplaySourceTurn({
5894+
id: "provider-turn-first",
5895+
ordinal: 1,
5896+
nativeId: "native-turn-first",
5897+
providerThreadId: harness.providerThread.id,
5898+
now,
5899+
});
5900+
const secondTurn = codexReplaySourceTurn({
5901+
id: "provider-turn-second",
5902+
ordinal: 2,
5903+
nativeId: "native-turn-second",
5904+
providerThreadId: harness.providerThread.id,
5905+
now,
5906+
});
5907+
5908+
const forkedProviderThread = yield* harness.runtime.forkThread({
5909+
sourceProviderThread: harness.providerThread,
5910+
sourceProviderTurns: [firstTurn, secondTurn],
5911+
providerTurnId: firstTurn.id,
5912+
targetThreadId: ThreadId.make("thread-fork-exclude-turns-target"),
5913+
});
5914+
5915+
assert.equal(forkedProviderThread.nativeThreadRef?.nativeId, forkThreadId);
5916+
assert.equal(forkedProviderThread.forkedFrom?.providerTurnId, firstTurn.id);
5917+
}).pipe(
5918+
Effect.scoped,
5919+
Effect.provide(
5920+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
5921+
),
5922+
),
5923+
);
5924+
58445925
describe("native goals", () => {
58455926
const nativeThreadId = "goal-thread";
58465927
const objective = "Ship the feature";

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7512,6 +7512,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
75127512
Effect.andThen(
75137513
client.request("thread/fork", {
75147514
threadId,
7515+
// The adapter only needs thread metadata; without this the
7516+
// response carries the whole history, which overruns the
7517+
// transport limit on very large threads.
7518+
excludeTurns: true,
75157519
...(boundary.lastTurnId === undefined
75167520
? {}
75177521
: { lastTurnId: boundary.lastTurnId }),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{"type":"emit_inbound","label":"thread/tokenUsage/updated","frame":{"method":"thread/tokenUsage/updated","params":{"threadId":"01a0d5ee-8dbe-7bd3-9a3e-115bc6af5a1b","turnId":"01a0d5ee-8e97-7201-b5b3-68c61f6b4cba","tokenUsage":{"total":{"totalTokens":21441,"inputTokens":21434,"cachedInputTokens":14080,"cacheWriteInputTokens":0,"outputTokens":7,"reasoningOutputTokens":0},"last":{"totalTokens":21441,"inputTokens":21434,"cachedInputTokens":14080,"cacheWriteInputTokens":0,"outputTokens":7,"reasoningOutputTokens":0},"modelContextWindow":258400}},"emittedAtMs":1790295580603}}
2727
{"type":"emit_inbound","label":"thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"01a0d5ee-8dbe-7bd3-9a3e-115bc6af5a1b","status":{"type":"idle"}},"emittedAtMs":1790295580611}}
2828
{"type":"emit_inbound","label":"turn/completed","frame":{"method":"turn/completed","params":{"threadId":"01a0d5ee-8dbe-7bd3-9a3e-115bc6af5a1b","turn":{"id":"01a0d5ee-8e97-7201-b5b3-68c61f6b4cba","items":[{"type":"agentMessage","id":"msg_014f95841dc5b650016ab5be1c299c87d09a10902b0219f7f3","text":"source marker stored","phase":"final_answer","memoryCitation":null,"delivery":null,"questions":null}],"itemsView":"summary","status":"completed","error":null,"startedAt":1790295576,"completedAt":1790295580,"durationMs":4383}},"emittedAtMs":1790295580611}}
29-
{"type":"expect_outbound","label":"thread/fork","frame":{"id":4,"method":"thread/fork","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000},"cwd":"<workspace>","lastTurnId":"01a0d5ee-8e97-7201-b5b3-68c61f6b4cba","model":"gpt-6-luna","threadId":"01a0d5ee-8dbe-7bd3-9a3e-115bc6af5a1b"}}}
29+
{"type":"expect_outbound","label":"thread/fork","frame":{"id":4,"method":"thread/fork","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000},"cwd":"<workspace>","excludeTurns":true,"lastTurnId":"01a0d5ee-8e97-7201-b5b3-68c61f6b4cba","model":"gpt-6-luna","threadId":"01a0d5ee-8dbe-7bd3-9a3e-115bc6af5a1b"}}}
3030
{"type":"emit_inbound","label":"deprecationNotice","frame":{"method":"deprecationNotice","params":{"summary":"Full-history hydration is deprecated for paginated threads; use `excludeTurns: true`, then page with `thread/turns/list` and `thread/items/list`.","details":null},"emittedAtMs":1790295580619}}
3131
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a0d5ee-9fec-76a0-b5a5-b59c2a46906d","name":"codex_apps","status":"starting","error":null,"failureReason":null},"emittedAtMs":1790295580849}}
3232
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a0d5ee-9fec-76a0-b5a5-b59c2a46906d","name":"xcodebuildmcp","status":"starting","error":null,"failureReason":null},"emittedAtMs":1790295580849}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
{"type":"emit_inbound","label":"account/rateLimits/updated","frame":{"method":"account/rateLimits/updated","params":{"rateLimits":{"limitId":"codex","limitName":null,"primary":{"usedPercent":61,"windowDurationMins":300,"resetsAt":1777429830},"secondary":{"usedPercent":23,"windowDurationMins":10080,"resetsAt":1777959590},"credits":null,"planType":"unknown","rateLimitReachedType":null}}}}
4949
{"type":"emit_inbound","label":"thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"019dd6ba-2681-7bf0-b051-141b0cbcbb27","status":{"type":"idle"}}}}
5050
{"type":"emit_inbound","label":"turn/completed","frame":{"method":"turn/completed","params":{"threadId":"019dd6ba-2681-7bf0-b051-141b0cbcbb27","turn":{"id":"019dd6ba-416d-7902-95cf-d4179c3f4738","items":[],"status":"completed","error":null,"startedAt":1777424023,"completedAt":1777424025,"durationMs":1596}}}}
51-
{"type":"expect_outbound","label":"thread/fork","frame":{"id":5,"method":"thread/fork","params":{"threadId":"019dd6ba-2681-7bf0-b051-141b0cbcbb27","lastTurnId":"019dd6ba-268b-7f82-8f4c-9fde0edcfd55","config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000}}}}
51+
{"type":"expect_outbound","label":"thread/fork","frame":{"id":5,"method":"thread/fork","params":{"threadId":"019dd6ba-2681-7bf0-b051-141b0cbcbb27","lastTurnId":"019dd6ba-268b-7f82-8f4c-9fde0edcfd55","excludeTurns":true,"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000}}}}
5252
{"type":"emit_inbound","label":"deprecationNotice","frame":{"method":"deprecationNotice","params":{"summary":"`[features].collab` is deprecated. Use `[features].multi_agent` instead.","details":"Enable it with `--enable multi_agent` or `[features].multi_agent` in config.toml. See https://developers.openai.com/codex/config-basic#feature-flags for details."}}}
5353
{"type":"emit_inbound","label":"warning","frame":{"method":"warning","params":{"threadId":"019dd6ba-47b7-7092-8688-9cf7fe5f6498","message":"Under-development features enabled: apply_patch_freeform. Under-development features are incomplete and may behave unpredictably. To suppress this warning, set `suppress_unstable_features_warning = true` in /home/replay-user/.codex/config.toml."}}}
5454
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"name":"uidotsh","status":"starting","error":null}}}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{"type":"emit_inbound","label":"thread/tokenUsage/updated","frame":{"method":"thread/tokenUsage/updated","params":{"threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529","turnId":"01a0d60f-9892-7f93-b79e-f5b7a69cacfb","tokenUsage":{"total":{"totalTokens":17749,"inputTokens":17741,"cachedInputTokens":11776,"cacheWriteInputTokens":0,"outputTokens":8,"reasoningOutputTokens":0},"last":{"totalTokens":17749,"inputTokens":17741,"cachedInputTokens":11776,"cacheWriteInputTokens":0,"outputTokens":8,"reasoningOutputTokens":0},"modelContextWindow":258400}},"emittedAtMs":1790297746158}}
2828
{"type":"emit_inbound","label":"thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529","status":{"type":"idle"}},"emittedAtMs":1790297746168}}
2929
{"type":"emit_inbound","label":"turn/completed","frame":{"method":"turn/completed","params":{"threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529","turn":{"id":"01a0d60f-9892-7f93-b79e-f5b7a69cacfb","items":[{"type":"agentMessage","id":"msg_0052ea29510335a5016ab5c691dae087d08079b58defc08b50","text":"sibling source stored","phase":"final_answer","memoryCitation":null,"delivery":null,"questions":null}],"itemsView":"summary","status":"completed","error":null,"startedAt":1790297741,"completedAt":1790297746,"durationMs":4697}},"emittedAtMs":1790297746168}}
30-
{"type":"expect_outbound","label":"thread/fork","frame":{"id":4,"method":"thread/fork","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000},"cwd":"<workspace>","lastTurnId":"01a0d60f-9892-7f93-b79e-f5b7a69cacfb","model":"gpt-6-sol","threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529"}}}
30+
{"type":"expect_outbound","label":"thread/fork","frame":{"id":4,"method":"thread/fork","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000},"cwd":"<workspace>","excludeTurns":true,"lastTurnId":"01a0d60f-9892-7f93-b79e-f5b7a69cacfb","model":"gpt-6-sol","threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529"}}}
3131
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529","name":"xcodebuildmcp","status":"ready","error":null,"failureReason":null},"emittedAtMs":1790297746181}}
3232
{"type":"emit_inbound","label":"deprecationNotice","frame":{"method":"deprecationNotice","params":{"summary":"Full-history hydration is deprecated for paginated threads; use `excludeTurns: true`, then page with `thread/turns/list` and `thread/items/list`.","details":null},"emittedAtMs":1790297746182}}
3333
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a0d60f-ab19-73c3-a515-18e6b7f73999","name":"xcodebuildmcp","status":"starting","error":null,"failureReason":null},"emittedAtMs":1790297746389}}
@@ -66,7 +66,7 @@
6666
{"type":"emit_inbound","label":"thread/tokenUsage/updated","frame":{"method":"thread/tokenUsage/updated","params":{"threadId":"01a0d60f-ab19-73c3-a515-18e6b7f73999","turnId":"01a0d60f-abe2-7222-a197-832e11fb901d","tokenUsage":{"total":{"totalTokens":39741,"inputTokens":39712,"cachedInputTokens":29312,"cacheWriteInputTokens":0,"outputTokens":29,"reasoningOutputTokens":0},"last":{"totalTokens":21992,"inputTokens":21971,"cachedInputTokens":17536,"cacheWriteInputTokens":0,"outputTokens":21,"reasoningOutputTokens":0},"modelContextWindow":258400}},"emittedAtMs":1790297750501}}
6767
{"type":"emit_inbound","label":"thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"01a0d60f-ab19-73c3-a515-18e6b7f73999","status":{"type":"idle"}},"emittedAtMs":1790297750505}}
6868
{"type":"emit_inbound","label":"turn/completed","frame":{"method":"turn/completed","params":{"threadId":"01a0d60f-ab19-73c3-a515-18e6b7f73999","turn":{"id":"01a0d60f-abe2-7222-a197-832e11fb901d","items":[{"type":"agentMessage","id":"msg_0052ea29510335a5016ab5c695f2a487d0920496ebe85a6c76","text":"sibling-source-8R3D|sibling-first-5L2P","phase":"final_answer","memoryCitation":null,"delivery":null,"questions":null}],"itemsView":"summary","status":"completed","error":null,"startedAt":1790297746,"completedAt":1790297750,"durationMs":4089}},"emittedAtMs":1790297750505}}
69-
{"type":"expect_outbound","label":"thread/fork","frame":{"id":6,"method":"thread/fork","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000},"cwd":"<workspace>","lastTurnId":"01a0d60f-9892-7f93-b79e-f5b7a69cacfb","model":"gpt-6-sol","threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529"}}}
69+
{"type":"expect_outbound","label":"thread/fork","frame":{"id":6,"method":"thread/fork","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000},"cwd":"<workspace>","excludeTurns":true,"lastTurnId":"01a0d60f-9892-7f93-b79e-f5b7a69cacfb","model":"gpt-6-sol","threadId":"01a0d60f-9778-7e42-9665-fcc03ff16529"}}}
7070
{"type":"emit_inbound","label":"deprecationNotice","frame":{"method":"deprecationNotice","params":{"summary":"Full-history hydration is deprecated for paginated threads; use `excludeTurns: true`, then page with `thread/turns/list` and `thread/items/list`.","details":null},"emittedAtMs":1790297750509}}
7171
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a0d60f-bc01-74c2-b3c9-eb58a6441a5f","name":"codex_apps","status":"starting","error":null,"failureReason":null},"emittedAtMs":1790297750665}}
7272
{"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"threadId":"01a0d60f-bc01-74c2-b3c9-eb58a6441a5f","name":"xcodebuildmcp","status":"starting","error":null,"failureReason":null},"emittedAtMs":1790297750665}}

0 commit comments

Comments
 (0)