Skip to content

Commit b71c9b6

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/talk-audio-meter-reentrant-stop-20260801
* origin/main: fix(openai): keep embedding identity stable across upgrades (#117557) fix(googlechat): drop invalid thread resource names before send (#108324) fix(skills): preserve profile in ClawHub command hints (#117555) fix(cli): explain filtered plugin policy without unsafe recovery (#117556) fix(irc): strip markdown from outbound text (#112961)
2 parents a984930 + 71b35c3 commit b71c9b6

10 files changed

Lines changed: 499 additions & 18 deletions

‎extensions/googlechat/src/api.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ async function fetchBuffer(
178178
});
179179
}
180180

181+
/**
182+
* A Google Chat `thread` must be a `spaces/{space}/threads/{thread}` resource
183+
* name that belongs to the target space. Reply routing sometimes yields other
184+
* shapes — a bare id, a `spaces/{space}/messages/{message}` name, or a thread
185+
* from a different (or wrongly-cased) space — and passing any of those makes the
186+
* Chat API reject the whole send with `400 INVALID_ARGUMENT`. Accept only a
187+
* well-formed, same-space thread name; callers drop the rest so the message
188+
* still delivers to the space (as a new thread) instead of failing outright.
189+
*/
190+
function isUsableGoogleChatThreadName(thread: string, space: string): boolean {
191+
return /^spaces\/[^/]+\/threads\/[^/]+$/.test(thread) && thread.startsWith(`${space}/threads/`);
192+
}
193+
181194
export async function sendGoogleChatMessage(params: {
182195
account: ResolvedGoogleChatAccount;
183196
space: string;
@@ -186,6 +199,7 @@ export async function sendGoogleChatMessage(params: {
186199
cardsV2?: GoogleChatCardV2[];
187200
}): Promise<{ messageName?: string; threadName?: string } | null> {
188201
const { account, space, text, thread, cardsV2 } = params;
202+
const usableThread = thread && isUsableGoogleChatThreadName(thread, space) ? thread : undefined;
189203
if (
190204
text &&
191205
(!cardsV2 || cardsV2.length === 0) &&
@@ -200,11 +214,11 @@ export async function sendGoogleChatMessage(params: {
200214
if (cardsV2 && cardsV2.length > 0) {
201215
body.cardsV2 = cardsV2;
202216
}
203-
if (thread) {
204-
body.thread = { name: thread };
217+
if (usableThread) {
218+
body.thread = { name: usableThread };
205219
}
206220
const urlObj = new URL(`${CHAT_API_BASE}/${space}/messages`);
207-
if (thread) {
221+
if (usableThread) {
208222
urlObj.searchParams.set("messageReplyOption", "REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD");
209223
}
210224
const url = urlObj.toString();

‎extensions/googlechat/src/targets.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,58 @@ describe("sendGoogleChatMessage", () => {
568568
expect(String(url)).not.toContain("messageReplyOption=");
569569
});
570570

571+
it.each([
572+
["a bare id", "113887189178345237288721356"],
573+
["a thread key without prefix", "pytxeqyhqck"],
574+
["a message resource name", "spaces/AAA/messages/1720896000000.000000"],
575+
["a space resource name", "spaces/AAA"],
576+
["a thread from a different space", "spaces/BBB/threads/xyz"],
577+
])(
578+
"drops an invalid thread resource name (%s) and posts to the space",
579+
async (_label, badThread) => {
580+
const fetchMock = stubSuccessfulSend("spaces/AAA/messages/126");
581+
582+
const result = await sendGoogleChatMessage({
583+
account,
584+
space: "spaces/AAA",
585+
text: "hello",
586+
thread: badThread,
587+
});
588+
589+
const url = mockCallArg(fetchMock);
590+
const init = mockCallArg(fetchMock, 0, 1) as RequestInit | undefined;
591+
// Invalid thread must not be forwarded, and the reply option must be omitted
592+
// so the Chat API accepts the send instead of returning 400 INVALID_ARGUMENT.
593+
expect(String(url)).not.toContain("messageReplyOption=");
594+
if (typeof init?.body !== "string") {
595+
throw new Error("Expected Google Chat request body");
596+
}
597+
const body = JSON.parse(init.body) as { thread?: unknown };
598+
expect(body.thread).toBeUndefined();
599+
expect(result).toEqual({ messageName: "spaces/AAA/messages/126" });
600+
},
601+
);
602+
603+
it("keeps a valid same-space thread resource name", async () => {
604+
const fetchMock = stubSuccessfulSend("spaces/AAA/messages/127", "spaces/AAA/threads/xyz");
605+
606+
await sendGoogleChatMessage({
607+
account,
608+
space: "spaces/AAA",
609+
text: "hello",
610+
thread: "spaces/AAA/threads/xyz",
611+
});
612+
613+
const url = mockCallArg(fetchMock);
614+
const init = mockCallArg(fetchMock, 0, 1) as RequestInit | undefined;
615+
expect(String(url)).toContain("messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD");
616+
if (typeof init?.body !== "string") {
617+
throw new Error("Expected Google Chat request body");
618+
}
619+
const body = JSON.parse(init.body) as { thread?: { name?: unknown } };
620+
expect(body.thread?.name).toBe("spaces/AAA/threads/xyz");
621+
});
622+
571623
it("sends cardsV2 with the text fallback", async () => {
572624
const fetchMock = stubSuccessfulSend("spaces/AAA/messages/125");
573625
const cardsV2 = [

‎extensions/irc/src/send.test.ts‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ const hoisted = vi.hoisted(() => {
1010
const loadConfig = vi.fn();
1111
const resolveMarkdownTableMode = vi.fn(() => "preserve");
1212
const convertMarkdownTables = vi.fn((text: string) => text);
13+
const stripMarkdown = vi.fn((text: string) => text);
1314
const record = vi.fn();
1415
return {
1516
loadConfig,
1617
resolveMarkdownTableMode,
1718
convertMarkdownTables,
19+
stripMarkdown,
1820
record,
1921
normalizeIrcMessagingTarget: vi.fn((value: string) => value.trim()),
2022
connectIrcClient: vi.fn(),
@@ -47,6 +49,14 @@ vi.mock("openclaw/plugin-sdk/plugin-config-runtime", async () => {
4749
string,
4850
unknown
4951
>;
52+
return original;
53+
});
54+
55+
vi.mock("openclaw/plugin-sdk/markdown-table-runtime", async () => {
56+
const original = (await vi.importActual("openclaw/plugin-sdk/markdown-table-runtime")) as Record<
57+
string,
58+
unknown
59+
>;
5060
return {
5161
...original,
5262
resolveMarkdownTableMode: hoisted.resolveMarkdownTableMode,
@@ -61,6 +71,7 @@ vi.mock("openclaw/plugin-sdk/text-chunking", async () => {
6171
return {
6272
...original,
6373
convertMarkdownTables: hoisted.convertMarkdownTables,
74+
stripMarkdown: hoisted.stripMarkdown,
6475
};
6576
});
6677

@@ -71,6 +82,7 @@ function resetHoistedMocks() {
7182
hoisted.loadConfig.mockReset();
7283
hoisted.resolveMarkdownTableMode.mockReset().mockReturnValue("preserve");
7384
hoisted.convertMarkdownTables.mockReset().mockImplementation((text: string) => text);
85+
hoisted.stripMarkdown.mockReset().mockImplementation((text: string) => text);
7486
hoisted.record.mockReset();
7587
hoisted.normalizeIrcMessagingTarget
7688
.mockReset()
@@ -85,6 +97,7 @@ afterAll(() => {
8597
vi.doUnmock("./connect-options.js");
8698
vi.doUnmock("./protocol.js");
8799
vi.doUnmock("openclaw/plugin-sdk/plugin-config-runtime");
100+
vi.doUnmock("openclaw/plugin-sdk/markdown-table-runtime");
88101
vi.doUnmock("openclaw/plugin-sdk/text-chunking");
89102
vi.resetModules();
90103
});
@@ -159,6 +172,39 @@ describe("sendMessageIrc cfg threading", () => {
159172
});
160173
});
161174

175+
it("strips markdown after table conversion before sending to IRC", async () => {
176+
const providedCfg = {
177+
channels: {
178+
irc: {
179+
host: "irc.example.com",
180+
nick: "openclaw",
181+
},
182+
},
183+
} as unknown as CoreConfig;
184+
const client = {
185+
isReady: vi.fn(() => true),
186+
sendPrivmsg: vi.fn(),
187+
} as unknown as IrcClient;
188+
hoisted.resolveMarkdownTableMode.mockReturnValue("bullets");
189+
hoisted.convertMarkdownTables.mockReturnValue("**Status**\n- [docs](https://example.com)");
190+
hoisted.stripMarkdown.mockReturnValue("Status\n- docs (https://example.com)");
191+
192+
await sendMessageIrc("#room", " | a |\n| - |\n| **docs** | ", {
193+
cfg: providedCfg,
194+
client,
195+
});
196+
197+
expect(hoisted.convertMarkdownTables).toHaveBeenCalledWith(
198+
"| a |\n| - |\n| **docs** |",
199+
"bullets",
200+
);
201+
expect(hoisted.stripMarkdown).toHaveBeenCalledWith("**Status**\n- [docs](https://example.com)");
202+
expect(client.sendPrivmsg).toHaveBeenCalledWith(
203+
"#room",
204+
"Status\n- docs (https://example.com)",
205+
);
206+
});
207+
162208
it("fails hard when cfg is omitted", async () => {
163209
const client = {
164210
isReady: vi.fn(() => true),
@@ -254,6 +300,33 @@ describe("sendMessageIrc cfg threading", () => {
254300
});
255301
});
256302

303+
it("rejects stripped-empty replies before adding reply metadata", async () => {
304+
const providedCfg = {
305+
channels: {
306+
irc: {
307+
host: "irc.example.com",
308+
nick: "openclaw",
309+
},
310+
},
311+
} as unknown as CoreConfig;
312+
const client = {
313+
isReady: vi.fn(() => true),
314+
sendPrivmsg: vi.fn(),
315+
} as unknown as IrcClient;
316+
hoisted.stripMarkdown.mockReturnValue("");
317+
318+
await expect(
319+
sendMessageIrc("#room", "#", {
320+
cfg: providedCfg,
321+
client,
322+
replyTo: "irc-parent-1",
323+
}),
324+
).rejects.toThrow("Message must be non-empty for IRC sends");
325+
326+
expect(client.sendPrivmsg).not.toHaveBeenCalled();
327+
expect(hoisted.record).not.toHaveBeenCalled();
328+
});
329+
257330
it("declares message adapter durable text, media, and reply with receipt proofs", async () => {
258331
const providedCfg = {
259332
channels: {

‎extensions/irc/src/send.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "openclaw/plugin-sdk/channel-outbound";
66
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
77
import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
8-
import { convertMarkdownTables } from "openclaw/plugin-sdk/text-chunking";
8+
import { convertMarkdownTables, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
99
import { resolveIrcAccount } from "./accounts.js";
1010
import type { IrcClient } from "./client.js";
1111
import { connectIrcClient } from "./client.js";
@@ -78,12 +78,11 @@ export async function sendMessageIrc(
7878
channel: "irc",
7979
accountId: account.accountId,
8080
});
81-
const prepared = convertMarkdownTables(text.trim(), tableMode);
82-
const payload = opts.replyTo ? `${prepared}\n\n[reply:${opts.replyTo}]` : prepared;
83-
84-
if (!payload.trim()) {
81+
const prepared = stripMarkdown(convertMarkdownTables(text.trim(), tableMode));
82+
if (!prepared.trim()) {
8583
throw new Error("Message must be non-empty for IRC sends");
8684
}
85+
const payload = opts.replyTo ? `${prepared}\n\n[reply:${opts.replyTo}]` : prepared;
8786

8887
const client = opts.client;
8988
if (client?.isReady()) {

‎extensions/openai/memory-embedding-adapter.test.ts‎

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Openai tests cover memory embedding adapter plugin behavior.
2-
import type { MemoryEmbeddingProvider } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
3-
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import {
3+
resolveRemoteEmbeddingBearerClient,
4+
type MemoryEmbeddingProvider,
5+
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
6+
import { hashText } from "openclaw/plugin-sdk/memory-core-host-engine-storage";
7+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
48

59
const mocks = vi.hoisted(() => ({
610
createOpenAiEmbeddingProvider: vi.fn(),
@@ -27,6 +31,10 @@ const provider: MemoryEmbeddingProvider = {
2731
};
2832

2933
describe("OpenAI memory embedding adapter", () => {
34+
afterEach(() => {
35+
vi.unstubAllEnvs();
36+
});
37+
3038
beforeEach(() => {
3139
mocks.createOpenAiEmbeddingProvider.mockReset();
3240
mocks.runOpenAiEmbeddingBatches.mockClear();
@@ -43,6 +51,105 @@ describe("OpenAI memory embedding adapter", () => {
4351
});
4452
});
4553

54+
it("keeps native OpenAI embedding cache identity stable across OpenClaw versions", async () => {
55+
const createForVersion = async (version: string) => {
56+
vi.stubEnv("OPENCLAW_VERSION", version);
57+
const client = await resolveRemoteEmbeddingBearerClient({
58+
provider: "openai",
59+
defaultBaseUrl: "https://api.openai.com/v1",
60+
options: {
61+
config: { models: {} } as never,
62+
model: "text-embedding-3-small",
63+
remote: { apiKey: "fixture-secret" },
64+
},
65+
});
66+
mocks.createOpenAiEmbeddingProvider.mockResolvedValueOnce({
67+
provider,
68+
client: { ...client, model: "text-embedding-3-small" },
69+
});
70+
const result = await openAiMemoryEmbeddingProviderAdapter.create({
71+
config: {} as never,
72+
provider: "openai",
73+
model: "text-embedding-3-small",
74+
fallback: "none",
75+
});
76+
return { headers: client.headers, cacheKeyData: result.runtime?.cacheKeyData };
77+
};
78+
79+
const previous = await createForVersion("2026.7.1");
80+
const current = await createForVersion("2026.7.2");
81+
82+
expect(previous.headers).toMatchObject({
83+
Authorization: "Bearer fixture-secret",
84+
version: "2026.7.1",
85+
"User-Agent": "openclaw/2026.7.1",
86+
});
87+
expect(current.headers).toMatchObject({
88+
Authorization: "Bearer fixture-secret",
89+
version: "2026.7.2",
90+
"User-Agent": "openclaw/2026.7.2",
91+
});
92+
expect(current.cacheKeyData).toEqual(previous.cacheKeyData);
93+
expect(hashText(JSON.stringify(current.cacheKeyData))).toBe(
94+
hashText(JSON.stringify(previous.cacheKeyData)),
95+
);
96+
expect(current.cacheKeyData).toMatchObject({
97+
provider: "openai",
98+
baseUrl: "https://api.openai.com/v1",
99+
model: "text-embedding-3-small",
100+
headers: [
101+
["Content-Type", "application/json"],
102+
["originator", "openclaw"],
103+
],
104+
});
105+
expect(JSON.stringify(current.cacheKeyData)).not.toContain("fixture-secret");
106+
});
107+
108+
it("preserves custom endpoint tenant and version-like cache identity headers", async () => {
109+
const createForTenant = async (tenant: string) => {
110+
const client = await resolveRemoteEmbeddingBearerClient({
111+
provider: "bailian-embedding",
112+
defaultBaseUrl: "https://embeddings.example/v1",
113+
options: {
114+
config: { models: {} } as never,
115+
model: "text-embedding-v3",
116+
remote: {
117+
apiKey: "fixture-secret",
118+
headers: {
119+
"X-Tenant": tenant,
120+
version: "tenant-api-v2",
121+
"User-Agent": "tenant-client/2",
122+
},
123+
},
124+
},
125+
});
126+
mocks.createOpenAiEmbeddingProvider.mockResolvedValueOnce({
127+
provider,
128+
client: { ...client, model: "text-embedding-v3" },
129+
});
130+
return await openAiMemoryEmbeddingProviderAdapter.create({
131+
config: {} as never,
132+
provider: "bailian-embedding",
133+
model: "text-embedding-v3",
134+
fallback: "none",
135+
});
136+
};
137+
138+
const first = await createForTenant("tenant-a");
139+
const second = await createForTenant("tenant-b");
140+
const headers = first.runtime?.cacheKeyData?.headers;
141+
142+
expect(headers).toEqual(
143+
expect.arrayContaining([
144+
["X-Tenant", "tenant-a"],
145+
["version", "tenant-api-v2"],
146+
["User-Agent", "tenant-client/2"],
147+
]),
148+
);
149+
expect(first.runtime?.cacheKeyData).not.toEqual(second.runtime?.cacheKeyData);
150+
expect(JSON.stringify(first.runtime?.cacheKeyData)).not.toContain("fixture-secret");
151+
});
152+
46153
it("sends document input_type in OpenAI batch embedding requests", async () => {
47154
const result = await openAiMemoryEmbeddingProviderAdapter.create({
48155
config: {} as never,

0 commit comments

Comments
 (0)