Skip to content

Commit a41ff81

Browse files
committed
Clear tool caches on compaction and add stale entry warning
- Clear toolParameters and prune.toolIds when compaction is detected - Add warning log when tool is in cache but not in toolIdList - Stale tool data from pre-compaction no longer lingers in state
1 parent 55475b4 commit a41ff81

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/messages/prune.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const buildPrunableToolsList = (
2727
return
2828
}
2929
const numericId = toolIdList.indexOf(toolCallId)
30+
if (numericId === -1) {
31+
logger.warn(`Tool in cache but not in toolIdList - possible stale entry`, { toolCallId, tool: toolParameterEntry.tool })
32+
return
33+
}
3034
const paramKey = extractParameterKey(toolParameterEntry.tool, toolParameterEntry.parameters)
3135
const description = paramKey ? `${toolParameterEntry.tool}, ${paramKey}` : toolParameterEntry.tool
3236
lines.push(`${numericId}: ${description}`)

lib/state/state.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export const checkSession = async (
3131
const lastCompactionTimestamp = findLastCompactionTimestamp(messages)
3232
if (lastCompactionTimestamp > state.lastCompaction) {
3333
state.lastCompaction = lastCompactionTimestamp
34-
logger.info("Detected compaction from messages", { timestamp: lastCompactionTimestamp })
34+
// Clear stale tool data - these tools no longer exist in context
35+
state.toolParameters.clear()
36+
state.prune.toolIds = []
37+
logger.info("Detected compaction from messages - cleared tool cache", { timestamp: lastCompactionTimestamp })
3538
}
3639
}
3740

0 commit comments

Comments
 (0)