Skip to content

[Bug]: Stopping an ACP MCP call leaves its stalled response open #37849

Closed

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

packages/contracts or packages/shared

Steps to reproduce

  1. Start an ACP agent that uses T3 Code tools through the MCP HTTP bridge.
  2. Ask the agent to run a tool whose HTTP response starts an event stream but then stops sending data without closing.
  3. Stop the pending call while it is waiting for the next event.

Expected behavior

Stopping the call cancels and releases its HTTP response body.

Actual behavior

The response body remains locked with its read pending after cancellation completes; the connection is not cancelled until the server sends more data or closes it.

Impact

Minor bug or occasional failure. ACP users leave a response connection and pending reader behind each time they cancel a tool call while its event stream is stalled.

Version or commit

main at 6dd092315e. The cause is at packages/shared/src/mcpResponsePayloads.ts:40.

Environment

Linux x64, the repository's own tests.

Logs or stack traces

interrupted SSE response must release its body: expected true to be false
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/packages/shared/src/mcpResponsePayloads.test.ts b/packages/shared/src/mcpResponsePayloads.test.ts
index 8027d6393f..7ca999180d 100644
--- a/packages/shared/src/mcpResponsePayloads.test.ts
+++ b/packages/shared/src/mcpResponsePayloads.test.ts
@@ -1,4 +1,6 @@
-import { expect, it } from "@effect/vitest";
+import { it } from "@effect/vitest";
+import { expect } from "vite-plus/test";
+import * as Fiber from "effect/Fiber";
 import * as Effect from "effect/Effect";
 import * as Stream from "effect/Stream";
 
@@ -91,3 +93,34 @@ it.effect("picks the SSE reader from the media type alone, whatever its case", (
     expect(Array.from(jsonPayloads)).toEqual([{ jsonrpc: "2.0", id: 1, result: {} }]);
   }),
 );
+
+it.effect("releases a stalled SSE response body when its consumer is interrupted", () =>
+  Effect.gen(function* () {
+    const reading = Promise.withResolvers<void>();
+    let controller!: ReadableStreamDefaultController<Uint8Array>;
+    const body = new ReadableStream<Uint8Array>(
+      {
+        start(value) {
+          controller = value;
+        },
+        pull() {
+          reading.resolve();
+        },
+      },
+      { highWaterMark: 0 },
+    );
+    const response = new Response(body, {
+      headers: { "content-type": "text/event-stream" },
+    });
+    const consumer = yield* Stream.runDrain(responsePayloads(response, String)).pipe(
+      Effect.forkChild,
+    );
+    yield* Effect.promise(() => reading.promise);
+    yield* Fiber.interrupt(consumer);
+    try {
+      expect(body.locked, "interrupted SSE response must release its body").toBe(false);
+    } finally {
+      if (body.locked) controller.close();
+    }
+  }),
+);
cd packages/shared && pnpm exec vp test run --config ../../vite.config.ts src/mcpResponsePayloads.test.ts

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 17, 2026
  2. added a commit that references this issue on Nov 17, 2026
    81857f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions