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

推荐订阅源

Y
Y Combinator Blog
有赞技术团队
有赞技术团队
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
博客园 - 【当耐特】
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
The Cloudflare Blog
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
Vercel News
Vercel News
IT之家
IT之家
MyScale Blog
MyScale Blog
博客园_首页
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
罗磊的独立博客

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
refactor(channels): move more turn policy into kernel · o...
steipete · 2026-04-30 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -1,2 +1,2 @@

1-

ae28566c922ce79527943b069abc199de28e3898ec08eea12c4ff6050795f276 plugin-sdk-api-baseline.json

2-

79446b23832949553b23e7cf92be37b81c69d123fc09bed6f8fc04bd98e9257d plugin-sdk-api-baseline.jsonl

1+

d26a70c9ea3bd277135a1712556f07195fb464b5cd846d04f18c2166c319a73d plugin-sdk-api-baseline.json

2+

9fe2cb122fb3de17eaaf54c7768f268aa689063cf9091bd4b0be9422550a70a8 plugin-sdk-api-baseline.jsonl

Original file line numberDiff line numberDiff line change

@@ -12,16 +12,9 @@ import {

1212

} from "openclaw/plugin-sdk/conversation-runtime";

1313

import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";

1414

import { normalizeScpRemoteHost } from "openclaw/plugin-sdk/host-runtime";

15-

import {

16-

hasFinalInboundReplyDispatch,

17-

runPreparedInboundReplyTurn,

18-

} from "openclaw/plugin-sdk/inbound-reply-dispatch";

15+

import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";

1916

import { isInboundPathAllowed, kindFromMime } from "openclaw/plugin-sdk/media-runtime";

20-

import {

21-

clearHistoryEntriesIfEnabled,

22-

DEFAULT_GROUP_HISTORY_LIMIT,

23-

type HistoryEntry,

24-

} from "openclaw/plugin-sdk/reply-history";

17+

import { DEFAULT_GROUP_HISTORY_LIMIT, type HistoryEntry } from "openclaw/plugin-sdk/reply-history";

2518

import { resolveTextChunkLimit } from "openclaw/plugin-sdk/reply-runtime";

2619

import { dispatchInboundMessage } from "openclaw/plugin-sdk/reply-runtime";

2720

import { createReplyDispatcher } from "openclaw/plugin-sdk/reply-runtime";

@@ -442,7 +435,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P

442435

},

443436

});

444437
445-

const { dispatchResult } = await runPreparedInboundReplyTurn({

438+

await runPreparedInboundReplyTurn({

446439

channel: "imessage",

447440

accountId: decision.route.accountId,

448441

routeSessionKey: decision.route.sessionKey,

@@ -475,6 +468,12 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P

475468

logVerbose(`imessage: failed updating session meta: ${String(err)}`);

476469

},

477470

},

471+

history: {

472+

isGroup: decision.isGroup,

473+

historyKey: decision.historyKey,

474+

historyMap: groupHistories,

475+

limit: historyLimit,

476+

},

478477

onPreDispatchFailure: () => settleReplyDispatcher({ dispatcher }),

479478

runDispatch: () =>

480479

dispatchInboundMessage({

@@ -490,23 +489,6 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P

490489

},

491490

}),

492491

});

493-

if (!hasFinalInboundReplyDispatch(dispatchResult)) {

494-

if (decision.isGroup && decision.historyKey) {

495-

clearHistoryEntriesIfEnabled({

496-

historyMap: groupHistories,

497-

historyKey: decision.historyKey,

498-

limit: historyLimit,

499-

});

500-

}

501-

return;

502-

}

503-

if (decision.isGroup && decision.historyKey) {

504-

clearHistoryEntriesIfEnabled({

505-

historyMap: groupHistories,

506-

historyKey: decision.historyKey,

507-

limit: historyLimit,

508-

});

509-

}

510492

}

511493
512494

