The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 11:00 UTC
fix(acp): a failed MCP-over-ACP disconnect can be retried (#33069)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Zenco committed
Nov 15, 2026 at 13:52 UTC
015eba4083974f8ed86694a8770a4311d8a4714b
2 files changed
+47
-22
packages/provider-acp/src/server/mcpOverAcpBridge.test.ts
+21
-1
@@ -10,11 +10,14 @@ describe("AcpMcpOverAcpBridge", () => {
10
const initializeStarted = Promise.withResolvers<void>();
11
const initializeResponse = Promise.withResolvers<void>();
12
const listQueued = Promise.withResolvers<void>();
13
+ const deleteStarted = Promise.withResolvers<void>();
14
+ const deleteResponse = Promise.withResolvers<void>();
15
const requests: Array<{
16
readonly method: string;
17
readonly headers: Headers;
18
readonly body: unknown;
19
}> = [];
20
+ let deletes = 0;
21
const bridge = yield* makeAcpMcpOverAcpBridge({
22
endpoint: "http://127.0.0.1:1/mcp",
23
authorization: "Bearer bridge-test",
@@ -24,7 +27,12 @@ describe("AcpMcpOverAcpBridge", () => {
27
const headers = new Headers(init?.headers);
28
const body = init?.body === undefined ? null : JSON.parse(String(init.body));
29
requests.push({ method, headers, body });
27
- if (method === "DELETE") return new Response(null, { status: 204 });
30
+ if (method === "DELETE") {
31
+ if (++deletes > 1) return new Response(null, { status: 204 });
32
+ deleteStarted.resolve();
33
+ await deleteResponse.promise;
34
+ return new Response(null, { status: 503 });
35
+ }
36
if (body === null || typeof body !== "object") return new Response(null, { status: 202 });
37
const request = body as { readonly id?: unknown; readonly method?: unknown };
38
if (request.method === "initialize") {
@@ -71,7 +79,19 @@ describe("AcpMcpOverAcpBridge", () => {
79
connectionId: connected.connectionId,
80
method: "notifications/initialized",
81
});
82
+ // Calls during a close are refused; a rejected close restores the connection for a retry.
83
+ const rejected = yield* bridge
84
+ .disconnect({ connectionId: connected.connectionId })
85
+ .pipe(Effect.flip, Effect.forkChild);
86
+ yield* Effect.promise(() => deleteStarted.promise);
87
+ const closing = yield* bridge
88
+ .message({ connectionId: connected.connectionId, method: "tools/list" })
89
+ .pipe(Effect.flip);
90
+ expect(closing.message).toContain("Unknown MCP-over-ACP connection");
91
+ deleteResponse.resolve();
92
+ expect((yield* Fiber.join(rejected)).message).toContain("HTTP 503");
93
yield* bridge.disconnect({ connectionId: connected.connectionId });
94
+ expect(deletes).toBe(2);
95
96
expect(requests[0]?.headers.get("authorization")).toBe("Bearer bridge-test");
97
expect(requests[1]?.headers.get("mcp-session-id")).toBe("session-42");
packages/provider-acp/src/server/mcpOverAcpBridge.ts
+26
-21
@@ -163,28 +163,33 @@ export const makeAcpMcpOverAcpBridge = Effect.fn("AcpMcpOverAcpBridge.make")(fun
163
connections.delete(request.connectionId);
164
const sessionId = connection.sessionId;
165
if (sessionId !== null) {
166
- const response = yield* Effect.tryPromise({
167
- try: (signal) =>
168
- fetchImplementation(options.endpoint, {
169
- method: "DELETE",
170
- signal,
171
- headers: {
172
- authorization: options.authorization,
173
- "mcp-session-id": sessionId,
174
- ...(connection.protocolVersion === null
175
- ? {}
176
- : { "mcp-protocol-version": connection.protocolVersion }),
177
- },
178
- }),
179
- catch: bridgeError,
180
- });
181
- if (!response.ok && response.status !== 404) {
182
- return yield* new AcpMcpOverAcpError({
183
- message: `T3 Code MCP endpoint rejected disconnect with HTTP ${response.status}.`,
166
+ yield* Effect.gen(function* () {
167
+ const response = yield* Effect.tryPromise({
168
+ try: (signal) =>
169
+ fetchImplementation(options.endpoint, {
170
+ method: "DELETE",
171
+ signal,
172
+ headers: {
173
+ authorization: options.authorization,
174
+ "mcp-session-id": sessionId,
175
+ ...(connection.protocolVersion === null
176
+ ? {}
177
+ : { "mcp-protocol-version": connection.protocolVersion }),
178
+ },
179
+ }),
180
+ catch: bridgeError,
181
});
185
- }
186
- yield* Effect.promise(
187
- () => response.body?.cancel().catch(() => undefined) ?? Promise.resolve(),
182
+ if (!response.ok && response.status !== 404) {
183
+ return yield* new AcpMcpOverAcpError({
184
+ message: `T3 Code MCP endpoint rejected disconnect with HTTP ${response.status}.`,
185
+ });
186
+ }
187
+ yield* Effect.promise(
188
+ () => response.body?.cancel().catch(() => undefined) ?? Promise.resolve(),
189
+ );
190
+ }).pipe(
191
+ // Restore a session that failed to close, so a retry or dispose can close it.
192
+ Effect.onError(() => Effect.sync(() => connections.set(request.connectionId, connection))),
193
);
194
}
195
return {};