Skip to content

Commit c258918

Browse files
committed
Fix case-sensitive tool ID comparison in pruning logic
Previously, tool call IDs were compared using case-sensitive includes() checks, which could cause re-processing of already pruned tools if the same ID appeared with different casing from different providers. This change normalizes IDs to lowercase before comparison using a Set for efficient O(1) lookups instead of O(n) array includes() calls.
1 parent 8d30228 commit c258918

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/core/janitor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ async function runWithStrategies(
116116
const { toolCallIds, toolOutputs, toolMetadata } = parseMessages(messages, state.toolParameters)
117117

118118
const alreadyPrunedIds = state.prunedIds.get(sessionID) ?? []
119-
const unprunedToolCallIds = toolCallIds.filter(id => !alreadyPrunedIds.includes(id))
119+
// Normalized set for filtering to avoid re-processing already pruned tools with different casing
120+
const alreadyPrunedLower = new Set(alreadyPrunedIds.map(id => id.toLowerCase()))
121+
const unprunedToolCallIds = toolCallIds.filter(id => !alreadyPrunedLower.has(id))
120122

121123
const gcPending = state.gcPending.get(sessionID) ?? null
122124

@@ -145,7 +147,7 @@ async function runWithStrategies(
145147
)
146148
}
147149

148-
const finalNewlyPrunedIds = llmPrunedIds.filter(id => !alreadyPrunedIds.includes(id))
150+
const finalNewlyPrunedIds = llmPrunedIds.filter(id => !alreadyPrunedLower.has(id.toLowerCase()))
149151

150152
if (finalNewlyPrunedIds.length === 0 && !gcPending) {
151153
return null

0 commit comments

Comments
 (0)