fix: improve stuck detection to track failed tool calls

- Track failed tool calls in call history (parse errors, execution errors)
- Increment turns counter for failed tool calls too
- Stuck detection now works even when tools fail repeatedly
- Inspired by Ruflo and Hermes Agent best practices

Fixes the bug where zCode would get stuck in infinite loops when tool calls fail.

Test results:  All stuck detection tests passing
This commit is contained in:
Kilo
2026-05-07 10:19:53 +00:00
Unverified
parent 8482cf72f9
commit 2bbe9f2b86
3 changed files with 138 additions and 1 deletions

47
test-intent-restart.cjs Normal file
View File

@@ -0,0 +1,47 @@
const intentDetector = require('./src/bot/intent-detector.js');
// Test cases from the original failing scenarios
const testCases = [
{ text: 'Hey', expected: 'greeting' },
{ text: 'Thanks', expected: 'greeting' },
{ text: 'Continue', expected: 'greeting' },
{ text: 'Done', expected: 'greeting' },
{ text: 'I asked you a question about your earlier task you ignore me…', expected: 'question' },
{ text: 'You didn\'t answer my question earlier', expected: 'question' },
{ text: 'What about the landing page design?', expected: 'question' },
{ text: 'How is it going?', expected: 'greeting' },
{ text: 'Status', expected: 'status' },
{ text: 'Ping', expected: 'status' },
{ text: 'Check my tasks', expected: 'status' },
];
console.log('🎯 INTENT DETECTOR TEST RESULTS\n');
console.log('─'.repeat(80));
let passed = 0;
let failed = 0;
testCases.forEach((test, index) => {
const result = intentDetector.detectIntent(test.text);
const status = result.type === test.expected ? '✅ PASS' : '❌ FAIL';
if (result.type === test.expected) {
passed++;
} else {
failed++;
}
console.log(`${status} ${index + 1}. "${test.text}"`);
console.log(` Expected: ${test.expected} → Got: ${result.type} (confidence: ${result.confidence.toFixed(2)})`);
if (result.type !== test.expected) {
console.log(` ❌ MISMATCH!`);
}
console.log('');
});
console.log('─'.repeat(80));
console.log(`\n📊 SUMMARY: ${passed}/${testCases.length} PASSED`);
console.log(` Success rate: ${(passed / testCases.length * 100).toFixed(1)}%`);
console.log(`\n${'─'.repeat(80)}\n`);
process.exit(failed > 0 ? 1 : 0);