From a809bddd462dedc65e32bb08370f218195d91aec Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 04:38:58 -0500 Subject: [PATCH] refactor: improve error handling in idle state fuel check to prevent infinite loop --- server/states/IdleState.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/states/IdleState.js b/server/states/IdleState.js index 50c32a0..890b7f6 100644 --- a/server/states/IdleState.js +++ b/server/states/IdleState.js @@ -14,8 +14,17 @@ export class IdleState extends BaseState { async *act() { // Periodic fuel check while idle (no scanning — avoids rotating turtle) + // Errors are caught here so they don't bubble up and trigger + // the _runStateLoop retry mechanism (which would create an + // infinite idle→timeout→idle loop). while (!this.cancelled) { - await this.checkFuel(); + try { + await this.checkFuel(); + } catch (e) { + // Fuel check failed (likely command timeout) — not critical in idle + // Just wait longer before trying again + await this._sleep(30000); + } yield; await this._sleep(10000); }