@devries-cameron20 / t3code-1 / commits / 4b9cf579ba
Fork 0

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

fix(acp): Copilot's reply after a background agent wakes it opens a continuation run (#37159)

Julius Marminge committed Nov 15, 2026 at 03:17 UTC 4b9cf579ba62a808d9f99506474d971e30e917ae
3 files changed +115
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+96
@@ -1901,6 +1901,102 @@ describe("AcpRegistryAdapterV2", () => {
1901 }).pipe(Effect.provide(layerTest)),
1902 );
1903
1904 + // Copilot wakes its root agent when a background subagent finishes, after the run settled.
1905 + it.effect("does not drop Copilot's root reply when a finished background agent wakes it", () =>
1906 + Effect.gen(function* () {
1907 + const sessionId = "copilot-session";
1908 + const sessionEvent = (type: string) => ({
1909 + type: "emit_inbound",
1910 + frame: {
1911 + kind: "notification",
1912 + method: "github.com/copilot/sessionEvent",
1913 + params: { sessionId, type, data: {} },
1914 + },
1915 + });
1916 + const update = (sessionUpdate: Record<string, unknown>) =>
1917 + claudeFrames.update(sessionId, sessionUpdate);
1918 + const session = yield* openClaudeReplaySession(
1919 + [
1920 + {
1921 + type: "expect_outbound",
1922 + frame: { kind: "request", method: "initialize", params: "<any>" },
1923 + },
1924 + {
1925 + type: "emit_inbound",
1926 + frame: {
1927 + kind: "response",
1928 + method: "initialize",
1929 + result: {
1930 + protocolVersion: 1,
1931 + agentInfo: { name: "Copilot", version: "1.0.112" },
1932 + agentCapabilities: { loadSession: true },
1933 + authMethods: [],
1934 + },
1935 + },
1936 + },
1937 + {
1938 + type: "expect_outbound",
1939 + frame: { kind: "request", method: "session/new", params: "<any>" },
1940 + },
1941 + {
1942 + type: "emit_inbound",
1943 + frame: { kind: "response", method: "session/new", result: { sessionId } },
1944 + },
1945 + {
1946 + type: "expect_outbound",
1947 + frame: { kind: "request", method: "session/prompt", params: "<any>" },
1948 + },
1949 + sessionEvent("assistant.turn_start"),
1950 + update({
1951 + sessionUpdate: "agent_message_chunk",
1952 + content: { type: "text", text: "Agents are still working." },
1953 + }),
1954 + sessionEvent("assistant.idle"),
1955 + update({ sessionUpdate: "session_info_update", title: "after foreground idle" }),
1956 + // The background agent finishes; Copilot reads it and starts a new root turn.
1957 + sessionEvent("assistant.turn_start"),
1958 + update({
1959 + sessionUpdate: "tool_call",
1960 + toolCallId: "read-agent-1",
1961 + title: "read_agent",
1962 + kind: "other",
1963 + status: "completed",
1964 + rawInput: { agent_id: "agent-1" },
1965 + }),
1966 + update({
1967 + sessionUpdate: "agent_message_chunk",
1968 + content: { type: "text", text: "Agent 1 finished" },
1969 + }),
1970 + sessionEvent("assistant.idle"),
1971 + {
1972 + type: "emit_inbound",
1973 + frame: {
1974 + kind: "response",
1975 + method: "session/prompt",
1976 + result: { stopReason: "end_turn" },
1977 + },
1978 + },
1979 + update({ sessionUpdate: "session_info_update", title: "after wake idle" }),
1980 + ],
1981 + undefined,
1982 + true,
1983 + "github-copilot-cli",
1984 + );
1985 + yield* session.runtime.startTurn(session.turnInput(1));
1986 + const foreground = yield* session.throughMarker("after foreground idle");
1987 + assert.isDefined(foreground.find((event) => event.type === "turn.terminal"));
1988 + const wake = yield* session.throughMarker("after wake idle");
1989 + assert.isTrue(
1990 + session.offers.length > 0 || JSON.stringify(wake).includes("Agent 1 finished"),
1991 + "the woken root reply is shown or opens a continuation run",
1992 + );
1993 + yield* session.runtime.startTurn(session.turnInput(2, { continuation: true }));
1994 + const continuation = yield* session.until((event) => event.type === "turn.terminal");
1995 + assert.include(JSON.stringify(continuation), "Agent 1 finished");
1996 + assert.include(JSON.stringify(continuation.at(-1)), '"status":"completed"');
1997 + }).pipe(Effect.provide(layerTest)),
1998 + );
1999 +
2000 it.effect.each([
2001 { kind: "approval", stopReason: "end_turn", status: "completed" },
2002 { kind: "question", stopReason: "error", status: "failed" },
packages/provider-acp-registry/src/server/adapter.ts
+2
@@ -281,6 +281,8 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
281 normalizeSessionUpdate: copilotRouting.normalizeSessionUpdate,
282 extractSubagentUpdate: extractCopilotSubagentUpdate,
283 restartRuntimeAfterPromptError: isCopilotLostSessionError,
284 + // A finished background agent wakes the root after assistant.idle settled the run.
285 + enablePostSettleContinuation: true,
286 // session/new reports a built-in default, not the model Copilot runs (github/copilot-cli#5363).
287 alwaysSetModel: true,
288 }),
packages/provider-acp/src/server/adapter.ts
+17
@@ -2049,6 +2049,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2049 EffectAcpSchema.SessionUpdate,
2050 { sessionUpdate: "state_update" }
2051 > | null = null;
2052 + // The root's last reportForegroundWork state; undefined until the agent reports one.
2053 + let rootForegroundWork: "running" | "idle" | undefined;
2054 const agentRequests = new Set<object>();
2055 const nativeChildren = new Map<string, AcpNativeChildSession>();
2056 const extractSubagentUpdate = (tool: AcpToolCallState) =>
@@ -2082,6 +2084,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2084 continuationRequests !== undefined &&
2085 setup.initializeResult.protocolVersion === 2;
2086 agentWork = null;
2087 + rootForegroundWork = undefined;
2088 agentRequests.clear();
2089 nativeChildren.clear();
2090 yield* Ref.set(activeSessionSetup, setup);
@@ -7163,6 +7166,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7166 handlerGeneration,
7167 Effect.gen(function* () {
7168 if (yield* Ref.get(stoppedRunQuarantine)) return;
7169 + if ((yield* Ref.get(activeSessionId)) === notice.sessionId) {
7170 + rootForegroundWork = notice.state;
7171 + }
7172 const context = yield* Ref.get(activeTurn);
7173 if (
7174 context === null ||
@@ -8759,6 +8765,17 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8765 ),
8766 Effect.map((drained) => drained.length),
8767 );
8768 + // A root woken after foreground idle ends on its next idle report.
8769 + if (drainedWakeCount > 0 && rootForegroundWork !== undefined) {
8770 + yield* runtimeCallbackPermit.withPermit(
8771 + Effect.suspend(() => {
8772 + if (rootForegroundWork === "idle") return finalizeTurn(context, "completed");
8773 + context.workAccepted = true;
8774 + return Effect.void;
8775 + }),
8776 + );
8777 + return;
8778 + }
8779 context.promptSettled = true;
8780 context.promptSettledStatus = "completed";
8781 if (drainedWakeCount === 0) {