fix: improve stuck detection to detect same tool repeated

- Previous fix required EXACT same tool call signature (including arguments)
- Bot was stuck reading file in sections with different line numbers
- New logic: detect stuck if SAME TOOL is called repeatedly (arguments may vary)
- Extract tool name from signature and check if all recent calls use same tool
- Still requires 3+ repetitions before triggering intervention

This fixes the infinite loop bug when bot tries to read large files in sections.

Example:
  - Before: bash:read:1-100, bash:read:101-200, bash:read:201-300 (different signatures) → not stuck
  - After: bash:read:1-100, bash:read:101-200, bash:read:201-300 (same tool, different args) → stuck!
This commit is contained in:
Kilo
2026-05-07 10:49:34 +00:00
Unverified
parent 662cf5a8e5
commit d4edf04508
2 changed files with 1611 additions and 5 deletions

View File

@@ -514,11 +514,24 @@ export async function initBot(config, api, tools, skills, agents) {
// Hash: tool name + first 80 chars of args (enough to detect repeated patterns) // Hash: tool name + first 80 chars of args (enough to detect repeated patterns)
return `${fn.name}:${args.slice(0, 80)}`; return `${fn.name}:${args.slice(0, 80)}`;
}; };
const isStuck = () => { const isStuck = () => {
if (callHistory.length < STUCK_THRESHOLD) return false; if (callHistory.length < STUCK_THRESHOLD) return false;
const recent = callHistory.slice(-STUCK_THRESHOLD); const recent = callHistory.slice(-STUCK_THRESHOLD);
return recent.every(s => s === recent[0]);
}; // Flexible: detect stuck even if arguments vary slightly
// Extract tool name from signature (everything before first colon)
const toolNames = recent.map(s => s.split(':')[0]);
const uniqueToolNames = [...new Set(toolNames)];
// If all calls use the same tool, check if they differ by arguments
if (uniqueToolNames.length === 1) {
// Same tool, different arguments → still stuck
return true;
}
// Different tools → not stuck
return false;
};
// Context compaction: trim old tool results to keep context manageable // Context compaction: trim old tool results to keep context manageable
const compactContext = () => { const compactContext = () => {

1593
src/bot/index.js.backup Normal file

File diff suppressed because it is too large Load Diff