惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
I
InfoQ
D
Docker
F
Fortinet All Blogs
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
月光博客
月光博客
B
Blog
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
罗磊的独立博客
博客园_首页
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog RSS Feed
IT之家
IT之家
V
V2EX

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(slack): preserve assistant thread context · openclaw/...
steipete · 2026-05-17 · via Recent Commits to openclaw:main

@@ -5,27 +5,45 @@ import { registerSlackAssistantEvents } from "./assistant.js";

5566

type Handler = (args: { event: Record<string, unknown>; body: unknown }) => Promise<void>;

778-

function createHarness(overrides?: { shouldDrop?: boolean }) {

8+

function createHarness(overrides?: {

9+

shouldDrop?: boolean;

10+

existingContext?: ReturnType<SlackMonitorContext["getSlackAssistantThreadContext"]>;

11+

replies?: ReturnType<typeof vi.fn>;

12+

update?: ReturnType<typeof vi.fn>;

13+

}) {

914

const handlers: Record<string, Handler> = {};

15+

const getSlackAssistantThreadContext = vi.fn(() => overrides?.existingContext);

1016

const saveSlackAssistantThreadContext = vi.fn();

1117

const setSlackAssistantSuggestedPrompts = vi.fn(async () => true);

18+

const replies = overrides?.replies ?? vi.fn(async () => ({ messages: [] }));

19+

const update = overrides?.update ?? vi.fn(async () => ({}));

1220

const trackEvent = vi.fn();

1321

const ctx = {

1422

app: {

23+

client: {

24+

conversations: { replies },

25+

chat: { update },

26+

},

1527

event: (name: string, handler: Handler) => {

1628

handlers[name] = handler;

1729

},

1830

} as unknown as App,

1931

runtime: { error: vi.fn() },

32+

botToken: "xoxb-test",

33+

botUserId: "B1",

2034

shouldDropMismatchedSlackEvent: () => overrides?.shouldDrop === true,

35+

getSlackAssistantThreadContext,

2136

saveSlackAssistantThreadContext,

2237

setSlackAssistantSuggestedPrompts,

2338

} as unknown as SlackMonitorContext;

2439

registerSlackAssistantEvents({ ctx, trackEvent });

2540

return {

2641

handlers,

42+

getSlackAssistantThreadContext,

2743

saveSlackAssistantThreadContext,

2844

setSlackAssistantSuggestedPrompts,

45+

replies,

46+

update,

2947

trackEvent,

3048

};

3149

}

@@ -112,6 +130,51 @@ describe("registerSlackAssistantEvents", () => {

112130

expect(harness.setSlackAssistantSuggestedPrompts).not.toHaveBeenCalled();

113131

});

114132133+

it("persists changed assistant thread context onto the first bot message", async () => {

134+

const replies = vi.fn(async () => ({

135+

messages: [

136+

{ user: "U123", ts: "1729999327.200000", text: "user asks" },

137+

{

138+

user: "B1",

139+

ts: "1729999327.300000",

140+

text: "assistant reply",

141+

blocks: [{ type: "section", text: { type: "mrkdwn", text: "assistant reply" } }],

142+

},

143+

],

144+

}));

145+

const update = vi.fn(async () => ({}));

146+

const harness = createHarness({ replies, update });

147+148+

await harness.handlers.assistant_thread_context_changed?.({

149+

event: makeThreadEvent("assistant_thread_context_changed"),

150+

body: {},

151+

});

152+153+

expect(replies).toHaveBeenCalledWith({

154+

token: "xoxb-test",

155+

channel: "D123",

156+

ts: "1729999327.187299",

157+

oldest: "1729999327.187299",

158+

include_all_metadata: true,

159+

limit: 4,

160+

});

161+

expect(update).toHaveBeenCalledWith({

162+

token: "xoxb-test",

163+

channel: "D123",

164+

ts: "1729999327.300000",

165+

text: "assistant reply",

166+

blocks: [{ type: "section", text: { type: "mrkdwn", text: "assistant reply" } }],

167+

metadata: {

168+

event_type: "assistant_thread_context",

169+

event_payload: {

170+

channel_id: "C456",

171+

team_id: "T789",

172+

enterprise_id: "E123",

173+

},

174+

},

175+

});

176+

});

177+115178

it("accepts Slack assistant context when it is sent beside the thread", async () => {

116179

const harness = createHarness();

117180

@@ -130,6 +193,77 @@ describe("registerSlackAssistantEvents", () => {

130193

});

131194

});

132195196+

it("merges partial assistant thread context per field", async () => {

197+

const harness = createHarness();

198+199+

await harness.handlers.assistant_thread_context_changed?.({

200+

event: {

201+

type: "assistant_thread_context_changed",

202+

assistant_thread: {

203+

user_id: "U123",

204+

channel_id: "D123",

205+

thread_ts: "1729999327.187299",

206+

context: {

207+

team_id: "T_THREAD",

208+

},

209+

},

210+

context: {

211+

channel_id: "C456",

212+

team_id: "T_EVENT",

213+

enterprise_id: "E123",

214+

},

215+

},

216+

body: {},

217+

});

218+219+

expect(harness.saveSlackAssistantThreadContext).toHaveBeenCalledWith({

220+

assistantChannelId: "D123",

221+

threadTs: "1729999327.187299",

222+

userId: "U123",

223+

channelId: "C456",

224+

teamId: "T_THREAD",

225+

enterpriseId: "E123",

226+

});

227+

});

228+229+

it("preserves cached assistant thread context when updates omit optional fields", async () => {

230+

const harness = createHarness({

231+

existingContext: {

232+

assistantChannelId: "D123",

233+

threadTs: "1729999327.187299",

234+

userId: "UOLD",

235+

channelId: "COLD",

236+

teamId: "TOLD",

237+

enterpriseId: "EOLD",

238+

updatedAt: 1,

239+

},

240+

});

241+242+

await harness.handlers.assistant_thread_context_changed?.({

243+

event: {

244+

type: "assistant_thread_context_changed",

245+

assistant_thread: {

246+

channel_id: "D123",

247+

thread_ts: "1729999327.187299",

248+

},

249+

},

250+

body: {},

251+

});

252+253+

expect(harness.getSlackAssistantThreadContext).toHaveBeenCalledWith(

254+

"D123",

255+

"1729999327.187299",

256+

);

257+

expect(harness.saveSlackAssistantThreadContext).toHaveBeenCalledWith({

258+

assistantChannelId: "D123",

259+

threadTs: "1729999327.187299",

260+

userId: "UOLD",

261+

channelId: "COLD",

262+

teamId: "TOLD",

263+

enterpriseId: "EOLD",

264+

});

265+

});

266+133267

it("drops mismatched workspace events before touching assistant state", async () => {

134268

const harness = createHarness({ shouldDrop: true });

135269