From 25ec00d213437d55b86af82f6afa72595e6103f6 Mon Sep 17 00:00:00 2001 From: chhhee10 Date: Wed, 18 Nov 2026 17:36:55 +0530 Subject: [PATCH 1/7] fix(openclaw-plugin): stop a busy gateway reading as an unreachable daemon (#1024) The plugin's 250 ms connect timer ran on the OpenClaw gateway's own event loop. A Unix-socket connect to a live daemon completes in the kernel at once, but the gateway only delivers the connect event on a later loop pass; when the gateway was busy for 250 ms or more (cron agents starting together), the overdue timer ran first and the call was blocked as "failproofaid could not be reached" against a healthy daemon. - Drop the connect timer. A missing daemon fails at once (ENOENT / ECONNREFUSED); one that accepts and hangs is caught by the existing 30 s request budget, now armed for the whole request. - Retry a connect that fails outright once, after 100 ms. Only `unreachable` is retried: nothing was sent, so no call is evaluated twice. - Carry the cause (error code, elapsed time, attempts) as `detail` and log it in the gateway log; the agent-facing message is unchanged. - Regression tests: a healthy daemon with the loop blocked for 300 ms and 1.5 s (fails on the old client every run), a daemon that starts listening between attempts, and the logged cause. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++ CLAUDE.md | 7 ++- __tests__/hooks/openclaw-plugin.test.ts | 61 +++++++++++++++++++ openclaw-plugin/daemon-client.js | 79 +++++++++++++++++-------- openclaw-plugin/hooks.js | 5 +- 5 files changed, 129 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f7ba173..14ef62956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 1.0.15-beta.0 — 2026-11-18 +### Fixes + +- The OpenClaw plugin no longer blocks tool calls as "failproofaid could not be reached" while the daemon is healthy. Its 250 ms connect timer ran on the gateway's own event loop, so a gateway busy for 250 ms or more (cron agents starting together) let the overdue timer beat the already-completed connect. The connect timer is gone (a missing daemon still fails at once, a hung one at the 30 s budget), a connect that fails outright is retried once after 100 ms, and the gateway log now says why: the error code, the elapsed time and the number of attempts (#1024) + ### Docs - Bring the README, npm description and English docs up to date with the website and the live Cloud dashboard: trace / analyse / fix navigation, insights, checks, the failproof agent, the free plan, and corrected CLI and OTLP details (#1022) diff --git a/CLAUDE.md b/CLAUDE.md index d99e93855..39a4262dc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -467,7 +467,12 @@ it is **daemon-only** (`requiresHealthyDaemon`): install refuses without a daemo and when no verdict comes back `before_tool_call` and `before_agent_run` **fail closed** (blocked, reason logged through `api.logger`) while `before_agent_finalize` does not force a revise — that cannot bring the daemon back and would only loop the -turn. All I/O is async: the gateway is a long-running multi-channel process. It +turn. All I/O is async: the gateway is a long-running multi-channel process. That +also means **no short timers in the plugin**: a timer shares the gateway's event loop +with every agent, so a busy gateway makes it fire late and ahead of I/O that already +completed. A 250 ms connect timer did exactly that and reported a healthy daemon as +unreachable (#1024); the client now has one 30 s request budget and retries a failed +connect once. It carries **no inline tool maps** (unlike the OpenCode/Pi shims) — it forwards raw event/tool names and a Claude-shaped stdin (`params→tool_input`, `toolName→tool_name`, `transcriptPath→transcript_path`, diff --git a/__tests__/hooks/openclaw-plugin.test.ts b/__tests__/hooks/openclaw-plugin.test.ts index 87a6b23ec..4715d4130 100644 --- a/__tests__/hooks/openclaw-plugin.test.ts +++ b/__tests__/hooks/openclaw-plugin.test.ts @@ -263,6 +263,52 @@ describe("openclaw-plugin daemon-client: requestHookVerdict", () => { expect(result).toMatchObject({ ok: false, failure: "unreachable" }); }); + // The plugin runs on the OpenClaw gateway's own event loop, shared with + // every agent on it. A healthy daemon accepts in the kernel at once, but + // the gateway only hears about it once it has finished whatever it is + // doing — so a busy gateway must not read as an unreachable daemon. + // + // The hook starts from a setImmediate callback, as one fired by the gateway + // does: the next loop pass then reaches its timers before its I/O poll, so + // an overdue timer always runs before the queued connect event. Started from + // arbitrary test code the order depends on the loop phase and the race is + // only sometimes lost. + it.each([300, 1_500])("still gets a verdict when the gateway is busy for %i ms", async (busyMs) => { + const daemon = await fakeDaemon(socketPath, () => hookResult("")); + try { + const pending = new Promise>>((done) => { + setImmediate(() => { + const result = requestHookVerdict({ event: "before_tool_call", payload: {}, socketPath }); + const until = Date.now() + busyMs; + while (Date.now() < until) { /* the gateway, busy with another agent */ } + done(result); + }); + }); + expect(await pending).toEqual({ ok: true, verdict: { permission: "allow" } }); + } finally { + await daemon.close(); + } + }); + + it("retries once when the daemon is briefly not listening", async () => { + const pending = requestHookVerdict({ event: "before_tool_call", payload: {}, socketPath }); + const daemon = await fakeDaemon(socketPath, () => hookResult("")); + try { + expect(await pending).toEqual({ ok: true, verdict: { permission: "allow" } }); + } finally { + await daemon.close(); + } + }); + + it("says why the daemon could not be reached, and does so promptly", async () => { + const started = Date.now(); + const result = await requestHookVerdict({ event: "before_tool_call", payload: {}, socketPath }); + expect(result).toMatchObject({ ok: false, failure: "unreachable" }); + expect(result.detail).toMatch(/ENOENT/); + expect(result.detail).toMatch(/2 attempts/); + expect(Date.now() - started).toBeLessThan(1_000); + }); + it("gives up on a daemon that never answers", async () => { const daemon = await fakeDaemon(socketPath, () => "hang"); try { @@ -373,6 +419,21 @@ describe("openclaw-plugin hooks", () => { expect(logged[0]).toContain("before_tool_call"); }); + it("logs why the daemon could not be reached, and keeps that out of the agent's reason", async () => { + const { api, handlers, logged } = fakeApi(); + registerFailproofaiHooks(api, { + evaluate: async () => ({ + ok: false, + failure: "unreachable", + message: "failproofaid could not be reached.", + detail: "ECONNREFUSED after 1 ms; 2 attempts", + }), + }); + const result = (await handlers.get("before_tool_call")!(toolCall, ctx)) as { blockReason: string }; + expect(logged[0]).toContain("failproofaid could not be reached. (ECONNREFUSED after 1 ms; 2 attempts)"); + expect(result.blockReason).not.toContain("ECONNREFUSED"); + }); + it.each([ ["an unknown permission", hookResult(JSON.stringify({ permission: "unknown" }))], ["a hookResult with no stdout", { type: "hookResult", protocolVersion: 2, exitCode: 0, stderr: "" }], diff --git a/openclaw-plugin/daemon-client.js b/openclaw-plugin/daemon-client.js index 7111fa2a7..fc6bb00ac 100644 --- a/openclaw-plugin/daemon-client.js +++ b/openclaw-plugin/daemon-client.js @@ -28,12 +28,25 @@ const MAX_FRAME_BYTES = 16 * 1024 * 1024; // applies to the envelope. export const MAX_PAYLOAD_BYTES = 1_048_576; -// The CLI's daemon client budgets these separately for the reason it gives: -// connecting is the "is anything listening" probe, the response covers the -// whole evaluation. 250 ms matches the Hermes plugin; 30 s matches the -// daemon's own read timeout on its worker (worker.rs). -export const CONNECT_TIMEOUT_MS = 250; +// One budget for the whole request, matching the daemon's own read timeout on +// its worker (worker.rs). +// +// There is deliberately NO separate connect timeout. This client runs on the +// OpenClaw gateway's event loop, shared with every agent on the gateway. A +// Unix-socket connect to a live daemon completes in the kernel at once, but +// the gateway only learns of it on a later loop pass; while the gateway is +// busy (a cron burst, a large transcript, GC) a timer that is already overdue +// runs before that connect event. The 250 ms connect timer this replaced +// therefore measured gateway load, and reported a healthy daemon as +// unreachable (#1024). A daemon that is not there needs no timer: the connect +// fails at once with ENOENT or ECONNREFUSED. One that accepts and then hangs is +// caught by this budget. export const RESPONSE_TIMEOUT_MS = 30_000; +// A connect that fails outright is retried once after this pause before the +// call fails closed: long enough to ride out a daemon restart re-binding its +// socket, short enough that a daemon that is really gone costs one tool call +// 100 ms. +export const UNREACHABLE_RETRY_DELAY_MS = 100; const PROTOCOL_MISMATCH_MESSAGE = "failproofaid is running a different protocol version than this plugin, so it cannot " + @@ -144,13 +157,31 @@ function isVerdict(verdict) { * CLI discards an oversized stdin and evaluates an empty payload; * `oversized: true` lets the caller say so instead of discarding it silently. */ -export function requestHookVerdict({ +export function requestHookVerdict(request) { + return requestWithRetry(request); +} + +/** + * One request, asked a second time if the first never reached the daemon. + * Only `unreachable` is retried: nothing was sent, so asking again cannot + * evaluate a call twice. Every other failure came from a daemon that saw the + * request, and is returned as it is. + */ +async function requestWithRetry(request) { + const first = await requestOnce(request); + if (first.ok || first.failure !== "unreachable") return first; + await new Promise((resume) => setTimeout(resume, request.retryDelayMs ?? UNREACHABLE_RETRY_DELAY_MS)); + const second = await requestOnce(request); + if (second.ok || second.failure !== "unreachable") return second; + return { ...second, detail: `${second.detail}; 2 attempts` }; +} + +function requestOnce({ event, payload, cwd = "", agentSettingsPath = "", socketPath = daemonSocketPath(), - connectTimeoutMs = CONNECT_TIMEOUT_MS, responseTimeoutMs = RESPONSE_TIMEOUT_MS, }) { return new Promise((done) => { @@ -190,6 +221,7 @@ export function requestHookVerdict({ let received = Buffer.alloc(0); let timer; let socket; + const startedAt = Date.now(); const finish = (result) => { if (settled) return; settled = true; @@ -197,22 +229,25 @@ export function requestHookVerdict({ try { socket?.destroy(); } catch { /* already closed */ } done(result); }; + // The agent-facing message stays the same; `detail` says what actually + // happened, for the gateway log (hooks.js), so the next field report can + // tell a missing socket from a refused one from a timeout. + const unreachable = (cause) => + finish({ ...failed("unreachable", UNREACHABLE_MESSAGE), detail: `${cause} after ${Date.now() - startedAt} ms` }); try { socket = createConnection(socketPath); - } catch { - finish(failed("unreachable", UNREACHABLE_MESSAGE)); + } catch (err) { + unreachable(err?.code ?? err?.message ?? String(err)); return; } - timer = setTimeout(() => finish(failed("unreachable", UNREACHABLE_MESSAGE)), connectTimeoutMs); + timer = setTimeout(() => { + if (connected) finish(failed("timeout", `failproofaid did not answer within ${responseTimeoutMs} ms`)); + else unreachable("no connection within the request budget"); + }, responseTimeoutMs); socket.on("connect", () => { connected = true; - clearTimeout(timer); - timer = setTimeout( - () => finish(failed("timeout", `failproofaid did not answer within ${responseTimeoutMs} ms`)), - responseTimeoutMs, - ); const header = Buffer.alloc(4); header.writeUInt32BE(body.length, 0); socket.write(Buffer.concat([header, body])); @@ -237,18 +272,12 @@ export function requestHookVerdict({ finish(result.ok && oversized ? { ...result, oversized: true } : result); }); socket.on("error", (err) => { - finish( - connected - ? failed("evaluation", `failproofaid connection failed: ${err?.message ?? String(err)}`) - : failed("unreachable", UNREACHABLE_MESSAGE), - ); + if (connected) finish(failed("evaluation", `failproofaid connection failed: ${err?.message ?? String(err)}`)); + else unreachable(err?.code ?? err?.message ?? String(err)); }); socket.on("close", () => { - finish( - connected - ? failed("evaluation", "failproofaid closed the connection before returning a verdict") - : failed("unreachable", UNREACHABLE_MESSAGE), - ); + if (connected) finish(failed("evaluation", "failproofaid closed the connection before returning a verdict")); + else unreachable("closed before connecting"); }); }); } diff --git a/openclaw-plugin/hooks.js b/openclaw-plugin/hooks.js index 2e7e5e3ad..8330b0b92 100644 --- a/openclaw-plugin/hooks.js +++ b/openclaw-plugin/hooks.js @@ -92,7 +92,10 @@ export function registerFailproofaiHooks(api, { } catch (err) { result = { ok: false, message: `the failproofai plugin failed: ${err?.message ?? String(err)}` }; } - if (!result?.ok) logFailure(api, event, result?.message ?? "no verdict"); + if (!result?.ok) { + const message = result?.message ?? "no verdict"; + logFailure(api, event, result?.detail ? `${message} (${result.detail})` : message); + } // Same outcome as the CLI's oversized stdin (warn, evaluate an empty // payload), and said out loud for the same reason it is there. else if (result.oversized) { From eeb8153817a252e29cc7af4be6704327107cf9b5 Mon Sep 17 00:00:00 2001 From: chhhee10 Date: Wed, 18 Nov 2026 17:43:00 +0530 Subject: [PATCH 2/7] docs(changelog): cite #1029 for the OpenClaw connect-timer fix Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14ef62956..3c478e0f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- The OpenClaw plugin no longer blocks tool calls as "failproofaid could not be reached" while the daemon is healthy. Its 250 ms connect timer ran on the gateway's own event loop, so a gateway busy for 250 ms or more (cron agents starting together) let the overdue timer beat the already-completed connect. The connect timer is gone (a missing daemon still fails at once, a hung one at the 30 s budget), a connect that fails outright is retried once after 100 ms, and the gateway log now says why: the error code, the elapsed time and the number of attempts (#1024) +- The OpenClaw plugin no longer blocks tool calls as "failproofaid could not be reached" while the daemon is healthy. Its 250 ms connect timer ran on the gateway's own event loop, so a gateway busy for 250 ms or more (cron agents starting together) let the overdue timer beat the already-completed connect. The connect timer is gone (a missing daemon still fails at once, a hung one at the 30 s budget), a connect that fails outright is retried once after 100 ms, and the gateway log now says why: the error code, the elapsed time and the number of attempts (#1024, #1029) ### Docs From 1a0e9733a4d594cf936a4d2231bd35ae9399e386 Mon Sep 17 00:00:00 2001 From: chhhee10 Date: Wed, 18 Nov 2026 18:12:38 +0530 Subject: [PATCH 3/7] ci(osv): allow-list picomatch GHSA-fc5q-39xc-vjpf until 2026-12-18 No fixed picomatch exists (every release through 4.0.7, the newest, is affected). It reaches the lockfiles only through build, lint and test tooling (vite, vitest, tinyglobby, fast-glob); neither the published package nor the TypeScript SDK ships it, and no code here passes it a pattern. The gate went red on main's scheduled run too. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ osv-scanner.toml | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c478e0f6..5b34daa6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ - Bring the README, npm description and English docs up to date with the website and the live Cloud dashboard: trace / analyse / fix navigation, insights, checks, the failproof agent, the free plan, and corrected CLI and OTLP details (#1022) +### Dependencies + +- OSV gate: time-boxed allow-list entry for picomatch GHSA-fc5q-39xc-vjpf (ReDoS, no fixed release; build/test tooling only, not shipped), re-review by 2026-12-18 (#1029) + ## 1.0.14-beta.0 — 2026-11-16 ### Features diff --git a/osv-scanner.toml b/osv-scanner.toml index 11772c471..71582b0af 100644 --- a/osv-scanner.toml +++ b/osv-scanner.toml @@ -84,3 +84,24 @@ reason = "chromadb 1.5.9 (published 2026-06-12, surfaced 2026-08-24). No fixed v id = "GHSA-xph7-9rjv-w5fr" ignoreUntil = 2026-11-20 reason = "chromadb 1.5.9 (published 2026-06-12, surfaced 2026-08-24). No fixed version. Transitive via crewai, dev/test lockfile only; see the shared justification above. Re-review by 2026-11-20." + +# --------------------------------------------------------------------------- +# picomatch — ReDoS through single-branch repeated extglobs (GHSA-fc5q-39xc-vjpf). +# +# Affects every release through 4.0.7, the newest on npm, so there is no fixed +# version to bump or override to. It reaches bun.lock (2.3.2 via micromatch / +# fast-glob, 4.0.4 and 4.0.7 via tinyglobby, vite and vitest) and +# sdk/typescript/package-lock.json (vitest, dev) — build, lint and test tooling +# only. Neither the published `failproofai` package (runtime dependencies: +# html-to-image, jsonc-parser, posthog-node, smol-toml, sql.js, yaml) nor +# `@failproofai/sdk` (no dependencies) brings picomatch to a user, and no code +# in this repo imports it or hands it a pattern. The attack needs an +# attacker-supplied glob; the tooling only matches globs from our own config. +# +# Re-review by 2026-12-18, or as soon as a fixed picomatch is published — +# then bump (or pin via `overrides`) and delete this entry. + +[[IgnoredVulns]] +id = "GHSA-fc5q-39xc-vjpf" +ignoreUntil = 2026-12-18 +reason = "picomatch <=4.0.7 ReDoS; no fixed release exists. Build/lint/test tooling only (vite, vitest, tinyglobby, fast-glob); not in the published package or SDK; no code here passes it a pattern. Re-review by 2026-12-18." From 49361ab861c745c04c4cc77f1a2a78b694049d7c Mon Sep 17 00:00:00 2001 From: chhhee10 Date: Wed, 18 Nov 2026 19:03:00 +0530 Subject: [PATCH 4/7] fix(openclaw-plugin): share one request budget across the retry; keep both attempts' causes Review round 1 on #1029. - One deadline for the whole request, set before the first attempt. The retry gets only what is left, and is skipped when the 100 ms pause would use the rest. Each attempt used to get a fresh 30 s, so a call could wait ~60 s, past the gateway's own hook timeout. - A failed retry keeps its own failure and agent-facing message, and its log-only `detail` now names both attempts, the attempt count and the total time, for every failure kind. ENOENT followed by a connected retry that closed early used to log only the close. - osv-scanner.toml: correct the picomatch justification. It does ship, in the Next.js dashboard bundle (next/dist/compiled/picomatch), used only by match-remote-pattern / match-local-pattern against globs from next.config, of which we declare none; no attacker-supplied glob reaches it. - CHANGELOG: describe what the fix removes, not a guarantee. CLAUDE.md: the rule is that no short timer may classify a pending connection as unreachable; the retry pause starts after a failure and classifies nothing. - Regression tests for the shared budget and the retained diagnostics; both fail on the previous client. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 +- CLAUDE.md | 12 +++--- __tests__/hooks/openclaw-plugin.test.ts | 53 +++++++++++++++++++++++++ openclaw-plugin/daemon-client.js | 41 ++++++++++++++++--- osv-scanner.toml | 28 ++++++++----- 5 files changed, 116 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b34daa6d..b5b2e4701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- The OpenClaw plugin no longer blocks tool calls as "failproofaid could not be reached" while the daemon is healthy. Its 250 ms connect timer ran on the gateway's own event loop, so a gateway busy for 250 ms or more (cron agents starting together) let the overdue timer beat the already-completed connect. The connect timer is gone (a missing daemon still fails at once, a hung one at the 30 s budget), a connect that fails outright is retried once after 100 ms, and the gateway log now says why: the error code, the elapsed time and the number of attempts (#1024, #1029) +- The OpenClaw plugin's 250 ms connect timer no longer blocks tool calls as "failproofaid could not be reached" while the gateway's event loop is busy and the daemon is healthy. The timer ran on the gateway's own event loop and fired ahead of a connect that had already completed; it is gone. A missing daemon still fails at once and a hung one within the 30 s request budget, which both attempts now share; a connect that fails outright is retried once after 100 ms; and the gateway log says why a call was blocked: each attempt's cause, the elapsed time and the attempt count (#1024, #1029) ### Docs @@ -12,7 +12,7 @@ ### Dependencies -- OSV gate: time-boxed allow-list entry for picomatch GHSA-fc5q-39xc-vjpf (ReDoS, no fixed release; build/test tooling only, not shipped), re-review by 2026-12-18 (#1029) +- OSV gate: time-boxed allow-list entry for picomatch GHSA-fc5q-39xc-vjpf (ReDoS, no fixed release). It is in build/test tooling and ships inside the Next.js dashboard bundle, where it only matches image URLs against globs from next.config, of which we declare none; re-review by 2026-12-18 (#1029) ## 1.0.14-beta.0 — 2026-11-16 diff --git a/CLAUDE.md b/CLAUDE.md index 39a4262dc..47c86dab1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -468,11 +468,13 @@ and when no verdict comes back `before_tool_call` and `before_agent_run` **fail closed** (blocked, reason logged through `api.logger`) while `before_agent_finalize` does not force a revise — that cannot bring the daemon back and would only loop the turn. All I/O is async: the gateway is a long-running multi-channel process. That -also means **no short timers in the plugin**: a timer shares the gateway's event loop -with every agent, so a busy gateway makes it fire late and ahead of I/O that already -completed. A 250 ms connect timer did exactly that and reported a healthy daemon as -unreachable (#1024); the client now has one 30 s request budget and retries a failed -connect once. It +also means **no short timer may decide that a pending connection is unreachable**: a +timer shares the gateway's event loop with every agent, so a busy gateway makes it fire +late and ahead of I/O that already completed. A 250 ms connect timer did exactly that +and reported a healthy daemon as unreachable (#1024). The client now has one 30 s +budget for the whole request, shared by both attempts, and retries once after 100 ms — +a pause that starts only after a connection has already failed, so it classifies +nothing. It carries **no inline tool maps** (unlike the OpenCode/Pi shims) — it forwards raw event/tool names and a Claude-shaped stdin (`params→tool_input`, `toolName→tool_name`, `transcriptPath→transcript_path`, diff --git a/__tests__/hooks/openclaw-plugin.test.ts b/__tests__/hooks/openclaw-plugin.test.ts index 4715d4130..fc492ed38 100644 --- a/__tests__/hooks/openclaw-plugin.test.ts +++ b/__tests__/hooks/openclaw-plugin.test.ts @@ -300,6 +300,59 @@ describe("openclaw-plugin daemon-client: requestHookVerdict", () => { } }); + // Both attempts share one budget: when the first used it up, there is no + // second attempt with a fresh one (that let a call wait twice as long). + it("does not retry past the request budget", async () => { + const daemon = await fakeDaemon(socketPath, () => "hang"); + try { + const started = Date.now(); + const pending = new Promise>>((done) => { + setImmediate(() => { + const result = requestHookVerdict({ + event: "before_tool_call", + payload: {}, + socketPath, + responseTimeoutMs: 150, + }); + const until = Date.now() + 250; // the gateway, busy past the whole budget + while (Date.now() < until) { /* busy */ } + done(result); + }); + }); + const result = await pending; + expect(result).toMatchObject({ ok: false, failure: "unreachable" }); + expect(result.detail).toMatch(/no time left in the 150 ms budget to retry/); + // A retry with a fresh 150 ms budget would have reached the hanging + // daemon and taken ≈ 250 + 100 + 150 ms. + expect(Date.now() - started).toBeLessThan(400); + expect(daemon.requests).toHaveLength(0); + } finally { + await daemon.close(); + } + }); + + it("keeps the first attempt's cause when the retry connects and then fails", async () => { + // First attempt: no socket yet (ENOENT). Retry: a listener that accepts the + // request and closes without a verdict. + let server: Server | undefined; + const pending = requestHookVerdict({ event: "before_tool_call", payload: {}, socketPath }); + server = createServer((socket) => socket.once("data", () => socket.destroy())); + await new Promise((done) => server!.listen(socketPath, done)); + try { + const result = await pending; + expect(result).toMatchObject({ + ok: false, + failure: "evaluation", + message: "failproofaid closed the connection before returning a verdict", + }); + expect(result.detail).toMatch(/attempt 1: ENOENT after \d+ ms/); + expect(result.detail).toMatch(/attempt 2: failproofaid closed the connection/); + expect(result.detail).toMatch(/2 attempts, \d+ ms total/); + } finally { + await new Promise((done) => server!.close(() => done())); + } + }); + it("says why the daemon could not be reached, and does so promptly", async () => { const started = Date.now(); const result = await requestHookVerdict({ event: "before_tool_call", payload: {}, socketPath }); diff --git a/openclaw-plugin/daemon-client.js b/openclaw-plugin/daemon-client.js index fc6bb00ac..dc075cb14 100644 --- a/openclaw-plugin/daemon-client.js +++ b/openclaw-plugin/daemon-client.js @@ -166,14 +166,40 @@ export function requestHookVerdict(request) { * Only `unreachable` is retried: nothing was sent, so asking again cannot * evaluate a call twice. Every other failure came from a daemon that saw the * request, and is returned as it is. + * + * Both attempts share ONE deadline of `responseTimeoutMs`, set before the + * first: the retry gets only what is left of it, and is skipped when the pause + * before it would use the rest. A fresh budget per attempt let a call wait + * twice as long, past the gateway's own hook timeout. + * + * A failed retry keeps its own failure and agent-facing message; its `detail` + * (gateway log only) names both attempts, so the first attempt's cause is + * never lost behind the second's. */ async function requestWithRetry(request) { - const first = await requestOnce(request); + const startedAt = Date.now(); + const budgetMs = request.responseTimeoutMs ?? RESPONSE_TIMEOUT_MS; + const deadline = startedAt + budgetMs; + const first = await requestOnce({ ...request, responseTimeoutMs: budgetMs, budgetMs }); if (first.ok || first.failure !== "unreachable") return first; - await new Promise((resume) => setTimeout(resume, request.retryDelayMs ?? UNREACHABLE_RETRY_DELAY_MS)); - const second = await requestOnce(request); - if (second.ok || second.failure !== "unreachable") return second; - return { ...second, detail: `${second.detail}; 2 attempts` }; + + const delayMs = request.retryDelayMs ?? UNREACHABLE_RETRY_DELAY_MS; + if (deadline - Date.now() - delayMs <= 0) { + return { ...first, detail: `${first.detail}; no time left in the ${budgetMs} ms budget to retry` }; + } + await new Promise((resume) => setTimeout(resume, delayMs)); + const remainingMs = deadline - Date.now(); + if (remainingMs <= 0) { + return { ...first, detail: `${first.detail}; no time left in the ${budgetMs} ms budget to retry` }; + } + const second = await requestOnce({ ...request, responseTimeoutMs: remainingMs, budgetMs }); + if (second.ok) return second; + return { + ...second, + detail: + `attempt 1: ${first.detail}; attempt 2: ${second.detail ?? second.message}; ` + + `2 attempts, ${Date.now() - startedAt} ms total`, + }; } function requestOnce({ @@ -183,6 +209,9 @@ function requestOnce({ agentSettingsPath = "", socketPath = daemonSocketPath(), responseTimeoutMs = RESPONSE_TIMEOUT_MS, + // The whole request's budget, for messages; `responseTimeoutMs` is what is + // left of it for this attempt. + budgetMs = responseTimeoutMs, }) { return new Promise((done) => { let body; @@ -242,7 +271,7 @@ function requestOnce({ return; } timer = setTimeout(() => { - if (connected) finish(failed("timeout", `failproofaid did not answer within ${responseTimeoutMs} ms`)); + if (connected) finish(failed("timeout", `failproofaid did not answer within ${budgetMs} ms`)); else unreachable("no connection within the request budget"); }, responseTimeoutMs); diff --git a/osv-scanner.toml b/osv-scanner.toml index 71582b0af..86e86b0ef 100644 --- a/osv-scanner.toml +++ b/osv-scanner.toml @@ -89,14 +89,24 @@ reason = "chromadb 1.5.9 (published 2026-06-12, surfaced 2026-08-24). No fixed v # picomatch — ReDoS through single-branch repeated extglobs (GHSA-fc5q-39xc-vjpf). # # Affects every release through 4.0.7, the newest on npm, so there is no fixed -# version to bump or override to. It reaches bun.lock (2.3.2 via micromatch / -# fast-glob, 4.0.4 and 4.0.7 via tinyglobby, vite and vitest) and -# sdk/typescript/package-lock.json (vitest, dev) — build, lint and test tooling -# only. Neither the published `failproofai` package (runtime dependencies: -# html-to-image, jsonc-parser, posthog-node, smol-toml, sql.js, yaml) nor -# `@failproofai/sdk` (no dependencies) brings picomatch to a user, and no code -# in this repo imports it or hands it a pattern. The attack needs an -# attacker-supplied glob; the tooling only matches globs from our own config. +# version to bump or override to. Where it is: +# +# - bun.lock (2.3.2 via micromatch / fast-glob, 4.0.4 and 4.0.7 via +# tinyglobby, vite and vitest) and sdk/typescript/package-lock.json (vitest, +# dev): build, lint and test tooling, which only ever matches globs from our +# own config. +# - SHIPPED, inside Next.js: the published tarball's dashboard bundle carries +# .next/standalone/node_modules/next/dist/compiled/picomatch. Its only +# importers there are next/dist/shared/lib/match-remote-pattern.js and +# match-local-pattern.js, which match an image URL against the GLOBS in +# next.config's images.remotePatterns / localPatterns. Our next.config sets +# `images: { unoptimized: true }` and declares no patterns, so those globs +# are build-time config at most and never come from a request. A visitor can +# only influence the string being matched, while this ReDoS needs an +# attacker-supplied glob. +# +# No code in this repo imports picomatch or hands it a pattern, and +# `@failproofai/sdk` has no dependencies. # # Re-review by 2026-12-18, or as soon as a fixed picomatch is published — # then bump (or pin via `overrides`) and delete this entry. @@ -104,4 +114,4 @@ reason = "chromadb 1.5.9 (published 2026-06-12, surfaced 2026-08-24). No fixed v [[IgnoredVulns]] id = "GHSA-fc5q-39xc-vjpf" ignoreUntil = 2026-12-18 -reason = "picomatch <=4.0.7 ReDoS; no fixed release exists. Build/lint/test tooling only (vite, vitest, tinyglobby, fast-glob); not in the published package or SDK; no code here passes it a pattern. Re-review by 2026-12-18." +reason = "picomatch <=4.0.7 ReDoS; no fixed release exists. In build/lint/test tooling, and shipped inside the Next.js dashboard bundle, where it only matches image URLs against globs from next.config (we declare none); no attacker-supplied glob reaches it. Re-review by 2026-12-18." From 9b92088ea118c902af26ce845b08117277691855 Mon Sep 17 00:00:00 2001 From: chhhee10 Date: Wed, 18 Nov 2026 19:21:25 +0530 Subject: [PATCH 5/7] fix(openclaw-plugin): absolute monotonic deadline per request; cover the capped retry Review round 2 on #1029 (CodeRabbit). - Each attempt now receives the request's absolute deadline and arms its timer with what is left just before connecting, so encoding time counts against the budget too; an attempt with nothing left fails without opening a socket. - The deadline, remaining time and elapsed diagnostics use performance.now(), a monotonic clock, so a wall-clock change can neither stretch nor shrink the budget. - The exhausted-budget test no longer asserts wall-clock time (flaky on a loaded runner); it asserts the detail and that no frame reached the daemon, which the previous client still fails. - New test: the first attempt fails, the retry connects with budget left and the daemon never answers; the call ends at the original deadline (~1,000 ms), not after a fresh budget (~1,600 ms on the previous client). Co-Authored-By: Claude Opus 5.5 --- __tests__/hooks/openclaw-plugin.test.ts | 33 ++++++++++++++-- openclaw-plugin/daemon-client.js | 52 +++++++++++++++---------- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/__tests__/hooks/openclaw-plugin.test.ts b/__tests__/hooks/openclaw-plugin.test.ts index fc492ed38..90a5ed025 100644 --- a/__tests__/hooks/openclaw-plugin.test.ts +++ b/__tests__/hooks/openclaw-plugin.test.ts @@ -305,7 +305,6 @@ describe("openclaw-plugin daemon-client: requestHookVerdict", () => { it("does not retry past the request budget", async () => { const daemon = await fakeDaemon(socketPath, () => "hang"); try { - const started = Date.now(); const pending = new Promise>>((done) => { setImmediate(() => { const result = requestHookVerdict({ @@ -322,15 +321,41 @@ describe("openclaw-plugin daemon-client: requestHookVerdict", () => { const result = await pending; expect(result).toMatchObject({ ok: false, failure: "unreachable" }); expect(result.detail).toMatch(/no time left in the 150 ms budget to retry/); - // A retry with a fresh 150 ms budget would have reached the hanging - // daemon and taken ≈ 250 + 100 + 150 ms. - expect(Date.now() - started).toBeLessThan(400); + // A retry with a fresh budget would have reached the hanging daemon, + // sent it a frame, and ended as a timeout instead. expect(daemon.requests).toHaveLength(0); } finally { await daemon.close(); } }); + it("gives a retry that connects only what is left of the request budget", async () => { + // First attempt: no socket (ENOENT). Then a daemon appears that accepts + // the request and never answers. With a 600 ms pause before the retry and + // a 1,000 ms budget, the retry has ~400 ms left: a shared budget ends near + // 1,000 ms, a fresh one would run to ~1,600 ms. + const started = performance.now(); + const pending = requestHookVerdict({ + event: "before_tool_call", + payload: {}, + socketPath, + responseTimeoutMs: 1_000, + retryDelayMs: 600, + }); + const daemon = await fakeDaemon(socketPath, () => "hang"); + try { + const result = await pending; + const elapsed = performance.now() - started; + expect(result).toMatchObject({ ok: false, failure: "timeout" }); + expect(result.detail).toMatch(/attempt 1: ENOENT/); + expect(daemon.requests).toHaveLength(1); + expect(elapsed).toBeGreaterThanOrEqual(950); + expect(elapsed).toBeLessThan(1_350); + } finally { + await daemon.close(); + } + }); + it("keeps the first attempt's cause when the retry connects and then fails", async () => { // First attempt: no socket yet (ENOENT). Retry: a listener that accepts the // request and closes without a verdict. diff --git a/openclaw-plugin/daemon-client.js b/openclaw-plugin/daemon-client.js index dc075cb14..627f267a3 100644 --- a/openclaw-plugin/daemon-client.js +++ b/openclaw-plugin/daemon-client.js @@ -16,6 +16,7 @@ * outside this directory — because the capture copies nothing else. */ import { createConnection } from "node:net"; +import { performance } from "node:perf_hooks"; import { homedir } from "node:os"; import { resolve } from "node:path"; @@ -168,37 +169,39 @@ export function requestHookVerdict(request) { * request, and is returned as it is. * * Both attempts share ONE deadline of `responseTimeoutMs`, set before the - * first: the retry gets only what is left of it, and is skipped when the pause - * before it would use the rest. A fresh budget per attempt let a call wait - * twice as long, past the gateway's own hook timeout. + * first and passed to each attempt as an absolute time: an attempt arms its + * timer with what is left of it just before connecting (so encoding time + * counts too), and the retry is skipped when the pause before it would use the + * rest. A fresh budget per attempt let a call wait twice as long, past the + * gateway's own hook timeout. Time is read from `performance.now()`, a + * monotonic clock, so a wall-clock change cannot stretch or shrink the budget. * * A failed retry keeps its own failure and agent-facing message; its `detail` * (gateway log only) names both attempts, so the first attempt's cause is * never lost behind the second's. */ async function requestWithRetry(request) { - const startedAt = Date.now(); + const startedAt = performance.now(); const budgetMs = request.responseTimeoutMs ?? RESPONSE_TIMEOUT_MS; const deadline = startedAt + budgetMs; - const first = await requestOnce({ ...request, responseTimeoutMs: budgetMs, budgetMs }); + const noTimeToRetry = (first) => + ({ ...first, detail: `${first.detail}; no time left in the ${budgetMs} ms budget to retry` }); + + const first = await requestOnce({ ...request, deadline, budgetMs }); if (first.ok || first.failure !== "unreachable") return first; const delayMs = request.retryDelayMs ?? UNREACHABLE_RETRY_DELAY_MS; - if (deadline - Date.now() - delayMs <= 0) { - return { ...first, detail: `${first.detail}; no time left in the ${budgetMs} ms budget to retry` }; - } + if (deadline - performance.now() - delayMs <= 0) return noTimeToRetry(first); await new Promise((resume) => setTimeout(resume, delayMs)); - const remainingMs = deadline - Date.now(); - if (remainingMs <= 0) { - return { ...first, detail: `${first.detail}; no time left in the ${budgetMs} ms budget to retry` }; - } - const second = await requestOnce({ ...request, responseTimeoutMs: remainingMs, budgetMs }); + if (deadline - performance.now() <= 0) return noTimeToRetry(first); + + const second = await requestOnce({ ...request, deadline, budgetMs }); if (second.ok) return second; return { ...second, detail: `attempt 1: ${first.detail}; attempt 2: ${second.detail ?? second.message}; ` + - `2 attempts, ${Date.now() - startedAt} ms total`, + `2 attempts, ${Math.round(performance.now() - startedAt)} ms total`, }; } @@ -208,10 +211,10 @@ function requestOnce({ cwd = "", agentSettingsPath = "", socketPath = daemonSocketPath(), - responseTimeoutMs = RESPONSE_TIMEOUT_MS, - // The whole request's budget, for messages; `responseTimeoutMs` is what is - // left of it for this attempt. - budgetMs = responseTimeoutMs, + // The whole request's budget (for messages) and its absolute end on the + // performance.now() clock, shared with any retry. + budgetMs = RESPONSE_TIMEOUT_MS, + deadline = performance.now() + budgetMs, }) { return new Promise((done) => { let body; @@ -250,7 +253,7 @@ function requestOnce({ let received = Buffer.alloc(0); let timer; let socket; - const startedAt = Date.now(); + const startedAt = performance.now(); const finish = (result) => { if (settled) return; settled = true; @@ -262,8 +265,15 @@ function requestOnce({ // happened, for the gateway log (hooks.js), so the next field report can // tell a missing socket from a refused one from a timeout. const unreachable = (cause) => - finish({ ...failed("unreachable", UNREACHABLE_MESSAGE), detail: `${cause} after ${Date.now() - startedAt} ms` }); + finish({ ...failed("unreachable", UNREACHABLE_MESSAGE), detail: `${cause} after ${Math.round(performance.now() - startedAt)} ms` }); + // Measured after encoding, so a large payload's encoding time is charged + // to the same budget. + const remainingMs = deadline - performance.now(); + if (remainingMs <= 0) { + unreachable("no time left in the request budget"); + return; + } try { socket = createConnection(socketPath); } catch (err) { @@ -273,7 +283,7 @@ function requestOnce({ timer = setTimeout(() => { if (connected) finish(failed("timeout", `failproofaid did not answer within ${budgetMs} ms`)); else unreachable("no connection within the request budget"); - }, responseTimeoutMs); + }, remainingMs); socket.on("connect", () => { connected = true; From d30c2835644cee3b97f8a2f6f331a62cb5310ea7 Mon Sep 17 00:00:00 2001 From: chhhee10 Date: Wed, 18 Nov 2026 19:30:11 +0530 Subject: [PATCH 6/7] fix(openclaw-plugin): count encoding time in an attempt's elapsed diagnostics Review round 3 on #1029 (CodeRabbit): start the attempt clock before the payload is encoded, so the 'no time left' and other unreachable details report the time actually spent. Co-Authored-By: Claude Opus 5.5 --- openclaw-plugin/daemon-client.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openclaw-plugin/daemon-client.js b/openclaw-plugin/daemon-client.js index 627f267a3..baa1da4f1 100644 --- a/openclaw-plugin/daemon-client.js +++ b/openclaw-plugin/daemon-client.js @@ -217,6 +217,8 @@ function requestOnce({ deadline = performance.now() + budgetMs, }) { return new Promise((done) => { + // Started before encoding, so the elapsed time in `detail` includes it. + const startedAt = performance.now(); let body; let oversized = false; try { @@ -253,7 +255,6 @@ function requestOnce({ let received = Buffer.alloc(0); let timer; let socket; - const startedAt = performance.now(); const finish = (result) => { if (settled) return; settled = true; From cb83899fee13d28a3db846abf87d7ad9912cf541 Mon Sep 17 00:00:00 2001 From: chhhee10 Date: Wed, 18 Nov 2026 19:46:47 +0530 Subject: [PATCH 7/7] chore(release): prepare 1.0.15 stable - Version 1.0.15 in package.json, Cargo.toml (+ Cargo.lock workspace members) and hermes-plugin/plugin.yaml; CI's version-consistency check passes. - CHANGELOG: the 1.0.15-beta.0 section becomes the stable `## 1.0.15` section with a one-line summary, as 1.0.13 did, and lists the runtime dependency bumps on main since 1.0.14 (posthog-node #1012, sql.js #1013, Next.js in the dashboard bundle #1007). - `release-announcement.mjs --check` finds notes for 1.0.15 from the changelog alone. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 ++++- Cargo.lock | 6 +++--- Cargo.toml | 2 +- hermes-plugin/plugin.yaml | 2 +- package.json | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5b2e4701..01c3166f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog -## 1.0.15-beta.0 — 2026-11-18 +## 1.0.15 — 2026-11-18 + +The stable release of the OpenClaw plugin fix for tool calls blocked as "failproofaid could not be reached" while the daemon was healthy, plus the refreshed README and docs and the dependency updates that landed on `main` since 1.0.14. ### Fixes @@ -13,6 +15,7 @@ ### Dependencies - OSV gate: time-boxed allow-list entry for picomatch GHSA-fc5q-39xc-vjpf (ReDoS, no fixed release). It is in build/test tooling and ships inside the Next.js dashboard bundle, where it only matches image URLs against globs from next.config, of which we declare none; re-review by 2026-12-18 (#1029) +- Bump `posthog-node` to 5.73.0 (#1012) and `sql.js` to 1.16.0 (#1013), and Next.js to 16.4.6 in the bundled dashboard (#1007) ## 1.0.14-beta.0 — 2026-11-16 diff --git a/Cargo.lock b/Cargo.lock index ee0791edd..892d4a1fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -298,7 +298,7 @@ dependencies = [ [[package]] name = "failproofaid" -version = "1.0.15-beta.0" +version = "1.0.15" dependencies = [ "fpai-collect", "fpai-ipc", @@ -361,7 +361,7 @@ dependencies = [ [[package]] name = "fpai-collect" -version = "1.0.15-beta.0" +version = "1.0.15" dependencies = [ "axum", "getrandom 0.4.3", @@ -382,7 +382,7 @@ dependencies = [ [[package]] name = "fpai-ipc" -version = "1.0.15-beta.0" +version = "1.0.15" dependencies = [ "libc", "proptest", diff --git a/Cargo.toml b/Cargo.toml index 6dceb2b72..c5e2f5372 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/*"] [workspace.package] -version = "1.0.15-beta.0" +version = "1.0.15" edition = "2024" license-file = "LICENSE" repository = "https://github.com/FailproofAI/failproofai" diff --git a/hermes-plugin/plugin.yaml b/hermes-plugin/plugin.yaml index 4a52a7873..9e24254cc 100644 --- a/hermes-plugin/plugin.yaml +++ b/hermes-plugin/plugin.yaml @@ -1,5 +1,5 @@ name: failproofai -version: 1.0.15-beta.0 +version: 1.0.15 description: Real-time FailproofAI policy enforcement for Hermes manifest_version: 2 api_version: 1 diff --git a/package.json b/package.json index 851d63bb4..8c47f4ebb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "failproofai", - "version": "1.0.15-beta.0", + "version": "1.0.15", "description": "The reliability layer for AI agents: see every failure, stop it in realtime. Policies hooked into 12 agent harnesses — Claude Code, Codex, Cursor, Hermes, OpenClaw and more — block the tool call before it runs. Local dashboard included, no account needed.", "bin": { "failproofai": "./dist/cli.mjs",