Skip to content

Commit ed2d32d

Browse files
committed
Add stricter validation for prune tool IDs
Reject prune requests for IDs not found in the tool cache, which catches both hallucinated IDs and turn-protected tools that aren't shown in the <prunable-tools> list.
1 parent df06fa8 commit ed2d32d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/strategies/prune-tool.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ export function createPruneTool(
8383
return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
8484
}
8585

86-
// Check for protected tools (model hallucinated an ID not in the prunable list)
86+
// Validate that all IDs exist in cache and aren't protected
87+
// (rejects hallucinated IDs and turn-protected tools not shown in <prunable-tools>)
8788
for (const index of numericToolIds) {
8889
const id = toolIdList[index]
8990
const metadata = state.toolParameters.get(id)
90-
if (metadata && config.strategies.pruneTool.protectedTools.includes(metadata.tool)) {
91+
if (!metadata) {
92+
logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id })
93+
return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
94+
}
95+
if (config.strategies.pruneTool.protectedTools.includes(metadata.tool)) {
96+
logger.debug("Rejecting prune request - protected tool", { index, id, tool: metadata.tool })
9197
return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
9298
}
9399
}

0 commit comments

Comments
 (0)