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

推荐订阅源

U
Unit 42
博客园 - 司徒正美
V
Visual Studio Blog
博客园 - 【当耐特】
T
Tailwind CSS Blog
美团技术团队
博客园 - 叶小钗
Jina AI
Jina AI
宝玉的分享
宝玉的分享
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC

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
matrix: persist approval reaction targets best-effort (#7...
amknight · 2026-05-03 · via Recent Commits to openclaw:main

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

11

import type { ExecApprovalReplyDecision } from "openclaw/plugin-sdk/approval-runtime";

2+

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

2334

const MATRIX_APPROVAL_REACTION_META = {

45

"allow-once": {

@@ -21,7 +22,11 @@ const MATRIX_APPROVAL_REACTION_ORDER = [

2122

"deny",

2223

] as const satisfies readonly ExecApprovalReplyDecision[];

232424-

type MatrixApprovalReactionBinding = {

25+

const PERSISTENT_NAMESPACE = "matrix.approval-reactions";

26+

const PERSISTENT_MAX_ENTRIES = 1000;

27+

const DEFAULT_REACTION_TARGET_TTL_MS = 24 * 60 * 60 * 1000;

28+29+

export type MatrixApprovalReactionBinding = {

2530

decision: ExecApprovalReplyDecision;

2631

emoji: string;

2732

label: string;

@@ -37,7 +42,24 @@ type MatrixApprovalReactionTarget = {

3742

allowedDecisions: readonly ExecApprovalReplyDecision[];

3843

};

394445+

type PersistedMatrixApprovalReactionTarget = {

46+

version: 1;

47+

target: MatrixApprovalReactionTarget;

48+

};

49+50+

type MatrixApprovalReactionStore = {

51+

register(

52+

key: string,

53+

value: PersistedMatrixApprovalReactionTarget,

54+

opts?: { ttlMs?: number },

55+

): Promise<void>;

56+

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

57+

delete(key: string): Promise<boolean>;

58+

};

59+4060

const matrixApprovalReactionTargets = new Map<string, MatrixApprovalReactionTarget>();

61+

let persistentStore: MatrixApprovalReactionStore | undefined;

62+

let persistentStoreDisabled = false;

41634264

function buildReactionTargetKey(roomId: string, eventId: string): string | null {

4365

const normalizedRoomId = roomId.trim();

@@ -48,6 +70,97 @@ function buildReactionTargetKey(roomId: string, eventId: string): string | null

4870

return `${normalizedRoomId}:${normalizedEventId}`;

4971

}

507273+

function reportPersistentApprovalReactionError(error: unknown): void {

74+

try {

75+

getOptionalMatrixRuntime()

76+

?.logging.getChildLogger({ plugin: "matrix", feature: "approval-reaction-state" })

77+

.warn("Matrix persistent approval reaction state failed", { error: String(error) });

78+

} catch {

79+

// Best effort only: persistent state must never break Matrix reactions.

80+

}

81+

}

82+83+

function disablePersistentApprovalReactionStore(error: unknown): void {

84+

persistentStoreDisabled = true;

85+

persistentStore = undefined;

86+

reportPersistentApprovalReactionError(error);

87+

}

88+89+

function getPersistentApprovalReactionStore(): MatrixApprovalReactionStore | undefined {

90+

if (persistentStoreDisabled) {

91+

return undefined;

92+

}

93+

if (persistentStore) {

94+

return persistentStore;

95+

}

96+

const runtime = getOptionalMatrixRuntime();

97+

if (!runtime) {

98+

return undefined;

99+

}

100+

try {

101+

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

102+

namespace: PERSISTENT_NAMESPACE,

103+

maxEntries: PERSISTENT_MAX_ENTRIES,

104+

defaultTtlMs: DEFAULT_REACTION_TARGET_TTL_MS,

105+

});

106+

return persistentStore;

107+

} catch (error) {

108+

disablePersistentApprovalReactionStore(error);

109+

return undefined;

110+

}

111+

}

112+113+

function readPersistedTarget(value: unknown): MatrixApprovalReactionTarget | null {

114+

const persisted = value as PersistedMatrixApprovalReactionTarget | undefined;

115+

if (

116+

persisted?.version !== 1 ||

117+

!persisted.target ||

118+

typeof persisted.target.approvalId !== "string" ||

119+

!Array.isArray(persisted.target.allowedDecisions)

120+

) {

121+

return null;

122+

}

123+

return persisted.target;

124+

}

125+126+

function rememberPersistentApprovalReactionTarget(params: {

127+

key: string;

128+

target: MatrixApprovalReactionTarget;

129+

ttlMs?: number;

130+

}): void {

131+

const ttlMs = params.ttlMs == null ? DEFAULT_REACTION_TARGET_TTL_MS : Math.max(1, params.ttlMs);

132+

const store = getPersistentApprovalReactionStore();

133+

if (!store) {

134+

return;

135+

}

136+

void store

137+

.register(params.key, { version: 1, target: params.target }, { ttlMs })

138+

.catch(disablePersistentApprovalReactionStore);

139+

}

140+141+

function forgetPersistentApprovalReactionTarget(key: string): void {

142+

const store = getPersistentApprovalReactionStore();

143+

if (!store) {

144+

return;

145+

}

146+

void store.delete(key).catch(disablePersistentApprovalReactionStore);

147+

}

148+149+

async function lookupPersistentApprovalReactionTarget(

150+

key: string,

151+

): Promise<MatrixApprovalReactionTarget | null> {

152+

const store = getPersistentApprovalReactionStore();

153+

if (!store) {

154+

return null;

155+

}

156+

try {

157+

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

158+

} catch (error) {

159+

disablePersistentApprovalReactionStore(error);

160+

return null;

161+

}

162+

}

163+51164

export function listMatrixApprovalReactionBindings(

52165

allowedDecisions: readonly ExecApprovalReplyDecision[],

53166

): MatrixApprovalReactionBinding[] {

@@ -96,6 +209,7 @@ export function registerMatrixApprovalReactionTarget(params: {

96209

eventId: string;

97210

approvalId: string;

98211

allowedDecisions: readonly ExecApprovalReplyDecision[];

212+

ttlMs?: number;

99213

}): void {

100214

const key = buildReactionTargetKey(params.roomId, params.eventId);

101215

const approvalId = params.approvalId.trim();

@@ -110,9 +224,15 @@ export function registerMatrixApprovalReactionTarget(params: {

110224

if (!key || !approvalId || allowedDecisions.length === 0) {

111225

return;

112226

}

113-

matrixApprovalReactionTargets.set(key, {

227+

const target = {

114228

approvalId,

115229

allowedDecisions,

230+

};

231+

matrixApprovalReactionTargets.set(key, target);

232+

rememberPersistentApprovalReactionTarget({

233+

key,

234+

target,

235+

ttlMs: params.ttlMs,

116236

});

117237

}

118238

@@ -125,18 +245,14 @@ export function unregisterMatrixApprovalReactionTarget(params: {

125245

return;

126246

}

127247

matrixApprovalReactionTargets.delete(key);

248+

forgetPersistentApprovalReactionTarget(key);

128249

}

129250130-

export function resolveMatrixApprovalReactionTarget(params: {

131-

roomId: string;

132-

eventId: string;

251+

function resolveTarget(params: {

252+

target: MatrixApprovalReactionTarget | null | undefined;

133253

reactionKey: string;

134254

}): MatrixApprovalReactionResolution | null {

135-

const key = buildReactionTargetKey(params.roomId, params.eventId);

136-

if (!key) {

137-

return null;

138-

}

139-

const target = matrixApprovalReactionTargets.get(key);

255+

const target = params.target;

140256

if (!target) {

141257

return null;

142258

}

@@ -153,6 +269,45 @@ export function resolveMatrixApprovalReactionTarget(params: {

153269

};

154270

}

155271272+

export function resolveMatrixApprovalReactionTarget(params: {

273+

roomId: string;

274+

eventId: string;

275+

reactionKey: string;

276+

}): MatrixApprovalReactionResolution | null {

277+

const key = buildReactionTargetKey(params.roomId, params.eventId);

278+

if (!key) {

279+

return null;

280+

}

281+

return resolveTarget({

282+

target: matrixApprovalReactionTargets.get(key),

283+

reactionKey: params.reactionKey,

284+

});

285+

}

286+287+

export async function resolveMatrixApprovalReactionTargetWithPersistence(params: {

288+

roomId: string;

289+

eventId: string;

290+

reactionKey: string;

291+

}): Promise<MatrixApprovalReactionResolution | null> {

292+

const key = buildReactionTargetKey(params.roomId, params.eventId);

293+

if (!key) {

294+

return null;

295+

}

296+

const inMemory = resolveTarget({

297+

target: matrixApprovalReactionTargets.get(key),

298+

reactionKey: params.reactionKey,

299+

});

300+

if (inMemory) {

301+

return inMemory;

302+

}

303+

return resolveTarget({

304+

target: await lookupPersistentApprovalReactionTarget(key),

305+

reactionKey: params.reactionKey,

306+

});

307+

}

308+156309

export function clearMatrixApprovalReactionTargetsForTest(): void {

157310

matrixApprovalReactionTargets.clear();

311+

persistentStore = undefined;

312+

persistentStoreDisabled = false;

158313

}