fix(agents): guard prompt cache tool names · openclaw/openclaw@b16a435
vincentkoc
·
2026-06-08
·
via Recent Commits to openclaw:main
File tree
src/agents/embedded-agent-runner
| Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,18 @@ describe("prompt cache observability", () => {
|
18 | 18 | ).toEqual(["read", "write"]); |
19 | 19 | }); |
20 | 20 | |
| 21 | +it("collects prompt-cache tool names without aborting on unreadable descriptors", () => { |
| 22 | +const unreadableTool = { |
| 23 | +get name(): string { |
| 24 | +throw new Error("tool name getter exploded"); |
| 25 | +}, |
| 26 | +}; |
| 27 | + |
| 28 | +expect( |
| 29 | +collectPromptCacheToolNames([{ name: " read " }, unreadableTool, { name: "write" }]), |
| 30 | +).toEqual(["read", "write"]); |
| 31 | +}); |
| 32 | + |
21 | 33 | it("tracks cache-relevant changes and reports a real cache-read drop", () => { |
22 | 34 | // Observability only emits when a material cache-read drop follows a tracked |
23 | 35 | // cache-affecting change. |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -140,8 +140,19 @@ function diffSnapshots(
|
140 | 140 | return changes.length > 0 ? changes : null; |
141 | 141 | } |
142 | 142 | |
143 | | -export function collectPromptCacheToolNames(tools: Array<{ name?: string }>): string[] { |
144 | | -return tools.map((tool) => tool.name?.trim()).filter((name): name is string => Boolean(name)); |
| 143 | +export function collectPromptCacheToolNames(tools: readonly { name?: string }[]): string[] { |
| 144 | +const names: string[] = []; |
| 145 | +for (const tool of tools) { |
| 146 | +try { |
| 147 | +const name = tool.name?.trim(); |
| 148 | +if (name) { |
| 149 | +names.push(name); |
| 150 | +} |
| 151 | +} catch { |
| 152 | +continue; |
| 153 | +} |
| 154 | +} |
| 155 | +return names; |
145 | 156 | } |
146 | 157 | |
147 | 158 | export function beginPromptCacheObservation(params: { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。