fix(antigravity): increase cancel timeout and ignore transport errors during prompt drainage #11626
main fromrefs/pull/11626/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
- @@ -928,4 +928,4 @@928928 return;929929 }930930931- yield* acp.agent.cancel({ sessionId: started.sessionId });931+ yield* acp.agent.cancel({ sessionId: started.sessionId }).pipe(Effect.ignore);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XS
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- @@ -221,3 +221,18 @@221221 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),222222 );223223224+ it.effect(225+ "drains active prompt successfully when session/cancel notification fails with transport error",226+ () =>227+ Effect.gen(function* () {228+ const toolStarted = yield* Deferred.make<void>();229+ const cancelReceived = yield* Deferred.make<void>();230+ let promptRequests = 0;231+ const events: Array<AcpSessionRuntime.AcpSessionRuntimeEvent> = [];232+ const runtime = yield* AcpSessionRuntime.make({233+ ...mockRuntimeOptions,234+ spawn: {235+ ...mockRuntimeOptions.spawn,236+ env: {237+ T3_ACP_COMPLETE_FIRST_PROMPT_ON_CANCEL: "1",238+ T3_ACP_FAIL_CANCEL: "1",
- apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts lines 384 to 455Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -223,0 +293,21 @@293+ event.toolCall.status === "failed" &&294+ event.toolCall.detail === "Cancelled.",295+ ),296+ ).toBe(true);297+ const cancelledDelta = events.find(298+ (event) => event._tag === "ContentDelta" && event.text === "Request cancelled.",299+ );300+ expect(cancelledDelta?._tag).toBe("ContentDelta");301+ if (cancelledDelta?._tag === "ContentDelta") {302+ expect(303+ events.filter(304+ (event) =>305+ event._tag === "AssistantItemCompleted" && event.itemId === cancelledDelta.itemId,306+ ),307+ ).toHaveLength(1);308+ }309+ expect(yield* Fiber.join(replacement)).toMatchObject({ stopReason: "end_turn" });310+ expect(promptRequests).toBe(2);311+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),312+ );313+
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
- @@ -928,4 +928,4 @@928928 return;929929 }930930931- yield* acp.agent.cancel({ sessionId: started.sessionId });931+ yield* acp.agent.cancel({ sessionId: started.sessionId }).pipe(Effect.ignore);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XS
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -221,3 +221,17 @@221221 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),222222 );223223224+ it.effect(225+ "drains active prompt successfully when agent cancels by failing in-flight prompt with context canceled",226+ () =>227+ Effect.gen(function* () {228+ const toolStarted = yield* Deferred.make<void>();229+ let promptRequests = 0;230+ const events: Array<AcpSessionRuntime.AcpSessionRuntimeEvent> = [];231+ const runtime = yield* AcpSessionRuntime.make({232+ ...mockRuntimeOptions,233+ spawn: {234+ ...mockRuntimeOptions.spawn,235+ env: {236+ T3_ACP_FAIL_PROMPT_ON_CANCEL: "1",237+ },@@ -317,3 +317,16 @@317317 interface AcpActivePrompt {318318 readonly fiber: Fiber.Fiber<EffectAcpSchema.PromptResponse, EffectAcpErrors.AcpError>;319319 readonly completed: Deferred.Deferred<void>;320+ readonly cancelled: Ref.Ref<boolean>;321+}322+323+function isPromptCancellationError(error: unknown): boolean {324+ if (325+ typeof error === "object" &&326+ error !== null &&327+ "_tag" in error &&328+ error._tag === "AcpRequestError"329+ ) {330+ const reqErr = error as EffectAcpErrors.AcpRequestError;331+ const msg = (reqErr.errorMessage ?? "").toLowerCase();332+ return reqErr.code === -32000 || msg.includes("cancel") || msg.includes("abort");
- apps/server/src/provider/acp/AcpSessionRuntime.ts line 332OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -317,3 +317,16 @@317317 interface AcpActivePrompt {318318 readonly fiber: Fiber.Fiber<EffectAcpSchema.PromptResponse, EffectAcpErrors.AcpError>;319319 readonly completed: Deferred.Deferred<void>;320+ readonly cancelled: Ref.Ref<boolean>;321+}322+323+function isPromptCancellationError(error: unknown): boolean {324+ if (325+ typeof error === "object" &&326+ error !== null &&327+ "_tag" in error &&328+ error._tag === "AcpRequestError"329+ ) {330+ const reqErr = error as EffectAcpErrors.AcpRequestError;331+ const msg = (reqErr.errorMessage ?? "").toLowerCase();332+ return reqErr.code === -32000 || msg.includes("cancel") || msg.includes("abort");apps/server/src/provider/acp/AcpSessionRuntime.ts lines 1057 to 1059Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1005,8 +1033,13 @@10051033 (activePrompt) =>10061034 Fiber.join(activePrompt.fiber).pipe(10071035 Effect.catchCause((cause) =>1008- options.cancelBehavior !== "wait-for-prompt" && Cause.hasInterruptsOnly(cause)1009- ? Effect.succeed({1036+ Effect.gen(function* () {1037+ const isCancelled = yield* Ref.get(activePrompt.cancelled);1038+ if (1039+ (options.cancelBehavior !== "wait-for-prompt" &&1040+ Cause.hasInterruptsOnly(cause)) ||1041+ (isCancelled && isPromptCancellationCause(cause))1042+ ) {1043+ return {10101044 stopReason: "cancelled",1011- } satisfies EffectAcpSchema.PromptResponse)1012- : Effect.failCause(cause),1045+ } satisfies EffectAcpSchema.PromptResponse;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -1273,0 +1321,21 @@1321+ * Finalizes any active in-flight tool calls with a failed terminal cancellation status1322+ * when an ACP prompt turn is cancelled.1323+ */1324+const finalizeActiveToolCallsOnCancellation = ({1325+ queue,1326+ toolCallsRef,1327+}: {1328+ readonly queue: Queue.Queue<AcpSessionRuntimeEvent>;1329+ readonly toolCallsRef: Ref.Ref<Map<string, AcpToolCallTrackedState>>;1330+}) =>1331+ Effect.gen(function* () {1332+ const activeToolCalls = yield* Ref.modify(toolCallsRef, (current) => {1333+ const active = Array.from(current.values()).map((tracked) => tracked.state);1334+ return [active, new Map<string, AcpToolCallTrackedState>()] as const;1335+ });1336+ for (const toolCall of activeToolCalls) {1337+ yield* Queue.offer(queue, {1338+ _tag: "ToolCallUpdated",1339+ toolCall: {1340+ ...toolCall,1341+ status: "failed",
- @@ -1005,5 +1043,11 @@10051043 (activePrompt) =>10061044 Fiber.join(activePrompt.fiber).pipe(10071045 Effect.catchCause((cause) =>1008- options.cancelBehavior !== "wait-for-prompt" && Cause.hasInterruptsOnly(cause)1009- ? Effect.succeed({1046+ Effect.gen(function* () {1047+ const isCancelled = yield* Ref.get(activePrompt.cancelled);1048+ if (1049+ (options.cancelBehavior !== "wait-for-prompt" &&1050+ Cause.hasInterruptsOnly(cause)) ||1051+ (isCancelled && isPromptCancellationCause(cause))1052+ ) {1053+ yield* finalizeActiveToolCallsOnCancellation({
juliusmarminge closed this
Sign in to join this conversation.
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
c9d42f9ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.