refactor: prevent infinite loop in idle state handling by adding retry mechanism

This commit is contained in:
MayaTheShy
2026-02-20 04:38:54 -05:00
parent 00d31698a1
commit 5ff1f3e7f0

View File

@@ -323,7 +323,17 @@ export class Turtle extends EventEmitter {
}
} else {
console.error(`[Turtle ${this.id}] State error in ${state.name}:`, error.message);
this.setState('idle');
// Don't transition idle→idle (causes infinite loop)
if (state.name !== 'idle') {
this.setState('idle');
} else {
// Already idle and erroring — just wait and retry the idle loop
console.log(`[Turtle ${this.id}] Idle loop paused, will retry in 60s`);
await new Promise(r => setTimeout(r, 60000));
if (this._state === state) {
this._runStateLoop(0);
}
}
}
}
}