refactor: improve error handling and retry logic in exploration state for enhanced stability

This commit is contained in:
MayaTheShy
2026-02-20 03:54:15 -05:00
parent 7385c258d5
commit 8fcd3f44c7

View File

@@ -26,6 +26,7 @@ export class ExploringState extends BaseState {
console.log(`[${this.turtle.id}] Starting exploration`); console.log(`[${this.turtle.id}] Starting exploration`);
while (!this.cancelled) { while (!this.cancelled) {
try {
// Safety checks // Safety checks
const fuel = await this.checkFuel(); const fuel = await this.checkFuel();
if (fuel !== 'unlimited' && fuel < this.minFuel) { if (fuel !== 'unlimited' && fuel < this.minFuel) {
@@ -67,6 +68,18 @@ export class ExploringState extends BaseState {
// Exploration movement // Exploration movement
yield* this._exploreStep(); yield* this._exploreStep();
} catch (error) {
const isTimeout = error.message?.includes('timed out');
if (isTimeout) {
console.warn(`[${this.turtle.id}] Exploration exec timeout, will retry next iteration`);
// Wait longer before retrying after a timeout
await this._sleep(3000);
} else {
// Non-timeout errors still propagate
throw error;
}
}
yield; yield;
await this._sleep(300); await this._sleep(300);
} }