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, 16:00 UTC
fix(codex): delegate_task children start as Codex subagents (#36525)
Julius Marminge committed
Nov 13, 2026 at 23:35 UTC
99071c4953bb50924f23c9282be11a5cfa0eda6a
4 files changed
+76
-6
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+62
@@ -1872,6 +1872,68 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1872
),
1873
);
1874
1875
+ // regression: #36520 MCP servers can tell a delegate_task child from a user thread
1876
+ it.effect("starts delegate_task children with the subagent thread source", () =>
1877
+ Effect.gen(function* () {
1878
+ const scenario = "delegated-thread-source";
1879
+ const preamble = codexReplayPreamble({
1880
+ nativeThreadId: "delegated-parent-thread",
1881
+ nativeTurnId: "unused",
1882
+ prompt: "unused",
1883
+ }).slice(0, 5);
1884
+ const childStart = codexReplayPreamble({
1885
+ nativeThreadId: "delegated-child-thread",
1886
+ nativeTurnId: "unused",
1887
+ prompt: "unused",
1888
+ })
1889
+ .slice(3, 5)
1890
+ .map((entry) => withReplayRequestId(entry, 3))
1891
+ .map((entry) =>
1892
+ entry.type === "expect_outbound" &&
1893
+ Predicate.isObject(entry.frame) &&
1894
+ Predicate.isObject(entry.frame["params"])
1895
+ ? {
1896
+ ...entry,
1897
+ frame: {
1898
+ ...entry.frame,
1899
+ params: { ...entry.frame["params"], threadSource: "subagent" },
1900
+ },
1901
+ }
1902
+ : entry,
1903
+ );
1904
+ const threadSources: Array<unknown> = [];
1905
+ const harness = yield* makeCodexReplayHarness(
1906
+ makeCodexReplayTranscript({ scenario, entries: [...preamble, ...childStart] }),
1907
+ () => Effect.void,
1908
+ (method, params) =>
1909
+ Effect.sync(() => {
1910
+ if (method === "thread/start" && Predicate.isObject(params)) {
1911
+ threadSources.push(params["threadSource"]);
1912
+ }
1913
+ }),
1914
+ );
1915
+ const childThreadId = (yield* IdAllocator.IdAllocatorV2).derive.delegatedTaskThread({
1916
+ commandId: CommandId.make(`mcp:${scenario}:delegate-task:child`),
1917
+ });
1918
+ yield* harness.runtime.ensureThread({
1919
+ threadId: childThreadId,
1920
+ modelSelection: CODEX_TEST_MODEL_SELECTION,
1921
+ runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
1922
+ });
1923
+ assert.deepEqual(threadSources, [undefined, "subagent"]);
1924
+ }).pipe(
1925
+ Effect.scoped,
1926
+ Effect.provide(
1927
+ Layer.mergeAll(
1928
+ IdAllocator.layer,
1929
+ McpProviderSessions.layer,
1930
+ NodeServices.layer,
1931
+ NodeCrypto.layer,
1932
+ ),
1933
+ ),
1934
+ ),
1935
+ );
1936
+
1937
// regression: #15839 launch-arg MCP servers survive the thread's t3-code server
1938
it.effect("replays historical and dotted MCP config while enforcing other thread config", () =>
1939
Effect.gen(function* () {
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+7
-4
@@ -7701,15 +7701,18 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
7701
ensureInitialized.pipe(
7702
Effect.andThen(mcpSessions.read(threadInput.threadId)),
7703
Effect.flatMap((mcpSession) =>
7704
- client.request(
7705
- "thread/start",
7706
- codexThreadRuntimeParams({
7704
+ client.request("thread/start", {
7705
+ ...codexThreadRuntimeParams({
7706
threadId: threadInput.threadId,
7707
mcpSession,
7708
modelSelection: threadInput.modelSelection,
7709
runtimePolicy: threadInput.runtimePolicy,
7710
}),
7712
- ),
7711
+ // Codex tags the child's MCP calls with thread_source "subagent".
7712
+ ...(IdAllocator.isDelegatedTaskThread(threadInput.threadId)
7713
+ ? { threadSource: "subagent" }
7714
+ : {}),
7715
+ }),
7716
),
7717
Effect.map((response): OrchestrationV2ProviderThread =>
7718
providerThreadFromCodexThread({
apps/server/src/orchestration-v2/testkit/fixtures/delegated_task_status/codex_transcript.ndjson
+1
-1
@@ -11,7 +11,7 @@
11
{"type":"emit_inbound","label":"parent.turn/start","frame":{"id":4,"result":{"turn":{"id":"019f1000-0000-7000-8000-000000000002","items":[],"status":"inProgress","error":null,"startedAt":null,"completedAt":null,"durationMs":null}}}}
12
{"type":"emit_inbound","label":"parent.thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"019f1000-0000-7000-8000-000000000001","status":{"type":"active","activeFlags":[]}}}}
13
{"type":"emit_inbound","label":"parent.turn/started","frame":{"method":"turn/started","params":{"threadId":"019f1000-0000-7000-8000-000000000001","turn":{"id":"019f1000-0000-7000-8000-000000000002","items":[],"status":"inProgress","error":null,"startedAt":1776739467,"completedAt":null,"durationMs":null}}}}
14
-{"type":"expect_outbound","label":"child.thread/start","frame":{"id":5,"method":"thread/start","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000,"features.concurrent_reasoning_summaries":true}}}}
14
+{"type":"expect_outbound","label":"child.thread/start","frame":{"id":5,"method":"thread/start","params":{"config":{"tools.update_plan.enabled":true,"mcp_optional_startup_grace_ms":10000,"features.concurrent_reasoning_summaries":true},"threadSource":"subagent"}}}
15
{"type":"emit_inbound","label":"child.thread/start","frame":{"id":5,"result":{"thread":{"id":"019f1000-0000-7000-8000-000000000003","forkedFromId":null,"preview":"","ephemeral":false,"modelProvider":"openai","createdAt":1776739468,"updatedAt":1776739468,"status":{"type":"idle"},"path":"/home/replay-user/.codex/sessions/delegated-task-status-child.jsonl","cwd":"/home/replay-user/t3code","cliVersion":"0.120.0","source":"vscode","agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"turns":[]},"model":"gpt-5.4","modelProvider":"openai","serviceTier":"fast","cwd":"/home/replay-user/t3code","approvalPolicy":"on-request","approvalsReviewer":"user","sandbox":{"type":"workspaceWrite","writableRoots":[],"readOnlyAccess":{"type":"fullAccess"},"networkAccess":false,"excludeTmpdirEnvVar":false,"excludeSlashTmp":false},"reasoningEffort":"xhigh"}}}
16
{"type":"expect_outbound","label":"config/read","frame":{"id":6,"method":"config/read","params":{"cwd":"<workspace>","includeLayers":false}}}
17
{"type":"emit_inbound","label":"config/read","frame":{"id":6,"result":{"config":{},"origins":{}}}}
packages/provider-core/src/server/IdAllocator.ts
+6
-1
@@ -271,6 +271,11 @@ const randomId =
271
),
272
);
273
274
+const DELEGATED_TASK_THREAD_PREFIX = joinId("thread", "delegated-task", "");
275
+
276
+export const isDelegatedTaskThread = (threadId: ThreadId): boolean =>
277
+ threadId.startsWith(DELEGATED_TASK_THREAD_PREFIX);
278
+
279
export const derive: IdAllocatorV2Derive = {
280
providerSession: (input) =>
281
ProviderSessionId.make(
@@ -278,7 +283,7 @@ export const derive: IdAllocatorV2Derive = {
283
),
284
delegatedTaskNode: (input) => NodeId.make(joinId("node", "delegated-task", input.commandId)),
285
delegatedTaskThread: (input) =>
281
- ThreadId.make(joinId("thread", "delegated-task", input.commandId)),
286
+ ThreadId.make(`${DELEGATED_TASK_THREAD_PREFIX}${encodePart(input.commandId)}`),
287
delegatedTaskMessage: (input) =>
288
MessageId.make(joinId("message", "delegated-task", input.commandId)),
289
delegatedTaskTurnItem: (input) =>