Repository navigation
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 a thread with an ACP provider that uses T3 tools through the MCP bridge.
- Ask the agent to call a tool that returns a multi-megabyte result over a connection delivering the SSE response in small chunks.
- Wait for the agent to receive the tool result.
Expected behavior
The bridge processes the result promptly, with work proportional to the response size even when the connection delivers many small chunks.
Actual behavior
Processing time grows quadratically with the size of a single streamed result. Locally, immediately available 1, 2, and 4 MiB results delivered in 256-byte chunks took approximately 1.2, 4.8, and 19.9 seconds; the same 4 MiB result delivered in one chunk took about 5 ms.
Impact
Minor bug or occasional failure. Agents using the MCP-over-ACP or stdio bridge wait unnecessarily and spend substantial CPU whenever a large SSE tool result arrives in many small chunks.
Version or commit
main at 705c7f2479. The cause is at packages/shared/src/mcpResponsePayloads.ts:16.
Environment
Linux x64 boat.dev default machine, a fresh checkout.
Logs or stack traces
SSE parsing exceeds 1500 ms CPU-work budget for 4 MiB in 256-byte chunks:Automated repro
Fails in 2 of 2 runs on main: run the command.
cd packages/shared && node --input-type=module <<'SSE_MEASUREMENT'
import * as Effect from 'effect/Effect';
import * as Stream from 'effect/Stream';
import { writeFileSync } from 'node:fs';
import { responsePayloads } from './src/mcpResponsePayloads.ts';
const samples = [];
for (const size of [1024 * 1024, 2 * 1024 * 1024, 4 * 1024 * 1024]) {
const bytes = new TextEncoder().encode('data: ' + JSON.stringify({jsonrpc:'2.0',id:1,result:{content:[{type:'text',text:'x'.repeat(size)}]}}) + '\n\n');
for (const chunkBytes of [bytes.length, 256]) {
let offset = 0;
const body = new ReadableStream({pull(controller) {
if (offset === bytes.length) return controller.close();
controller.enqueue(bytes.subarray(offset, offset + chunkBytes));
offset = Math.min(offset + chunkBytes, bytes.length);
}});
const start = performance.now();
const payloads = await Effect.runPromise(Stream.runCollect(responsePayloads(new Response(body, {headers:{'content-type':'text/event-stream'}}), String)));
const elapsedMs = performance.now() - start;
if (Array.from(payloads)[0]?.result.content[0].text.length !== size) throw new Error('Incorrect payload');
samples.push({size,chunkBytes,elapsedMs});
console.log(JSON.stringify(samples.at(-1)));
}
}
writeFileSync(process.env.FLEET_OUT + '/sse-samples.json', JSON.stringify(samples, null, 2));
const slow = samples.at(-1);
if (slow.elapsedMs > 1500) throw new Error('SSE parsing exceeds 1500 ms CPU-work budget for 4 MiB in 256-byte chunks: ' + slow.elapsedMs.toFixed(1) + ' ms');
SSE_MEASUREMENTWorkaround
No response
Activity