From 197d7a52b356e533a66cf3d6e1e713405a580a27 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 08:02:07 +0000 Subject: [PATCH 1/3] test(server): Antigravity command still running at end_turn is not marked completed Failing reproduction for #16442: the ACP adapter finalizes an Antigravity turn on end_turn and marks an execute tool that is still in progress as completed, and Stop afterwards cannot reach it. AI-assisted; verified with the tests and tools listed above. --- .../Adapters/AntigravityAdapterV2.test.ts | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts index 0945a282cee2c..89594fd656689 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -22,6 +22,7 @@ import * as Exit from "effect/Exit"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; import * as Path from "effect/Path"; +import * as Queue from "effect/Queue"; import * as Stream from "effect/Stream"; import { ChildProcessSpawner } from "effect/process"; import type * as EffectAcpSchema from "effect-acp/compat"; @@ -839,6 +840,166 @@ describe("AntigravityAdapterV2 html_render pages", () => { ); }); +describe("AntigravityAdapterV2 running commands", () => { + it.effect("does not mark a command completed while it is still running at end_turn", () => + Effect.gen(function* () { + const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; + const path = yield* Path.Path; + const crypto = yield* SecureRandom.SecureRandom; + const mockAgentPath = yield* path.fromFileUrl( + new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), + ); + type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; + let sessionUpdate: Parameters[0] | undefined; + const promptReturned = yield* Deferred.make(); + const instanceId = ProviderInstanceId.make("antigravity-running-command-test"); + const threadId = ThreadId.make("thread-antigravity-running-command"); + const adapter = yield* makeAntigravityAdapterV2({ + instanceId, + selfInvocation: yield* resolveSelfInvocation(), + makeRuntime: (input) => + makeAntigravityAcpRuntime({ + ...input, + childProcessSpawner, + spawn: { + command: process.execPath, + args: [mockAgentPath], + cwd: input.cwd, + env: { T3_ACP_ANTIGRAVITY: "1" }, + }, + }).pipe( + Effect.provideService(SecureRandom.SecureRandom, crypto), + Effect.map((runtime): RuntimeService => ({ + ...runtime, + handleSessionUpdate: (handler) => + Effect.sync(() => { + sessionUpdate = handler; + }).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))), + // The agent starts a watcher, answers, and ends its turn while it runs. + prompt: () => + Effect.gen(function* () { + if (sessionUpdate === undefined) { + return yield* Effect.die("the adapter must handle session updates"); + } + yield* sessionUpdate( + normalizeAntigravitySessionUpdate({ + sessionId: "mock-session-1", + update: { + sessionUpdate: "tool_call", + toolCallId: "watcher", + title: "Running run_command", + kind: "execute", + status: "in_progress", + rawInput: { CommandLine: "tail -f app.log" }, + }, + }), + ); + return { stopReason: "end_turn" as const }; + }).pipe(Effect.ensuring(Deferred.succeed(promptReturned, undefined))), + })), + ), + withProcess: (_stop, task) => task, + defaultModel: Effect.undefined, + }); + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "full-access", + interactionMode: "default", + cwd: process.cwd(), + }); + const modelSelection = { instanceId, model: "gemini-test-low" } as const; + const session = yield* adapter.openSession({ + threadId, + providerSessionId: ProviderSessionId.make("provider-session-antigravity-running-command"), + modelSelection, + runtimePolicy, + }); + const events = yield* Queue.unbounded(); + yield* session.events.pipe( + Stream.runForEach((event) => Queue.offer(events, event)), + Effect.forkScoped, + ); + const providerThread = yield* session.ensureThread({ + threadId, + modelSelection, + runtimePolicy, + }); + const now = yield* DateTime.now; + yield* session.startTurn({ + appThread: { + createdBy: "user", + creationSource: "web", + id: threadId, + projectId: ProjectId.make("project-antigravity-running-command"), + title: "Antigravity running command", + providerInstanceId: instanceId, + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: process.cwd(), + activeProviderThreadId: providerThread.id, + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId }, + forkedFrom: null, + createdAt: now, + updatedAt: now, + archivedAt: null, + settledOverride: null, + settledAt: null, + lastVisitedAt: null, + deletedAt: null, + }, + threadId, + runId: RunId.make("run-antigravity-running-command"), + runOrdinal: 1, + providerTurnOrdinal: 1, + attemptId: RunAttemptId.make("attempt-antigravity-running-command"), + rootNodeId: NodeId.make("node-antigravity-running-command"), + providerThread, + message: { + createdBy: "user", + creationSource: "web", + messageId: MessageId.make("message-antigravity-running-command"), + text: "watch the log", + attachments: [], + }, + modelSelection, + runtimePolicy, + }); + + let providerTurnId: ProviderAdapter.ProviderAdapterV2InterruptInput["providerTurnId"] | null = + null; + let commandStatus: string | null = null; + while (providerTurnId === null || commandStatus === null) { + const event = yield* Queue.take(events); + if (event.type === "provider_turn.updated") providerTurnId = event.providerTurn.id; + if ( + event.type === "turn_item.updated" && + event.turnItem.nativeItemRef?.nativeId === "watcher" + ) { + commandStatus = event.turnItem.status; + } + } + yield* Deferred.await(promptReturned); + yield* session.interruptTurn({ providerThread, providerTurnId, requestRuntimeRestart: true }); + + // Whether the turn waits for the command or leaves it running past the reply, + // it never reported finishing, so it must not be shown as completed. + let terminalSeen = false; + while (!terminalSeen) { + const event = yield* Queue.take(events); + if ( + event.type === "turn_item.updated" && + event.turnItem.nativeItemRef?.nativeId === "watcher" + ) { + commandStatus = event.turnItem.status; + } + terminalSeen = event.type === "turn.terminal"; + } + assert.notEqual(commandStatus, "completed"); + }).pipe(Effect.provide(layerSession), Effect.scoped), + ); +}); + describe("AntigravityAdapterV2 subagent reads", () => { it.effect("completes a read T3 served when the agent later fails it with a step error", () => Effect.gen(function* () { From 942f398432b6e6796b0e4b0926162bd7c9706207 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 09:10:37 +0000 Subject: [PATCH 2/3] fix(server): Antigravity commands still running after the reply keep the turn open, and Stop ends them At end_turn the Antigravity turn finalized as completed and marked every in-progress command completed, so Stop had no turn to end and the command kept running. Antigravity commands now count as background work: the turn stays open until they report finishing, and Stop restarts the runtime, which now runs in its own process group, so the commands end too. Fixes pingdotgg/t3code#16442 AI-assisted; verified with the tests and tools listed above. --- .../src/orchestration-v2/Adapters/AntigravityAdapterV2.ts | 6 ++++++ apps/server/src/provider/acp/AntigravityAcpSupport.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts index 1490140c1e6e2..2b06a97243f39 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts @@ -233,6 +233,12 @@ export function makeAntigravityAcpAdapterFlavor( ), // Loading history replays tool calls; resume avoids replay. subagentsIdleOnTurnCompletion: true, + // A command can outlive end_turn; session/cancel leaves it running, so Stop ends the process group. + extractBackgroundTaskId: (toolCall) => + toolCall.kind === "execute" ? toolCall.toolCallId : undefined, + deferFinalizeForBackgroundWork: true, + restartRuntimeAfterInterrupt: true, + terminateRuntimeProcessGroupOnInterrupt: true, ...(options.onSessionEvent === undefined ? {} : { onSessionEvent: options.onSessionEvent }), applyModelSelection: Effect.fn("AntigravityAdapterV2.applyModelSelection")(function* ({ runtime, diff --git a/apps/server/src/provider/acp/AntigravityAcpSupport.ts b/apps/server/src/provider/acp/AntigravityAcpSupport.ts index 66eab95c9fb39..dd93207bc9591 100644 --- a/apps/server/src/provider/acp/AntigravityAcpSupport.ts +++ b/apps/server/src/provider/acp/AntigravityAcpSupport.ts @@ -126,9 +126,13 @@ export const makeAntigravityAcpRuntime = Effect.fn("makeAntigravityAcpRuntime")( EffectAcpErrors.AcpError, SecureRandom.SecureRandom | Scope.Scope > { + const processGroupPlatform = yield* HostProcess.Platform; const context = yield* Layer.build( AcpSessionRuntime.layer({ ...input, + // Stop tears down the agent's process group to end commands session/cancel leaves running. + ownDetachedProcessGroup: true, + processGroupPlatform, authMethodId: input.authMethod ?? "oauth-personal", authenticateEagerly: true, resumeMethod: "resume", From a53c4580bf435c19c883587c91e0e6b6bb7f0d5c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 09:27:38 +0000 Subject: [PATCH 3/3] fix(server): Antigravity turns with a launched subagent batch still settle Holding the turn for background work also waited on running subagents, but Antigravity marks launched subagents running until finalizeTurn idles them, so a finished turn never settled. Subagents that the flavor idles at turn completion no longer hold the deferred finalize. AI-assisted; verified with the tests and tools listed above. --- .../Adapters/AntigravityAdapterV2.test.ts | 330 ++++++++++-------- packages/provider-acp/src/server/adapter.ts | 2 + 2 files changed, 182 insertions(+), 150 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts index 89594fd656689..a80520e4c29af 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -840,163 +840,193 @@ describe("AntigravityAdapterV2 html_render pages", () => { ); }); -describe("AntigravityAdapterV2 running commands", () => { - it.effect("does not mark a command completed while it is still running at end_turn", () => - Effect.gen(function* () { - const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; - const path = yield* Path.Path; - const crypto = yield* SecureRandom.SecureRandom; - const mockAgentPath = yield* path.fromFileUrl( - new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), - ); - type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; - let sessionUpdate: Parameters[0] | undefined; - const promptReturned = yield* Deferred.make(); - const instanceId = ProviderInstanceId.make("antigravity-running-command-test"); - const threadId = ThreadId.make("thread-antigravity-running-command"); - const adapter = yield* makeAntigravityAdapterV2({ - instanceId, - selfInvocation: yield* resolveSelfInvocation(), - makeRuntime: (input) => - makeAntigravityAcpRuntime({ - ...input, - childProcessSpawner, - spawn: { - command: process.execPath, - args: [mockAgentPath], - cwd: input.cwd, - env: { T3_ACP_ANTIGRAVITY: "1" }, - }, - }).pipe( - Effect.provideService(SecureRandom.SecureRandom, crypto), - Effect.map((runtime): RuntimeService => ({ - ...runtime, - handleSessionUpdate: (handler) => - Effect.sync(() => { - sessionUpdate = handler; - }).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))), - // The agent starts a watcher, answers, and ends its turn while it runs. - prompt: () => - Effect.gen(function* () { - if (sessionUpdate === undefined) { - return yield* Effect.die("the adapter must handle session updates"); - } - yield* sessionUpdate( - normalizeAntigravitySessionUpdate({ - sessionId: "mock-session-1", - update: { - sessionUpdate: "tool_call", - toolCallId: "watcher", - title: "Running run_command", - kind: "execute", - status: "in_progress", - rawInput: { CommandLine: "tail -f app.log" }, - }, - }), - ); - return { stopReason: "end_turn" as const }; - }).pipe(Effect.ensuring(Deferred.succeed(promptReturned, undefined))), - })), - ), - withProcess: (_stop, task) => task, - defaultModel: Effect.undefined, - }); - const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ +/** The agent reports one tool, answers end_turn, and the user optionally presses Stop after. */ +const endTurnAfterTool = ( + tool: Extract, + options: { readonly stopAfterReply: boolean }, +) => + Effect.gen(function* () { + const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; + const path = yield* Path.Path; + const crypto = yield* SecureRandom.SecureRandom; + const mockAgentPath = yield* path.fromFileUrl( + new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), + ); + type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; + let sessionUpdate: Parameters[0] | undefined; + const promptReturned = yield* Deferred.make(); + const instanceId = ProviderInstanceId.make("antigravity-running-command-test"); + const threadId = ThreadId.make("thread-antigravity-running-command"); + const adapter = yield* makeAntigravityAdapterV2({ + instanceId, + selfInvocation: yield* resolveSelfInvocation(), + makeRuntime: (input) => + makeAntigravityAcpRuntime({ + ...input, + childProcessSpawner, + spawn: { + command: process.execPath, + args: [mockAgentPath], + cwd: input.cwd, + env: { T3_ACP_ANTIGRAVITY: "1" }, + }, + }).pipe( + Effect.provideService(SecureRandom.SecureRandom, crypto), + Effect.map((runtime): RuntimeService => ({ + ...runtime, + handleSessionUpdate: (handler) => + Effect.sync(() => { + sessionUpdate = handler; + }).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))), + prompt: () => + Effect.gen(function* () { + if (sessionUpdate === undefined) { + return yield* Effect.die("the adapter must handle session updates"); + } + yield* sessionUpdate( + normalizeAntigravitySessionUpdate({ + sessionId: "mock-session-1", + update: tool, + }), + ); + return { stopReason: "end_turn" as const }; + }).pipe(Effect.ensuring(Deferred.succeed(promptReturned, undefined))), + })), + ), + withProcess: (_stop, task) => task, + defaultModel: Effect.undefined, + }); + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "full-access", + interactionMode: "default", + cwd: process.cwd(), + }); + const modelSelection = { instanceId, model: "gemini-test-low" } as const; + const session = yield* adapter.openSession({ + threadId, + providerSessionId: ProviderSessionId.make("provider-session-antigravity-running-command"), + modelSelection, + runtimePolicy, + }); + const events = yield* Queue.unbounded(); + yield* session.events.pipe( + Stream.runForEach((event) => Queue.offer(events, event)), + Effect.forkScoped, + ); + const providerThread = yield* session.ensureThread({ + threadId, + modelSelection, + runtimePolicy, + }); + const now = yield* DateTime.now; + yield* session.startTurn({ + appThread: { + createdBy: "user", + creationSource: "web", + id: threadId, + projectId: ProjectId.make("project-antigravity-running-command"), + title: "Antigravity running command", + providerInstanceId: instanceId, + modelSelection, runtimeMode: "full-access", interactionMode: "default", - cwd: process.cwd(), - }); - const modelSelection = { instanceId, model: "gemini-test-low" } as const; - const session = yield* adapter.openSession({ - threadId, - providerSessionId: ProviderSessionId.make("provider-session-antigravity-running-command"), - modelSelection, - runtimePolicy, - }); - const events = yield* Queue.unbounded(); - yield* session.events.pipe( - Stream.runForEach((event) => Queue.offer(events, event)), - Effect.forkScoped, - ); - const providerThread = yield* session.ensureThread({ - threadId, - modelSelection, - runtimePolicy, - }); - const now = yield* DateTime.now; - yield* session.startTurn({ - appThread: { - createdBy: "user", - creationSource: "web", - id: threadId, - projectId: ProjectId.make("project-antigravity-running-command"), - title: "Antigravity running command", - providerInstanceId: instanceId, - modelSelection, - runtimeMode: "full-access", - interactionMode: "default", - branch: null, - worktreePath: process.cwd(), - activeProviderThreadId: providerThread.id, - lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId }, - forkedFrom: null, - createdAt: now, - updatedAt: now, - archivedAt: null, - settledOverride: null, - settledAt: null, - lastVisitedAt: null, - deletedAt: null, - }, - threadId, - runId: RunId.make("run-antigravity-running-command"), - runOrdinal: 1, - providerTurnOrdinal: 1, - attemptId: RunAttemptId.make("attempt-antigravity-running-command"), - rootNodeId: NodeId.make("node-antigravity-running-command"), - providerThread, - message: { - createdBy: "user", - creationSource: "web", - messageId: MessageId.make("message-antigravity-running-command"), - text: "watch the log", - attachments: [], - }, - modelSelection, - runtimePolicy, - }); + branch: null, + worktreePath: process.cwd(), + activeProviderThreadId: providerThread.id, + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId }, + forkedFrom: null, + createdAt: now, + updatedAt: now, + archivedAt: null, + settledOverride: null, + settledAt: null, + lastVisitedAt: null, + deletedAt: null, + }, + threadId, + runId: RunId.make("run-antigravity-running-command"), + runOrdinal: 1, + providerTurnOrdinal: 1, + attemptId: RunAttemptId.make("attempt-antigravity-running-command"), + rootNodeId: NodeId.make("node-antigravity-running-command"), + providerThread, + message: { + createdBy: "user", + creationSource: "web", + messageId: MessageId.make("message-antigravity-running-command"), + text: "watch the log", + attachments: [], + }, + modelSelection, + runtimePolicy, + }); - let providerTurnId: ProviderAdapter.ProviderAdapterV2InterruptInput["providerTurnId"] | null = - null; - let commandStatus: string | null = null; - while (providerTurnId === null || commandStatus === null) { - const event = yield* Queue.take(events); - if (event.type === "provider_turn.updated") providerTurnId = event.providerTurn.id; - if ( - event.type === "turn_item.updated" && - event.turnItem.nativeItemRef?.nativeId === "watcher" - ) { - commandStatus = event.turnItem.status; - } + let providerTurnId: ProviderAdapter.ProviderAdapterV2InterruptInput["providerTurnId"] | null = + null; + let itemStatus: string | null = null; + while (providerTurnId === null || itemStatus === null) { + const event = yield* Queue.take(events); + if (event.type === "provider_turn.updated") providerTurnId = event.providerTurn.id; + if ( + event.type === "turn_item.updated" && + event.turnItem.nativeItemRef?.nativeId === tool.toolCallId + ) { + itemStatus = event.turnItem.status; } - yield* Deferred.await(promptReturned); + } + yield* Deferred.await(promptReturned); + if (options.stopAfterReply) { yield* session.interruptTurn({ providerThread, providerTurnId, requestRuntimeRestart: true }); + } - // Whether the turn waits for the command or leaves it running past the reply, - // it never reported finishing, so it must not be shown as completed. - let terminalSeen = false; - while (!terminalSeen) { - const event = yield* Queue.take(events); - if ( - event.type === "turn_item.updated" && - event.turnItem.nativeItemRef?.nativeId === "watcher" - ) { - commandStatus = event.turnItem.status; - } - terminalSeen = event.type === "turn.terminal"; + let terminalStatus: string | null = null; + while (terminalStatus === null) { + const event = yield* Queue.take(events); + if ( + event.type === "turn_item.updated" && + event.turnItem.nativeItemRef?.nativeId === tool.toolCallId + ) { + itemStatus = event.turnItem.status; } - assert.notEqual(commandStatus, "completed"); - }).pipe(Effect.provide(layerSession), Effect.scoped), + if (event.type === "turn.terminal") terminalStatus = event.status; + } + return { itemStatus, terminalStatus }; + }).pipe(Effect.provide(layerSession), Effect.scoped); + +describe("AntigravityAdapterV2 running commands", () => { + it.effect("does not mark a command completed while it is still running at end_turn", () => + Effect.gen(function* () { + const result = yield* endTurnAfterTool( + { + sessionUpdate: "tool_call", + toolCallId: "watcher", + title: "Running run_command", + kind: "execute", + status: "in_progress", + rawInput: { CommandLine: "tail -f app.log" }, + }, + { stopAfterReply: true }, + ); + // It never reported finishing, so it must not be shown as completed. + assert.notEqual(result.itemStatus, "completed"); + }), + ); + + it.effect("completes the turn at end_turn while a launched subagent batch runs", () => + Effect.gen(function* () { + const result = yield* endTurnAfterTool( + { + sessionUpdate: "tool_call", + toolCallId: "batch", + title: "Running start_subagent", + kind: "other", + status: "completed", + rawOutput: "Started two agents.", + }, + { stopAfterReply: false }, + ); + assert.equal(result.terminalStatus, "completed"); + }), ); }); diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 6f818c442e0cd..3c290a1452551 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -3782,6 +3782,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( const status = toolStatus(tool.status); if (status === "pending" || status === "running") return true; } + // finalizeTurn idles these subagents, so waiting on them would never settle. + if (flavor.subagentsIdleOnTurnCompletion === true) return false; for (const subagent of context.subagents.values()) { if (acpSubagentStatusBlocksTurnSettlement(subagent.task.status)) { return true;