From 1c9716e4609df1932236e8d2cbcf814e5cae1caf Mon Sep 17 00:00:00 2001 From: catlog22 Date: Sun, 14 Dec 2025 12:16:48 +0800 Subject: [PATCH] fix(ccw): only cache positive tool availability results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes CLI tool detection failure after server restart. The previous caching implementation cached negative results (errors, timeouts) which caused persistent failures if the first check failed for any transient reason (environment, timing, etc.). Changes: - Only cache positive tool availability results - Don't cache errors or timeouts - they may be transient - Subsequent checks will retry if a tool wasn't found This ensures that once a tool is found, lookups are fast, but transient failures don't persist in the cache. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- ccw/src/tools/cli-executor.ts | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/ccw/src/tools/cli-executor.ts b/ccw/src/tools/cli-executor.ts index cbaf1136..70cd75db 100644 --- a/ccw/src/tools/cli-executor.ts +++ b/ccw/src/tools/cli-executor.ts @@ -222,39 +222,27 @@ async function checkToolAvailability(tool: string): Promise { ? { available: true, path: stdout.trim().split('\n')[0] } : { available: false, path: null }; - // Cache the result - toolAvailabilityCache.set(tool, { - result, - timestamp: Date.now() - }); + // Only cache positive results to avoid caching transient failures + if (result.available) { + toolAvailabilityCache.set(tool, { + result, + timestamp: Date.now() + }); + } resolve(result); }); child.on('error', () => { - const result: ToolAvailability = { available: false, path: null }; - - // Cache negative results too - toolAvailabilityCache.set(tool, { - result, - timestamp: Date.now() - }); - - resolve(result); + // Don't cache errors - they may be transient + resolve({ available: false, path: null }); }); // Timeout after 5 seconds setTimeout(() => { child.kill(); - const result: ToolAvailability = { available: false, path: null }; - - // Cache timeout results - toolAvailabilityCache.set(tool, { - result, - timestamp: Date.now() - }); - - resolve(result); + // Don't cache timeouts - they may be transient + resolve({ available: false, path: null }); }, 5000); }); }