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

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

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
slack: persist thread participation best-effort (#75583) ...
amknight · 2026-05-01 · via Recent Commits to openclaw:main

@@ -1,4 +1,5 @@

11

import { resolveGlobalDedupeCache } from "openclaw/plugin-sdk/dedupe-runtime";

2+

import { getOptionalSlackRuntime } from "./runtime.js";

2334

/**

45

* In-memory cache of Slack threads the bot has participated in.

@@ -8,6 +9,22 @@ import { resolveGlobalDedupeCache } from "openclaw/plugin-sdk/dedupe-runtime";

89910

const TTL_MS = 24 * 60 * 60 * 1000; // 24 hours

1011

const MAX_ENTRIES = 5000;

12+

const PERSISTENT_MAX_ENTRIES = 1000;

13+

const PERSISTENT_NAMESPACE = "slack.thread-participation";

14+15+

type SlackThreadParticipationRecord = {

16+

agentId?: string;

17+

repliedAt: number;

18+

};

19+20+

type SlackThreadParticipationStore = {

21+

register(

22+

key: string,

23+

value: SlackThreadParticipationRecord,

24+

opts?: { ttlMs?: number },

25+

): Promise<void>;

26+

lookup(key: string): Promise<SlackThreadParticipationRecord | undefined>;

27+

};

11281229

/**

1330

* Keep Slack thread participation shared across bundled chunks so thread

@@ -19,19 +36,92 @@ const threadParticipation = resolveGlobalDedupeCache(SLACK_THREAD_PARTICIPATION_

1936

maxSize: MAX_ENTRIES,

2037

});

213839+

let persistentStore: SlackThreadParticipationStore | undefined;

40+

let persistentStoreDisabled = false;

41+2242

function makeKey(accountId: string, channelId: string, threadTs: string): string {

2343

return `${accountId}:${channelId}:${threadTs}`;

2444

}

254546+

function reportPersistentThreadParticipationError(error: unknown): void {

47+

try {

48+

getOptionalSlackRuntime()

49+

?.logging.getChildLogger({ plugin: "slack", feature: "thread-participation-state" })

50+

.warn("Slack persistent thread participation state failed", { error: String(error) });

51+

} catch {

52+

// Best effort only: persistent state must never break Slack message handling.

53+

}

54+

}

55+56+

function disablePersistentThreadParticipation(error: unknown): void {

57+

persistentStoreDisabled = true;

58+

persistentStore = undefined;

59+

reportPersistentThreadParticipationError(error);

60+

}

61+62+

function getPersistentThreadParticipationStore(): SlackThreadParticipationStore | undefined {

63+

if (persistentStoreDisabled) {

64+

return undefined;

65+

}

66+

if (persistentStore) {

67+

return persistentStore;

68+

}

69+

const runtime = getOptionalSlackRuntime();

70+

if (!runtime) {

71+

return undefined;

72+

}

73+

try {

74+

persistentStore = runtime.state.openKeyedStore<SlackThreadParticipationRecord>({

75+

namespace: PERSISTENT_NAMESPACE,

76+

maxEntries: PERSISTENT_MAX_ENTRIES,

77+

defaultTtlMs: TTL_MS,

78+

});

79+

return persistentStore;

80+

} catch (error) {

81+

disablePersistentThreadParticipation(error);

82+

return undefined;

83+

}

84+

}

85+86+

function rememberPersistentThreadParticipation(params: { key: string; agentId?: string }): void {

87+

const store = getPersistentThreadParticipationStore();

88+

if (!store) {

89+

return;

90+

}

91+

void store

92+

.register(params.key, {

93+

// Stored for future per-agent thread routing; current reads only need presence.

94+

...(params.agentId ? { agentId: params.agentId } : {}),

95+

repliedAt: Date.now(),

96+

})

97+

.catch(disablePersistentThreadParticipation);

98+

}

99+100+

async function lookupPersistentThreadParticipation(key: string): Promise<boolean> {

101+

const store = getPersistentThreadParticipationStore();

102+

if (!store) {

103+

return false;

104+

}

105+

try {

106+

return Boolean(await store.lookup(key));

107+

} catch (error) {

108+

disablePersistentThreadParticipation(error);

109+

return false;

110+

}

111+

}

112+26113

export function recordSlackThreadParticipation(

27114

accountId: string,

28115

channelId: string,

29116

threadTs: string,

117+

opts?: { agentId?: string },

30118

): void {

31119

if (!accountId || !channelId || !threadTs) {

32120

return;

33121

}

34-

threadParticipation.check(makeKey(accountId, channelId, threadTs));

122+

const key = makeKey(accountId, channelId, threadTs);

123+

threadParticipation.check(key);

124+

rememberPersistentThreadParticipation({ key, agentId: opts?.agentId });

35125

}

3612637127

export function hasSlackThreadParticipation(

@@ -45,6 +135,27 @@ export function hasSlackThreadParticipation(

45135

return threadParticipation.peek(makeKey(accountId, channelId, threadTs));

46136

}

47137138+

export async function hasSlackThreadParticipationWithPersistence(params: {

139+

accountId: string;

140+

channelId: string;

141+

threadTs: string;

142+

}): Promise<boolean> {

143+

if (!params.accountId || !params.channelId || !params.threadTs) {

144+

return false;

145+

}

146+

const key = makeKey(params.accountId, params.channelId, params.threadTs);

147+

if (threadParticipation.peek(key)) {

148+

return true;

149+

}

150+

const found = await lookupPersistentThreadParticipation(key);

151+

if (found) {

152+

threadParticipation.check(key);

153+

}

154+

return found;

155+

}

156+48157

export function clearSlackThreadParticipationCache(): void {

49158

threadParticipation.clear();

159+

persistentStore = undefined;

160+

persistentStoreDisabled = false;

50161

}