fix: isolate Slack thread sessions (#758)

This commit is contained in:
Peter Steinberger
2026-01-15 08:01:15 +00:00
parent 627cc1f04b
commit c269d5f258
11 changed files with 221 additions and 70 deletions

View File

@@ -202,10 +202,60 @@ describe("monitorSlackProvider tool results", () => {
ParentSessionKey?: string;
};
expect(ctx.SessionKey).toBe("agent:main:main:thread:123");
expect(ctx.ParentSessionKey).toBe("agent:main:main");
expect(ctx.ParentSessionKey).toBeUndefined();
});
it("forks thread sessions and injects starter context", async () => {
it("keeps thread parent inheritance opt-in", async () => {
replyMock.mockResolvedValue({ text: "thread reply" });
config = {
messages: { responsePrefix: "PFX" },
channels: {
slack: {
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
channels: { C1: { allow: true, requireMention: false } },
thread: { inheritParent: true },
},
},
};
const controller = new AbortController();
const run = monitorSlackProvider({
botToken: "bot-token",
appToken: "app-token",
abortSignal: controller.signal,
});
await waitForEvent("message");
const handler = getSlackHandlers()?.get("message");
if (!handler) throw new Error("Slack message handler not registered");
await handler({
event: {
type: "message",
user: "U1",
text: "hello",
ts: "123",
thread_ts: "111.222",
channel: "C1",
channel_type: "channel",
},
});
await flush();
controller.abort();
await run;
expect(replyMock).toHaveBeenCalledTimes(1);
const ctx = replyMock.mock.calls[0]?.[0] as {
SessionKey?: string;
ParentSessionKey?: string;
};
expect(ctx.SessionKey).toBe("agent:main:slack:channel:C1:thread:111.222");
expect(ctx.ParentSessionKey).toBe("agent:main:slack:channel:C1");
});
it("injects starter context for thread replies", async () => {
replyMock.mockResolvedValue({ text: "ok" });
const client = getSlackClient();
@@ -265,7 +315,7 @@ describe("monitorSlackProvider tool results", () => {
ThreadLabel?: string;
};
expect(ctx.SessionKey).toBe("agent:main:slack:channel:C1:thread:111.222");
expect(ctx.ParentSessionKey).toBe("agent:main:slack:channel:C1");
expect(ctx.ParentSessionKey).toBeUndefined();
expect(ctx.ThreadStarterBody).toContain("starter message");
expect(ctx.ThreadLabel).toContain("Slack thread #general");
});
@@ -329,7 +379,7 @@ describe("monitorSlackProvider tool results", () => {
ParentSessionKey?: string;
};
expect(ctx.SessionKey).toBe("agent:support:slack:channel:C1:thread:111.222");
expect(ctx.ParentSessionKey).toBe("agent:support:slack:channel:C1");
expect(ctx.ParentSessionKey).toBeUndefined();
});
it("keeps replies in channel root when message is not threaded (replyToMode off)", async () => {