From 9cb08cfef4c0533ce51fc40addcfb489a53140c9 Mon Sep 17 00:00:00 2001 From: Oleg Petrush <258429733+ap-beep-ship-it@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:04:15 +0100 Subject: [PATCH] Let agents raise the request deadline with PROOFLINE_REQUEST_TIMEOUT_MS Slow tools such as codebase questions and plans on large repositories can need more than 35 seconds. The bridge now reads an optional PROOFLINE_REQUEST_TIMEOUT_MS (35000 to 600000, whole milliseconds) and refuses anything else at startup with an error that names the variable. The default is unchanged and timed-out requests still get the correlated -32000 error. --- README.md | 4 +++- src/bridge.js | 16 ++++++++++++-- src/cli.js | 10 +++++---- tests/bridge.test.js | 44 +++++++++++++++++++++++++++++++++++++ tests/configuration.test.js | 23 +++++++++++++++++++ 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 tests/configuration.test.js diff --git a/README.md b/README.md index 2d4e510..41234cb 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ Create a personal token in the Proofline console for the organization you want t The default server URL is `https://proofline.sh`. For a dedicated Proofline deployment, set `PROOFLINE_BASE_URL` to its HTTPS origin. The package never opens a browser or stores credentials. +Each request has a 35 second deadline by default. If your agent regularly calls slower tools, such as codebase questions or plans on a large repository, or works over a slow link, set `PROOFLINE_REQUEST_TIMEOUT_MS` to a longer deadline in milliseconds, for example `"PROOFLINE_REQUEST_TIMEOUT_MS": "120000"` in the `env` block above. The value must be a whole number from 35000 to 600000; anything else stops the bridge at startup with an error that names the variable. The deadline cannot go below the default because the server can take that long to answer, and a request the bridge abandons may still complete. Agents also apply their own tool call limits, so raise those too if they are shorter. + ## Tools and results The package forwards the server's tool catalog and results unchanged. Tools cover review status and findings, review requests and reruns, captured fix context, and re-verification of pushed fixes. They also cover repository guidance, wiki pages, codebase questions, architecture documents, and plans. Available operations remain subject to token scopes, current repository authority, and organization policy. @@ -50,7 +52,7 @@ The server keeps model and repository text wrapped as `untrusted_text`. Treat it The bridge accepts newline-delimited JSON-RPC on stdin and writes only protocol responses to stdout. Diagnostics go to stderr. The bridge forwards one request at a time and never retries. A failed mutation may have committed; inspect its state before making another request. -The bridge supports Proofline's stateless JSON transport with protocol `2025-11-25`. Initialize, then send `notifications/initialized` before calling tools. The bridge limits input frames to 8 KiB, responses to 8 MiB, and requests to 35 seconds. A timed-out request returns a correlated JSON-RPC `-32000` error (`data.category: "timeout"`) without ending the bridge, so no restart is needed; because the call may still have run on the server, read state before repeating a write. It refuses redirects, SSE, and `MCP-Session-Id`. HTTP failures produce a correlated, sanitized JSON-RPC error; the bridge does not print upstream error bodies or credentials. HTTP refusals, timed-out notifications, and other transport failures exit 1. Clean input EOF exits 0. +The bridge supports Proofline's stateless JSON transport with protocol `2025-11-25`. Initialize, then send `notifications/initialized` before calling tools. The bridge limits input frames to 8 KiB, responses to 8 MiB, and requests to 35 seconds unless `PROOFLINE_REQUEST_TIMEOUT_MS` sets a longer deadline. A timed-out request returns a correlated JSON-RPC `-32000` error (`data.category: "timeout"`) without ending the bridge, so no restart is needed; because the call may still have run on the server, read state before repeating a write. It refuses redirects, SSE, and `MCP-Session-Id`. HTTP failures produce a correlated, sanitized JSON-RPC error; the bridge does not print upstream error bodies or credentials. HTTP refusals, timed-out notifications, and other transport failures exit 1. Clean input EOF exits 0. ## Development and releases diff --git a/src/bridge.js b/src/bridge.js index 577b6c4..cab9d9a 100644 --- a/src/bridge.js +++ b/src/bridge.js @@ -4,6 +4,9 @@ export const PROTOCOL = "2025-11-25"; const REQUEST_LIMIT = 8192; const RESPONSE_LIMIT = 8 * 1024 * 1024; const REQUEST_TIMEOUT = 35_000; +// The server may legitimately take up to the default to answer, and a write +// can still commit after the bridge gives up, so the deadline can only grow. +export const REQUEST_TIMEOUT_RANGE = Object.freeze({ min: REQUEST_TIMEOUT, max: 600_000 }); const TRANSPORT_TIMEOUTS = new Set(["UND_ERR_CONNECT_TIMEOUT", "UND_ERR_HEADERS_TIMEOUT", "UND_ERR_BODY_TIMEOUT", "ETIMEDOUT"]); const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value); const identity = (value) => typeof value === "string" || Number.isSafeInteger(value); @@ -31,7 +34,16 @@ export function configuration(env) { ["127.0.0.1", "[::1]"].includes(origin.hostname)))) { throw new BridgeError("configuration: require an HTTPS origin or loopback IP"); } - return { token, origin: origin.origin }; + return { token, origin: origin.origin, timeout: requestTimeout(env.PROOFLINE_REQUEST_TIMEOUT_MS) }; +} + +function requestTimeout(raw) { + if (raw === undefined) return REQUEST_TIMEOUT; + const milliseconds = /^[0-9]+$/u.test(raw) ? Number(raw) : NaN; + if (!(milliseconds >= REQUEST_TIMEOUT_RANGE.min && milliseconds <= REQUEST_TIMEOUT_RANGE.max)) { + throw new BridgeError("configuration: invalid PROOFLINE_REQUEST_TIMEOUT_MS"); + } + return milliseconds; } async function* frames(input) { @@ -58,7 +70,7 @@ async function send(output, message) { async function post(frame, config, protocol, notification) { let response; - const signal = AbortSignal.timeout(REQUEST_TIMEOUT); + const signal = AbortSignal.timeout(config.timeout ?? REQUEST_TIMEOUT); try { response = await fetch(`${config.origin}/mcp`, { method: "POST", diff --git a/src/cli.js b/src/cli.js index 0a895d8..afc30e0 100755 --- a/src/cli.js +++ b/src/cli.js @@ -1,10 +1,10 @@ #!/usr/bin/env node import { readFileSync } from "node:fs"; -import { bridge, configuration } from "./bridge.js"; +import { REQUEST_TIMEOUT_RANGE, bridge, configuration } from "./bridge.js"; const args = process.argv.slice(2); if (args.length === 1 && args[0] === "--help") { - console.log("Usage: proofline-mcp\n\nSet PROOFLINE_TOKEN to a scoped Proofline token.\nOptional: PROOFLINE_BASE_URL (default https://proofline.sh).\nReads MCP JSON-RPC from stdin and writes responses to stdout.\nRequires Node.js 22 or later."); + console.log(`Usage: proofline-mcp\n\nSet PROOFLINE_TOKEN to a scoped Proofline token.\nOptional: PROOFLINE_BASE_URL (default https://proofline.sh).\nOptional: PROOFLINE_REQUEST_TIMEOUT_MS (default ${REQUEST_TIMEOUT_RANGE.min}, at most ${REQUEST_TIMEOUT_RANGE.max}).\nReads MCP JSON-RPC from stdin and writes responses to stdout.\nRequires Node.js 22 or later.`); } else if (args.length === 1 && args[0] === "--version") { console.log(JSON.parse(readFileSync(new URL("../package.json", import.meta.url))).version); } else if (args.length) { @@ -15,8 +15,10 @@ if (args.length === 1 && args[0] === "--help") { const config = configuration(process.env); process.exitCode = await bridge(process.stdin, process.stdout, process.stderr, config); process.stdin.destroy(); - } catch { - console.error("Proofline MCP configuration invalid. Set PROOFLINE_TOKEN and use an HTTPS origin for PROOFLINE_BASE_URL."); + } catch (error) { + console.error(error?.category === "configuration: invalid PROOFLINE_REQUEST_TIMEOUT_MS" ? + `Proofline MCP configuration invalid. Set PROOFLINE_REQUEST_TIMEOUT_MS to a whole number of milliseconds from ${REQUEST_TIMEOUT_RANGE.min} to ${REQUEST_TIMEOUT_RANGE.max}, or leave it unset.` : + "Proofline MCP configuration invalid. Set PROOFLINE_TOKEN and use an HTTPS origin for PROOFLINE_BASE_URL."); process.exitCode = 1; } } diff --git a/tests/bridge.test.js b/tests/bridge.test.js index 5abf266..d4200e5 100644 --- a/tests/bridge.test.js +++ b/tests/bridge.test.js @@ -169,3 +169,47 @@ test("a timed-out response produces a correlated error and leaves stdio open", { "initialize", "notifications/initialized", "tools/call", "tools/list", ]); }); + +test("PROOFLINE_REQUEST_TIMEOUT_MS sets the request deadline and keeps the correlated timeout", { timeout: 10_000 }, async (t) => { + const slow = { ...call, id: "slow-plan" }; + const next = { jsonrpc: "2.0", id: 9, method: "tools/list" }; + const tools = { tools: [] }; + const fixture = await server(t, (body, response) => { + if (body.id === slow.id) { + response.writeHead(200, { "content-type": "application/json" }); + response.write("{"); + return; + } + json(response, { jsonrpc: "2.0", id: body.id, result: tools }); + }); + // Every request must use the configured deadline; it is shortened only so the test stays fast. + const preload = ` + const timeout = AbortSignal.timeout; + AbortSignal.timeout = (milliseconds) => { + if (milliseconds !== 120_000) throw new RangeError("expected the configured 120000 ms deadline"); + return timeout.call(AbortSignal, 1_000); + }; + `; + const outcome = await run(fixture.origin, [initialize, notification, slow, next], { + PROOFLINE_REQUEST_TIMEOUT_MS: "120000", + NODE_OPTIONS: `--import=data:text/javascript,${encodeURIComponent(preload)}`, + }); + assert.equal(outcome.code, 0); + assert.equal(outcome.stderr, ""); + assert.equal(outcome.responses[1].id, slow.id); + assert.equal(outcome.responses[1].error.code, -32000); + assert.equal(outcome.responses[1].error.data.category, "timeout"); + assert.deepEqual(outcome.responses[2], { jsonrpc: "2.0", id: next.id, result: tools }); +}); + +test("an invalid PROOFLINE_REQUEST_TIMEOUT_MS is refused before any request and named in the error", async (t) => { + const fixture = await server(t, () => assert.fail("unexpected request")); + for (const value of ["", "abc", "0", "34999", "600001", "60e3", "60000.5", " 60000", "-60000", "0x9c40"]) { + const outcome = await run(fixture.origin, [initialize], { PROOFLINE_REQUEST_TIMEOUT_MS: value }); + assert.equal(outcome.code, 1, JSON.stringify(value)); + assert.equal(outcome.responses.length, 0); + assert.match(outcome.stderr, /PROOFLINE_REQUEST_TIMEOUT_MS/u); + assert.match(outcome.stderr, /35000 to 600000/u); + } + assert.equal(fixture.requests.length, 0); +}); diff --git a/tests/configuration.test.js b/tests/configuration.test.js new file mode 100644 index 0000000..dba5c4b --- /dev/null +++ b/tests/configuration.test.js @@ -0,0 +1,23 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { REQUEST_TIMEOUT_RANGE, configuration } from "../src/bridge.js"; + +const env = { PROOFLINE_TOKEN: "token" }; + +test("the request timeout defaults to 35 seconds", () => { + assert.equal(configuration(env).timeout, 35_000); + assert.deepEqual(REQUEST_TIMEOUT_RANGE, { min: 35_000, max: 600_000 }); +}); + +test("the request timeout accepts whole milliseconds within the range", () => { + for (const [raw, expected] of [["35000", 35_000], ["120000", 120_000], ["600000", 600_000]]) { + assert.equal(configuration({ ...env, PROOFLINE_REQUEST_TIMEOUT_MS: raw }).timeout, expected); + } +}); + +test("the request timeout refuses values outside the range or not written as an integer", () => { + for (const raw of ["", "abc", "34999", "600001", "1e5", "60000.0", "+60000", "60000 ", "Infinity"]) { + assert.throws(() => configuration({ ...env, PROOFLINE_REQUEST_TIMEOUT_MS: raw }), + { category: "configuration: invalid PROOFLINE_REQUEST_TIMEOUT_MS" }, JSON.stringify(raw)); + } +});