@devries-cameron20 / t3code-1 / commits / fd1adc888a
Fork 0

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

fix(acp): retain streamed child tool output (#32411)

Co-authored-by: GPT 6.1 Sol <codex@openai.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Wout Stiens committed Nov 7, 2026 at 11:40 UTC fd1adc888a676d5f658da48f687247bb09a374c3
2 files changed +393 -10
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+327 -3
@@ -208,6 +208,7 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* (
208 entries: ReadonlyArray<unknown>,
209 replayGate?: ProviderReplayGate,
210 continuationEnabled = true,
211 + agentId = "claude-acp",
212 ) {
213 const fileSystem = yield* FileSystem.FileSystem;
214 const path = yield* Path.Path;
@@ -248,7 +249,7 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* (
249 const adapterOptions = {
250 selfInvocation: yield* resolveSelfInvocation(),
251 instanceId,
251 - settings: yield* decodeAcpRegistryAdapterSettings({ agentId: "claude-acp" }),
252 + settings: yield* decodeAcpRegistryAdapterSettings({ agentId }),
253 environment: {},
254 ...(continuationEnabled ? { continuationRequests } : {}),
255 makeRuntime: (runtimeInput: Parameters<typeof replayRuntime>[0]) => {
@@ -1808,6 +1809,290 @@ describe("AcpRegistryAdapterV2", () => {
1809 }).pipe(Effect.provide(layerTest), Effect.scoped),
1810 );
1811
1812 + it.effect("retains streamed child tool output through the generic Devin route", () =>
1813 + Effect.gen(function* () {
1814 + const { update } = claudeFrames;
1815 + const session = yield* openClaudeReplaySession(
1816 + [
1817 + ...claudeFrames.open,
1818 + ...claudeFrames.prompt(1),
1819 + update("child-1", {
1820 + sessionUpdate: "tool_call_update",
1821 + toolCallId: "early-tool",
1822 + status: "in_progress",
1823 + rawInput: { command: "echo early" },
1824 + }),
1825 + update("child-1", {
1826 + sessionUpdate: "tool_call_content_chunk",
1827 + toolCallId: "early-tool",
1828 + content: { type: "content", content: { type: "text", text: "early" } },
1829 + }),
1830 + update("child-1", {
1831 + sessionUpdate: "tool_call_update",
1832 + toolCallId: "early-tool",
1833 + status: "completed",
1834 + }),
1835 + update(CLAUDE_ROOT_SESSION, {
1836 + sessionUpdate: "tool_call_update",
1837 + toolCallId: "spawn",
1838 + status: "in_progress",
1839 + _meta: { "cognition.ai/subagent_started": { agentId: "child-1", task: "Review" } },
1840 + }),
1841 + ...[CLAUDE_ROOT_SESSION, "child-1"].map((sessionId) =>
1842 + update(sessionId, {
1843 + sessionUpdate: "tool_call_update",
1844 + toolCallId: "shared-tool",
1845 + title: "Read package",
1846 + kind: "execute",
1847 + status: "in_progress",
1848 + rawInput: { command: "cat package.json" },
1849 + ...(sessionId === "child-1"
1850 + ? { content: [{ type: "content", content: { type: "text", text: "one" } }] }
1851 + : {}),
1852 + }),
1853 + ),
1854 + update("child-1", {
1855 + sessionUpdate: "tool_call_content_chunk",
1856 + toolCallId: "shared-tool",
1857 + content: { type: "content", content: { type: "text", text: "two" } },
1858 + }),
1859 + update("child-1", {
1860 + sessionUpdate: "tool_call_update",
1861 + toolCallId: "shared-tool",
1862 + status: "completed",
1863 + }),
1864 + update("child-1", {
1865 + sessionUpdate: "tool_call_update",
1866 + toolCallId: "shared-tool",
1867 + content: [{ type: "content", content: { type: "text", text: "replacement" } }],
1868 + }),
1869 + update("child-1", {
1870 + sessionUpdate: "tool_call_update",
1871 + toolCallId: "shared-tool",
1872 + content: [],
1873 + }),
1874 + update("child-1", {
1875 + sessionUpdate: "tool_call_update",
1876 + toolCallId: "shared-tool",
1877 + rawOutput: { stdout: "structured", stderr: "" },
1878 + }),
1879 + update("child-1", {
1880 + sessionUpdate: "tool_call_update",
1881 + toolCallId: "shared-tool",
1882 + content: [{ type: "content", content: { type: "text", text: "display" } }],
1883 + }),
1884 + update("child-1", {
1885 + sessionUpdate: "tool_call_update",
1886 + toolCallId: "shared-tool",
1887 + rawOutput: { type: "Text", text: "vendor" },
1888 + }),
1889 + update("child-1", {
1890 + sessionUpdate: "tool_call_update",
1891 + toolCallId: "shared-tool",
1892 + content: [{ type: "content", content: { type: "text", text: "display" } }],
1893 + }),
1894 + claudeMarker("tools complete"),
1895 + claudeFrames.idle("end_turn"),
1896 + claudeFrames.closeRequest,
1897 + claudeFrames.closed,
1898 + ],
1899 + undefined,
1900 + false,
1901 + "devin",
1902 + );
1903 + yield* session.runtime.startTurn(session.turnInput(1));
1904 + const events = yield* session.throughMarker("tools complete");
1905 + const child = events.find((event) => event.type === "subagent.updated");
1906 + if (child?.type !== "subagent.updated") throw new Error("Missing child");
1907 + const tools = events.flatMap((event) =>
1908 + event.type === "turn_item.updated" && event.turnItem.type === "dynamic_tool"
1909 + ? [event.turnItem]
1910 + : [],
1911 + );
1912 + const childTools = tools.filter((item) => item.threadId === child.subagent.childThreadId);
1913 + assert.deepEqual(
1914 + childTools.map((item) => item.output),
1915 + [
1916 + [{ type: "content", content: { type: "text", text: "one" } }],
1917 + [{ type: "content", content: { type: "text", text: "onetwo" } }],
1918 + [{ type: "content", content: { type: "text", text: "onetwo" } }],
1919 + [{ type: "content", content: { type: "text", text: "replacement" } }],
1920 + [],
1921 + { stdout: "structured", stderr: "" },
1922 + { stdout: "structured", stderr: "" },
1923 + { type: "Text", text: "vendor" },
1924 + { type: "Text", text: "vendor" },
1925 + ],
1926 + );
1927 + assert.equal(new Set(childTools.map((item) => item.id)).size, 1);
1928 + assert.equal(childTools.at(-1)?.nativeItemRef?.nativeId, "child-1:tool:shared-tool");
1929 + assert.equal(childTools.at(-1)?.status, "completed");
1930 + assert.deepEqual(childTools.at(-1)?.input, { command: "cat package.json" });
1931 + const parentTools = events.flatMap((event) =>
1932 + event.type === "turn_item.updated" &&
1933 + event.turnItem.type === "command_execution" &&
1934 + event.turnItem.threadId === session.turnInput(1).threadId &&
1935 + event.turnItem.nativeItemRef?.nativeId === "shared-tool"
1936 + ? [event.turnItem]
1937 + : [],
1938 + );
1939 + assert.lengthOf(parentTools, 1);
1940 + assert.isUndefined(parentTools[0]?.output);
1941 + assert.isFalse(
1942 + events.some(
1943 + (event) => event.type === "message.updated" && event.message.text.includes("onetwo"),
1944 + ),
1945 + );
1946 + }).pipe(Effect.provide(layerTest), Effect.scoped),
1947 + );
1948 +
1949 + it.effect("keeps stopped child tools interrupted when a late output chunk arrives", () =>
1950 + Effect.gen(function* () {
1951 + const { update } = claudeFrames;
1952 + const session = yield* openClaudeReplaySession(
1953 + [
1954 + ...claudeFrames.open.map((entry) =>
1955 + entry.frame.method === "initialize" && entry.type === "emit_inbound"
1956 + ? {
1957 + ...entry,
1958 + frame: {
1959 + ...entry.frame,
1960 + result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] },
1961 + },
1962 + }
1963 + : entry,
1964 + ),
1965 + {
1966 + type: "expect_outbound",
1967 + frame: { kind: "request", method: "session/prompt", params: "<any>" },
1968 + },
1969 + update(CLAUDE_ROOT_SESSION, {
1970 + sessionUpdate: "tool_call_update",
1971 + toolCallId: "spawn",
1972 + status: "in_progress",
1973 + _meta: { "cognition.ai/subagent_started": { agentId: "child-1", task: "Review" } },
1974 + }),
1975 + update("child-1", {
1976 + sessionUpdate: "tool_call_update",
1977 + toolCallId: "stopped-tool",
1978 + status: "in_progress",
1979 + }),
1980 + claudeMarker("before cancel"),
1981 + {
1982 + type: "expect_outbound",
1983 + frame: {
1984 + kind: "notification",
1985 + method: "session/cancel",
1986 + params: { sessionId: CLAUDE_ROOT_SESSION },
1987 + },
1988 + },
1989 + update("child-1", {
1990 + sessionUpdate: "tool_call_update",
1991 + toolCallId: "stopped-tool",
1992 + status: "failed",
1993 + }),
1994 + update("child-1", {
1995 + sessionUpdate: "tool_call_update",
1996 + toolCallId: "stopped-tool",
1997 + content: [{ type: "content", content: { type: "text", text: "stopping" } }],
1998 + }),
1999 + update("child-1", {
2000 + sessionUpdate: "tool_call_content_chunk",
2001 + toolCallId: "stopped-tool",
2002 + content: { type: "content", content: { type: "text", text: "cancelled" } },
2003 + }),
2004 + claudeMarker("late output"),
2005 + update(CLAUDE_ROOT_SESSION, {
2006 + sessionUpdate: "tool_call_update",
2007 + toolCallId: "spawn",
2008 + status: "failed",
2009 + _meta: { "cognition.ai/subagent_completed": { agentId: "child-1", success: false } },
2010 + }),
2011 + {
2012 + type: "emit_inbound",
2013 + frame: {
2014 + kind: "response",
2015 + method: "session/prompt",
2016 + result: { stopReason: "cancelled" },
2017 + },
2018 + },
2019 + claudeFrames.closeRequest,
2020 + claudeFrames.closed,
2021 + ],
2022 + undefined,
2023 + false,
2024 + "devin",
2025 + );
2026 + const starting = yield* session.runtime
2027 + .startTurn(session.turnInput(1))
2028 + .pipe(Effect.forkScoped);
2029 + const started = yield* session.throughMarker("before cancel");
2030 + const running = started.findLast((event) => event.type === "provider_turn.updated");
2031 + if (running?.type !== "provider_turn.updated") throw new Error("Missing active turn");
2032 + const closing = yield* session.runtime
2033 + .interruptTurn({
2034 + providerThread: session.providerThread,
2035 + providerTurnId: running.providerTurn.id,
2036 + })
2037 + .pipe(Effect.forkScoped);
2038 + const events = yield* session.throughMarker("late output");
2039 + yield* Fiber.join(closing);
2040 + yield* Fiber.join(starting);
2041 + const tools = events.flatMap((event) =>
2042 + event.type === "turn_item.updated" && event.turnItem.type === "dynamic_tool"
2043 + ? [event.turnItem]
2044 + : [],
2045 + );
2046 + assert.deepEqual(
2047 + tools.map((item) => item.status),
2048 + ["interrupted", "interrupted", "interrupted"],
2049 + );
2050 + assert.deepEqual(tools.at(-1)?.output, [
2051 + { type: "content", content: { type: "text", text: "stoppingcancelled" } },
2052 + ]);
2053 + }).pipe(Effect.provide(layerTest), Effect.scoped),
2054 + );
2055 +
2056 + it.effect("keeps native child tools interrupted after idle and late output", () =>
2057 + Effect.gen(function* () {
2058 + const { update, childState } = claudeFrames;
2059 + const session = yield* openClaudeReplaySession([
2060 + ...claudeFrames.open,
2061 + ...claudeFrames.prompt(1),
2062 + ...claudeChild.slice(0, -1),
2063 + update("child-1", {
2064 + sessionUpdate: "tool_call_update",
2065 + toolCallId: "unfinished",
2066 + status: "in_progress",
2067 + }),
2068 + childState(CLAUDE_ROOT_SESSION, "child-1", "idle"),
2069 + update("child-1", {
2070 + sessionUpdate: "tool_call_content_chunk",
2071 + toolCallId: "unfinished",
2072 + content: { type: "content", content: { type: "text", text: "late" } },
2073 + }),
2074 + claudeMarker("late native output"),
2075 + claudeFrames.idle("end_turn"),
2076 + claudeFrames.closeRequest,
2077 + claudeFrames.closed,
2078 + ]);
2079 + yield* session.runtime.startTurn(session.turnInput(1));
2080 + const events = yield* session.throughMarker("late native output");
2081 + const tools = events.flatMap((event) =>
2082 + event.type === "turn_item.updated" && event.turnItem.type === "dynamic_tool"
2083 + ? [event.turnItem]
2084 + : [],
2085 + );
2086 + assert.deepEqual(
2087 + tools.map((tool) => tool.status),
2088 + ["running", "interrupted", "interrupted"],
2089 + );
2090 + assert.deepEqual(tools.at(-1)?.output, [
2091 + { type: "content", content: { type: "text", text: "late" } },
2092 + ]);
2093 + }).pipe(Effect.provide(layerTest), Effect.scoped),
2094 + );
2095 +
2096 it.effect.each(["error", "end_turn"])(
2097 "hands live Claude child tools to the next run after %s and keeps nested output in the child",
2098 (stopReason) =>
@@ -1899,6 +2184,18 @@ describe("AcpRegistryAdapterV2", () => {
2184 status: "in_progress",
2185 rawInput: { command: "cat nested/package.json" },
2186 }),
2187 + ...["one", "two"].map((text) =>
2188 + update("grandchild", {
2189 + sessionUpdate: "tool_call_content_chunk",
2190 + toolCallId: "nested-tool",
2191 + content: { type: "content", content: { type: "text", text } },
2192 + }),
2193 + ),
2194 + update("grandchild", {
2195 + sessionUpdate: "tool_call_update",
2196 + toolCallId: "nested-tool",
2197 + status: "completed",
2198 + }),
2199 update("grandchild", {
2200 sessionUpdate: "agent_message_chunk",
2201 messageId: "nested-reply",
@@ -1996,7 +2293,7 @@ describe("AcpRegistryAdapterV2", () => {
2293 if (messages[0]?.type === "message.updated") {
2294 assert.equal(messages[0].message.threadId, row.subagent.childThreadId);
2295 }
1999 - const nestedTool = nested.find(
2296 + const nestedTool = nested.findLast(
2297 (event) =>
2298 event.type === "turn_item.updated" &&
2299 event.turnItem.type === "dynamic_tool" &&
@@ -2006,9 +2303,36 @@ describe("AcpRegistryAdapterV2", () => {
2303 assert.isDefined(nestedTool);
2304 if (nestedTool?.type === "turn_item.updated") {
2305 assert.equal(nestedTool.turnItem.threadId, row.subagent.childThreadId);
2009 - if (nestedTool.turnItem.type === "dynamic_tool")
2306 + if (nestedTool.turnItem.type === "dynamic_tool") {
2307 assert.deepEqual(nestedTool.turnItem.input, { command: "cat nested/package.json" });
2308 + assert.equal(nestedTool.turnItem.status, "completed");
2309 + }
2310 + const toolUpdates = nested.flatMap((event) =>
2311 + event.type === "turn_item.updated" &&
2312 + event.turnItem.type === "dynamic_tool" &&
2313 + event.turnItem.id === nestedTool.turnItem.id
2314 + ? [event.turnItem]
2315 + : [],
2316 + );
2317 + assert.deepEqual(
2318 + toolUpdates.map((item) => item.output),
2319 + [
2320 + null,
2321 + [{ type: "content", content: { type: "text", text: "one" } }],
2322 + [{ type: "content", content: { type: "text", text: "onetwo" } }],
2323 + [{ type: "content", content: { type: "text", text: "onetwo" } }],
2324 + ],
2325 + );
2326 }
2327 + assert.isFalse(
2328 + nested.some(
2329 + (event) =>
2330 + event.type === "turn_item.updated" &&
2331 + event.turnItem.threadId === session.turnInput(1).threadId &&
2332 + event.turnItem.type === "dynamic_tool" &&
2333 + JSON.stringify(event.turnItem.output).includes("onetwo"),
2334 + ),
2335 + );
2336 assert.isTrue(
2337 nested.some(
2338 (event) =>
packages/provider-acp/src/server/adapter.ts
+66 -7
@@ -1591,6 +1591,8 @@ interface ActiveAcpSubagent {
1591 nextChildOrdinal: number;
1592 terminalStatusProjected: boolean;
1593 readonly toolState: Pick<ActiveAcpTurn, "tools" | "toolUpdatesSkipped" | "toolStartedAt">;
1594 + // ACP has no interrupted tool status; keep forced interruption across late updates.
1595 + readonly interruptedToolIds: Set<string>;
1596 readonly toolSessionIds: Map<string, string>;
1597 }
1598
@@ -2979,6 +2981,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2981 const projectSubagentNotification = Effect.fnUntraced(function* (
2982 subagent: ActiveAcpSubagent,
2983 notification: EffectAcpSchema.SessionNotification,
2984 + owner: ActiveAcpTurn,
2985 ) {
2986 const update = notification.update;
2987 if (update.sessionUpdate === "agent_message_chunk") {
@@ -2986,6 +2989,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2989 if (text !== undefined) {
2990 yield* emitSubagentAssistant(subagent, text, "append", update.messageId);
2991 }
2992 + } else if (update.sessionUpdate === "tool_call_content_chunk") {
2993 + yield* projectSubagentTool(subagent, notification.sessionId, update, undefined, owner);
2994 } else if (update.sessionUpdate === "agent_message") {
2995 if (update.content === undefined) return;
2996 const text = (update.content ?? [])
@@ -3001,8 +3006,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3006 const projectSubagentTool = Effect.fnUntraced(function* (
3007 subagent: ActiveAcpSubagent,
3008 sessionId: string,
3004 - toolCall: AcpToolCallState,
3009 + toolCall:
3010 + | AcpToolCallState
3011 + | Extract<EffectAcpSchema.SessionUpdate, { sessionUpdate: "tool_call_content_chunk" }>,
3012 projectedStatus?: ProjectedToolStatus,
3013 + owner?: ActiveAcpTurn,
3014 ) {
3015 const nativeTaskId = subagent.task.nativeTaskRef?.nativeId ?? String(subagent.task.id);
3016 const key =
@@ -3013,7 +3021,38 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3021 const rootSessionId = yield* Ref.get(activeSessionId);
3022 subagent.toolSessionIds.set(key, sessionId);
3023 const previous = context.tools.get(key);
3024 + if ("sessionUpdate" in toolCall) {
3025 + if (toolCall.content.type !== "content") return;
3026 + const text = acpContentBlockDisplayText(toolCall.content.content);
3027 + if (text === undefined || text.length === 0) return;
3028 + const content: unknown[] = Array.isArray(previous?.data.content)
3029 + ? [...previous.data.content]
3030 + : [];
3031 + const last = unknownRecord(content.at(-1));
3032 + const lastContent = unknownRecord(last?.content);
3033 + if (
3034 + last?.type === "content" &&
3035 + lastContent?.type === "text" &&
3036 + typeof lastContent.text === "string"
3037 + ) {
3038 + content[content.length - 1] = {
3039 + ...last,
3040 + content: { ...lastContent, text: `${lastContent.text}${text}` },
3041 + };
3042 + } else {
3043 + content.push({ type: "content", content: { type: "text", text } });
3044 + }
3045 + toolCall = {
3046 + toolCallId: toolCall.toolCallId,
3047 + data: { content },
3048 + };
3049 + }
3050 const merged = mergeToolCallState(previous, toolCall);
3051 + projectedStatus ??= owner === undefined ? undefined : stoppedToolStatus(owner, merged);
3052 + if (merged.status !== "failed") subagent.interruptedToolIds.delete(key);
3053 + if (projectedStatus === "interrupted") subagent.interruptedToolIds.add(key);
3054 + if (merged.status === "failed" && subagent.interruptedToolIds.has(key))
3055 + projectedStatus = "interrupted";
3056 context.tools.set(key, merged);
3057 if (
3058 projectedStatus === undefined &&
@@ -3195,6 +3234,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3234 toolUpdatesSkipped: new Map(),
3235 toolStartedAt: new Map(),
3236 },
3237 + interruptedToolIds: new Set(),
3238 toolSessionIds: new Map(),
3239 };
3240 subagent.task = task;
@@ -3283,7 +3323,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3323 context.pendingSubagentNotifications.delete(childSessionId);
3324 yield* Effect.forEach(
3325 buffered,
3286 - (notification) => projectSubagentNotification(subagent, notification),
3326 + (notification) => projectSubagentNotification(subagent, notification, context),
3327 { concurrency: 1, discard: true },
3328 );
3329 }
@@ -3523,7 +3563,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3563 )
3564 continue;
3565 subagent.toolState.toolUpdatesSkipped.delete(key);
3526 - yield* projectSubagentTool(subagent, toolSessionId, tool, toolStatus(tool.status));
3566 + yield* projectSubagentTool(
3567 + subagent,
3568 + toolSessionId,
3569 + tool,
3570 + toolStatus(tool.status),
3571 + context,
3572 + );
3573 }
3574 }
3575 if (
@@ -3603,12 +3649,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3649 subagent,
3650 notification.sessionId,
3651 tool,
3606 - stoppedToolStatus(owner.owner, tool),
3652 + undefined,
3653 + owner.owner,
3654 );
3655 }
3656 }
3657 } else {
3611 - yield* projectSubagentNotification(subagent, notification);
3658 + yield* projectSubagentNotification(subagent, notification, owner.owner);
3659 }
3660 });
3661
@@ -5261,11 +5308,23 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
5308 subagent,
5309 notification.sessionId,
5310 toolCall,
5264 - stoppedToolStatus(context, toolCall),
5311 + undefined,
5312 + context,
5313 );
5314 }
5315 return;
5316 }
5317 + if (update.sessionUpdate === "tool_call_content_chunk") {
5318 + if (subagent !== undefined)
5319 + yield* projectSubagentTool(
5320 + subagent,
5321 + notification.sessionId,
5322 + update,
5323 + undefined,
5324 + context,
5325 + );
5326 + return;
5327 + }
5328 const isDisplayableAssistantUpdate =
5329 (update.sessionUpdate === "agent_message_chunk" &&
5330 acpContentBlockDisplayText(update.content) !== undefined) ||
@@ -5274,7 +5333,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
5333 return;
5334 }
5335 if (subagent !== undefined) {
5277 - yield* projectSubagentNotification(subagent, notification);
5336 + yield* projectSubagentNotification(subagent, notification, context);
5337 return;
5338 }
5339 const buffered = context.pendingSubagentNotifications.get(notification.sessionId) ?? [];