diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f7ba173..01c3166f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,22 @@ # 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 + +- 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 - 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). 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 ### Features diff --git a/CLAUDE.md b/CLAUDE.md index d99e93855..47c86dab1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -467,7 +467,14 @@ 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 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/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/__tests__/hooks/openclaw-plugin.test.ts b/__tests__/hooks/openclaw-plugin.test.ts index 87a6b23ec..90a5ed025 100644 --- a/__tests__/hooks/openclaw-plugin.test.ts +++ b/__tests__/hooks/openclaw-plugin.test.ts @@ -263,6 +263,130 @@ 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(); + } + }); + + // 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 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 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. + 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 }); + 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 +497,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/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/openclaw-plugin/daemon-client.js b/openclaw-plugin/daemon-client.js index 7111fa2a7..baa1da4f1 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"; @@ -28,12 +29,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,16 +158,67 @@ 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. + * + * Both attempts share ONE deadline of `responseTimeoutMs`, set before the + * 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 = performance.now(); + const budgetMs = request.responseTimeoutMs ?? RESPONSE_TIMEOUT_MS; + const deadline = startedAt + 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 - performance.now() - delayMs <= 0) return noTimeToRetry(first); + await new Promise((resume) => setTimeout(resume, delayMs)); + 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, ${Math.round(performance.now() - startedAt)} ms total`, + }; +} + +function requestOnce({ event, payload, cwd = "", agentSettingsPath = "", socketPath = daemonSocketPath(), - connectTimeoutMs = CONNECT_TIMEOUT_MS, - responseTimeoutMs = RESPONSE_TIMEOUT_MS, + // 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) => { + // Started before encoding, so the elapsed time in `detail` includes it. + const startedAt = performance.now(); let body; let oversized = false; try { @@ -197,22 +262,32 @@ 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 ${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 { - 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 ${budgetMs} ms`)); + else unreachable("no connection within the request budget"); + }, remainingMs); 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 +312,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) { diff --git a/osv-scanner.toml b/osv-scanner.toml index 11772c471..86e86b0ef 100644 --- a/osv-scanner.toml +++ b/osv-scanner.toml @@ -84,3 +84,34 @@ 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. 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. + +[[IgnoredVulns]] +id = "GHSA-fc5q-39xc-vjpf" +ignoreUntil = 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." 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",