fix(ccw): only cache positive tool availability results

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 <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-12-14 12:16:48 +08:00
parent 7e70e4c299
commit 1c9716e460

View File

@@ -222,39 +222,27 @@ async function checkToolAvailability(tool: string): Promise<ToolAvailability> {
? { available: true, path: stdout.trim().split('\n')[0] } ? { available: true, path: stdout.trim().split('\n')[0] }
: { available: false, path: null }; : { available: false, path: null };
// Cache the result // Only cache positive results to avoid caching transient failures
toolAvailabilityCache.set(tool, { if (result.available) {
result, toolAvailabilityCache.set(tool, {
timestamp: Date.now() result,
}); timestamp: Date.now()
});
}
resolve(result); resolve(result);
}); });
child.on('error', () => { child.on('error', () => {
const result: ToolAvailability = { available: false, path: null }; // Don't cache errors - they may be transient
resolve({ available: false, path: null });
// Cache negative results too
toolAvailabilityCache.set(tool, {
result,
timestamp: Date.now()
});
resolve(result);
}); });
// Timeout after 5 seconds // Timeout after 5 seconds
setTimeout(() => { setTimeout(() => {
child.kill(); child.kill();
const result: ToolAvailability = { available: false, path: null }; // Don't cache timeouts - they may be transient
resolve({ available: false, path: null });
// Cache timeout results
toolAvailabilityCache.set(tool, {
result,
timestamp: Date.now()
});
resolve(result);
}, 5000); }, 5000);
}); });
} }