fix(hooks): avoid stale thread ownership startup fallback

This commit is contained in:
Vincent Koc
2026-04-22 14:18:35 -07:00
parent 50c95d1d21
commit 65ae1e54de
3 changed files with 33 additions and 3 deletions

View File

@@ -211,6 +211,32 @@ describe("thread-ownership plugin", () => {
expect(globalThis.fetch).not.toHaveBeenCalled();
});
it("does not fall back to startup allowlists when live plugin config is removed", async () => {
api.pluginConfig = { abTestChannels: ["C999"] };
register.register(api as unknown as OpenClawPluginApi);
vi.mocked(globalThis.fetch).mockResolvedValue(
new Response(JSON.stringify({ owner: "test-agent" }), { status: 200 }),
);
const result = await hooks.message_sending(
{
content: "hello",
replyToId: "1234.5678",
to: "C123",
},
{ channelId: "slack", conversationId: "C123" },
);
expect(result).toBeUndefined();
expect(globalThis.fetch).toHaveBeenCalledWith(
"http://localhost:8750/api/v1/ownership/C123/1234.5678",
expect.objectContaining({
method: "POST",
body: JSON.stringify({ agent_id: "test-agent" }),
}),
);
});
it("cancels when thread owned by another agent", async () => {
vi.mocked(globalThis.fetch).mockResolvedValue(
new Response(JSON.stringify({ owner: "other-agent" }), { status: 409 }),

View File

@@ -83,11 +83,14 @@ export default definePluginEntry({
description: "Slack thread claim coordination for multi-agent setups",
register(api: OpenClawPluginApi) {
const resolveCurrentState = () => {
const currentConfig = api.runtime.config?.loadConfig?.() ?? api.config;
const runtimeConfigAvailable = typeof api.runtime.config?.loadConfig === "function";
const currentConfig = runtimeConfigAvailable
? (api.runtime.config.loadConfig() ?? api.config)
: api.config;
const livePluginCfg = resolvePluginConfigObject(currentConfig, "thread-ownership");
const pluginCfg = isThreadOwnershipConfig(livePluginCfg)
? livePluginCfg
: isThreadOwnershipConfig(api.pluginConfig)
: !runtimeConfigAvailable && isThreadOwnershipConfig(api.pluginConfig)
? api.pluginConfig
: {};
return {

View File

@@ -70,7 +70,8 @@ const BUNDLED_LIVE_CONFIG_HOOK_GUARDS = {
],
"extensions/thread-ownership/index.ts": [
'resolvePluginConfigObject(currentConfig, "thread-ownership")',
"api.runtime.config?.loadConfig?.() ?? api.config",
'typeof api.runtime.config?.loadConfig === "function"',
"api.runtime.config.loadConfig() ?? api.config",
],
} as const satisfies Record<string, readonly string[]>;