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

推荐订阅源

G
Google Developers Blog
D
Docker
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
H
Help Net Security
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
L
LangChain Blog
MongoDB | Blog
MongoDB | Blog
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
博客园 - 司徒正美
C
Check Point Blog
B
Blog
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
F
Fortinet All Blogs
美团技术团队
D
DataBreaches.Net

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
perf: cache validated session prompt blobs · openclaw/ope...
steipete · 2026-05-31 · via Recent Commits to openclaw:main

@@ -10,6 +10,7 @@ const PROMPT_BLOB_VERSION: SessionSkillPromptRef["version"] = 1;

1010

const MIN_PROMPT_BLOB_CHARS = 512;

1111

const MAX_PROMPT_BLOB_BYTES = 512 * 1024;

1212

const PROMPT_REF_CACHE_MAX_ENTRIES = 256;

13+

const VALID_PROMPT_BLOB_CACHE_MAX_ENTRIES = 256;

13141415

type PersistedSessionStore = {

1516

store: Record<string, SessionEntry>;

@@ -27,13 +28,15 @@ export type SessionStorePersistenceProjection = PersistedSessionStore & {

2728

};

28292930

const promptRefCache = new Map<string, SessionSkillPromptRef>();

31+

const validPromptBlobCache = new Map<string, { mtimeMs: number; size: number; prompt: string }>();

30323133

function hashPrompt(prompt: string): string {

3234

return crypto.createHash(PROMPT_BLOB_ALGORITHM).update(prompt).digest("hex");

3335

}

34363537

export function clearSessionSkillPromptRefCache(): void {

3638

promptRefCache.clear();

39+

validPromptBlobCache.clear();

3740

}

38413942

export function getSessionSkillPromptRefCacheStatsForTest(): {

@@ -46,6 +49,16 @@ export function getSessionSkillPromptRefCacheStatsForTest(): {

4649

};

4750

}

485152+

export function getValidSessionSkillPromptBlobCacheStatsForTest(): {

53+

entries: number;

54+

maxEntries: number;

55+

} {

56+

return {

57+

entries: validPromptBlobCache.size,

58+

maxEntries: VALID_PROMPT_BLOB_CACHE_MAX_ENTRIES,

59+

};

60+

}

61+4962

function isSha256Hex(value: string): boolean {

5063

return /^[a-f0-9]{64}$/u.test(value);

5164

}

@@ -90,6 +103,17 @@ function shouldStorePromptAsBlob(prompt: string): boolean {

90103

return prompt.length >= MIN_PROMPT_BLOB_CHARS && bytes <= MAX_PROMPT_BLOB_BYTES;

91104

}

92105106+

function rememberValidPromptBlob(blobPath: string, stat: fs.Stats, prompt: string): void {

107+

validPromptBlobCache.set(blobPath, { mtimeMs: stat.mtimeMs, size: stat.size, prompt });

108+

while (validPromptBlobCache.size > VALID_PROMPT_BLOB_CACHE_MAX_ENTRIES) {

109+

const oldest = validPromptBlobCache.keys().next().value;

110+

if (typeof oldest !== "string") {

111+

break;

112+

}

113+

validPromptBlobCache.delete(oldest);

114+

}

115+

}

116+93117

function readValidPromptBlob(storePath: string, ref: SessionSkillPromptRef): string | null {

94118

if (

95119

ref.version !== PROMPT_BLOB_VERSION ||

@@ -109,13 +133,22 @@ function readValidPromptBlob(storePath: string, ref: SessionSkillPromptRef): str

109133

try {

110134

const stat = fs.statSync(blobPath);

111135

if (!stat.isFile() || stat.size !== ref.bytes) {

136+

validPromptBlobCache.delete(blobPath);

112137

return null;

113138

}

139+

const cached = validPromptBlobCache.get(blobPath);

140+

if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {

141+

return cached.prompt;

142+

}

114143

const prompt = fs.readFileSync(blobPath, "utf8");

115-

return hashPrompt(prompt) === ref.hash && Buffer.byteLength(prompt, "utf8") === ref.bytes

116-

? prompt

117-

: null;

144+

if (hashPrompt(prompt) !== ref.hash || Buffer.byteLength(prompt, "utf8") !== ref.bytes) {

145+

validPromptBlobCache.delete(blobPath);

146+

return null;

147+

}

148+

rememberValidPromptBlob(blobPath, stat, prompt);

149+

return prompt;

118150

} catch {

151+

validPromptBlobCache.delete(blobPath);

119152

return null;

120153

}

121154

}

@@ -140,6 +173,7 @@ async function ensurePromptBlob(storePath: string, prompt: string): Promise<Sess

140173

// sessions.json is replaced. Refresh its mtime so orphan cleanup does not

141174

// reclaim the blob while the store write is still in flight.

142175

await fs.promises.utimes(blobPath, now, now);

176+

rememberValidPromptBlob(blobPath, await fs.promises.stat(blobPath), prompt);

143177

return ref;

144178

} catch {

145179

// A concurrent cleanup may have removed it; rewrite below.

@@ -151,6 +185,7 @@ async function ensurePromptBlob(storePath: string, prompt: string): Promise<Sess

151185

mode: 0o600,

152186

tempPrefix: path.basename(blobPath),

153187

});

188+

rememberValidPromptBlob(blobPath, await fs.promises.stat(blobPath), prompt);

154189

return ref;

155190

}

156191