const handleMessage = async (raw: unknown) => {

Original file line numberDiff line numberDiff line change

@@ -1,15 +1,8 @@

11

import type { webhook } from "@line/bot-sdk";

22

import { createChannelReplyPipeline } from "openclaw/plugin-sdk/channel-reply-pipeline";

33

import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";

4-

import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";

5-

import {

6-

hasFinalInboundReplyDispatch,

7-

runPreparedInboundReplyTurn,

8-

} from "openclaw/plugin-sdk/inbound-reply-dispatch";

9-

import {

10-

dispatchReplyWithBufferedBlockDispatcher,

11-

chunkMarkdownText,

12-

} from "openclaw/plugin-sdk/reply-runtime";

4+

import { hasFinalInboundReplyDispatch } from "openclaw/plugin-sdk/inbound-reply-dispatch";

5+

import { chunkMarkdownText } from "openclaw/plugin-sdk/reply-runtime";

136

import {

147

danger,

158

logVerbose,

@@ -32,6 +25,7 @@ import { deliverLineAutoReply } from "./auto-reply-delivery.js";

3225

import { createLineBot } from "./bot.js";

3326

import { processLineMessage } from "./markdown-to-line.js";

3427

import { sendLineReplyChunks } from "./reply-chunks.js";

28+

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

3529

import {

3630

createFlexMessage,

3731

createImageMessage,

@@ -236,21 +230,36 @@ export async function monitorLineProvider(

236230

accountId: route.accountId,

237231

});

238232
239-

const { dispatchResult } = await runPreparedInboundReplyTurn({

233+

const core = getLineRuntime();

234+

const { dispatchResult } = await core.channel.turn.run({

240235

channel: "line",

241236

accountId: route.accountId,

242-

routeSessionKey: route.sessionKey,

243-

storePath: ctx.turn.storePath,

244-

ctxPayload,

245-

recordInboundSession,

246-

record: ctx.turn.record,

247-

runDispatch: () =>

248-

dispatchReplyWithBufferedBlockDispatcher({

249-

ctx: ctxPayload,

237+

raw: ctx,

238+

adapter: {

239+

ingest: () => ({

240+

id: ctxPayload.MessageSid ?? `${ctxPayload.From}:${Date.now()}`,

241+

rawText: ctxPayload.RawBody ?? ctxPayload.BodyForAgent ?? "",

242+

}),

243+

resolveTurn: () => ({

250244

cfg: config,

245+

channel: "line",

246+

accountId: route.accountId,

247+

agentId: route.agentId,

248+

routeSessionKey: route.sessionKey,

249+

storePath: ctx.turn.storePath,

250+

ctxPayload,

251+

recordInboundSession: core.channel.session.recordInboundSession,

252+

dispatchReplyWithBufferedBlockDispatcher:

253+

core.channel.reply.dispatchReplyWithBufferedBlockDispatcher,

254+

record: ctx.turn.record,

251255

dispatcherOptions: {

252256

...replyPipeline,

253-

deliver: async (payload, _info) => {

257+

},

258+

replyOptions: {

259+

onModelSelected,

260+

},

261+

delivery: {

262+

deliver: async (payload) => {

254263

const lineData = (payload.channelData?.line as LineChannelData | undefined) ?? {};

255264
256265

if (ctx.userId && !ctx.isGroup) {

@@ -304,10 +313,8 @@ export async function monitorLineProvider(

304313

runtime.error?.(danger(`line ${info.kind} reply failed: ${String(err)}`));

305314

},

306315

},

307-

replyOptions: {

308-

onModelSelected,

309-

},

310316

}),

317+

},

311318

});

312319

if (!hasFinalInboundReplyDispatch(dispatchResult)) {

313320

logVerbose(`line: no response generated for message from ${ctxPayload.From}`);

Original file line numberDiff line numberDiff line change

@@ -25,14 +25,10 @@ import {

2525

toInternalMessageReceivedContext,

2626

triggerInternalHook,

2727

} from "openclaw/plugin-sdk/hook-runtime";

28-

import {

29-

hasFinalInboundReplyDispatch,

30-

runPreparedInboundReplyTurn,

31-

} from "openclaw/plugin-sdk/inbound-reply-dispatch";

28+

import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";

3229

import { kindFromMime } from "openclaw/plugin-sdk/media-runtime";

3330

import {

3431

buildPendingHistoryContextFromMap,

35-

clearHistoryEntriesIfEnabled,

3632

recordPendingHistoryEntryIfEnabled,

3733

} from "openclaw/plugin-sdk/reply-history";

3834

import { dispatchInboundMessage } from "openclaw/plugin-sdk/reply-runtime";

@@ -292,7 +288,7 @@ export function createSignalEventHandler(deps: SignalEventHandlerDeps) {

292288

},

293289

});

294290
295-

const { dispatchResult } = await runPreparedInboundReplyTurn({

291+

await runPreparedInboundReplyTurn({

296292

channel: "signal",

297293

accountId: route.accountId,

298294

routeSessionKey: route.sessionKey,

@@ -331,6 +327,12 @@ export function createSignalEventHandler(deps: SignalEventHandlerDeps) {

331327

logVerbose(`signal: failed updating session meta: ${String(err)}`);

332328

},

333329

},

330+

history: {

331+

isGroup: entry.isGroup,

332+

historyKey,

333+

historyMap: deps.groupHistories,

334+

limit: deps.historyLimit,

335+

},

334336

onPreDispatchFailure: () =>

335337

settleReplyDispatcher({

336338

dispatcher,

@@ -354,23 +356,6 @@ export function createSignalEventHandler(deps: SignalEventHandlerDeps) {

354356

}

355357

},

356358

});

357-

if (!hasFinalInboundReplyDispatch(dispatchResult)) {

358-

if (entry.isGroup && historyKey) {

359-

clearHistoryEntriesIfEnabled({

360-

historyMap: deps.groupHistories,

361-

historyKey,

362-

limit: deps.historyLimit,

363-

});

364-

}

365-

return;

366-

}

367-

if (entry.isGroup && historyKey) {

368-

clearHistoryEntriesIfEnabled({

369-

historyMap: deps.groupHistories,

370-

historyKey,

371-

limit: deps.historyLimit,

372-

});

373-

}

374359

}

375360
376361

const { debouncer: inboundDebouncer } = createChannelInboundDebouncer<SignalInboundEntry>({

Original file line numberDiff line numberDiff line change

@@ -1,5 +1,40 @@

11

import { describe, expect, it } from "vitest";

2-

import { buildChannelTurnContext } from "./context.js";

2+

import { buildChannelTurnContext, type BuildChannelTurnContextParams } from "./context.js";

3+
4+

function createBaseContextParams(

5+

overrides: Partial<BuildChannelTurnContextParams> = {},

6+

): BuildChannelTurnContextParams {

7+

return {

8+

channel: "test",

9+

accountId: "acct",

10+

messageId: "msg-1",

11+

from: "test:user:u1",

12+

sender: {

13+

id: "u1",

14+

},

15+

conversation: {

16+

kind: "group",

17+

id: "room-1",

18+

routePeer: {

19+

kind: "group",

20+

id: "room-1",

21+

},

22+

},

23+

route: {

24+

agentId: "main",

25+

routeSessionKey: "agent:main:test:group:room-1",

26+

},

27+

reply: {

28+

to: "test:room:room-1",

29+

originatingTo: "test:room:room-1",

30+

},

31+

message: {

32+

rawBody: "hello",

33+

envelopeFrom: "User One",

34+

},

35+

...overrides,

36+

};

37+

}

338
439

describe("buildChannelTurnContext", () => {

540

it("maps normalized turn facts into a finalized message context", () => {

@@ -139,4 +174,92 @@ describe("buildChannelTurnContext", () => {

139174

}),

140175

);

141176

});

177+
178+

it("filters supplemental context with channel visibility policy", () => {

179+

const ctx = buildChannelTurnContext(

180+

createBaseContextParams({

181+

supplemental: {

182+

quote: {

183+

id: "quote-1",

184+

body: "quoted",

185+

sender: "Quoted User",

186+

senderAllowed: false,

187+

isQuote: true,

188+

},

189+

forwarded: {

190+

from: "Forwarded User",

191+

fromId: "f1",

192+

senderAllowed: false,

193+

},

194+

thread: {

195+

starterBody: "thread starter",

196+

historyBody: "thread history",

197+

senderAllowed: false,

198+

},

199+

},

200+

contextVisibility: "allowlist",

201+

}),

202+

);

203+
204+

expect(ctx.ReplyToBody).toBeUndefined();

205+

expect(ctx.ReplyToSender).toBeUndefined();

206+

expect(ctx.ForwardedFrom).toBeUndefined();

207+

expect(ctx.ThreadStarterBody).toBeUndefined();

208+

expect(ctx.ThreadHistoryBody).toBeUndefined();

209+

});

210+
211+

it("keeps quoted context in allowlist_quote mode", () => {

212+

const ctx = buildChannelTurnContext(

213+

createBaseContextParams({

214+

supplemental: {

215+

quote: {

216+

id: "quote-1",

217+

body: "quoted",

218+

sender: "Quoted User",

219+

senderAllowed: false,

220+

isQuote: true,

221+

},

222+

thread: {

223+

starterBody: "thread starter",

224+

senderAllowed: false,

225+

},

226+

},

227+

contextVisibility: "allowlist_quote",

228+

}),

229+

);

230+
231+

expect(ctx.ReplyToBody).toBe("quoted");

232+

expect(ctx.ReplyToSender).toBe("Quoted User");

233+

expect(ctx.ThreadStarterBody).toBeUndefined();

234+

});

235+
236+

it("drops supplemental context with unknown sender allow state in restrictive modes", () => {

237+

const ctx = buildChannelTurnContext(

238+

createBaseContextParams({

239+

supplemental: {

240+

quote: {

241+

id: "quote-1",

242+

body: "quoted",

243+

sender: "Quoted User",

244+

isQuote: true,

245+

},

246+

forwarded: {

247+

from: "Forwarded User",

248+

fromId: "f1",

249+

},

250+

thread: {

251+

starterBody: "thread starter",

252+

historyBody: "thread history",

253+

},

254+

},

255+

contextVisibility: "allowlist_quote",

256+

}),

257+

);

258+
259+

expect(ctx.ReplyToBody).toBeUndefined();

260+

expect(ctx.ReplyToSender).toBeUndefined();

261+

expect(ctx.ForwardedFrom).toBeUndefined();

262+

expect(ctx.ThreadStarterBody).toBeUndefined();

263+

expect(ctx.ThreadHistoryBody).toBeUndefined();

264+

});

142265

});