#7339 · Idle plugin-tool response exceeds the fetch body deadline
Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high
1. TL;DR
A plugin computation can lose its agent-facing result when it stays silent for approximately five minutes. Two real-time runs used the real daemon client, the authenticated server route, a real SQLite harness, Hono's HTTP adapter, and Node's unchanged built-in fetch. The HTTP head arrives promptly, but reading the result fails with UND_ERR_BODY_TIMEOUT before the scheduled 310-second completion. The separate claim that this automatically becomes a detached result is not supported: the observed tool signal is aborted and its registry entry is removed. Deliberately detached user-input tools follow a different path.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| The daemon uses fetch without a custom timeout dispatcher. | Verified | Actual createServerClient callTool invokes built-in fetch; both real runs fail at the body deadline. |
| The response starts before completion, then carries no result data until completion. | Verified | HTTP 200 arrives early. The streaming response enqueues its JSON only when the invocation promise settles. |
| A computation exceeding five minutes loses the normal round trip. | Verified | Both runs produce TypeError: terminated, caused by BodyTimeoutError / UND_ERR_BODY_TIMEOUT. |
| The late result automatically becomes a detached message. | Not reproduced; ordinary-tool lifecycle contradicts this generalization | Both runs observe toolAborted=true and trackedCalls=0. Detachment requires an explicit detachWith call, not a transport failure. |
| A proposed transport-dependency change is necessary. | Not established | No issue-supplied patch or test was used, and no dependency was added. A server-side keepalive is another candidate, but must bypass buffering compression and preserve cancellation. |
3. Environment
- Public repository get-bb/bb; trusted origin/main at the full commit shown above.
- Linux 4.19.0-gvisor; Node v22.19.0, bundled undici 6.21.2; pnpm 9.15.0; Vitest 4.1.12.
- No real provider, live BB instance, user runtime data, external tool service, or credentials were used.
- Each run used its own clean Git worktree, frozen dependency install, migrated SQLite test harness, ephemeral loopback TCP port, and disposable harness data directory.
- The broad build initially needed the SDK runtime build before plugin compilation; after the SDK build, all 73 broad build tasks passed.
4. Minimal reproduction
Run these commands in a new directory. The test intentionally takes about five minutes and fails on the unmodified base.
WORK=$(mktemp -d) git clone https://github.com/get-bb/bb.git "$WORK/base" cd "$WORK/base" git checkout 7c1353d80729983b86ea1555d18b42407f320406 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build # Save the test below as apps/server/test/internal/tool-call-idle-timeout.test.ts pnpm exec turbo run test --filter=@bb/server -- test/internal/tool-call-idle-timeout.test.ts
Expected: callTool resolves to the supplied success result after 310 seconds. Actual: its body read throws around 300 seconds, before completion. The test does not shorten the timeout, alter a dispatcher, or fake time.
First clean run
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: HEAD status=200 elapsedMs=41
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: TRANSPORT name=TypeError message=terminated elapsedMs=300789
@bb/server:test: CAUSE BodyTimeoutError: Body Timeout Error
@bb/server:test: code: 'UND_ERR_BODY_TIMEOUT'
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: LIFECYCLE toolAborted=true trackedCalls=0
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: AFTER_RESULT toolAborted=true trackedCalls=0
@bb/server:test: × returns a plugin result after 310 seconds of idle computation 301059ms
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
@bb/server:test: FAIL |@bb/server| test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: TypeError: terminated
@bb/server:test: Caused by: BodyTimeoutError: Body Timeout Error
@bb/server:test: Serialized Error: { code: 'UND_ERR_BODY_TIMEOUT' }
@bb/server:test: Test Files 1 failed (1)
@bb/server:test: Tests 1 failed (1)
@bb/server:test: Duration 310.30s (transform 4.92s, setup 1.64s, import 4.93s, tests 301.76s, environment 0ms)
@bb/server:test: ELIFECYCLE Test failed. See above for more details.
Second clean run
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: HEAD status=200 elapsedMs=41
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: TRANSPORT name=TypeError message=terminated elapsedMs=300759
@bb/server:test: CAUSE BodyTimeoutError: Body Timeout Error
@bb/server:test: code: 'UND_ERR_BODY_TIMEOUT'
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: LIFECYCLE toolAborted=true trackedCalls=0
@bb/server:test: stdout | test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: AFTER_RESULT toolAborted=true trackedCalls=0
@bb/server:test: × returns a plugin result after 310 seconds of idle computation 301028ms
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
@bb/server:test: FAIL |@bb/server| test/internal/tool-call-idle-timeout.test.ts > returns a plugin result after 310 seconds of idle computation
@bb/server:test: TypeError: terminated
@bb/server:test: Caused by: BodyTimeoutError: Body Timeout Error
@bb/server:test: Serialized Error: { code: 'UND_ERR_BODY_TIMEOUT' }
@bb/server:test: Test Files 1 failed (1)
@bb/server:test: Tests 1 failed (1)
@bb/server:test: Duration 310.44s (transform 5.10s, setup 1.62s, import 5.29s, tests 301.66s, environment 0ms)
@bb/server:test: ELIFECYCLE Test failed. See above for more details.
Complete reproduction test
The test is inline to comply with the public reports repository's no-script/no-log-file publication policy.
import { once } from "node:events";
import { performance } from "node:perf_hooks";
import { serve } from "@hono/node-server";
import type { ToolCallResponse } from "@bb/domain";
import { expect, it, vi } from "vitest";
import { createServerClient } from "../../../host-daemon/src/server-client.js";
import { setPluginAgentContributions } from "../../src/services/plugins/plugin-agent-contributions.js";
import { requirePluginToolCallRegistry } from "../../src/services/plugins/plugin-tool-calls.js";
import { internalAuthHeaders } from "../helpers/commands.js";
import { seedEnvironment, seedHostSession, seedProjectWithSource, seedThread } from "../helpers/seed.js";
import { withTestHarness } from "../helpers/test-app.js";
it("returns a plugin result after 310 seconds of idle computation", async () => {
await withTestHarness(async (harness) => {
const { host, session } = seedHostSession(harness.deps, { id: "host-idle-transport" });
const { project } = seedProjectWithSource(harness.deps, { hostId: host.id });
const environment = seedEnvironment(harness.deps, { hostId: host.id, projectId: project.id });
const thread = seedThread(harness.deps, { projectId: project.id, environmentId: environment.id });
const result: ToolCallResponse = { success: true, contentItems: [{ type: "inputText", text: "finished" }] };
let completeTool!: (response: ToolCallResponse) => void;
const pending = new Promise<ToolCallResponse>((resolve) => { completeTool = resolve; });
let toolSignal: AbortSignal | undefined;
setPluginAgentContributions({
listSkillRootContributions: () => [],
listAgentTools: () => [],
listInstructionContributions: () => [],
findAgentTool: (name) => name === "idle_transport_probe" ? {
pluginId: "fixture",
record: {
name: "idle_transport_probe", description: "Transport probe", presentation: null,
instructions: null, inputSchema: {}, parse: (input) => ({ ok: true, value: input }),
execute: () => "unused",
},
} : undefined,
resolveMention: async () => ({ ok: false, error: "unused" }),
invokeAgentTool: ({ ctx }) => { toolSignal = ctx.signal; return pending; },
});
const server = serve({ fetch: harness.app.fetch, hostname: "127.0.0.1", port: 0 });
const started = performance.now();
const completion = setTimeout(() => completeTool(result), 310_000);
try {
if (!server.listening) await once(server, "listening");
const address = server.address();
if (address === null || typeof address === "string") throw new Error("Expected TCP address");
const authorization = new Headers(internalAuthHeaders(harness)).get("authorization");
if (!authorization?.startsWith("Bearer ")) throw new Error("Expected fixture authentication");
const client = createServerClient({
serverUrl: `http://127.0.0.1:${address.port}`,
hostKey: authorization.slice(7), getSessionId: () => session.id,
logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
fetchFn: async (input, init) => {
const response = await fetch(input, init);
console.log(`HEAD status=${response.status} elapsedMs=${Math.round(performance.now() - started)}`);
return response;
},
});
let received: ToolCallResponse;
try {
received = await client.callTool({
threadId: thread.id, providerThreadId: "provider-probe", turnId: "turn-probe",
callId: "call-probe", tool: "idle_transport_probe", arguments: {},
});
} catch (error) {
if (!(error instanceof Error)) throw error;
console.log(`TRANSPORT name=${error.name} message=${error.message} elapsedMs=${Math.round(performance.now() - started)}`);
console.log("CAUSE", error.cause);
await new Promise<void>((resolve) => setTimeout(resolve, 100));
console.log(`LIFECYCLE toolAborted=${toolSignal?.aborted} trackedCalls=${requirePluginToolCallRegistry().size}`);
throw error;
}
expect(received).toEqual(result);
} finally {
clearTimeout(completion);
completeTool(result);
await new Promise<void>((resolve) => setTimeout(resolve, 100));
console.log(`AFTER_RESULT toolAborted=${toolSignal?.aborted} trackedCalls=${requirePluginToolCallRegistry().size}`);
server.closeAllConnections();
await new Promise<void>((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
setPluginAgentContributions(undefined);
}
});
}, 330_000);
5. Root cause
apps/host-daemon/src/server-client.ts:315 chooses built-in fetch. apps/host-daemon/src/server-client.ts:520 posts the call and then awaits response.json(), without a request-specific dispatcher. Sending the response head avoids a header timeout, but does not disable the client's idle body timeout.
const response = await fetchFn(buildInternalUrl("/session/tool-call"), {
signal,
method: "POST",
headers: headers(),
body: JSON.stringify(payload),
});
if (!response.ok) {
throw await createResponseError("call tool", response);
}
return hostDaemonToolCallResponseSchema.parse(await response.json());
apps/server/src/internal/tool-calls.ts:25 creates a stream but emits no application body bytes until the result promise settles. Hono may send a compression preamble, which likewise does not provide ongoing progress. Thus a quiet tool crosses fetch's body-idle deadline even though the computation remains legitimate.
function streamToolCallResponse(
result: Promise<ToolCallResponse>,
abortController: AbortController,
): Response {
const body = new ReadableStream<Uint8Array>({
cancel() {
abortController.abort();
},
start(controller) {
void result.then(
(response) => {
try {
controller.enqueue(textEncoder.encode(JSON.stringify(response)));
controller.close();
} catch (error) {
controller.error(error);
}
},
(error) => controller.error(error),
);
},
});
return new Response(body, {
headers: { "content-type": "application/json; charset=UTF-8" },
});
The timeout is not an automatic detachment trigger. apps/server/src/services/plugins/plugin-tool-calls.ts:75 aborts and settles an ordinary failed round trip; detached is set only by detachWith. The route wires disconnect cancellation to the round-trip controller. A plugin ignoring its abort signal may continue work, but that alone does not enqueue its late response as a detached message.
return new Promise<ToolCallResponse>((resolve) => {
let detached = false;
let settled = false;
const abort = () => {
controller.abort(args.roundTrip.reason);
settle(failedToolCallResponse(args.toolName, args.roundTrip.reason));
};
detachWith = (response) => {
if (settled || detached || controller.signal.aborted) return;
detached = true;
args.roundTrip.removeEventListener("abort", abort);
resolve(response);
};
const settle = (response: ToolCallResponse) => {
if (settled) return;
settled = true;
args.roundTrip.removeEventListener("abort", abort);
this.calls.delete(tracked);
if (!detached) {
resolve(response);
return;
6. Proposed fix and safety assessment
The tested dependency-free repair adds JSON whitespace every 30 seconds while the existing result promise is pending, with Cache-Control: no-transform so Hono's compression cannot buffer those tiny heartbeats. Its interval is unreferenced and cleared on completion, rejection, or stream cancellation. The parsed JSON fields, cancellation ownership, daemon code, and protocol version remain unchanged. This stays within the server subsystem and changes 142 text lines across two files (140 additions, 2 deletions), with no dependency, migration, generated output, or stored-data change.
The focused regression exercises two heartbeats, unchanged result decoding, and cancellation/timer cleanup. Both cases fail on trusted main with “pending tools must send periodic body data: expected null not to be null”; both pass after the repair. All 44 tests in the new regression and the three relevant existing suites pass, as does the server Turbo typecheck. A separate real-time 310-second run uses the unchanged daemon client and default fetch: it passes with the repair, establishing old-client JSON compatibility rather than relying only on accelerated clocks.
Fixed-client real-time run
@bb/server:test: ✓ returns a plugin result after 310 seconds of idle computation 310176ms @bb/server:test: Test Files 1 passed (1) @bb/server:test: Tests 1 passed (1) @bb/server:test: Duration 319.30s (transform 4.95s, setup 1.61s, import 5.00s, tests 310.79s, environment 0ms)
7. Verification
The same agent repeated the reproduction, not an independent reviewer. A second clean worktree was created directly at the recorded trusted base commit, before copying only the investigator-authored test. A second frozen install and SDK build were performed. The same Turbo test command ran with a fresh ephemeral HTTP port and fresh temporary harness data. Both runs agree on the body-timeout failure and the aborted, non-detached lifecycle. The report narrows the issue's detachment claim accordingly.
8. Related issues
No open pull request linked to #7339 was found in issue timeline metadata, the open-PR search, or open pull requests' closing-issue references at investigation time. Other question-timeout reports involve explicitly detached user interactions and are not evidence for this ordinary-tool transport failure.
9. Appendix and scope
Repository issue text was untrusted evidence only. Its implementation suggestion and code were not executed or copied. No linked branch or external URL from issue data was fetched. Logs and test files remain local; selected exact output and the complete reproduction test are embedded above. This report does not claim a real-model UI reproduction or a verified detached-message delivery.
Read-only preparation: repository visibility, issue properties and comments, valid field options/labels, similar issue classifications, linked/open PR metadata, trusted origin/main SHA, source history/blame, Node and package-manager versions. Local commands: frozen installs; Turbo SDK builds; full Turbo build; focused Turbo test in each checkout. No production connect logs were accessed.
pnpm exec turbo run test --filter=@bb/server -- test/internal/internal-tool-call-keepalive.test.ts test/internal/internal-events-tool-calls.test.ts test/internal/internal-tool-call-regressions.test.ts test/services/plugins/plugin-tool-calls.test.ts pnpm exec turbo run typecheck --filter=@bb/server pnpm exec oxfmt --check apps/server/src/internal/tool-calls.ts apps/server/test/internal/internal-tool-call-keepalive.test.ts git diff --check git diff --numstat origin/main
The optional broad verification-map inventory check reports an unrelated pre-existing unmapped diagnostics CLI family; no inventory baseline was rewritten. No full-app/browser smoke pass is claimed. The exploratory cross-package reproduction is not shipped as a permanent test; the permanent owner-boundary regression stays within the server package and typechecks cleanly.