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

推荐订阅源

宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
Jina AI
Jina AI
博客园 - 叶小钗
雷峰网
雷峰网
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
量子位

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
improve: reduce hot-path linear scans and redundant I/O (...
vincentkoc · 2026-06-23 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -19,6 +19,7 @@ import {

1919

import {

2020

applyShortTermPromotions,

2121

auditShortTermPromotionArtifacts,

22+

filterLiveShortTermRecallEntries,

2223

isShortTermMemoryPath,

2324

loadShortTermPromotionDreamingStats,

2425

recordGroundedShortTermCandidates,

@@ -171,6 +172,42 @@ describe("short-term promotion", () => {

171172

});

172173

});

173174
175+

it("deduplicates source-file checks within a recall batch", async () => {

176+

await withTempWorkspace(async (workspaceDir) => {

177+

const notePath = await writeDailyMemoryNote(workspaceDir, "2026-04-03", [

178+

"Deduplicated source check note.",

179+

]);

180+

const relativePath = path.relative(workspaceDir, notePath).replaceAll("\\", "/");

181+

const entry = {

182+

key: "duplicate-source",

183+

path: relativePath,

184+

startLine: 1,

185+

endLine: 1,

186+

source: "memory" as const,

187+

snippet: "Deduplicated source check note.",

188+

recallCount: 1,

189+

dailyCount: 1,

190+

groundedCount: 0,

191+

totalScore: 0.9,

192+

maxScore: 0.9,

193+

firstRecalledAt: "2026-04-03T00:00:00.000Z",

194+

lastRecalledAt: "2026-04-03T00:00:00.000Z",

195+

queryHashes: ["query"],

196+

recallDays: ["2026-04-03"],

197+

conceptTags: [],

198+

};

199+

const statSpy = vi.spyOn(fs, "stat");

200+
201+

const live = await filterLiveShortTermRecallEntries({

202+

workspaceDir,

203+

entries: [entry, { ...entry, key: "duplicate-source-2" }],

204+

});

205+
206+

expect(live).toHaveLength(2);

207+

expect(statSpy).toHaveBeenCalledTimes(1);

208+

});

209+

});

210+
174211

it("falls back when the injected recall timestamp is outside Date range", async () => {

175212

vi.spyOn(Date, "now").mockReturnValue(Date.UTC(2026, 4, 30, 12, 0, 0));

176213

await withTempWorkspace(async (workspaceDir) => {

Original file line numberDiff line numberDiff line change

@@ -1302,39 +1302,47 @@ export async function loadShortTermPromotionDreamingStats(params: {

13021302

};

13031303

}

13041304
1305-

async function shortTermRecallSourceExists(params: {

1306-

workspaceDir: string;

1307-

entry: Pick<ShortTermRecallEntry, "path">;

1308-

}): Promise<boolean> {

1309-

const workspaceDir = params.workspaceDir.trim();

1310-

if (!workspaceDir) {

1311-

return false;

1312-

}

1313-

for (const sourcePath of resolveShortTermSourcePathCandidates(workspaceDir, params.entry.path)) {

1314-

try {

1315-

const stat = await fs.stat(sourcePath);

1316-

if (stat.isFile()) {

1317-

return true;

1318-

}

1319-

} catch (err) {

1320-

if ((err as NodeJS.ErrnoException).code === "ENOENT") {

1321-

continue;

1322-

}

1323-

throw err;

1305+

async function shortTermRecallSourceIsFile(sourcePath: string): Promise<boolean> {

1306+

try {

1307+

const stat = await fs.stat(sourcePath);

1308+

return stat.isFile();

1309+

} catch (err) {

1310+

if ((err as NodeJS.ErrnoException).code === "ENOENT") {

1311+

return false;

13241312

}

1313+

throw err;

13251314

}

1326-

return false;

13271315

}

13281316
13291317

export async function filterLiveShortTermRecallEntries(params: {

13301318

workspaceDir: string;

13311319

entries: ShortTermRecallEntry[];

13321320

}): Promise<ShortTermRecallEntry[]> {

1321+

const workspaceDir = params.workspaceDir.trim();

1322+

if (!workspaceDir) {

1323+

return [];

1324+

}

1325+

const sourceFileChecks = new Map<string, Promise<boolean>>();

1326+

const checkSourceFile = (sourcePath: string): Promise<boolean> => {

1327+

const existing = sourceFileChecks.get(sourcePath);

1328+

if (existing) {

1329+

return existing;

1330+

}

1331+

const check = shortTermRecallSourceIsFile(sourcePath);

1332+

sourceFileChecks.set(sourcePath, check);

1333+

return check;

1334+

};

13331335

const results = await Promise.all(

1334-

params.entries.map(async (entry) => ({

1335-

entry,

1336-

exists: await shortTermRecallSourceExists({ workspaceDir: params.workspaceDir, entry }),

1337-

})),

1336+

params.entries.map(async (entry) => {

1337+

let exists = false;

1338+

for (const sourcePath of resolveShortTermSourcePathCandidates(workspaceDir, entry.path)) {

1339+

if (await checkSourceFile(sourcePath)) {

1340+

exists = true;

1341+

break;

1342+

}

1343+

}

1344+

return { entry, exists };

1345+

}),

13381346

);

13391347

return results.filter((result) => result.exists).map((result) => result.entry);

13401348

}

Original file line numberDiff line numberDiff line change

@@ -107,6 +107,19 @@ describe("renderMarkdownIRChunksWithinLimit", () => {

107107

expect(chunks.map((chunk) => chunk.source.text)).toEqual(["A", "😀"]);

108108

});

109109
110+

it("keeps split order while processing the worklist as a stack", () => {

111+

const text = "abcdefghijklmnopqrstuvwx";

112+

const chunks = renderMarkdownIRChunksWithinLimit({

113+

ir: markdownToIR(text),

114+

limit: 5,

115+

renderChunk: (chunk) => chunk.text,

116+

measureRendered: (rendered) => rendered.length,

117+

});

118+
119+

expect(chunks.map((chunk) => chunk.source.text).join("")).toBe(text);

120+

expect(chunks.every((chunk) => chunk.rendered.length <= 5)).toBe(true);

121+

});

122+
110123

it("treats Infinity as no size cap and returns a single chunk", () => {

111124

const text = "one two three four five six seven eight nine ten";

112125

const ir = markdownToIR(text);

Original file line numberDiff line numberDiff line change

@@ -56,11 +56,14 @@ export function renderMarkdownIRChunksWithinLimit<TRendered>(

5656

}

5757
5858

const normalizedLimit = resolveIntegerOption(options.limit, 1, { min: 1 });

59-

const pending = chunkMarkdownIR(options.ir, normalizedLimit);

59+

// Treat the pending worklist as a stack so each dequeue/enqueue stays O(1).

60+

// The initial reverse keeps the final order stable while avoiding shift/unshift

61+

// moving every remaining chunk for long messages.

62+

const pending = chunkMarkdownIR(options.ir, normalizedLimit).toReversed();

6063

const finalized: MarkdownIR[] = [];

6164
6265

while (pending.length > 0) {

63-

const chunk = pending.shift();

66+

const chunk = pending.pop();

6467

if (!chunk) {

6568

continue;

6669

}

@@ -77,7 +80,12 @@ export function renderMarkdownIRChunksWithinLimit<TRendered>(

7780

finalized.push(chunk);

7881

continue;

7982

}

80-

pending.unshift(...split);

83+

for (let index = split.length - 1; index >= 0; index -= 1) {

84+

const next = split[index];

85+

if (next) {

86+

pending.push(next);

87+

}

88+

}

8189

}

8290
8391

return coalesceWhitespaceOnlyMarkdownIRChunks(finalized, normalizedLimit, options).map(

Original file line numberDiff line numberDiff line change

@@ -2854,6 +2854,7 @@ async function processOpenAICompletionsStream(

28542854

const toolCallBlocksByIndex = new Map<number, ToolCallBlock>();

28552855

const toolCallBlocksById = new Map<string, ToolCallBlock>();

28562856

const toolCallBlockBytes = new WeakMap<ToolCallBlock, number>();

2857+

const toolCallBlockIndices = new WeakMap<ToolCallBlock, number>();

28572858

let sawStopFinishReason = false;

28582859

const blockIndex = () => output.content.length - 1;

28592860

const measureUtf8Bytes = (text: string) => Buffer.byteLength(text, "utf8");

@@ -2986,14 +2987,15 @@ async function processOpenAICompletionsStream(

29862987

};

29872988

currentBlock = block;

29882989

output.content.push(block);

2990+

toolCallBlockIndices.set(block, output.content.length - 1);

29892991

pushStreamEvent({

29902992

type: "toolcall_start",

2991-

contentIndex: output.content.indexOf(block),

2993+

contentIndex: toolCallBlockIndices.get(block) ?? -1,

29922994

partial: output,

29932995

});

29942996

pushStreamEvent({

29952997

type: "toolcall_delta",

2996-

contentIndex: output.content.indexOf(block),

2998+

contentIndex: toolCallBlockIndices.get(block) ?? -1,

29972999

delta: toolCall.partialArgs,

29983000

partial: output,

29993001

});

@@ -3186,9 +3188,10 @@ async function processOpenAICompletionsStream(

31863188

...(initialSig ? { thoughtSignature: initialSig } : {}),

31873189

};

31883190

output.content.push(block);

3191+

toolCallBlockIndices.set(block, output.content.length - 1);

31893192

pushStreamEvent({

31903193

type: "toolcall_start",

3191-

contentIndex: output.content.indexOf(block),

3194+

contentIndex: toolCallBlockIndices.get(block) ?? -1,

31923195

partial: output,

31933196

});

31943197

}

@@ -3218,7 +3221,7 @@ async function processOpenAICompletionsStream(

32183221

block.arguments = parseStreamingJson(block.partialArgs);

32193222

pushStreamEvent({

32203223

type: "toolcall_delta",

3221-

contentIndex: output.content.indexOf(block),

3224+

contentIndex: toolCallBlockIndices.get(block) ?? -1,

32223225

delta: toolCall.function.arguments,

32233226

partial: output,

32243227

});

Original file line numberDiff line numberDiff line change

@@ -223,7 +223,7 @@ async function resolveTranscriptLeafIdFromTrailingControls(

223223

return { appendMode: "active" };

224224

}

225225
226-

async function readTranscriptLeafInfo(transcriptPath: string): Promise<TranscriptLeafInfo> {

226+

async function readTranscriptLeafInfoForward(transcriptPath: string): Promise<TranscriptLeafInfo> {

227227

let leafId: string | undefined;

228228

let hasParentLinkedEntries = false;

229229

let nonSessionEntryCount = 0;

@@ -266,6 +266,57 @@ async function readTranscriptLeafInfo(transcriptPath: string): Promise<Transcrip

266266

};

267267

}

268268
269+

async function readTranscriptLeafInfo(transcriptPath: string): Promise<TranscriptLeafInfo> {

270+

let latestEntryId: string | undefined;

271+

for await (const line of streamSessionTranscriptLinesReverse(transcriptPath)) {

272+

const lineInfo = readTranscriptLineInfo(line);

273+

if (!lineInfo.entryId) {

274+

continue;

275+

}

276+

if (lineInfo.invalidLeafControl) {

277+

break;

278+

}

279+

if (lineInfo.leafControl) {

280+

if (latestEntryId) {

281+

const valid = await validateTranscriptLeafControlReferences({

282+

transcriptPath,

283+

leafControlId: lineInfo.entryId,

284+

leafControl: lineInfo.leafControl,

285+

});

286+

if (!valid) {

287+

break;

288+

}

289+

return {

290+

leafId: latestEntryId,

291+

appendMode: lineInfo.leafControl.appendMode === "side" ? "side" : "active",

292+

hasParentLinkedEntries: true,

293+

nonSessionEntryCount: 0,

294+

};

295+

}

296+

const resolvedLeaf = await resolveTranscriptLeafIdFromTrailingControls(transcriptPath);

297+

return {

298+

...(resolvedLeaf.leafId ? { leafId: resolvedLeaf.leafId } : {}),

299+

appendMode: resolvedLeaf.appendMode,

300+

hasParentLinkedEntries: true,

301+

nonSessionEntryCount: 0,

302+

};

303+

}

304+

latestEntryId ??= lineInfo.entryId;

305+

if (lineInfo.isCanonicalEntry && lineInfo.hasParentLinkedEntry) {

306+

return {

307+

leafId: latestEntryId,

308+

appendMode: lineInfo.appendMode === "side" ? "side" : "active",

309+

hasParentLinkedEntries: true,

310+

nonSessionEntryCount: 0,

311+

};

312+

}

313+

// A latest entry without parent linkage may be a legacy linear transcript.

314+

// Fall back to the full scan only when migration detection needs it.

315+

break;

316+

}

317+

return await readTranscriptLeafInfoForward(transcriptPath);

318+

}

319+
269320

async function migrateLinearTranscriptToParentLinked(transcriptPath: string): Promise<{

270321

leafId?: string;

271322

}> {