Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(openclaw): read the retrieve hash from params, not the tool-call id (#4641)

Vivek Singh362e1fc65b97
diff --git a/plugins/openclaw/src/tools/headroom-retrieve.ts b/plugins/openclaw/src/tools/headroom-retrieve.ts
index af32cb3ac..1ccbd483d 100644
--- a/plugins/openclaw/src/tools/headroom-retrieve.ts
+++ b/plugins/openclaw/src/tools/headroom-retrieve.ts
@@ -32,8 +32,16 @@ export function createHeadroomRetrieveTool(config: RetrieveToolConfig) {
},
required: ["hash"],
},
- execute: async (args: { hash: string }): Promise<string> => {
- const { hash } = args;
+ // OpenClaw calls a registered tool as execute(toolCallId, params, signal?,
+ // onUpdate?). The hash used to be read from the first argument, so the
+ // tool-call id was validated as a hash and every real call failed before
+ // any request was sent (#4638). A direct execute({ hash }) call still works.
+ execute: async (
+ toolCallIdOrArgs: string | { hash: string },
+ params?: { hash: string },
+ ): Promise<string> => {
+ const args = typeof toolCallIdOrArgs === "string" ? params : toolCallIdOrArgs;
+ const hash = typeof args?.hash === "string" ? args.hash : "";
// Validate hash format
if (!/^[a-f0-9]{24}$/i.test(hash)) {
diff --git a/plugins/openclaw/test/headroom-retrieve-execute-args.test.ts b/plugins/openclaw/test/headroom-retrieve-execute-args.test.ts
new file mode 100644
index 000000000..803fd345e
--- /dev/null
+++ b/plugins/openclaw/test/headroom-retrieve-execute-args.test.ts
@@ -0,0 +1,63 @@
+import { describe, it, expect, afterEach, vi } from "vitest";
+import { createHeadroomRetrieveTool } from "../src/tools/headroom-retrieve.js";
+
+const HASH = "a".repeat(24);
+
+afterEach(() => {
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+});
+
+function stubFetch() {
+ const mock = vi.fn().mockResolvedValue({
+ ok: true,
+ status: 200,
+ json: () => Promise.resolve({ original_content: "offline fixture" }),
+ text: () => Promise.resolve(""),
+ });
+ vi.stubGlobal("fetch", mock);
+ return mock;
+}
+
+describe("headroom_retrieve execute arguments (#4638)", () => {
+ it("reads the hash from params when called the way OpenClaw calls tools", async () => {
+ const fetchMock = stubFetch();
+ const tool = createHeadroomRetrieveTool({ proxyUrl: "http://127.0.0.1:8080" });
+
+ const result = await tool.execute("call_fixture", { hash: HASH });
+
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ expect(String(fetchMock.mock.calls[0][0])).toBe(`http://127.0.0.1:8080/v1/retrieve/${HASH}`);
+ expect(JSON.parse(result)).toEqual({ original_content: "offline fixture" });
+ });
+
+ it("still accepts a direct execute({ hash }) call", async () => {
+ const fetchMock = stubFetch();
+ const tool = createHeadroomRetrieveTool({ proxyUrl: "http://127.0.0.1:8080" });
+
+ const result = await tool.execute({ hash: HASH });
+
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ expect(JSON.parse(result)).toEqual({ original_content: "offline fixture" });
+ });
+
+ it("rejects a bad hash in params without sending a request", async () => {
+ const fetchMock = stubFetch();
+ const tool = createHeadroomRetrieveTool({ proxyUrl: "http://127.0.0.1:8080" });
+
+ const result = await tool.execute("call_fixture", { hash: "not-a-hash" });
+
+ expect(fetchMock).not.toHaveBeenCalled();
+ expect(result).toContain("Invalid hash format");
+ });
+
+ it("rejects a missing params object without sending a request", async () => {
+ const fetchMock = stubFetch();
+ const tool = createHeadroomRetrieveTool({ proxyUrl: "http://127.0.0.1:8080" });
+
+ const result = await tool.execute("call_fixture");
+
+ expect(fetchMock).not.toHaveBeenCalled();
+ expect(result).toContain("Invalid hash format");
+ });
+});