Repository navigation
Closed
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Description
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
- Start an ACP agent that uses T3 Code tools through the MCP HTTP bridge.
- Ask the agent to run a tool whose HTTP response starts an event stream but then stops sending data without closing.
- 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 falseAutomated 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.tsWorkaround
No response
Metadata
Metadata
Assignees
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Activity
fix(acp): Stop ends the agent's in-flight MCP-over-ACP calls