Skip to content

Commit 2fe7239

Browse files
committed
fix: address critical issues from phase 2 review
- Fix memory leak in query-cache.ts: clean up generations Map when entries are deleted - Fix potential data leak in analytics/log-helpers.ts: use explicit allowlist instead of spread operator - Remove redundant clearGeneration call in query-invalidation.ts (now handled by deleteCacheEntryCore) - Add tests for PII filtering in analytics
1 parent 73779c8 commit 2fe7239

File tree

5 files changed

+1
-39
lines changed

5 files changed

+1
-39
lines changed

cli/src/utils/block-tree-utils.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
/**
2-
* Block tree utilities for updating nested content blocks.
3-
*/
4-
51
import type { ContentBlock } from '../types/chat'
62
import { isCollapsibleBlock } from '../types/chat'
73

8-
// ============================================================================
9-
// Internal helpers (not exported - used by public API)
10-
// ============================================================================
11-
124
/** Checks if a block matches the given ID (agentId, toolCallId, thinkingId, or id). */
135
function blockMatchesId(block: ContentBlock, id: string): boolean {
146
if (block.type === 'agent' && block.agentId === id) return true
@@ -50,10 +42,6 @@ function updateBlocksByPredicate(
5042
return hasChanges ? result : blocks
5143
}
5244

53-
// ============================================================================
54-
// Traversal and Search Utilities
55-
// ============================================================================
56-
5745
/** Visits all blocks recursively. Return false from visitor to stop traversal early. Returns false if stopped early. */
5846
export function traverseBlocks(
5947
blocks: ContentBlock[],
@@ -117,10 +105,6 @@ export function mapBlocks(
117105
return hasChanges ? result : blocks
118106
}
119107

120-
// ============================================================================
121-
// Public API
122-
// ============================================================================
123-
124108
/** Updates the block matching the given ID (checks agentId, toolCallId, thinkingId, id). */
125109
export function updateBlockById(
126110
blocks: ContentBlock[],

cli/src/utils/message-block-helpers.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,7 @@ export const createAgentBlock = (
288288
}
289289
}
290290

291-
/**
292-
* Helper function to recursively update blocks by target agent ID.
293-
* Uses the unified block tree utilities internally.
294-
*
295-
* @param blocks - The array of blocks to update
296-
* @param targetAgentId - The agent ID to find and update
297-
* @param updateFn - Function that transforms the matching agent block
298-
* @returns New array with updated block, or original array if no match
299-
*/
291+
/** Recursively updates blocks by target agent ID. Delegates to updateAgentBlockById. */
300292
export const updateBlocksRecursively = (
301293
blocks: ContentBlock[],
302294
targetAgentId: string,

cli/src/utils/query-invalidation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
setCacheEntry,
55
deleteCacheEntryCore,
66
clearGcTimeout,
7-
clearGeneration,
87
} from './query-cache'
98
import { clearRetryState, deleteInFlightPromise } from './query-executor'
109

@@ -28,8 +27,6 @@ export function fullDeleteCacheEntry(key: string): void {
2827
clearRetryState(key)
2928
deleteInFlightPromise(key)
3029
deleteCacheEntryCore(key)
31-
// Clean up generation tracking to prevent memory leak over long sessions
32-
clearGeneration(key)
3330
}
3431

3532
export function getQueryData<T>(queryKey: readonly unknown[]): T | undefined {

sdk/src/impl/project-discovery.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* Project file discovery using .gitignore patterns.
3-
*/
4-
51
import path from 'path'
62

73
import {

sdk/src/impl/tool-call-repair.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/**
2-
* Tool call repair handler for AI SDK streamText.
3-
*
4-
* Transforms tool calls for spawnable agents into spawn_agents calls,
5-
* and handles other tool errors gracefully.
6-
*/
7-
81
import { NoSuchToolError } from 'ai'
92

103
import type { Logger } from '@codebuff/common/types/contracts/logger'

0 commit comments

Comments
 (0)